Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a chain agnostic Head interface in the core Transaction Manager #8674

Merged
merged 66 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
53a01fd
Initial changes
prashantkumar1982 Feb 27, 2023
4422700
Resolving merge conflicts
prashantkumar1982 Feb 27, 2023
8cb32ca
midpoint
prashantkumar1982 Mar 1, 2023
248a535
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 1, 2023
6b4bcc5
Initial changes with generic HeadView interface
prashantkumar1982 Mar 1, 2023
f4a1437
test fixes
prashantkumar1982 Mar 1, 2023
97aadd4
Merge issues
prashantkumar1982 Mar 2, 2023
08715d7
test fixes
prashantkumar1982 Mar 2, 2023
7c95323
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 2, 2023
ba27396
docker changes testing
prashantkumar1982 Mar 2, 2023
89c5571
mocks
prashantkumar1982 Mar 2, 2023
cf8bbfe
mocks fix
prashantkumar1982 Mar 2, 2023
8166f75
test fixes
prashantkumar1982 Mar 2, 2023
d03175f
Merge
prashantkumar1982 Mar 8, 2023
bdc3f1a
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 8, 2023
1e3573c
merging
prashantkumar1982 Mar 8, 2023
23d0be7
Merge conflicts and Generic types
prashantkumar1982 Mar 8, 2023
13928c6
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 8, 2023
58796ad
Small fixes
prashantkumar1982 Mar 8, 2023
eae70df
Small fixes
prashantkumar1982 Mar 8, 2023
bea18e1
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 8, 2023
8471df7
Build fixes
prashantkumar1982 Mar 9, 2023
15df148
build fixes
prashantkumar1982 Mar 9, 2023
510ceef
mocks
prashantkumar1982 Mar 9, 2023
b10e528
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 9, 2023
a6d24dc
Import fixes
prashantkumar1982 Mar 9, 2023
d15caa9
Fixes
prashantkumar1982 Mar 9, 2023
7db5b1d
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 9, 2023
6249aae
Test fixes
prashantkumar1982 Mar 9, 2023
cd72f52
test fixes
prashantkumar1982 Mar 9, 2023
d9ad2d1
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 9, 2023
a949f0a
refactoring
prashantkumar1982 Mar 9, 2023
ea12d46
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 9, 2023
1d43f66
test fixes
prashantkumar1982 Mar 9, 2023
0db994d
Lint fixes
prashantkumar1982 Mar 9, 2023
b49420e
cleanups
prashantkumar1982 Mar 9, 2023
1390b5e
Response to comments
prashantkumar1982 Mar 10, 2023
3f3e4dd
nits
prashantkumar1982 Mar 10, 2023
f71fb29
Generic Head for TxMgr
prashantkumar1982 Mar 10, 2023
88f9231
fixes
prashantkumar1982 Mar 10, 2023
c4cc209
build fixes
prashantkumar1982 Mar 10, 2023
99fa1ba
test fixes
prashantkumar1982 Mar 10, 2023
f5128e3
test fixes
prashantkumar1982 Mar 10, 2023
db75340
test refactors
prashantkumar1982 Mar 10, 2023
6fa173d
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 10, 2023
e4a8425
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 13, 2023
ba9636a
Response to comments
prashantkumar1982 Mar 13, 2023
2c65e30
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 13, 2023
141a81b
A failed try at using generics for the Head type
prashantkumar1982 Mar 15, 2023
08319ac
Switch to using generics
prashantkumar1982 Mar 16, 2023
52593c2
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 16, 2023
26fc924
mocks regenerate
prashantkumar1982 Mar 16, 2023
efd4350
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 16, 2023
b4899a2
minor nits
prashantkumar1982 Mar 16, 2023
58faa21
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 16, 2023
c30d8cb
nit fixes
prashantkumar1982 Mar 16, 2023
f1d2594
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 16, 2023
4c64f50
Head interface method signature change
prashantkumar1982 Mar 16, 2023
2bc5c38
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 17, 2023
2206d7c
simplify types (#8744)
jmank88 Mar 17, 2023
0a4c636
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 17, 2023
654d844
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 17, 2023
b441836
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
prashantkumar1982 Mar 17, 2023
f6f7f31
Fix mocks and tests
prashantkumar1982 Mar 17, 2023
cc207bc
remove mockery line
prashantkumar1982 Mar 17, 2023
1ae15c6
Update mocks with new mockery version
prashantkumar1982 Mar 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/txmgr/types/fee_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type PriorAttempt[FEE any, HASH any] interface {
// FeeEstimator provides a generic interface for fee estimation
//
//go:generate mockery --quiet --name FeeEstimator --output ./mocks/ --case=underscore
type FeeEstimator[HEAD any, FEE any, MAXPRICE any, HASH any] interface {
OnNewLongestChain(context.Context, HEAD)
type FeeEstimator[H Head, FEE any, MAXPRICE any, HASH any] interface {
HeadTrackable[H]
Start(context.Context) error
Close() error

Expand Down
28 changes: 28 additions & 0 deletions common/txmgr/types/head.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package types

import "github.com/ethereum/go-ethereum/common"

// Head provides access to a chain's head, as needed by the TxManager.
// This is a generic interface which ALL chains will implement.
//
//go:generate mockery --quiet --name Head --output ./mocks/ --case=underscore
type Head interface {
// BlockNumber is the head's block number
BlockNumber() int64
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is int64 large enough for all chains?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't answer that right now. For EVM, it seems large enough, as it is already hard-coded in our codebase. Thus I didn't change it.

For future families, if they require uint256, we will have to convert it to that, or change this to a big.Int kind of interface.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably good enough for now - max int64 (assuming the block generation rate of solana 0.4s/block) would last 116e9 years


// ChainLength returns the length of the chain followed by recursively looking up parents
ChainLength() uint32

// EarliestInChain traverses through parents until it finds the earliest one
EarliestInChain() Head

// Hash is the head's block hash
BlockHash() common.Hash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that Head doesn't use generic, how do we specify different hash types for different chains

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I didn't touch the Hash yet in this PR.

The current Hash native type(common.Hash) is actually used by Txmgr. So have to see if we can do with a generic, or a common Hash interface.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are other chains just different length arrays? Could we use a byte slice in that case?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be an interface with some methods implemented? e.g. Scan, Value, Cmp, Equal etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I prefer an interface which allows serializing/deserializing, comparing, stringifying etc.

But I don't want to bring that in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not do this change in the PR? seems easier to put everything together and finalize the interface

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the to and fro we take, for finalizing the approach. Whether to implement Hash as an interface, or byte[], or generic. I want to keep changes isolated more.


// Parent is the head's parent block
GetParent() Head

// HashAtHeight returns the hash of the block at the given height, if it is in the chain.
// If not in chain, returns the zero hash
HashAtHeight(blockNum int64) common.Hash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in a follow-up PR

}
12 changes: 12 additions & 0 deletions common/txmgr/types/head_trackable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package types

import "context"

// HeadTrackable is implemented by the core txm,
// to be able to receive head events from any chain.
// Chain implementations should notify head events to the core txm via this interface.
//
//go:generate mockery --quiet --name HeadTrackable --output ./mocks/ --case=underscore
type HeadTrackable[H Head] interface {
OnNewLongestChain(ctx context.Context, head H)
}
20 changes: 10 additions & 10 deletions common/txmgr/types/mocks/fee_estimator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions core/chains/evm/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type chain struct {
id *big.Int
cfg evmconfig.ChainScopedConfig
client evmclient.Client
txm txmgr.TxManager
txm *evmTxm
logger logger.Logger
headBroadcaster httypes.HeadBroadcaster
headTracker httypes.HeadTracker
Expand Down Expand Up @@ -115,15 +115,7 @@ func newChain(ctx context.Context, cfg evmconfig.ChainScopedConfig, nodes []*v2.
}
}

var txm txmgr.TxManager
if !cfg.EVMRPCEnabled() {
txm = &txmgr.NullTxManager{ErrMsg: fmt.Sprintf("Ethereum is disabled for chain %d", chainID)}
} else if opts.GenTxManager == nil {
checker := &txmgr.CheckerFactory{Client: client}
txm = txmgr.NewTxm(db, client, cfg, opts.KeyStore, opts.EventBroadcaster, l, checker, logPoller)
} else {
txm = opts.GenTxManager(chainID)
}
txm := newEvmTxm(db, cfg, client, l, logPoller, opts)

headBroadcaster.Subscribe(txm)

Expand Down Expand Up @@ -213,7 +205,7 @@ func (c *chain) Close() error {
merr = multierr.Combine(merr, c.headTracker.Close())
c.logger.Debug("Chain: stopping headBroadcaster")
merr = multierr.Combine(merr, c.headBroadcaster.Close())
c.logger.Debug("Chain: stopping txm")
c.logger.Debug("Chain: stopping evmTxm")
merr = multierr.Combine(merr, c.txm.Close())
c.logger.Debug("Chain: stopping client")
c.client.Close()
Expand Down Expand Up @@ -262,7 +254,7 @@ func (c *chain) Config() evmconfig.ChainScopedConfig { return c.cfg }
func (c *chain) LogBroadcaster() log.Broadcaster { return c.logBroadcaster }
func (c *chain) LogPoller() logpoller.LogPoller { return c.logPoller }
func (c *chain) HeadBroadcaster() httypes.HeadBroadcaster { return c.headBroadcaster }
func (c *chain) TxManager() txmgr.TxManager { return c.txm }
func (c *chain) TxManager() txmgr.TxManager { return c.txm.TxManager }
func (c *chain) HeadTracker() httypes.HeadTracker { return c.headTracker }
func (c *chain) Logger() logger.Logger { return c.logger }
func (c *chain) BalanceMonitor() monitor.BalanceMonitor { return c.balanceMonitor }
Expand Down
49 changes: 49 additions & 0 deletions core/chains/evm/evm_txm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package evm

import (
"context"
"fmt"

"github.com/smartcontractkit/sqlx"

evmclient "github.com/smartcontractkit/chainlink/core/chains/evm/client"
evmconfig "github.com/smartcontractkit/chainlink/core/chains/evm/config"
httypes "github.com/smartcontractkit/chainlink/core/chains/evm/headtracker/types"
"github.com/smartcontractkit/chainlink/core/chains/evm/logpoller"
"github.com/smartcontractkit/chainlink/core/chains/evm/txmgr"
evmtypes "github.com/smartcontractkit/chainlink/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/core/logger"
)

var _ httypes.HeadTrackable = &evmTxm{}

// evmTxm is an evm wrapper over the generic TxManager interface
type evmTxm struct {
httypes.HeadTrackable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this redundant? TxManager already requires txmgrtypes.HeadTrackable[*evmtypes.Head]

Copy link
Contributor

@jmank88 jmank88 Mar 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the whole evmTxm type is actually not neccesssary: #8744

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot Jordan!

txmgr.TxManager
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be able to use the TxManager struct embedded/anonymous.

type evmTxm struct {
	httypes.HeadTrackable
	txmgr.TxManager
}

Copy link
Contributor

@augustbleeds augustbleeds Mar 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simsonraj I think the above doesn't work because you can't do this

func (e evmTxm) OnNewLongestChain(ctx context.Context, head *evmtypes.Head) {
	e.txmgr.TxManager.OnNewLongestChain(ctx, head)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you cannot initialize evmTxm without creating the type alias GenericTxManager.
See my comments on lines 18-21 for why.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, i think you can directly call on the TxManager. unless I'm missing something?

type evmTxm struct {
	httypes.HeadTrackable
	txmgr.TxManager
}

func (e evmTxm) OnNewLongestChain(ctx context.Context, head *evmtypes.Head) {
	e.TxManager.OnNewLongestChain(ctx, head)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that part is fine. It actually complains on line 53.
This works: return &evmTxm{GenericTxManager: txm}
This fails: return &evmTxm{txmgr.TxManager: txm}

For more discussion on this topic, see this: https://chainlink-core.slack.com/archives/C03Q4FAGZFC/p1678327210251719

At first, I did what you are suggesting. When it kept failing, I sent this slack thread, and Jordan replied how to make it work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh thanks for the context, ill check it out

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way of fixing without the type alias, but what you have here is good too 👍 , thanks I learned something new :)
https://gotipplay.golang.org/p/csPUU1k1XC1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failing case is trying to use the package in the field name. Won't it work with just the type?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are the comments on lines 18 thru 21?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samsondav , He changed it, it looks good now!


func (e evmTxm) OnNewLongestChain(ctx context.Context, head *evmtypes.Head) {
e.TxManager.OnNewLongestChain(ctx, head)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why this is necessary but I believe you that it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. I don't know why it doesn't work without this, but if I remove this function, I see these errors:

FAIL github.com/smartcontractkit/chainlink/core/chains/evm [build failed]

github.com/smartcontractkit/chainlink/core/chains/evm [github.com/smartcontractkit/chainlink/core/chains/evm/client.test]

./evm_txm.go:16:31: cannot use &evmTxm{} (value of type *evmTxm) as "github.com/smartcontractkit/chainlink/core/chains/evm/headtracker/types".HeadTrackable value in variable declaration: *evmTxm does not implement "github.com/smartcontractkit/chainlink/core/chains/evm/headtracker/types".HeadTrackable (missing method OnNewLongestChain)
./chain.go:120:28: cannot use txm (variable of type *evmTxm) as "github.com/smartcontractkit/chainlink/core/chains/evm/headtracker/types".HeadTrackable value in argument to headBroadcaster.Subscribe: *evmTxm does not implement "github.com/smartcontractkit/chainlink/core/chains/evm/headtracker/types".HeadTrackable (missing method OnNewLongestChain)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, weird. Could it have been a pointer issue? I'm surprised to see the receiver here is not a pointer.

Copy link
Contributor Author

@prashantkumar1982 prashantkumar1982 Mar 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand your question.

evmTxm implements both interfaces:

  • httypes.HeadTrackable. (requires OnLongestChain(..., *evmtypes.Head))
  • txmgr.TxManager (requires OnLongestChain(..., txmgrtypes.Head))

I earlier assumed that in evmTxm, just letting the OnLongestChain method inheriting from TxManager would work, but it doesn't. I have to create above function to pass-through.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding of go, this shouldn't be necessary. Can we figure out why it's here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is not necessary. This is because the type assertion is generic instead of specifying [*evmtypes.Head].

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er, the concrete type with the same name is not connected to the generic one. This should be removable if they are derived from one another.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this whole type is not necessary: #8744


func newEvmTxm(
db *sqlx.DB,
cfg evmconfig.ChainScopedConfig,
client evmclient.Client,
lggr logger.Logger,
logPoller logpoller.LogPoller,
opts ChainSetOpts,
) *evmTxm {
chainID := cfg.ChainID()
var txm txmgr.TxManager
if !cfg.EVMRPCEnabled() {
txm = &txmgr.NullTxManager{ErrMsg: fmt.Sprintf("Ethereum is disabled for chain %d", chainID)}
} else if opts.GenTxManager == nil {
checker := &txmgr.CheckerFactory{Client: client}
txm = txmgr.NewTxm(db, client, cfg, opts.KeyStore, opts.EventBroadcaster, lggr, checker, logPoller)
} else {
txm = opts.GenTxManager(chainID)
}
return &evmTxm{TxManager: txm}
}
3 changes: 2 additions & 1 deletion core/chains/evm/gas/block_history_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func NewBlockHistoryEstimator(lggr logger.Logger, ethClient evmclient.Client, cf
// OnNewLongestChain recalculates and sets global gas price if a sampled new head comes
// in and we are not currently fetching
func (b *BlockHistoryEstimator) OnNewLongestChain(_ context.Context, head *evmtypes.Head) {

prashantkumar1982 marked this conversation as resolved.
Show resolved Hide resolved
// set latest base fee here to avoid potential lag introduced by block delay
// it is really important that base fee be as up-to-date as possible
b.setLatest(head)
Expand Down Expand Up @@ -581,7 +582,7 @@ func (b *BlockHistoryEstimator) FetchBlocks(ctx context.Context, head *evmtypes.
// chain, refetch blocks that got re-org'd out.
// NOTE: Any blocks in the history that are older than the oldest block
// in the provided chain will be assumed final.
if block.Number < head.EarliestInChain().Number {
if block.Number < head.EarliestInChain().BlockNumber() {
blocks[block.Number] = block
} else if head.IsInChain(block.Hash) {
blocks[block.Number] = block
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/gas/l2_suggested_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (o *l2SuggestedPriceEstimator) refreshPrice() (t *time.Timer) {
return
}

func (o *l2SuggestedPriceEstimator) OnNewLongestChain(_ context.Context, _ *evmtypes.Head) {}
func (o *l2SuggestedPriceEstimator) OnNewLongestChain(context.Context, *evmtypes.Head) {}

func (*l2SuggestedPriceEstimator) GetDynamicFee(_ context.Context, _ uint32, _ *assets.Wei) (fee DynamicFee, chainSpecificGasLimit uint32, err error) {
err = errors.New("dynamic fees are not implemented for this layer 2")
Expand Down
6 changes: 3 additions & 3 deletions core/chains/evm/gas/mocks/evm_estimator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions core/chains/evm/gas/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func MakeEvmPriorAttempt(a txmgrtypes.PriorAttempt[EvmFee, common.Hash]) EvmPrio
//
//go:generate mockery --quiet --name EvmEstimator --output ./mocks/ --case=underscore
type EvmEstimator interface {
OnNewLongestChain(context.Context, *evmtypes.Head)
txmgrtypes.HeadTrackable[*evmtypes.Head]
Start(context.Context) error
Close() error
// GetLegacyGas Calculates initial gas fee for non-EIP1559 transaction
Expand Down Expand Up @@ -145,7 +145,6 @@ type WrappedEvmEstimator struct {
EIP1559Enabled bool
}

// var _ FeeEstimator = (*WrappedEvmEstimator)(nil)
var _ txmgrtypes.FeeEstimator[*evmtypes.Head, EvmFee, *assets.Wei, common.Hash] = (*WrappedEvmEstimator)(nil)

func NewWrappedEvmEstimator(e EvmEstimator, cfg Config) txmgrtypes.FeeEstimator[*evmtypes.Head, EvmFee, *assets.Wei, common.Hash] {
Expand Down
8 changes: 4 additions & 4 deletions core/chains/evm/gas/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"context"
"testing"

"github.com/smartcontractkit/chainlink/core/assets"
"github.com/smartcontractkit/chainlink/core/chains/evm/gas"
"github.com/smartcontractkit/chainlink/core/chains/evm/gas/mocks"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink/core/assets"
"github.com/smartcontractkit/chainlink/core/chains/evm/gas"
"github.com/smartcontractkit/chainlink/core/chains/evm/gas/mocks"
)

func TestWrappedEvmEstimator(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/headtracker/head_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (ht *headTracker) Backfill(ctx context.Context, headWithChain *evmtypes.Hea
baseHeight = 0
}

return ht.backfill(ctx, headWithChain.EarliestInChain(), baseHeight)
return ht.backfill(ctx, headWithChain.EarliestInChain().(*evmtypes.Head), baseHeight)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to end up with typecasts everywhere like this now that head is more generic? That seems like a step backwards

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was due to the fact that EarliestInChain() was already used by evm native code, and also needed for generic Txmgr, so i merged them to a single interface method, that returns interface Head, instead of native head.

Changed it now.
The interface method is different from native method, so avoids having to use different types.

}

func (ht *headTracker) LatestChain() *evmtypes.Head {
Expand Down
10 changes: 5 additions & 5 deletions core/chains/evm/headtracker/head_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,8 +855,8 @@ func TestHeadTracker_Backfill(t *testing.T) {

require.Equal(t, uint32(8), h.ChainLength())
earliestInChain := h.EarliestInChain()
assert.Equal(t, head8.Number, earliestInChain.Number)
assert.Equal(t, head8.Hash, earliestInChain.Hash)
assert.Equal(t, head8.Number, earliestInChain.BlockNumber())
assert.Equal(t, head8.Hash, earliestInChain.BlockHash())
})

t.Run("does not backfill if chain length is already greater than or equal to depth", func(t *testing.T) {
Expand Down Expand Up @@ -902,7 +902,7 @@ func TestHeadTracker_Backfill(t *testing.T) {
require.NotNil(t, h)

require.Equal(t, uint32(2), h.ChainLength())
require.Equal(t, int64(0), h.EarliestInChain().Number)
require.Equal(t, int64(0), h.EarliestInChain().BlockNumber())
})

t.Run("abandons backfill and returns error if the eth node returns not found", func(t *testing.T) {
Expand Down Expand Up @@ -933,7 +933,7 @@ func TestHeadTracker_Backfill(t *testing.T) {

// Should contain 12, 11, 10, 9
assert.Equal(t, 4, int(h.ChainLength()))
assert.Equal(t, int64(9), h.EarliestInChain().Number)
assert.Equal(t, int64(9), h.EarliestInChain().BlockNumber())
})

t.Run("abandons backfill and returns error if the context time budget is exceeded", func(t *testing.T) {
Expand Down Expand Up @@ -962,7 +962,7 @@ func TestHeadTracker_Backfill(t *testing.T) {

// Should contain 12, 11, 10, 9
assert.Equal(t, 4, int(h.ChainLength()))
assert.Equal(t, int64(9), h.EarliestInChain().Number)
assert.Equal(t, int64(9), h.EarliestInChain().BlockNumber())
})
}

Expand Down
6 changes: 4 additions & 2 deletions core/chains/evm/txmgr/eth_broadcaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,8 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_OptimisticLockingOnEthTx(t *testi
chStartEstimate := make(chan struct{})
chBlock := make(chan struct{})

estimator := txmgrmocks.NewFeeEstimator[*evmtypes.Head, gas.EvmFee, *assets.Wei, gethCommon.Hash](t)
var estimator = txmgrmocks.NewFeeEstimator[*evmtypes.Head, gas.EvmFee, *assets.Wei, gethCommon.Hash](t)

estimator.On("GetFee", mock.Anything, mock.Anything, mock.Anything, evmcfg.KeySpecificMaxGasPriceWei(fromAddress)).Return(gas.EvmFee{Legacy: assets.GWei(32)}, uint32(500), nil).Run(func(_ mock.Arguments) {
close(chStartEstimate)
<-chBlock
Expand Down Expand Up @@ -1140,8 +1141,9 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) {
require.NoError(t, err)
t.Cleanup(func() { assert.NoError(t, eventBroadcaster.Close()) })
lggr := logger.TestLogger(t)
estimator := gas.NewWrappedEvmEstimator(gas.NewFixedPriceEstimator(evmcfg, lggr), evmcfg)
eb = txmgr.NewEthBroadcaster(borm, ethClient, evmcfg, ethKeyStore, eventBroadcaster,
[]ethkey.State{keyState}, gas.NewWrappedEvmEstimator(gas.NewFixedPriceEstimator(evmcfg, lggr), evmcfg), fn, lggr,
[]ethkey.State{keyState}, estimator, fn, lggr,
&testCheckerFactory{}, false)

{
Expand Down
Loading