Commit 929077b1 authored by Andreas Bigger's avatar Andreas Bigger

stash txmgr changes

parent 1b797f2d
...@@ -101,6 +101,8 @@ type ETHBackend interface { ...@@ -101,6 +101,8 @@ type ETHBackend interface {
// TODO(CLI-3318): Maybe need a generic interface to support different RPC providers // TODO(CLI-3318): Maybe need a generic interface to support different RPC providers
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
SuggestGasTipCap(ctx context.Context) (*big.Int, error) SuggestGasTipCap(ctx context.Context) (*big.Int, error)
// NonceAt returns the account nonce of the given account.
// The block number can be nil, in which case the nonce is taken from the latest known block.
NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
} }
...@@ -166,6 +168,7 @@ func (m *SimpleTxManager) CraftTx(ctx context.Context, candidate TxCandidate) (* ...@@ -166,6 +168,7 @@ func (m *SimpleTxManager) CraftTx(ctx context.Context, candidate TxCandidate) (*
return nil, err return nil, err
} }
// Fetch the sender's nonce from the latest known block (nil `blockNumber`)
childCtx, cancel := context.WithTimeout(ctx, m.Config.NetworkTimeout) childCtx, cancel := context.WithTimeout(ctx, m.Config.NetworkTimeout)
nonce, err := m.backend.NonceAt(childCtx, candidate.From, nil) nonce, err := m.backend.NonceAt(childCtx, candidate.From, nil)
cancel() cancel()
...@@ -181,8 +184,9 @@ func (m *SimpleTxManager) CraftTx(ctx context.Context, candidate TxCandidate) (* ...@@ -181,8 +184,9 @@ func (m *SimpleTxManager) CraftTx(ctx context.Context, candidate TxCandidate) (*
GasFeeCap: gasFeeCap, GasFeeCap: gasFeeCap,
Data: candidate.TxData, Data: candidate.TxData,
} }
m.l.Info("creating tx", "to", rawTx.To, "from", candidate.From)
// Calculate the intrinsic gas for the transaction
m.l.Info("creating tx", "to", rawTx.To, "from", candidate.From)
gas, err := core.IntrinsicGas(rawTx.Data, nil, false, true, true, false) gas, err := core.IntrinsicGas(rawTx.Data, nil, false, true, true, false)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to calculate intrinsic gas: %w", err) return nil, fmt.Errorf("failed to calculate intrinsic gas: %w", err)
...@@ -278,6 +282,9 @@ func NewSimpleTxManager(name string, l log.Logger, cfg Config, backend ETHBacken ...@@ -278,6 +282,9 @@ func NewSimpleTxManager(name string, l log.Logger, cfg Config, backend ETHBacken
if cfg.NumConfirmations == 0 { if cfg.NumConfirmations == 0 {
panic("txmgr: NumConfirmations cannot be zero") panic("txmgr: NumConfirmations cannot be zero")
} }
if cfg.NetworkTimeout == 0 {
cfg.NetworkTimeout = 2 * time.Second
}
return &SimpleTxManager{ return &SimpleTxManager{
name: name, name: name,
......
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