Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat(repo): introduce txmgr package (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Mar 25, 2024
1 parent 6fe4dda commit ba65882
Show file tree
Hide file tree
Showing 45 changed files with 807 additions and 2,010 deletions.
5 changes: 5 additions & 0 deletions bindings/encoding/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ var (
var (
TaikoL1ABI *abi.ABI
TaikoL2ABI *abi.ABI
TaikoTokenABI *abi.ABI
GuardianProverABI *abi.ABI
LibDepositingABI *abi.ABI
LibProposingABI *abi.ABI
Expand All @@ -264,6 +265,10 @@ func init() {
log.Crit("Get TaikoL2 ABI error", "error", err)
}

if TaikoTokenABI, err = bindings.TaikoTokenMetaData.GetAbi(); err != nil {
log.Crit("Get TaikoToken ABI error", "error", err)
}

if GuardianProverABI, err = bindings.GuardianProverMetaData.GetAbi(); err != nil {
log.Crit("Get GuardianProver ABI error", "error", err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/flags/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var (
driverCategory = "DRIVER"
proposerCategory = "PROPOSER"
proverCategory = "PROVER"
txmgrCategory = "TX_MANAGER"
)

// Required flags used by all client software.
Expand Down Expand Up @@ -112,7 +113,7 @@ var (
Name: "rpc.timeout",
Usage: "Timeout in seconds for RPC calls",
Category: commonCategory,
Value: 1 * time.Minute,
Value: 12 * time.Second,
}
WaitReceiptTimeout = &cli.DurationFlag{
Name: "rpc.waitReceiptTimeout",
Expand Down
23 changes: 2 additions & 21 deletions cmd/flags/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,29 +97,13 @@ var (
Value: 1,
Category: proposerCategory,
}
// Transaction related.
ProposeBlockTxGasLimit = &cli.Uint64Flag{
Name: "tx.gasLimit",
Usage: "Gas limit will be used for TaikoL1.proposeBlock transactions",
Category: proposerCategory,
}
ProposeBlockTxReplacementMultiplier = &cli.Uint64Flag{
Name: "tx.replacementMultiplier",
Value: 2,
Usage: "Gas tip multiplier when replacing a TaikoL1.proposeBlock transaction with same nonce",
Category: proposerCategory,
}
ProposeBlockTxGasTipCap = &cli.Uint64Flag{
Name: "tx.gasTipCap",
Usage: "Gas tip cap (in wei) for a TaikoL1.proposeBlock transaction when doing the transaction replacement",
Category: proposerCategory,
}
ProposeBlockIncludeParentMetaHash = &cli.BoolFlag{
Name: "includeParentMetaHash",
Usage: "Include parent meta hash when proposing block",
Value: false,
Category: proposerCategory,
}
// Transaction related.
BlobAllowed = &cli.BoolFlag{
Name: "l1.blobAllowed",
Usage: "Send EIP-4844 blob transactions when proposing blocks",
Expand All @@ -145,9 +129,6 @@ var ProposerFlags = MergeFlags(CommonFlags, []cli.Flag{
ExtraData,
ProposeEmptyBlocksInterval,
MaxProposedTxListsPerEpoch,
ProposeBlockTxGasLimit,
ProposeBlockTxReplacementMultiplier,
ProposeBlockTxGasTipCap,
ProverEndpoints,
OptimisticTierFee,
SgxTierFee,
Expand All @@ -157,4 +138,4 @@ var ProposerFlags = MergeFlags(CommonFlags, []cli.Flag{
ProposerAssignmentHookAddress,
BlobAllowed,
L1BlockBuilderTip,
})
}, TxmgrFlags)
29 changes: 1 addition & 28 deletions cmd/flags/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,29 +93,6 @@ var (
Value: 0 * time.Second,
Category: proverCategory,
}
// Transaction related.
ProofSubmissionMaxRetry = &cli.Uint64Flag{
Name: "tx.submissionMaxRetry",
Usage: "Max retry counts for proof submission",
Value: 3,
Category: proverCategory,
}
ProveBlockTxGasLimit = &cli.Uint64Flag{
Name: "tx.gasLimit",
Usage: "Gas limit will be used for TaikoL1.proveBlock transactions",
Category: proverCategory,
}
ProveBlockMaxTxGasFeeCap = &cli.Uint64Flag{
Name: "tx.maxGasFeeCap",
Usage: "Gas fee cap (in wei) for a TaikoL1.proveBlock transaction when doing the transaction replacement",
Category: proverCategory,
}
TxReplacementGasGrowthRate = &cli.Uint64Flag{
Name: "tx.replacementProveBlockGasGrowthRate",
Value: 50,
Usage: "Gas tip growth rate when replacing a TaikoL1.proveBlock transaction with same nonce",
Category: proverCategory,
}
// Running mode
ContesterMode = &cli.BoolFlag{
Name: "mode.contester",
Expand Down Expand Up @@ -211,13 +188,9 @@ var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{
GuardianProver,
GuardianProofSubmissionDelay,
GuardianProverHealthCheckServerEndpoint,
ProofSubmissionMaxRetry,
TxReplacementGasGrowthRate,
ProveBlockMaxTxGasFeeCap,
Graffiti,
ProveUnassignedBlocks,
ContesterMode,
ProveBlockTxGasLimit,
ProverHTTPServerPort,
ProverCapacity,
MaxExpiry,
Expand All @@ -229,4 +202,4 @@ var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{
L1NodeVersion,
L2NodeVersion,
BlockConfirmations,
})
}, TxmgrFlags)
92 changes: 92 additions & 0 deletions cmd/flags/txmgr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package flags

import (
"time"

"github.com/urfave/cli/v2"
)

var (
NumConfirmations = &cli.Uint64Flag{
Name: "tx.numConfirmations",
Usage: "Number of confirmations which we will wait after sending a transaction",
Value: 1,
Category: txmgrCategory,
}
SafeAbortNonceTooLowCount = cli.Uint64Flag{
Name: "tx.safeAbortNonceTooLowCount",
Usage: "Number of ErrNonceTooLow observations required to give up on " +
"a tx at a particular nonce without receiving confirmation",
Value: 3,
Category: txmgrCategory,
}
FeeLimitMultiplier = &cli.Uint64Flag{
Name: "tx.feeLimitMultiplier",
Usage: "The multiplier applied to fee suggestions to put a hard limit on fee increases",
Value: 10,
Category: txmgrCategory,
}
FeeLimitThreshold = &cli.Float64Flag{
Name: "tx.feeLimitThreshold",
Usage: "The minimum threshold (in GWei) at which fee bumping starts to be capped. " +
"Allows arbitrary fee bumps below this threshold.",
Value: 100.0,
Category: txmgrCategory,
}
MinTipCap = &cli.Float64Flag{
Name: "tx.minTipCap",
Usage: "Enforces a minimum tip cap (in GWei) to use when determining tx fees. 1 GWei by default.",
Value: 1.0,
Category: txmgrCategory,
}
MinBaseFee = &cli.Float64Flag{
Name: "tx.minBaseFee",
Usage: "Enforces a minimum base fee (in GWei) to assume when determining tx fees. 1 GWei by default.",
Value: 1.0,
Category: txmgrCategory,
}
ResubmissionTimeout = &cli.DurationFlag{
Name: "tx.resubmissionTimeout",
Usage: "Duration we will wait before resubmitting a transaction to L1",
Value: 48 * time.Second,
Category: txmgrCategory,
}
TxSendTimeout = &cli.DurationFlag{
Name: "tx.sendTimeout",
Usage: "Timeout for sending transactions. If 0 it is disabled.",
Value: 0,
Category: txmgrCategory,
}
TxNotInMempoolTimeout = &cli.DurationFlag{
Name: "tx.notInMempoolTimeout",
Usage: "Timeout for aborting a tx send if the tx does not make it to the mempool.",
Value: 2 * time.Minute,
Category: txmgrCategory,
}
ReceiptQueryInterval = &cli.DurationFlag{
Name: "tx.receiptQueryInterval",
Usage: "Frequency to poll for receipts",
Value: 12 * time.Second,
Category: txmgrCategory,
}
TxGasLimit = &cli.Uint64Flag{
Name: "tx.gasLimit",
Usage: "Gas limit will be used for transactions (0 means using gas estimation)",
Value: 0,
Category: txmgrCategory,
}
)

var TxmgrFlags = []cli.Flag{
NumConfirmations,
&SafeAbortNonceTooLowCount,
FeeLimitMultiplier,
FeeLimitThreshold,
MinTipCap,
MinBaseFee,
ResubmissionTimeout,
TxSendTimeout,
TxNotInMempoolTimeout,
ReceiptQueryInterval,
TxGasLimit,
}
79 changes: 49 additions & 30 deletions driver/chain_syncer/calldata/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"
"time"

"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -43,33 +44,7 @@ func (s *CalldataSyncerTestSuite) SetupTest() {
s.Nil(err)
s.s = syncer

prop := new(proposer.Proposer)
l1ProposerPrivKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_PROPOSER_PRIVATE_KEY")))
s.Nil(err)

s.Nil(prop.InitFromConfig(context.Background(), &proposer.Config{
ClientConfig: &rpc.ClientConfig{
L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"),
L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"),
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
},
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
L1ProposerPrivKey: l1ProposerPrivKey,
L2SuggestedFeeRecipient: common.HexToAddress(os.Getenv("L2_SUGGESTED_FEE_RECIPIENT")),
ProposeInterval: 1024 * time.Hour,
MaxProposedTxListsPerEpoch: 1,
WaitReceiptTimeout: 12 * time.Second,
ProverEndpoints: s.ProverEndpoints,
OptimisticTierFee: common.Big256,
SgxTierFee: common.Big256,
MaxTierFeePriceBumps: 3,
TierFeePriceBump: common.Big2,
L1BlockBuilderTip: common.Big0,
}))

s.p = prop
s.initProposer()
}
func (s *CalldataSyncerTestSuite) TestCancelNewSyncer() {
ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -222,7 +197,6 @@ func (s *CalldataSyncerTestSuite) TestRetrievePastBlock() {
5,
)
s.Nil(err)
sender := s.p.GetSender()

s.s = syncer
for i := 0; i < 10; i++ {
Expand All @@ -235,8 +209,8 @@ func (s *CalldataSyncerTestSuite) TestRetrievePastBlock() {
s.ProposeAndInsertValidBlock(s.p, s.s)
}
s.RevertL1Snapshot(l1Snapshot)
// Because of evm_revert operation, the nonce of the proposer need to be adjusted.
s.Nil(sender.SetNonce(nil, true))
s.initProposer()

// Propose 5 blocks on another fork
for i := 0; i < 5; i++ {
s.ProposeInvalidTxListBytes(s.p)
Expand All @@ -248,6 +222,51 @@ func (s *CalldataSyncerTestSuite) TestRetrievePastBlock() {
s.GreaterOrEqual(reorgResult.L1CurrentToReset.Number.Uint64(), genesisL1Header.Number.Uint64())
}

func (s *CalldataSyncerTestSuite) initProposer() {
prop := new(proposer.Proposer)
l1ProposerPrivKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_PROPOSER_PRIVATE_KEY")))
s.Nil(err)

s.Nil(prop.InitFromConfig(context.Background(), &proposer.Config{
ClientConfig: &rpc.ClientConfig{
L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"),
L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"),
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
},
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
L1ProposerPrivKey: l1ProposerPrivKey,
L2SuggestedFeeRecipient: common.HexToAddress(os.Getenv("L2_SUGGESTED_FEE_RECIPIENT")),
ProposeInterval: 1024 * time.Hour,
MaxProposedTxListsPerEpoch: 1,
WaitReceiptTimeout: 12 * time.Second,
ProverEndpoints: s.ProverEndpoints,
OptimisticTierFee: common.Big256,
SgxTierFee: common.Big256,
MaxTierFeePriceBumps: 3,
TierFeePriceBump: common.Big2,
L1BlockBuilderTip: common.Big0,
TxmgrConfigs: &txmgr.CLIConfig{
L1RPCURL: os.Getenv("L1_NODE_WS_ENDPOINT"),
NumConfirmations: 1,
SafeAbortNonceTooLowCount: txmgr.DefaultBatcherFlagValues.SafeAbortNonceTooLowCount,
PrivateKey: common.Bytes2Hex(crypto.FromECDSA(l1ProposerPrivKey)),
FeeLimitMultiplier: txmgr.DefaultBatcherFlagValues.FeeLimitMultiplier,
FeeLimitThresholdGwei: txmgr.DefaultBatcherFlagValues.FeeLimitThresholdGwei,
MinBaseFeeGwei: txmgr.DefaultBatcherFlagValues.MinBaseFeeGwei,
MinTipCapGwei: txmgr.DefaultBatcherFlagValues.MinTipCapGwei,
ResubmissionTimeout: txmgr.DefaultBatcherFlagValues.ResubmissionTimeout,
ReceiptQueryInterval: 1 * time.Second,
NetworkTimeout: txmgr.DefaultBatcherFlagValues.NetworkTimeout,
TxSendTimeout: txmgr.DefaultBatcherFlagValues.TxSendTimeout,
TxNotInMempoolTimeout: txmgr.DefaultBatcherFlagValues.TxNotInMempoolTimeout,
},
}))

s.p = prop
}

func TestCalldataSyncerTestSuite(t *testing.T) {
suite.Run(t, new(CalldataSyncerTestSuite))
}
16 changes: 16 additions & 0 deletions driver/chain_syncer/chain_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"time"

"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -69,6 +70,21 @@ func (s *ChainSyncerTestSuite) SetupTest() {
TierFeePriceBump: common.Big2,
ExtraData: "test",
L1BlockBuilderTip: common.Big0,
TxmgrConfigs: &txmgr.CLIConfig{
L1RPCURL: os.Getenv("L1_NODE_WS_ENDPOINT"),
NumConfirmations: 1,
SafeAbortNonceTooLowCount: txmgr.DefaultBatcherFlagValues.SafeAbortNonceTooLowCount,
PrivateKey: common.Bytes2Hex(crypto.FromECDSA(l1ProposerPrivKey)),
FeeLimitMultiplier: txmgr.DefaultBatcherFlagValues.FeeLimitMultiplier,
FeeLimitThresholdGwei: txmgr.DefaultBatcherFlagValues.FeeLimitThresholdGwei,
MinBaseFeeGwei: txmgr.DefaultBatcherFlagValues.MinBaseFeeGwei,
MinTipCapGwei: txmgr.DefaultBatcherFlagValues.MinTipCapGwei,
ResubmissionTimeout: txmgr.DefaultBatcherFlagValues.ResubmissionTimeout,
ReceiptQueryInterval: 1 * time.Second,
NetworkTimeout: txmgr.DefaultBatcherFlagValues.NetworkTimeout,
TxSendTimeout: txmgr.DefaultBatcherFlagValues.TxSendTimeout,
TxNotInMempoolTimeout: txmgr.DefaultBatcherFlagValues.TxNotInMempoolTimeout,
},
}))

s.p = prop
Expand Down
Loading

0 comments on commit ba65882

Please sign in to comment.