Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(taiko-client): add optional l1.private #17962

Merged
merged 7 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/taiko-client/cmd/flags/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ var (
Category: commonCategory,
EnvVars: []string{"L1_WS"},
}
L1PrivateTxEndpoint = &cli.StringFlag{
Name: "l1.privateTx",
YoGhurt111 marked this conversation as resolved.
Show resolved Hide resolved
Usage: "RPC endpoint of a L1 private tx ethereum node",
Category: commonCategory,
EnvVars: []string{"L1_PRIVATE_TX"},
YoGhurt111 marked this conversation as resolved.
Show resolved Hide resolved
}
L2WSEndpoint = &cli.StringFlag{
Name: "l2.ws",
Usage: "Websocket RPC endpoint of a L2 taiko-geth execution engine",
Expand Down Expand Up @@ -167,6 +173,7 @@ var CommonFlags = []cli.Flag{
BackOffMaxRetries,
BackOffRetryInterval,
RPCTimeout,
L1PrivateTxEndpoint,
}

// MergeFlags merges the given flag slices.
Expand Down
17 changes: 16 additions & 1 deletion packages/taiko-client/driver/chain_syncer/blob/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,22 @@ func (s *BlobSyncerTestSuite) initProposer() {
TxSendTimeout: txmgr.DefaultBatcherFlagValues.TxSendTimeout,
TxNotInMempoolTimeout: txmgr.DefaultBatcherFlagValues.TxNotInMempoolTimeout,
},
}, nil))
PrivateTxmgrConfigs: &txmgr.CLIConfig{
L1RPCURL: os.Getenv("L1_WS"),
NumConfirmations: 0,
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,
},
}, nil, nil))

s.p = prop
}
Expand Down
17 changes: 16 additions & 1 deletion packages/taiko-client/driver/chain_syncer/chain_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,22 @@ func (s *ChainSyncerTestSuite) SetupTest() {
TxSendTimeout: txmgr.DefaultBatcherFlagValues.TxSendTimeout,
TxNotInMempoolTimeout: txmgr.DefaultBatcherFlagValues.TxNotInMempoolTimeout,
},
}, nil))
PrivateTxmgrConfigs: &txmgr.CLIConfig{
L1RPCURL: os.Getenv("L1_WS"),
NumConfirmations: 0,
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,
},
}, nil, nil))

s.p = prop
}
Expand Down
17 changes: 16 additions & 1 deletion packages/taiko-client/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,22 @@ func (s *DriverTestSuite) InitProposer() {
TxSendTimeout: txmgr.DefaultBatcherFlagValues.TxSendTimeout,
TxNotInMempoolTimeout: txmgr.DefaultBatcherFlagValues.TxNotInMempoolTimeout,
},
}, nil))
PrivateTxmgrConfigs: &txmgr.CLIConfig{
L1RPCURL: os.Getenv("L1_WS"),
NumConfirmations: 0,
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,
},
}, nil, nil))
s.p = p
}

Expand Down
6 changes: 6 additions & 0 deletions packages/taiko-client/proposer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Config struct {
IncludeParentMetaHash bool
BlobAllowed bool
TxmgrConfigs *txmgr.CLIConfig
PrivateTxmgrConfigs *txmgr.CLIConfig
}

// NewConfigFromCliContext initializes a Config instance from
Expand Down Expand Up @@ -105,5 +106,10 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
l1ProposerPrivKey,
c,
),
PrivateTxmgrConfigs: pkgFlags.InitTxmgrConfigsFromCli(
c.String(flags.L1PrivateTxEndpoint.Name),
YoGhurt111 marked this conversation as resolved.
Show resolved Hide resolved
l1ProposerPrivKey,
c,
),
}, nil
}
58 changes: 48 additions & 10 deletions packages/taiko-client/proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ type Proposer struct {
lastProposedAt time.Time
totalEpochs uint64

txmgr *txmgr.SimpleTxManager
txmgr *txmgr.SimpleTxManager
privateTxmgr *txmgr.SimpleTxManager

ctx context.Context
wg sync.WaitGroup
Expand All @@ -64,11 +65,15 @@ func (p *Proposer) InitFromCli(ctx context.Context, c *cli.Context) error {
return err
}

return p.InitFromConfig(ctx, cfg, nil)
return p.InitFromConfig(ctx, cfg, nil, nil)
}

