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

Add Transaction Simulation to the TXM #12503

Merged
merged 27 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5a87d87
Added tx simulator to maintain chain specific simulation methods
amit-momin Mar 20, 2024
bdb9fef
Fixed linting
amit-momin Mar 20, 2024
46b13be
Fixed linting and regenerated config docs
amit-momin Mar 20, 2024
141dfea
Generated mock
amit-momin Mar 20, 2024
4835554
Fixed config tests
amit-momin Mar 20, 2024
27922a3
Merge branch 'develop' into zk-tx-simulation
amit-momin Mar 20, 2024
befeaf0
Moved the tx simulator to the chain client
amit-momin Mar 20, 2024
fbdd110
Removed client from Txm struct
amit-momin Mar 20, 2024
2f7078f
Removed config from test helper
amit-momin Mar 20, 2024
fc70e7f
Added tests and logging
amit-momin Mar 21, 2024
389e18f
Added changeset
amit-momin Mar 21, 2024
37b783e
Fixed multinode test
amit-momin Mar 21, 2024
cdc58b2
Merge branch 'develop' into zk-tx-simulation
amit-momin Mar 21, 2024
e126805
Fixed linting
amit-momin Mar 21, 2024
0c22a6f
Merge branch 'develop' into zk-tx-simulation
amit-momin Mar 22, 2024
c7eae50
Fixed comment
amit-momin Mar 22, 2024
53efe22
Added test for non-OOC error
amit-momin Mar 22, 2024
8ad2510
Reduced context initializations in tests
amit-momin Mar 22, 2024
3f53867
Updated to account for all types of OOC errors
amit-momin Mar 22, 2024
ce8a3c7
Removed custom zk counter method and simplified error handling
amit-momin Mar 25, 2024
d7605cc
Removed zkevm chain type
amit-momin Mar 25, 2024
f301d43
Changed simulate tx method return object
amit-momin Mar 25, 2024
eb34bc7
Cleaned up stale comments
amit-momin Mar 25, 2024
68de594
Removed unused error message
amit-momin Mar 25, 2024
1a25270
Changed zk overflow validation method name
amit-momin Mar 26, 2024
6798e4d
Reverted method name change
amit-momin Mar 26, 2024
87c8eac
Merge branch 'develop' into zk-tx-simulation
amit-momin Mar 26, 2024
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: 3 additions & 1 deletion common/config/chaintype.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
ChainScroll ChainType = "scroll"
ChainWeMix ChainType = "wemix"
ChainXDai ChainType = "xdai" // Deprecated: use ChainGnosis instead
ChainZkEvm ChainType = "zkevm"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed?
Didn't see any behavior depending on this type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good call, missed cleaning this out after removing the zkevm specific method

ChainZkSync ChainType = "zksync"
)

Expand All @@ -31,13 +32,14 @@ var ErrInvalidChainType = fmt.Errorf("must be one of %s or omitted", strings.Joi
string(ChainOptimismBedrock),
string(ChainScroll),
string(ChainWeMix),
string(ChainZkEvm),
string(ChainZkSync),
}, ", "))

// IsValid returns true if the ChainType value is known or empty.
func (c ChainType) IsValid() bool {
switch c {
case "", ChainArbitrum, ChainCelo, ChainGnosis, ChainKroma, ChainMetis, ChainOptimismBedrock, ChainScroll, ChainWeMix, ChainXDai, ChainZkSync:
case "", ChainArbitrum, ChainCelo, ChainGnosis, ChainKroma, ChainMetis, ChainOptimismBedrock, ChainScroll, ChainWeMix, ChainXDai, ChainZkEvm, ChainZkSync:
return true
}
return false
Expand Down
11 changes: 11 additions & 0 deletions common/txmgr/txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type Txm[
services.StateMachine
logger logger.SugaredLogger
txStore txmgrtypes.TxStore[ADDR, CHAIN_ID, TX_HASH, BLOCK_HASH, R, SEQ, FEE]
client txmgrtypes.TxmClient[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]
config txmgrtypes.TransactionManagerChainConfig
txConfig txmgrtypes.TransactionManagerTransactionsConfig
keyStore txmgrtypes.KeyStore[ADDR, CHAIN_ID, SEQ]
Expand Down Expand Up @@ -139,6 +140,7 @@ func NewTxm[
confirmer *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE],
resender *Resender[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE],
tracker *Tracker[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE],
client txmgrtypes.TxmClient[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE],
) *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE] {
b := Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]{
logger: logger.Sugared(lggr),
Expand All @@ -159,6 +161,7 @@ func NewTxm[
confirmer: confirmer,
resender: resender,
tracker: tracker,
client: client,
}

if txCfg.ResendAfterThreshold() <= 0 {
Expand Down Expand Up @@ -603,6 +606,10 @@ func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) CountTrans
return b.txStore.CountTransactionsByState(ctx, state, b.chainID)
}

