Commit a3da36fe authored by Andreas Bigger's avatar Andreas Bigger

txmgr fixes

parent ddaf933a
...@@ -357,7 +357,6 @@ func (l *BatchSubmitter) SendTransaction(ctx context.Context, data []byte) (*typ ...@@ -357,7 +357,6 @@ func (l *BatchSubmitter) SendTransaction(ctx context.Context, data []byte) (*typ
To: l.Rollup.BatchInboxAddress, To: l.Rollup.BatchInboxAddress,
TxData: data, TxData: data,
From: l.From, From: l.From,
ChainID: l.Rollup.L1ChainID,
GasLimit: gas, GasLimit: gas,
}) })
if err != nil { if err != nil {
......
...@@ -47,7 +47,6 @@ func TestSendTransaction(t *testing.T) { ...@@ -47,7 +47,6 @@ func TestSendTransaction(t *testing.T) {
To: batcherInboxAddress, To: batcherInboxAddress,
TxData: txData, TxData: txData,
From: sender, From: sender,
ChainID: chainID,
GasLimit: uint64(0), GasLimit: uint64(0),
} }
......
...@@ -109,13 +109,16 @@ type ETHBackend interface { ...@@ -109,13 +109,16 @@ type ETHBackend interface {
/// EstimateGas returns an estimate of the amount of gas needed to execute the given /// EstimateGas returns an estimate of the amount of gas needed to execute the given
/// transaction against the current pending block. /// transaction against the current pending block.
EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)
// ChainID returns the chain ID for this ethereum chain.
ChainID(ctx context.Context) (*big.Int, error)
} }
// SimpleTxManager is a implementation of TxManager that performs linear fee // SimpleTxManager is a implementation of TxManager that performs linear fee
// bumping of a tx until it confirms. // bumping of a tx until it confirms.
type SimpleTxManager struct { type SimpleTxManager struct {
Config // embed the config directly Config // embed the config directly
name string name string
chainID *big.Int
backend ETHBackend backend ETHBackend
l log.Logger l log.Logger
...@@ -132,8 +135,6 @@ type TxCandidate struct { ...@@ -132,8 +135,6 @@ type TxCandidate struct {
GasLimit uint64 GasLimit uint64
// From is the sender (or `from`) of the constructed tx. // From is the sender (or `from`) of the constructed tx.
From common.Address From common.Address
/// ChainID is the chain ID to be used in the constructed tx.
ChainID *big.Int
} }
// calcGasTipAndFeeCap queries L1 to determine what a suitable miner tip & basefee limit would be for timely inclusion // calcGasTipAndFeeCap queries L1 to determine what a suitable miner tip & basefee limit would be for timely inclusion
...@@ -183,8 +184,19 @@ func (m *SimpleTxManager) CraftTx(ctx context.Context, candidate TxCandidate) (* ...@@ -183,8 +184,19 @@ func (m *SimpleTxManager) CraftTx(ctx context.Context, candidate TxCandidate) (*
return nil, fmt.Errorf("failed to get nonce: %w", err) return nil, fmt.Errorf("failed to get nonce: %w", err)
} }
// If the configured chain ID is nil (can occur if the fetch fails in the constructor),
// we need to try to fetch it again from the backend.
if m.chainID == nil {
childCtx, cancel := context.WithTimeout(ctx, m.Config.NetworkTimeout)
m.chainID, err = m.backend.ChainID(childCtx)
cancel()
if err != nil {
return nil, fmt.Errorf("failed to get chain ID: %w", err)
}
}
rawTx := &types.DynamicFeeTx{ rawTx := &types.DynamicFeeTx{
ChainID: candidate.ChainID, ChainID: m.chainID,
Nonce: nonce, Nonce: nonce,
To: &candidate.To, To: &candidate.To,
GasTipCap: gasTipCap, GasTipCap: gasTipCap,
...@@ -316,7 +328,11 @@ func NewSimpleTxManager(name string, l log.Logger, cfg Config, backend ETHBacken ...@@ -316,7 +328,11 @@ func NewSimpleTxManager(name string, l log.Logger, cfg Config, backend ETHBacken
cfg.NetworkTimeout = 2 * time.Second cfg.NetworkTimeout = 2 * time.Second
} }
// On error, ignore. We will try to get the chainID again when used.
chainID, _ := backend.ChainID(context.Background())
return &SimpleTxManager{ return &SimpleTxManager{
chainID: chainID,
name: name, name: name,
Config: cfg, Config: cfg,
backend: backend, backend: backend,
......
...@@ -54,13 +54,11 @@ func newTestHarness(t *testing.T) *testHarness { ...@@ -54,13 +54,11 @@ func newTestHarness(t *testing.T) *testHarness {
// createTxCandidate creates a mock [TxCandidate]. // createTxCandidate creates a mock [TxCandidate].
func (h testHarness) createTxCandidate() TxCandidate { func (h testHarness) createTxCandidate() TxCandidate {
inbox := common.HexToAddress("0x42000000000000000000000000000000000000ff") inbox := common.HexToAddress("0x42000000000000000000000000000000000000ff")
chainID := big.NewInt(1)
sender := common.HexToAddress("0xdeadbeef") sender := common.HexToAddress("0xdeadbeef")
return TxCandidate{ return TxCandidate{
To: inbox, To: inbox,
TxData: []byte{0x00, 0x01, 0x02}, TxData: []byte{0x00, 0x01, 0x02},
From: sender, From: sender,
ChainID: chainID,
GasLimit: uint64(1337), GasLimit: uint64(1337),
} }
} }
...@@ -210,6 +208,10 @@ func (b *mockBackend) NonceAt(ctx context.Context, account common.Address, block ...@@ -210,6 +208,10 @@ func (b *mockBackend) NonceAt(ctx context.Context, account common.Address, block
return 0, nil return 0, nil
} }
func (*mockBackend) ChainID(ctx context.Context) (*big.Int, error) {
return big.NewInt(1), nil
}
// TransactionReceipt queries the mockBackend for a mined txHash. If none is // TransactionReceipt queries the mockBackend for a mined txHash. If none is
// found, nil is returned for both return values. Otherwise, it retruns a // found, nil is returned for both return values. Otherwise, it retruns a
// receipt containing the txHash and the gasFeeCap used in the GasUsed to make // receipt containing the txHash and the gasFeeCap used in the GasUsed to make
...@@ -652,6 +654,10 @@ func (b *failingBackend) NonceAt(_ context.Context, _ common.Address, _ *big.Int ...@@ -652,6 +654,10 @@ func (b *failingBackend) NonceAt(_ context.Context, _ common.Address, _ *big.Int
return 0, errors.New("unimplemented") return 0, errors.New("unimplemented")
} }
func (b *failingBackend) ChainID(ctx context.Context) (*big.Int, error) {
return nil, errors.New("unimplemented")
}
// TestWaitMinedReturnsReceiptAfterFailure asserts that WaitMined is able to // TestWaitMinedReturnsReceiptAfterFailure asserts that WaitMined is able to
// recover from failed calls to the backend. It uses the failedBackend to // recover from failed calls to the backend. It uses the failedBackend to
// simulate an rpc call failure, followed by the successful return of a receipt. // simulate an rpc call failure, followed by the successful return of a receipt.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment