From 2e05351bce78320c9df8699e23064c6cd0a9aec2 Mon Sep 17 00:00:00 2001 From: maskpp Date: Tue, 14 Jan 2025 10:15:56 +0800 Subject: [PATCH 1/3] blob sync robustness test --- .../driver/chain_syncer/blob/syncer_test.go | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/packages/taiko-client/driver/chain_syncer/blob/syncer_test.go b/packages/taiko-client/driver/chain_syncer/blob/syncer_test.go index 5ac39a757e..6e6b2a90c6 100644 --- a/packages/taiko-client/driver/chain_syncer/blob/syncer_test.go +++ b/packages/taiko-client/driver/chain_syncer/blob/syncer_test.go @@ -8,10 +8,13 @@ import ( "time" "github.com/ethereum-optimism/optimism/op-service/txmgr" + "github.com/ethereum/go-ethereum/beacon/engine" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/consensus/taiko" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/rlp" "github.com/stretchr/testify/suite" "github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings" @@ -53,6 +56,98 @@ func (s *BlobSyncerTestSuite) SetupTest() { s.initProposer() } +func (s *BlobSyncerTestSuite) TestBlobCases() { + ctx := context.Background() + + meta := s.ProposeAndInsertValidBlock(s.p, s.s) + + block, err := s.RPCClient.L2.BlockByNumber(ctx, meta.GetBlockID()) + s.Nil(err) + + lastVerifiedBlockInfo, err := s.s.rpc.GetLastVerifiedBlock(ctx) + s.Nil(err) + + txListBytes, err := rlp.EncodeToBytes(block.Transactions()) + + parent, err := s.RPCClient.L2ParentByBlockID(context.Background(), meta.GetBlockID()) + s.Nil(err) + + // Reset l2 chain. + s.Nil(rpc.SetHead(ctx, s.RPCClient.L2, common.Big0)) + + attributes := &engine.PayloadAttributes{ + Timestamp: meta.GetTimestamp(), + Random: meta.GetDifficulty(), + SuggestedFeeRecipient: meta.GetCoinbase(), + Withdrawals: make([]*types.Withdrawal, 0), + BlockMetadata: &engine.BlockMetadata{ + Beneficiary: meta.GetCoinbase(), + GasLimit: uint64(meta.GetGasLimit()) + taiko.AnchorGasLimit, + Timestamp: meta.GetTimestamp(), + TxList: txListBytes, + MixHash: meta.GetDifficulty(), + ExtraData: meta.GetExtraData(), + }, + BaseFeePerGas: block.BaseFee(), + L1Origin: &rawdb.L1Origin{ + BlockID: meta.GetBlockID(), + L2BlockHash: common.Hash{}, // Will be set by taiko-geth. + L1BlockHeight: meta.GetRawBlockHeight(), + L1BlockHash: meta.GetRawBlockHash(), + }, + } + + step0 := func() *engine.ForkChoiceResponse { + fcRes, err := s.RPCClient.L2Engine.ForkchoiceUpdate( + ctx, + &engine.ForkchoiceStateV1{HeadBlockHash: parent.Hash()}, + attributes, + ) + s.Nil(err) + s.Equal(engine.VALID, fcRes.PayloadStatus.Status) + s.True(true, fcRes.PayloadID != nil) + return fcRes + } + + step1 := func(fcRes *engine.ForkChoiceResponse) *engine.ExecutableData { + payload, err := s.RPCClient.L2Engine.GetPayload(ctx, fcRes.PayloadID) + s.Nil(err) + return payload + } + + step2 := func(payload *engine.ExecutableData) *engine.ExecutableData { + execStatus, err := s.RPCClient.L2Engine.NewPayload(ctx, payload) + s.Nil(err) + s.Equal(engine.VALID, execStatus.Status) + return payload + } + + step3 := func(payload *engine.ExecutableData) { + fcRes, err := s.RPCClient.L2Engine.ForkchoiceUpdate(ctx, &engine.ForkchoiceStateV1{ + HeadBlockHash: payload.BlockHash, + SafeBlockHash: lastVerifiedBlockInfo.BlockHash, + FinalizedBlockHash: lastVerifiedBlockInfo.BlockHash, + }, nil) + s.Nil(err) + s.Equal(engine.VALID, fcRes.PayloadStatus.Status) + } + + loopSize := 10 + for i := 0; i < loopSize; i++ { + step0() + } + + for i := 0; i < loopSize; i++ { + step1(step0()) + } + + for i := 0; i < loopSize; i++ { + step2(step1(step0())) + } + + step3(step2(step1(step0()))) +} + func (s *BlobSyncerTestSuite) TestProcessL1Blocks() { s.Nil(s.s.ProcessL1Blocks(context.Background())) } From 6e77d64fa578e72030e7c58034afb5f8eeddf0a2 Mon Sep 17 00:00:00 2001 From: maskpp Date: Tue, 14 Jan 2025 10:16:11 +0800 Subject: [PATCH 2/3] blob sync robustness test --- packages/taiko-client/driver/chain_syncer/blob/syncer_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/taiko-client/driver/chain_syncer/blob/syncer_test.go b/packages/taiko-client/driver/chain_syncer/blob/syncer_test.go index 6e6b2a90c6..3f1d57a51b 100644 --- a/packages/taiko-client/driver/chain_syncer/blob/syncer_test.go +++ b/packages/taiko-client/driver/chain_syncer/blob/syncer_test.go @@ -56,7 +56,7 @@ func (s *BlobSyncerTestSuite) SetupTest() { s.initProposer() } -func (s *BlobSyncerTestSuite) TestBlobCases() { +func (s *BlobSyncerTestSuite) TestBlobSyncRobustness() { ctx := context.Background() meta := s.ProposeAndInsertValidBlock(s.p, s.s) From ea0fb5738e5987b8d7aef25f4d7f3c0fbf9e6313 Mon Sep 17 00:00:00 2001 From: maskpp Date: Tue, 14 Jan 2025 10:25:58 +0800 Subject: [PATCH 3/3] fix lint --- packages/taiko-client/driver/chain_syncer/blob/syncer_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/taiko-client/driver/chain_syncer/blob/syncer_test.go b/packages/taiko-client/driver/chain_syncer/blob/syncer_test.go index 3f1d57a51b..f9861b7f32 100644 --- a/packages/taiko-client/driver/chain_syncer/blob/syncer_test.go +++ b/packages/taiko-client/driver/chain_syncer/blob/syncer_test.go @@ -68,6 +68,7 @@ func (s *BlobSyncerTestSuite) TestBlobSyncRobustness() { s.Nil(err) txListBytes, err := rlp.EncodeToBytes(block.Transactions()) + s.Nil(err) parent, err := s.RPCClient.L2ParentByBlockID(context.Background(), meta.GetBlockID()) s.Nil(err)