func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) CheckTxValidity(ctx context.Context, from ADDR, to ADDR, data []byte) error {
prashantkumar1982 marked this conversation as resolved.
Show resolved Hide resolved
return b.client.SimulateTransaction(ctx, from, to, data)
}

type NullTxManager[
CHAIN_ID types.ID,
HEAD types.Head[BLOCK_HASH],
Expand Down Expand Up @@ -682,6 +689,10 @@ func (n *NullTxManager[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) Cou
return count, errors.New(n.ErrMsg)
}

func (n *NullTxManager[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) CheckTxValidity(ctx context.Context, from ADDR, to ADDR, data []byte) error {
return nil
}

func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) pruneQueueAndCreateTxn(
ctx context.Context,
txRequest txmgrtypes.TxRequest[ADDR, TX_HASH],
Expand Down
1 change: 1 addition & 0 deletions common/txmgr/types/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type TransactionClient[
attempt TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE],
blockNumber *big.Int,
) (rpcErr fmt.Stringer, extractErr error)
SimulateTransaction(ctx context.Context, from ADDR, to ADDR, data []byte) error
}

// ChainClient contains the interfaces for reading chain parameters (chain id, sequences, etc)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ChainID = '2442'
ChainType = 'zkevm'
FinalityDepth = 500
NoNewHeadsThreshold = '12m'
MinIncomingConfirmations = 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ChainID = '1442'
ChainType = 'zkevm'
FinalityDepth = 500
NoNewHeadsThreshold = '12m'
MinIncomingConfirmations = 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ChainID = '1101'
ChainType = 'zkevm'
FinalityDepth = 500
NoNewHeadsThreshold = '6m'
MinIncomingConfirmations = 1
Expand Down
38 changes: 19 additions & 19 deletions core/chains/evm/txmgr/broadcaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewTestEthBroadcaster(
return gas.NewFixedPriceEstimator(config.EVM().GasEstimator(), ge.BlockHistory(), lggr)
}, ge.EIP1559DynamicFees(), nil)
txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), ge, keyStore, estimator)
ethBroadcaster := txmgrcommon.NewBroadcaster(txStore, txmgr.NewEvmTxmClient(ethClient), txmgr.NewEvmTxmConfig(config.EVM()), txmgr.NewEvmTxmFeeConfig(config.EVM().GasEstimator()), config.EVM().Transactions(), config.Database().Listener(), keyStore, txBuilder, nonceTracker, lggr, checkerFactory, nonceAutoSync)
ethBroadcaster := txmgrcommon.NewBroadcaster(txStore, txmgr.NewEvmTxmClient(ethClient, ""), txmgr.NewEvmTxmConfig(config.EVM()), txmgr.NewEvmTxmFeeConfig(config.EVM().GasEstimator()), config.EVM().Transactions(), config.Database().Listener(), keyStore, txBuilder, nonceTracker, lggr, checkerFactory, nonceAutoSync)

// Mark instance as test
ethBroadcaster.XXXTestDisableUnstartedTxAutoProcessing()
Expand All @@ -84,7 +84,7 @@ func TestEthBroadcaster_Lifecycle(t *testing.T) {
cltest.MustInsertRandomKeyReturningState(t, ethKeyStore)
estimator := gasmocks.NewEvmFeeEstimator(t)
txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), evmcfg.EVM().GasEstimator(), ethKeyStore, estimator)
txmClient := txmgr.NewEvmTxmClient(ethClient)
txmClient := txmgr.NewEvmTxmClient(ethClient, "")
ethClient.On("PendingNonceAt", mock.Anything, mock.Anything).Return(uint64(0), nil)
eb := txmgr.NewEvmBroadcaster(
txStore,
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestEthBroadcaster_LoadNextSequenceMapFailure_StartupSuccess(t *testing.T)
estimator := gasmocks.NewEvmFeeEstimator(t)
txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), evmcfg.EVM().GasEstimator(), ethKeyStore, estimator)
ethClient.On("PendingNonceAt", mock.Anything, mock.Anything).Return(uint64(0), errors.New("Getting on-chain nonce failed"))
txmClient := txmgr.NewEvmTxmClient(ethClient)
txmClient := txmgr.NewEvmTxmClient(ethClient, "")
eb := txmgr.NewEvmBroadcaster(
txStore,
txmClient,
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) {
ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once()
ethClient.On("PendingNonceAt", mock.Anything, otherAddress).Return(uint64(0), nil).Once()
lggr := logger.Test(t)
nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient))
nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient, ""))
eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, checkerFactory, false, nonceTracker)

