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
To: l.Rollup.BatchInboxAddress,
TxData: data,
From: l.From,
ChainID: l.Rollup.L1ChainID,
GasLimit: gas,
})
if err != nil {
......
......@@ -47,7 +47,6 @@ func TestSendTransaction(t *testing.T) {
To: batcherInboxAddress,
TxData: txData,
From: sender,
ChainID: chainID,
GasLimit: uint64(0),
}
......
......@@ -109,13 +109,16 @@ type ETHBackend interface {
/// EstimateGas returns an estimate of the amount of gas needed to execute the given
/// transaction against the current pending block.
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
// bumping of a tx until it confirms.
type SimpleTxManager struct {
Config // embed the config directly
name string
Config // embed the config directly
name string
chainID *big.Int
backend ETHBackend
l log.Logger
......@@ -132,8 +135,6 @@ type TxCandidate struct {
GasLimit uint64
// From is the sender (or `from`) of the constructed tx.
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
......@@ -183,8 +184,19 @@ func (m *SimpleTxManager) CraftTx(ctx context.Context, candidate TxCandidate) (*
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{
ChainID: candidate.ChainID,
ChainID: m.chainID,
Nonce: nonce,
To: &candidate.To,
GasTipCap: gasTipCap,
......@@ -316,7 +328,11 @@ func NewSimpleTxManager(name string, l log.Logger, cfg Config, backend ETHBacken
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{
chainID: chainID,
name: name,
Config: cfg,
backend: backend,
......
......@@ -54,13 +54,11 @@ func newTestHarness(t *testing.T) *testHarness {
// createTxCandidate creates a mock [TxCandidate].
func (h testHarness) createTxCandidate() TxCandidate {
inbox := common.HexToAddress("0x42000000000000000000000000000000000000ff")
chainID := big.NewInt(1)
sender := common.HexToAddress("0xdeadbeef")
return TxCandidate{
To: inbox,
TxData: []byte{0x00, 0x01, 0x02},
From: sender,
ChainID: chainID,
GasLimit: uint64(1337),
}
}
......@@ -210,6 +208,10 @@ func (b *mockBackend) NonceAt(ctx context.Context, account common.Address, block
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
// 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
......@@ -652,6 +654,10 @@ func (b *failingBackend) NonceAt(_ context.Context, _ common.Address, _ *big.Int
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
// 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.
......
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