Commit ea396762 authored by mergify[bot]'s avatar mergify[bot] Committed by GitHub

Merge pull request #4555 from mdehoog/pass-context-to-signer-fn

[op-batcher / op-proposer] Provide context to signer function
parents 4e07584d 1528dbd4
......@@ -84,7 +84,7 @@ func NewBatchSubmitter(cfg Config, l log.Logger) (*BatchSubmitter, error) {
signer := func(chainID *big.Int) SignerFn {
s := types.LatestSignerForChainID(chainID)
return func(rawTx types.TxData) (*types.Transaction, error) {
return func(_ context.Context, rawTx types.TxData) (*types.Transaction, error) {
return types.SignNewTx(sequencerPrivKey, s, rawTx)
}
}
......
......@@ -16,7 +16,7 @@ import (
const networkTimeout = 2 * time.Second // How long a single network request can take. TODO: put in a config somewhere
type SignerFn func(rawTx types.TxData) (*types.Transaction, error)
type SignerFn func(ctx context.Context, rawTx types.TxData) (*types.Transaction, error)
// TransactionManager wraps the simple txmgr package to make it easy to send & wait for transactions
type TransactionManager struct {
......@@ -121,7 +121,7 @@ func (t *TransactionManager) CraftTx(ctx context.Context, data []byte) (*types.T
}
rawTx.Gas = gas
return t.signerFn(rawTx)
return t.signerFn(ctx, rawTx)
}
// UpdateGasPrice signs an otherwise identical txn to the one provided but with
......@@ -146,5 +146,5 @@ func (t *TransactionManager) UpdateGasPrice(ctx context.Context, tx *types.Trans
// Only log the new tip/fee cap because the updateGasPrice closure reuses the same initial transaction
t.log.Trace("updating gas price", "tip_cap", gasTipCap, "fee_cap", gasFeeCap)
return t.signerFn(rawTx)
return t.signerFn(ctx, rawTx)
}
package actions
import (
"context"
"crypto/ecdsa"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
......@@ -32,6 +34,7 @@ type L2Proposer struct {
func NewL2Proposer(t Testing, log log.Logger, cfg *ProposerCfg, l1 *ethclient.Client, rollupCl *sources.RollupClient) *L2Proposer {
chainID, err := l1.ChainID(t.Ctx())
require.NoError(t, err)
signer := opcrypto.PrivateKeySignerFn(cfg.ProposerKey, chainID)
dr, err := proposer.NewDriver(proposer.DriverConfig{
Log: log,
Name: "proposer",
......@@ -40,7 +43,9 @@ func NewL2Proposer(t Testing, log log.Logger, cfg *ProposerCfg, l1 *ethclient.Cl
AllowNonFinalized: cfg.AllowNonFinalized,
L2OOAddr: cfg.OutputOracleAddr,
From: crypto.PubkeyToAddress(cfg.ProposerKey.PublicKey),
SignerFn: opcrypto.PrivateKeySignerFn(cfg.ProposerKey, chainID),
SignerFn: func(_ context.Context, addr common.Address, tx *types.Transaction) (*types.Transaction, error) {
return signer(addr, tx)
},
})
require.NoError(t, err)
return &L2Proposer{
......
......@@ -22,6 +22,8 @@ import (
var bigOne = big.NewInt(1)
var supportedL2OutputVersion = eth.Bytes32{}
type SignerFn func(context.Context, common.Address, *types.Transaction) (*types.Transaction, error)
type DriverConfig struct {
Log log.Logger
Name string
......@@ -44,7 +46,7 @@ type DriverConfig struct {
From common.Address
// SignerFn is the function used to sign transactions
SignerFn bind.SignerFn
SignerFn SignerFn
}
type Driver struct {
......@@ -183,7 +185,9 @@ func (d *Driver) CraftTx(ctx context.Context, start, end, nonce *big.Int) (*type
opts := &bind.TransactOpts{
From: d.cfg.From,
Signer: d.cfg.SignerFn,
Signer: func(addr common.Address, tx *types.Transaction) (*types.Transaction, error) {
return d.cfg.SignerFn(ctx, addr, tx)
},
Context: ctx,
Nonce: nonce,
NoSend: true,
......@@ -226,7 +230,9 @@ func (d *Driver) CraftTx(ctx context.Context, start, end, nonce *big.Int) (*type
func (d *Driver) UpdateGasPrice(ctx context.Context, tx *types.Transaction) (*types.Transaction, error) {
opts := &bind.TransactOpts{
From: d.cfg.From,
Signer: d.cfg.SignerFn,
Signer: func(addr common.Address, tx *types.Transaction) (*types.Transaction, error) {
return d.cfg.SignerFn(ctx, addr, tx)
},
Context: ctx,
Nonce: new(big.Int).SetUint64(tx.Nonce()),
NoSend: true,
......
......@@ -15,8 +15,8 @@ import (
hdwallet "github.com/ethereum-optimism/go-ethereum-hdwallet"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
......@@ -161,13 +161,16 @@ func NewL2OutputSubmitter(
}
}
signer := func(chainID *big.Int) bind.SignerFn {
return opcrypto.PrivateKeySignerFn(l2OutputPrivKey, chainID)
signer := func(chainID *big.Int) SignerFn {
s := opcrypto.PrivateKeySignerFn(l2OutputPrivKey, chainID)
return func(_ context.Context, addr common.Address, tx *types.Transaction) (*types.Transaction, error) {
return s(addr, tx)
}
}
return NewL2OutputSubmitterWithSigner(cfg, crypto.PubkeyToAddress(l2OutputPrivKey.PublicKey), signer, gitVersion, l)
}
type SignerFactory func(chainID *big.Int) bind.SignerFn
type SignerFactory func(chainID *big.Int) SignerFn
func NewL2OutputSubmitterWithSigner(
cfg Config,
......
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