// InitFromConfig initializes the proposer instance based on the given configurations.
func (p *Proposer) InitFromConfig(ctx context.Context, cfg *Config, txMgr *txmgr.SimpleTxManager) (err error) {
func (p *Proposer) InitFromConfig(
ctx context.Context, cfg *Config,
txMgr *txmgr.SimpleTxManager,
privateTxMgr *txmgr.SimpleTxManager,
) (err error) {
p.proposerAddress = crypto.PubkeyToAddress(cfg.L1ProposerPrivKey.PublicKey)
p.ctx = ctx
p.Config = cfg
Expand Down Expand Up @@ -100,6 +105,22 @@ func (p *Proposer) InitFromConfig(ctx context.Context, cfg *Config, txMgr *txmgr
return err
}
}
if privateTxMgr != nil {
p.privateTxmgr = privateTxMgr
} else {
if cfg.PrivateTxmgrConfigs != nil && len(cfg.PrivateTxmgrConfigs.L1RPCURL) > 0 {
if p.privateTxmgr, err = txmgr.NewSimpleTxManager(
"privateTxProposer",
log.Root(),
&metrics.TxMgrMetrics,
*cfg.PrivateTxmgrConfigs,
); err != nil {
return err
}
} else {
p.privateTxmgr = nil
}
}

chainConfig := config.NewChainConfig(p.rpc.L2.ChainID, new(big.Int).SetUint64(p.protocolConfigs.OntakeForkHeight))

Expand Down Expand Up @@ -356,16 +377,10 @@ func (p *Proposer) ProposeTxList(
return err
}

receipt, err := p.txmgr.Send(ctx, *txCandidate)
if err != nil {
log.Warn("Failed to send TaikoL1.proposeBlock transaction", "error", encoding.TryParsingCustomError(err))
if err := p.sendTx(ctx, txCandidate); err != nil {
return err
}

if receipt.Status != types.ReceiptStatusSuccessful {
return fmt.Errorf("failed to propose block: %s", receipt.TxHash.Hex())
}

log.Info("📝 Propose transactions succeeded", "txs", txNum)

metrics.ProposerProposedTxListsCounter.Add(1)
Expand All @@ -392,6 +407,29 @@ func (p *Proposer) updateProposingTicker() {
p.proposingTimer = time.NewTimer(duration)
}

func (p *Proposer) sendTx(ctx context.Context, txCandidate *txmgr.TxCandidate) error {
if p.privateTxmgr != nil {
receipt, err := p.privateTxmgr.Send(ctx, *txCandidate)
if err != nil || receipt.Status != types.ReceiptStatusSuccessful {
log.Warn("Failed to send TaikoL1.proposeBlock transaction by private tx manager",
mask-pp marked this conversation as resolved.
Show resolved Hide resolved
"error", encoding.TryParsingCustomError(err),
)
} else {
return nil
}
}
receipt, err := p.txmgr.Send(ctx, *txCandidate)
if err != nil {
log.Warn("Failed to send TaikoL1.proposeBlock transaction", "error", encoding.TryParsingCustomError(err))
return err
}

if receipt.Status != types.ReceiptStatusSuccessful {
return fmt.Errorf("failed to propose block: %s", receipt.TxHash.Hex())
}
return nil
}

// Name returns the application name.
func (p *Proposer) Name() string {
return "proposer"
Expand Down
17 changes: 16 additions & 1 deletion packages/taiko-client/proposer/proposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,22 @@ func (s *ProposerTestSuite) SetupTest() {
TxSendTimeout: txmgr.DefaultBatcherFlagValues.TxSendTimeout,
TxNotInMempoolTimeout: txmgr.DefaultBatcherFlagValues.TxNotInMempoolTimeout,
},
}, nil))
PrivateTxmgrConfigs: &txmgr.CLIConfig{
L1RPCURL: os.Getenv("L1_WS"),
NumConfirmations: 0,
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,
},
}, nil, nil))

s.p = p
s.cancel = cancel
Expand Down
6 changes: 6 additions & 0 deletions packages/taiko-client/prover/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Config struct {
L2NodeVersion string
BlockConfirmations uint64
TxmgrConfigs *txmgr.CLIConfig
PrivateTxmgrConfigs *txmgr.CLIConfig
}