toAddress := gethCommon.HexToAddress("0x6C03DDA95a2AEd917EeCc6eddD4b9D16E6380411")
Expand Down Expand Up @@ -380,7 +380,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) {
})
evmcfg = evmtest.NewChainScopedConfig(t, cfg)
ethClient.On("PendingNonceAt", mock.Anything, otherAddress).Return(uint64(1), nil).Once()
nonceTracker = txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient))
nonceTracker = txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient, ""))
eb = NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, checkerFactory, false, nonceTracker)

t.Run("sends transactions with type 0x2 in EIP-1559 mode", func(t *testing.T) {
Expand Down Expand Up @@ -529,7 +529,7 @@ func TestEthBroadcaster_TransmitChecking(t *testing.T) {
evmcfg := evmtest.NewChainScopedConfig(t, cfg)
checkerFactory := &testCheckerFactory{}
ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once()
nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient))
nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient, ""))
eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, checkerFactory, false, nonceTracker)

checker := txmgr.TransmitCheckerSpec{
Expand Down Expand Up @@ -621,7 +621,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_OptimisticLockingOnEthTx(t *testi
<-chBlock
}).Once()
ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil)
txmClient := txmgr.NewEvmTxmClient(ethClient)
txmClient := txmgr.NewEvmTxmClient(ethClient, "")
eb := txmgr.NewEvmBroadcaster(
txStore,
txmClient,
Expand Down Expand Up @@ -678,7 +678,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success_WithMultiplier(t *testing

ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once()
nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient))
nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient, ""))
eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false, nonceTracker)

ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool {
Expand Down Expand Up @@ -759,7 +759,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) {

ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once()
nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient))
nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient, ""))
eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false, nonceTracker)

// Crashed right after we commit the database transaction that saved
Expand Down Expand Up @@ -798,7 +798,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) {

ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once()
nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient))
nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient, ""))
eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false, nonceTracker)

// Crashed right after we commit the database transaction that saved the nonce to the eth_tx
Expand Down Expand Up @@ -835,7 +835,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) {

ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once()
nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient))
nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient, ""))
eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false, nonceTracker)

// Crashed right after we commit the database transaction that saved the nonce to the eth_tx
Expand Down Expand Up @@ -871,7 +871,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) {

ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once()
nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient))
nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient, ""))
eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false, nonceTracker)

// Crashed right after we commit the database transaction that saved the nonce to the eth_tx
Expand Down Expand Up @@ -909,7 +909,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) {

ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once()
nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient))
nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient, ""))
eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false, nonceTracker)

// Crashed right after we commit the database transaction that saved the nonce to the eth_tx
Expand Down Expand Up @@ -951,7 +951,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) {

ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once()
nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient))
nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient, ""))
eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false, nonceTracker)

// Crashed right after we commit the database transaction that saved the nonce to the eth_tx
Expand Down Expand Up @@ -1016,7 +1016,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) {
ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once()
lggr := logger.Test(t)
txmClient := txmgr.NewEvmTxmClient(ethClient)
txmClient := txmgr.NewEvmTxmClient(ethClient, "")
nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmClient)
eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false, nonceTracker)
ctx := testutils.Context(t)
Expand Down Expand Up @@ -1661,7 +1661,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_KeystoreErrors(t *testing.T) {
kst.On("EnabledAddressesForChain", mock.Anything, &cltest.FixtureChainID).Return(addresses, nil).Once()
ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once()
lggr := logger.Test(t)
nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient))
nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient, ""))
eb := NewTestEthBroadcaster(t, txStore, ethClient, kst, evmcfg, &testCheckerFactory{}, false, nonceTracker)
ctx := testutils.Context(t)
_, err := nonceTracker.GetNextSequence(ctx, fromAddress)
Expand Down Expand Up @@ -1710,7 +1710,7 @@ func TestEthBroadcaster_Trigger(t *testing.T) {
ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
lggr := logger.Test(t)
nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient))
nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient, ""))
eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false, nonceTracker)

