From 40009de36df9dc4cefc7ed1ab600970c122e5530 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 2 May 2024 20:40:05 +0800 Subject: [PATCH 01/11] Revert "feat(proposer): introduce `TxSender` for proposer (#723)" This reverts commit c71155e1fa2d0ba0359d36ab98d450855e022dfa. --- internal/docker/nodes/docker-compose.yml | 2 + internal/testutils/helper.go | 12 +-- internal/testutils/interfaces.go | 6 +- pkg/rpc/methods.go | 30 +++++++ proposer/proposer.go | 107 ++++++++--------------- proposer/proposer_test.go | 78 ----------------- 6 files changed, 76 insertions(+), 159 deletions(-) diff --git a/internal/docker/nodes/docker-compose.yml b/internal/docker/nodes/docker-compose.yml index bd0d48940..9587a07e6 100644 --- a/internal/docker/nodes/docker-compose.yml +++ b/internal/docker/nodes/docker-compose.yml @@ -1,3 +1,5 @@ +version: "3.9" + services: l1_node: container_name: l1_node diff --git a/internal/testutils/helper.go b/internal/testutils/helper.go index fffcb9dbf..b022471dc 100644 --- a/internal/testutils/helper.go +++ b/internal/testutils/helper.go @@ -31,17 +31,13 @@ import ( func (s *ClientTestSuite) ProposeInvalidTxListBytes(proposer Proposer) { invalidTxListBytes := RandomBytes(256) - for _, err := range proposer.ProposeTxLists(context.Background(), [][]byte{invalidTxListBytes}) { - s.Nil(err) - } + s.Nil(proposer.ProposeTxList(context.Background(), invalidTxListBytes, 1)) } func (s *ClientTestSuite) proposeEmptyBlockOp(ctx context.Context, proposer Proposer) { emptyTxListBytes, err := rlp.EncodeToBytes(types.Transactions{}) s.Nil(err) - for _, err := range proposer.ProposeTxLists(ctx, [][]byte{emptyTxListBytes}) { - s.Nil(err) - } + s.Nil(proposer.ProposeTxList(ctx, emptyTxListBytes, 0)) } func (s *ClientTestSuite) ProposeAndInsertEmptyBlocks( @@ -67,9 +63,7 @@ func (s *ClientTestSuite) ProposeAndInsertEmptyBlocks( encoded, err := rlp.EncodeToBytes(emptyTxs) s.Nil(err) - for _, err := range proposer.ProposeTxLists(context.Background(), [][]byte{encoded}) { - s.Nil(err) - } + s.Nil(proposer.ProposeTxList(context.Background(), encoded, 0)) s.ProposeInvalidTxListBytes(proposer) diff --git a/internal/testutils/interfaces.go b/internal/testutils/interfaces.go index 88a5602ab..fb1ff35a6 100644 --- a/internal/testutils/interfaces.go +++ b/internal/testutils/interfaces.go @@ -13,5 +13,9 @@ type BlobSyncer interface { type Proposer interface { utils.SubcommandApplication ProposeOp(ctx context.Context) error - ProposeTxLists(ctx context.Context, txListsBytes [][]byte) []error + ProposeTxList( + ctx context.Context, + txListBytes []byte, + txNum uint, + ) error } diff --git a/pkg/rpc/methods.go b/pkg/rpc/methods.go index b5af64a34..a7112102f 100644 --- a/pkg/rpc/methods.go +++ b/pkg/rpc/methods.go @@ -724,3 +724,33 @@ func (c *Client) GetTaikoDataSlotBByNumber(ctx context.Context, number uint64) ( return nil, fmt.Errorf("failed to get state variables by block number %d", number) } + +// WaitL1NewPendingTransaction waits until the L1 account has a new pending transaction. +func (c *Client) WaitL1NewPendingTransaction( + ctx context.Context, + address common.Address, + oldPendingNonce uint64, +) error { + ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, defaultTimeout) + defer cancel() + + ticker := time.NewTicker(rpcPollingInterval) + defer ticker.Stop() + + for ; true; <-ticker.C { + if ctxWithTimeout.Err() != nil { + return ctxWithTimeout.Err() + } + + nonce, err := c.L1.PendingNonceAt(ctxWithTimeout, address) + if err != nil { + return err + } + + if nonce != oldPendingNonce { + break + } + } + + return nil +} diff --git a/proposer/proposer.go b/proposer/proposer.go index cbbcbf6fd..39c3c9206 100644 --- a/proposer/proposer.go +++ b/proposer/proposer.go @@ -5,11 +5,9 @@ import ( "context" "fmt" "math/rand" - "strings" "sync" "time" - "github.com/ethereum-optimism/optimism/op-challenger/sender" "github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" @@ -60,7 +58,7 @@ type Proposer struct { lastProposedAt time.Time - txSender *sender.TxSender + txmgr *txmgr.SimpleTxManager ctx context.Context wg sync.WaitGroup @@ -104,16 +102,14 @@ func (p *Proposer) InitFromConfig(ctx context.Context, cfg *Config) (err error) return err } - txmgr, err := txmgr.NewSimpleTxManager( + if p.txmgr, err = txmgr.NewSimpleTxManager( "proposer", log.Root(), &metrics.TxMgrMetrics, *cfg.TxmgrConfigs, - ) - if err != nil { + ); err != nil { return err } - p.txSender = sender.NewTxSender(p.ctx, log.Root(), txmgr, p.Config.MaxProposedTxListsPerEpoch) if p.proverSelector, err = selector.NewETHFeeEOASelector( &protocolConfigs, @@ -277,10 +273,7 @@ func (p *Proposer) fetchPoolContent(filterPoolContent bool) ([]types.Transaction // and then proposing them to TaikoL1 contract. func (p *Proposer) ProposeOp(ctx context.Context) error { // Check if it's time to propose unfiltered pool content. - var ( - filterPoolContent = time.Now().Before(p.lastProposedAt.Add(p.MinProposingInternal)) - txListsBytes = make([][]byte, 0) - ) + filterPoolContent := time.Now().Before(p.lastProposedAt.Add(p.MinProposingInternal)) // Wait until L2 execution engine is synced at first. if err := p.rpc.WaitTillL2ExecutionEngineSynced(ctx); err != nil { @@ -293,7 +286,6 @@ func (p *Proposer) ProposeOp(ctx context.Context) error { "lastProposedAt", p.lastProposedAt, ) - // Fetch the pool content with the given limits. txLists, err := p.fetchPoolContent(filterPoolContent) if err != nil { return err @@ -315,81 +307,54 @@ func (p *Proposer) ProposeOp(ctx context.Context) error { return fmt.Errorf("failed to encode transactions: %w", err) } - txListsBytes = append(txListsBytes, txListBytes) - } - - for i, err := range p.ProposeTxLists(ctx, txListsBytes) { - if err != nil { - log.Error( - "Failed to send TaikoL1.proposeBlock transaction", - "index", i, - "error", err, - ) - continue + if err := p.ProposeTxList(ctx, txListBytes, uint(txs.Len())); err != nil { + return fmt.Errorf("failed to send TaikoL1.proposeBlock transactions: %w", err) } - metrics.ProposerProposedTxListsCounter.Add(1) - metrics.ProposerProposedTxsCounter.Add(float64(len(txLists[i]))) - - log.Info("📝 Propose transactions succeeded", "txs", len(txLists[i])) p.lastProposedAt = time.Now() } return nil } -// ProposeTxLists proposes the given transaction lists to TaikoL1 contract. -func (p *Proposer) ProposeTxLists(ctx context.Context, txListsBytes [][]byte) []error { - txCandidates := make([]txmgr.TxCandidate, 0) - - for i, txListBytes := range txListsBytes { - compressedTxListBytes, err := utils.Compress(txListBytes) - if err != nil { - log.Error("Failed to compress transactions list", "index", i, "error", err) - break - } +// ProposeTxList proposes the given transactions list to TaikoL1 smart contract. +func (p *Proposer) ProposeTxList( + ctx context.Context, + txListBytes []byte, + txNum uint, +) error { + compressedTxListBytes, err := utils.Compress(txListBytes) + if err != nil { + return err + } - candidate, err := p.txBuilder.Build( - ctx, - p.tierFees, - p.IncludeParentMetaHash, - compressedTxListBytes, - ) - if err != nil { - log.Error("Failed to build TaikoL1.proposeBlock transaction", "error", err) - break - } + txCandidate, err := p.txBuilder.Build( + ctx, + p.tierFees, + p.IncludeParentMetaHash, + compressedTxListBytes, + ) + if err != nil { + log.Warn("Failed to build TaikoL1.proposeBlock transaction", "error", encoding.TryParsingCustomError(err)) + return err + } - txCandidates = append(txCandidates, *candidate) + receipt, err := p.txmgr.Send(p.ctx, *txCandidate) + if err != nil { + log.Warn("Failed to send TaikoL1.proposeBlock transaction", "error", encoding.TryParsingCustomError(err)) + return err } - if len(txCandidates) == 0 { - return []error{} + if receipt.Status != types.ReceiptStatusSuccessful { + return fmt.Errorf("failed to propose block: %s", receipt.TxHash.Hex()) } - // Send the transactions to the TaikoL1 contract, and if any of them fails, try - // to parse the custom error. - errors := p.txSender.SendAndWaitDetailed("proposeBlock", txCandidates...) - for i, err := range errors { - if err == nil { - continue - } + log.Info("📝 Propose transactions succeeded", "txs", txNum) - // If a transaction is reverted on chain, the error string returned by txSender will like this: - // fmt.Errorf("%w purpose: %v hash: %v", ErrTransactionReverted, txPurpose, rcpt.Receipt.TxHash) - // Then we try parsing the custom error for more details in log. - if strings.Contains(err.Error(), "purpose: ") && strings.Contains(err.Error(), "hash: ") { - txHash := strings.Split(err.Error(), "hash: ")[1] - receipt, err := p.rpc.L1.TransactionReceipt(ctx, common.HexToHash(txHash)) - if err != nil { - log.Error("Failed to fetch receipt", "txHash", txHash, "error", err) - continue - } - errors[i] = encoding.TryParsingCustomErrorFromReceipt(ctx, p.rpc.L1, p.proposerAddress, receipt) - } - } + metrics.ProposerProposedTxListsCounter.Add(1) + metrics.ProposerProposedTxsCounter.Add(float64(txNum)) - return errors + return nil } // updateProposingTicker updates the internal proposing timer. diff --git a/proposer/proposer_test.go b/proposer/proposer_test.go index 1db83e881..557ef2608 100644 --- a/proposer/proposer_test.go +++ b/proposer/proposer_test.go @@ -3,11 +3,9 @@ package proposer import ( "context" "os" - "strings" "testing" "time" - "github.com/ethereum-optimism/optimism/op-service/eth" "github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" @@ -19,7 +17,6 @@ import ( "github.com/stretchr/testify/suite" "github.com/taikoxyz/taiko-client/bindings" - "github.com/taikoxyz/taiko-client/bindings/encoding" "github.com/taikoxyz/taiko-client/driver/chain_syncer/beaconsync" "github.com/taikoxyz/taiko-client/driver/chain_syncer/blob" "github.com/taikoxyz/taiko-client/driver/state" @@ -28,7 +25,6 @@ import ( "github.com/taikoxyz/taiko-client/internal/utils" "github.com/taikoxyz/taiko-client/pkg/jwt" "github.com/taikoxyz/taiko-client/pkg/rpc" - builder "github.com/taikoxyz/taiko-client/proposer/transaction_builder" ) type ProposerTestSuite struct { @@ -289,80 +285,6 @@ func (s *ProposerTestSuite) TestAssignProverSuccessFirstRound() { s.Equal(fee.Uint64(), s.p.OptimisticTierFee.Uint64()) } -func (s *ProposerTestSuite) TestProposeTxLists() { - p := s.p - ctx := p.ctx - cfg := s.p.Config - - txBuilder := builder.NewBlobTransactionBuilder( - p.rpc, - p.L1ProposerPrivKey, - p.proverSelector, - p.Config.L1BlockBuilderTip, - cfg.TaikoL1Address, - cfg.L2SuggestedFeeRecipient, - cfg.AssignmentHookAddress, - cfg.ProposeBlockTxGasLimit, - cfg.ExtraData, - ) - - emptyTxListBytes, err := rlp.EncodeToBytes(types.Transactions{}) - s.Nil(err) - txListsBytes := [][]byte{emptyTxListBytes} - txCandidates := make([]txmgr.TxCandidate, len(txListsBytes)) - for i, txListBytes := range txListsBytes { - compressedTxListBytes, err := utils.Compress(txListBytes) - if err != nil { - log.Warn("Failed to compress transactions list", "index", i, "error", err) - break - } - - candidate, err := txBuilder.Build( - p.ctx, - p.tierFees, - p.IncludeParentMetaHash, - compressedTxListBytes, - ) - if err != nil { - log.Warn("Failed to build TaikoL1.proposeBlock transaction", "error", err) - break - } - - // trigger the error - candidate.Blobs = []*eth.Blob{} - candidate.GasLimit = 10000000 - - txCandidates[i] = *candidate - } - - // Send the transactions to the TaikoL1 contract, and if any of them fails, try - // to parse the custom error. - errors := p.txSender.SendAndWaitDetailed("proposeBlock", txCandidates...) - for i, err := range errors { - if err == nil { - continue - } - - // If a transaction is reverted on chain, the error string returned by txSender will like this: - // fmt.Errorf("%w purpose: %v hash: %v", ErrTransactionReverted, txPurpose, rcpt.Receipt.TxHash) - // Then we try parsing the custom error for more details in log. - if strings.Contains(err.Error(), "purpose: ") && strings.Contains(err.Error(), "hash: ") { - txHash := strings.Split(err.Error(), "hash: ")[1] - receipt, err := p.rpc.L1.TransactionReceipt(ctx, common.HexToHash(txHash)) - if err != nil { - log.Error("Failed to fetch receipt", "txHash", txHash, "error", err) - continue - } - errors[i] = encoding.TryParsingCustomErrorFromReceipt(ctx, p.rpc.L1, p.proposerAddress, receipt) - } - } - - // confirm errors handled - for _, err := range errors { - s.Equal("L1_BLOB_NOT_AVAILABLE", err.Error()) - } -} - func (s *ProposerTestSuite) TestUpdateProposingTicker() { s.p.ProposeInterval = 1 * time.Hour s.NotPanics(s.p.updateProposingTicker) From 804f78ec9c4c1f7f659d768e4de66963fb251a8d Mon Sep 17 00:00:00 2001 From: David Date: Thu, 2 May 2024 20:49:05 +0800 Subject: [PATCH 02/11] feat(proposer): improve `ProposeOp` --- proposer/proposer.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/proposer/proposer.go b/proposer/proposer.go index 39c3c9206..9b3d755da 100644 --- a/proposer/proposer.go +++ b/proposer/proposer.go @@ -16,6 +16,7 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" "github.com/urfave/cli/v2" + "golang.org/x/sync/errgroup" "github.com/taikoxyz/taiko-client/bindings" "github.com/taikoxyz/taiko-client/bindings/encoding" @@ -296,6 +297,7 @@ func (p *Proposer) ProposeOp(ctx context.Context) error { return nil } + g, ctx := errgroup.WithContext(ctx) // Propose all L2 transactions lists. for i, txs := range txLists { if i >= int(p.MaxProposedTxListsPerEpoch) { @@ -307,14 +309,25 @@ func (p *Proposer) ProposeOp(ctx context.Context) error { return fmt.Errorf("failed to encode transactions: %w", err) } - if err := p.ProposeTxList(ctx, txListBytes, uint(txs.Len())); err != nil { - return fmt.Errorf("failed to send TaikoL1.proposeBlock transactions: %w", err) + nonce, err := p.rpc.L1.PendingNonceAt(ctx, p.proposerAddress) + if err != nil { + return fmt.Errorf("failed to get proposer nonce: %w", err) } - p.lastProposedAt = time.Now() + g.Go(func() error { + if err := p.ProposeTxList(ctx, txListBytes, uint(txs.Len())); err != nil { + return err + } + p.lastProposedAt = time.Now() + return nil + }) + + if err := p.rpc.WaitL1NewPendingTransaction(ctx, p.proposerAddress, nonce); err != nil { + log.Error("Failed to wait for new pending transaction", "error", err) + } } - return nil + return g.Wait() } // ProposeTxList proposes the given transactions list to TaikoL1 smart contract. From 1f2faa248d801ca6ee8258ec80dc96c81128b7fe Mon Sep 17 00:00:00 2001 From: David Date: Thu, 2 May 2024 20:50:49 +0800 Subject: [PATCH 03/11] feat: update docker-compose --- internal/docker/nodes/docker-compose.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/docker/nodes/docker-compose.yml b/internal/docker/nodes/docker-compose.yml index 9587a07e6..bd0d48940 100644 --- a/internal/docker/nodes/docker-compose.yml +++ b/internal/docker/nodes/docker-compose.yml @@ -1,5 +1,3 @@ -version: "3.9" - services: l1_node: container_name: l1_node From d84c8455bd328d8ce31159d705e6d33b37b07378 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 2 May 2024 20:54:35 +0800 Subject: [PATCH 04/11] feat: update tests --- proposer/proposer_test.go | 61 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/proposer/proposer_test.go b/proposer/proposer_test.go index 557ef2608..98f12fc64 100644 --- a/proposer/proposer_test.go +++ b/proposer/proposer_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/ethereum-optimism/optimism/op-service/eth" "github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" @@ -17,6 +18,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/taikoxyz/taiko-client/bindings" + "github.com/taikoxyz/taiko-client/bindings/encoding" "github.com/taikoxyz/taiko-client/driver/chain_syncer/beaconsync" "github.com/taikoxyz/taiko-client/driver/chain_syncer/blob" "github.com/taikoxyz/taiko-client/driver/state" @@ -25,6 +27,7 @@ import ( "github.com/taikoxyz/taiko-client/internal/utils" "github.com/taikoxyz/taiko-client/pkg/jwt" "github.com/taikoxyz/taiko-client/pkg/rpc" + builder "github.com/taikoxyz/taiko-client/proposer/transaction_builder" ) type ProposerTestSuite struct { @@ -135,6 +138,64 @@ func parseTxs(client *rpc.Client, event *bindings.TaikoL1ClientBlockProposed) (t var txs types.Transactions return txs, rlp.DecodeBytes(txListBytes, &txs) } +func (s *ProposerTestSuite) TestProposeTxLists() { + p := s.p + ctx := p.ctx + cfg := s.p.Config + + txBuilder := builder.NewBlobTransactionBuilder( + p.rpc, + p.L1ProposerPrivKey, + p.proverSelector, + p.Config.L1BlockBuilderTip, + cfg.TaikoL1Address, + cfg.L2SuggestedFeeRecipient, + cfg.AssignmentHookAddress, + cfg.ProposeBlockTxGasLimit, + cfg.ExtraData, + ) + + emptyTxListBytes, err := rlp.EncodeToBytes(types.Transactions{}) + s.Nil(err) + txListsBytes := [][]byte{emptyTxListBytes} + txCandidates := make([]txmgr.TxCandidate, len(txListsBytes)) + for i, txListBytes := range txListsBytes { + compressedTxListBytes, err := utils.Compress(txListBytes) + if err != nil { + log.Warn("Failed to compress transactions list", "index", i, "error", err) + break + } + + candidate, err := txBuilder.Build( + p.ctx, + p.tierFees, + p.IncludeParentMetaHash, + compressedTxListBytes, + ) + if err != nil { + log.Warn("Failed to build TaikoL1.proposeBlock transaction", "error", err) + break + } + + // trigger the error + candidate.Blobs = []*eth.Blob{} + candidate.GasLimit = 10000000 + + txCandidates[i] = *candidate + } + + var errors []error + for _, txCandidate := range txCandidates { + receipt, err := p.txmgr.Send(ctx, txCandidate) + s.Nil(err) + errors = append(errors, encoding.TryParsingCustomErrorFromReceipt(ctx, p.rpc.L1, p.proposerAddress, receipt)) + } + + // confirm errors handled + for _, err := range errors { + s.Equal("L1_BLOB_NOT_AVAILABLE", err.Error()) + } +} func (s *ProposerTestSuite) getLatestProposedTxs( n int, From 158dfcca690f4f87c610947e2a9ebdef558377b2 Mon Sep 17 00:00:00 2001 From: maskpp Date: Thu, 2 May 2024 21:29:39 +0800 Subject: [PATCH 05/11] upgrade logic --- proposer/proposer.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/proposer/proposer.go b/proposer/proposer.go index 9b3d755da..4eb82ce52 100644 --- a/proposer/proposer.go +++ b/proposer/proposer.go @@ -297,25 +297,24 @@ func (p *Proposer) ProposeOp(ctx context.Context) error { return nil } - g, ctx := errgroup.WithContext(ctx) + g, gCtx := errgroup.WithContext(ctx) // Propose all L2 transactions lists. - for i, txs := range txLists { - if i >= int(p.MaxProposedTxListsPerEpoch) { - return nil - } - - txListBytes, err := rlp.EncodeToBytes(txs) - if err != nil { - return fmt.Errorf("failed to encode transactions: %w", err) - } + for _, txs := range txLists[:utils.Min(p.MaxProposedTxListsPerEpoch, uint64(len(txLists)-1))] { - nonce, err := p.rpc.L1.PendingNonceAt(ctx, p.proposerAddress) + var nonce uint64 + nonce, err = p.rpc.L1.PendingNonceAt(ctx, p.proposerAddress) if err != nil { - return fmt.Errorf("failed to get proposer nonce: %w", err) + err = fmt.Errorf("failed to get proposer nonce: %w", err) + break } + txs := txs g.Go(func() error { - if err := p.ProposeTxList(ctx, txListBytes, uint(txs.Len())); err != nil { + txListBytes, err := rlp.EncodeToBytes(txs) + if err != nil { + return fmt.Errorf("failed to encode transactions: %w", err) + } + if err := p.ProposeTxList(gCtx, txListBytes, uint(txs.Len())); err != nil { return err } p.lastProposedAt = time.Now() @@ -326,8 +325,11 @@ func (p *Proposer) ProposeOp(ctx context.Context) error { log.Error("Failed to wait for new pending transaction", "error", err) } } + if gErr := g.Wait(); gErr != nil { + return gErr + } - return g.Wait() + return err } // ProposeTxList proposes the given transactions list to TaikoL1 smart contract. From 4a8dbbb36b5cc3768e33bce6a30bba8b8cbca472 Mon Sep 17 00:00:00 2001 From: maskpp Date: Thu, 2 May 2024 21:49:42 +0800 Subject: [PATCH 06/11] upgrade logic --- proposer/proposer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposer/proposer.go b/proposer/proposer.go index 4eb82ce52..b9d026166 100644 --- a/proposer/proposer.go +++ b/proposer/proposer.go @@ -354,7 +354,7 @@ func (p *Proposer) ProposeTxList( return err } - receipt, err := p.txmgr.Send(p.ctx, *txCandidate) + receipt, err := p.txmgr.Send(ctx, *txCandidate) if err != nil { log.Warn("Failed to send TaikoL1.proposeBlock transaction", "error", encoding.TryParsingCustomError(err)) return err From 65122f9caca50334b6ead2e69af21229eac650ba Mon Sep 17 00:00:00 2001 From: maskpp Date: Thu, 2 May 2024 21:51:51 +0800 Subject: [PATCH 07/11] fix lint --- proposer/proposer.go | 1 - 1 file changed, 1 deletion(-) diff --git a/proposer/proposer.go b/proposer/proposer.go index b9d026166..a7f3ac1fa 100644 --- a/proposer/proposer.go +++ b/proposer/proposer.go @@ -300,7 +300,6 @@ func (p *Proposer) ProposeOp(ctx context.Context) error { g, gCtx := errgroup.WithContext(ctx) // Propose all L2 transactions lists. for _, txs := range txLists[:utils.Min(p.MaxProposedTxListsPerEpoch, uint64(len(txLists)-1))] { - var nonce uint64 nonce, err = p.rpc.L1.PendingNonceAt(ctx, p.proposerAddress) if err != nil { From 89acb3a40cd04b64eb2d4ae96d12b2ecfcb6776c Mon Sep 17 00:00:00 2001 From: David Date: Fri, 3 May 2024 12:14:15 +0800 Subject: [PATCH 08/11] feat: update code --- proposer/proposer.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/proposer/proposer.go b/proposer/proposer.go index a7f3ac1fa..694a207a1 100644 --- a/proposer/proposer.go +++ b/proposer/proposer.go @@ -300,14 +300,12 @@ func (p *Proposer) ProposeOp(ctx context.Context) error { g, gCtx := errgroup.WithContext(ctx) // Propose all L2 transactions lists. for _, txs := range txLists[:utils.Min(p.MaxProposedTxListsPerEpoch, uint64(len(txLists)-1))] { - var nonce uint64 - nonce, err = p.rpc.L1.PendingNonceAt(ctx, p.proposerAddress) + nonce, err := p.rpc.L1.PendingNonceAt(ctx, p.proposerAddress) if err != nil { - err = fmt.Errorf("failed to get proposer nonce: %w", err) + log.Error("Failed to get proposer nonce", "error", err) break } - txs := txs g.Go(func() error { txListBytes, err := rlp.EncodeToBytes(txs) if err != nil { @@ -324,11 +322,11 @@ func (p *Proposer) ProposeOp(ctx context.Context) error { log.Error("Failed to wait for new pending transaction", "error", err) } } - if gErr := g.Wait(); gErr != nil { - return gErr + if err := g.Wait(); err != nil { + return err } - return err + return nil } // ProposeTxList proposes the given transactions list to TaikoL1 smart contract. From 4a3a530bd82acc562b1d45827b2f2e3d07630783 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 3 May 2024 12:41:09 +0800 Subject: [PATCH 09/11] fix a bug --- proposer/proposer.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/proposer/proposer.go b/proposer/proposer.go index 694a207a1..d186e8262 100644 --- a/proposer/proposer.go +++ b/proposer/proposer.go @@ -299,13 +299,15 @@ func (p *Proposer) ProposeOp(ctx context.Context) error { g, gCtx := errgroup.WithContext(ctx) // Propose all L2 transactions lists. - for _, txs := range txLists[:utils.Min(p.MaxProposedTxListsPerEpoch, uint64(len(txLists)-1))] { + for _, txs := range txLists[:utils.Min(p.MaxProposedTxListsPerEpoch, uint64(len(txLists)))-1] { nonce, err := p.rpc.L1.PendingNonceAt(ctx, p.proposerAddress) if err != nil { log.Error("Failed to get proposer nonce", "error", err) break } + log.Debug("Proposer current pending nonce", "nonce", nonce) + g.Go(func() error { txListBytes, err := rlp.EncodeToBytes(txs) if err != nil { From 4b37a0de346c36ac17a8f073cf02a5095314617a Mon Sep 17 00:00:00 2001 From: David Date: Fri, 3 May 2024 12:48:11 +0800 Subject: [PATCH 10/11] fix a bug --- proposer/proposer.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proposer/proposer.go b/proposer/proposer.go index d186e8262..3e2d231d2 100644 --- a/proposer/proposer.go +++ b/proposer/proposer.go @@ -299,14 +299,14 @@ func (p *Proposer) ProposeOp(ctx context.Context) error { g, gCtx := errgroup.WithContext(ctx) // Propose all L2 transactions lists. - for _, txs := range txLists[:utils.Min(p.MaxProposedTxListsPerEpoch, uint64(len(txLists)))-1] { + for _, txs := range txLists[:utils.Min(p.MaxProposedTxListsPerEpoch, uint64(len(txLists)))] { nonce, err := p.rpc.L1.PendingNonceAt(ctx, p.proposerAddress) if err != nil { log.Error("Failed to get proposer nonce", "error", err) break } - log.Debug("Proposer current pending nonce", "nonce", nonce) + log.Info("Proposer current pending nonce", "nonce", nonce) g.Go(func() error { txListBytes, err := rlp.EncodeToBytes(txs) From 0ea017f0bc75cc67d234f4c69929b07e2455329f Mon Sep 17 00:00:00 2001 From: David Date: Fri, 3 May 2024 13:32:18 +0800 Subject: [PATCH 11/11] test: fix tests --- driver/driver_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/driver/driver_test.go b/driver/driver_test.go index fe741b6dc..f74e09bf9 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -127,7 +127,6 @@ func (s *DriverTestSuite) TestCheckL1ReorgToHigherFork() { // Reorg back to l2Head1 s.RevertL1Snapshot(testnetL1SnapshotID) - s.IncreaseTime(uint64((3 * time.Second).Seconds())) s.InitProposer() // Because of evm_revert operation, the nonce of the proposer need to be adjusted.