// NewConfigFromCliContext creates a new config instance from command line flags.
Expand Down Expand Up @@ -177,5 +178,10 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
l1ProverPrivKey,
c,
),
PrivateTxmgrConfigs: pkgFlags.InitTxmgrConfigsFromCli(
c.String(flags.L1PrivateTxEndpoint.Name),
l1ProverPrivKey,
c,
),
}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,22 @@ func (s *EventHandlerTestSuite) SetupTest() {
TxSendTimeout: txmgr.DefaultBatcherFlagValues.TxSendTimeout,
TxNotInMempoolTimeout: txmgr.DefaultBatcherFlagValues.TxNotInMempoolTimeout,
},
}, nil))
PrivateTxmgrConfigs: &txmgr.CLIConfig{
L1RPCURL: os.Getenv("L1_WS"),
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,
},
}, nil, nil))

s.proposer = prop
}
Expand Down
4 changes: 2 additions & 2 deletions packages/taiko-client/prover/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func (p *Prover) setApprovalAmount(ctx context.Context, contract common.Address)

// initProofSubmitters initializes the proof submitters from the given tiers in protocol.
func (p *Prover) initProofSubmitters(
txmgr *txmgr.SimpleTxManager,
txBuilder *transaction.ProveBlockTxBuilder,
tiers []*rpc.TierProviderTierWithID,
) error {
Expand Down Expand Up @@ -138,7 +137,8 @@ func (p *Prover) initProofSubmitters(
p.cfg.TaikoL2Address,
p.cfg.Graffiti,
p.cfg.ProveBlockGasLimit,
txmgr,
p.txmgr,
p.privateTxmgr,
txBuilder,
tiers,
p.IsGuardianProver(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ func NewProofContester(
rpcClient *rpc.Client,
gasLimit uint64,
txmgr *txmgr.SimpleTxManager,
privateTxmgr *txmgr.SimpleTxManager,
proverSetAddress common.Address,
graffiti string,
builder *transaction.ProveBlockTxBuilder,
) *ProofContester {
return &ProofContester{
rpc: rpcClient,
txBuilder: builder,
sender: transaction.NewSender(rpcClient, txmgr, proverSetAddress, gasLimit),
sender: transaction.NewSender(rpcClient, txmgr, privateTxmgr, proverSetAddress, gasLimit),
graffiti: rpc.StringToBytes32(graffiti),
}
}
Expand Down Expand Up @@ -93,7 +94,6 @@ func (c *ProofContester) SubmitContest(
if err != nil {
return err
}

return c.sender.Send(
ctx,
&proofProducer.ProofWithHeader{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func NewProofSubmitter(
graffiti string,
gasLimit uint64,
txmgr *txmgr.SimpleTxManager,
privateTxmgr *txmgr.SimpleTxManager,
builder *transaction.ProveBlockTxBuilder,
tiers []*rpc.TierProviderTierWithID,
isGuardian bool,
Expand All @@ -76,7 +77,7 @@ func NewProofSubmitter(
resultCh: resultCh,
anchorValidator: anchorValidator,
txBuilder: builder,
sender: transaction.NewSender(rpcClient, txmgr, proverSetAddress, gasLimit),
sender: transaction.NewSender(rpcClient, txmgr, privateTxmgr, proverSetAddress, gasLimit),
proverAddress: txmgr.From(),
proverSetAddress: proverSetAddress,
taikoL2Address: taikoL2Address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (s *ProofSubmitterTestSuite) SetupTest() {
"test",
0,
txMgr,
nil,
builder,
tiers,
false,
Expand All @@ -97,6 +98,7 @@ func (s *ProofSubmitterTestSuite) SetupTest() {
s.RPCClient,
0,
txMgr,
nil,
rpc.ZeroAddress,
"test",
builder,
Expand Down Expand Up @@ -137,7 +139,7 @@ func (s *ProofSubmitterTestSuite) SetupTest() {
L2SuggestedFeeRecipient: common.HexToAddress(os.Getenv("L2_SUGGESTED_FEE_RECIPIENT")),
ProposeInterval: 1024 * time.Hour,
MaxProposedTxListsPerEpoch: 1,
}, txMgr))
}, txMgr, txMgr))

s.proposer = prop
}
Expand Down Expand Up @@ -176,6 +178,7 @@ func (s *ProofSubmitterTestSuite) TestGetRandomBumpedSubmissionDelay() {
"test",
0,
txMgr,
nil,
s.submitter.txBuilder,
s.submitter.tiers,
false,
Expand All @@ -196,6 +199,7 @@ func (s *ProofSubmitterTestSuite) TestGetRandomBumpedSubmissionDelay() {
"test",
0,
txMgr,
nil,
s.submitter.txBuilder,
s.submitter.tiers,
false,
Expand Down
Loading
Loading