eb.Trigger(testutils.NewAddress())
Expand Down Expand Up @@ -1748,7 +1748,7 @@ func TestEthBroadcaster_SyncNonce(t *testing.T) {
addresses := []gethCommon.Address{fromAddress}
kst.On("EnabledAddressesForChain", mock.Anything, &cltest.FixtureChainID).Return(addresses, nil).Once()
ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once()
txmClient := txmgr.NewEvmTxmClient(ethClient)
txmClient := txmgr.NewEvmTxmClient(ethClient, "")
eb := txmgr.NewEvmBroadcaster(txStore, txmClient, evmTxmCfg, txmgr.NewEvmTxmFeeConfig(ge), evmcfg.EVM().Transactions(), cfg.Database().Listener(), kst, txBuilder, lggr, checkerFactory, false)
err := eb.Start(ctx)
assert.NoError(t, err)
Expand Down Expand Up @@ -1783,7 +1783,7 @@ func TestEthBroadcaster_NonceTracker_InProgressTx(t *testing.T) {

// Tx with nonce 0 in DB will set local nonce map to value to 1
mustInsertInProgressEthTxWithAttempt(t, txStore, evmtypes.Nonce(inProgressTxNonce), fromAddress)
nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient))
nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient, ""))
eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, checkerFactory, false, nonceTracker)

// Check the local nonce map was set to 1 higher than in-progress tx nonce
Expand Down
11 changes: 6 additions & 5 deletions core/chains/evm/txmgr/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ func NewTxm(
txAttemptBuilder := NewEvmTxAttemptBuilder(*client.ConfiguredChainID(), fCfg, keyStore, estimator)
txStore := NewTxStore(sqlxDB, lggr, dbConfig)

txmCfg := NewEvmTxmConfig(chainConfig) // wrap Evm specific config
feeCfg := NewEvmTxmFeeConfig(fCfg) // wrap Evm specific config
txmClient := NewEvmTxmClient(client) // wrap Evm specific client
txmCfg := NewEvmTxmConfig(chainConfig) // wrap Evm specific config
feeCfg := NewEvmTxmFeeConfig(fCfg) // wrap Evm specific config
txmClient := NewEvmTxmClient(client, chainConfig.ChainType()) // wrap Evm specific client
chainID := txmClient.ConfiguredChainID()
evmBroadcaster := NewEvmBroadcaster(txStore, txmClient, txmCfg, feeCfg, txConfig, listenerConfig, keyStore, txAttemptBuilder, lggr, checker, chainConfig.NonceAutoSync())
evmTracker := NewEvmTracker(txStore, keyStore, chainID, lggr)
Expand All @@ -59,7 +59,7 @@ func NewTxm(
if txConfig.ResendAfterThreshold() > 0 {
evmResender = NewEvmResender(lggr, txStore, txmClient, evmTracker, keyStore, txmgr.DefaultResenderPollInterval, chainConfig, txConfig)
}
txm = NewEvmTxm(chainID, txmCfg, txConfig, keyStore, lggr, checker, fwdMgr, txAttemptBuilder, txStore, evmBroadcaster, evmConfirmer, evmResender, evmTracker)
txm = NewEvmTxm(chainID, txmCfg, txConfig, keyStore, lggr, checker, fwdMgr, txAttemptBuilder, txStore, evmBroadcaster, evmConfirmer, evmResender, evmTracker, txmClient)
return txm, nil
}

Expand All @@ -78,8 +78,9 @@ func NewEvmTxm(
confirmer *Confirmer,
resender *Resender,
tracker *Tracker,
txmClient *evmTxmClient,
) *Txm {
return txmgr.NewTxm(chainId, cfg, txCfg, keyStore, lggr, checkerFactory, fwdMgr, txAttemptBuilder, txStore, broadcaster, confirmer, resender, tracker)
return txmgr.NewTxm(chainId, cfg, txCfg, keyStore, lggr, checkerFactory, fwdMgr, txAttemptBuilder, txStore, broadcaster, confirmer, resender, tracker, txmClient)
}

// NewEvmResender creates a new concrete EvmResender
Expand Down
15 changes: 13 additions & 2 deletions core/chains/evm/txmgr/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/utils"

commonclient "github.com/smartcontractkit/chainlink/v2/common/client"
"github.com/smartcontractkit/chainlink/v2/common/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
Expand All @@ -25,10 +26,11 @@ import (
var _ TxmClient = (*evmTxmClient)(nil)

type evmTxmClient struct {
client client.Client
client client.Client
chainType config.ChainType
}

func NewEvmTxmClient(c client.Client) *evmTxmClient {
func NewEvmTxmClient(c client.Client, chainType config.ChainType) *evmTxmClient {
return &evmTxmClient{client: c}
}

Expand Down Expand Up @@ -181,3 +183,12 @@ func (c *evmTxmClient) CallContract(ctx context.Context, a TxAttempt, blockNumbe
}, blockNumber)
return client.ExtractRPCError(errCall)
}

func (c *evmTxmClient) SimulateTransaction(ctx context.Context, from common.Address, to common.Address, data []byte) error {
msg := ethereum.CallMsg{
From: from,
To: &to,
Data: data,
}
return SimulateTransaction(ctx, c.client, c.chainType, msg)
}
Loading
Loading