From 085fd740a52c01d1364c81d1825043b1d525061c Mon Sep 17 00:00:00 2001 From: Maciej Skrzypkowski Date: Tue, 2 Jul 2024 14:46:41 +0200 Subject: [PATCH] parent meta hash for the GetL2TxLists --- packages/taiko-client/proposer/proposer.go | 16 +++++++++++++--- .../proposer/transaction_builder/blob.go | 2 +- .../proposer/transaction_builder/calldata.go | 2 +- .../proposer/transaction_builder/common.go | 4 ++-- .../proposer/transaction_builder/common_test.go | 2 +- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/taiko-client/proposer/proposer.go b/packages/taiko-client/proposer/proposer.go index 460f5bef73..cc045c1b46 100644 --- a/packages/taiko-client/proposer/proposer.go +++ b/packages/taiko-client/proposer/proposer.go @@ -175,8 +175,9 @@ type Args struct { } type RPCReplyL2TxLists struct { - TxLists []types.Transactions - TxListBytes [][]byte + TxLists []types.Transactions + TxListBytes [][]byte + ParentMetaHash common.Hash } type CustomResponse struct { @@ -198,7 +199,13 @@ func (p *RPC) GetL2TxLists(_ *http.Request, _ *Args, reply *RPCReplyL2TxLists) e if len(txLists) == 1 { log.Info("Single L2 txList", "txList", txLists[0]) } - *reply = RPCReplyL2TxLists{TxLists: txLists, TxListBytes: compressedTxLists} + + parentMetaHash, err := builder.GetParentMetaHash(p.proposer.ctx, p.proposer.rpc) + if err != nil { + return err + } + + *reply = RPCReplyL2TxLists{TxLists: txLists, TxListBytes: compressedTxLists, ParentMetaHash: parentMetaHash} return nil } @@ -452,6 +459,9 @@ func (p *Proposer) ProposeOpForTakingL2Blocks(ctx context.Context) ([]types.Tran } compressedTxLists := [][]byte{} + if err != nil { + return nil, nil, fmt.Errorf("failed to get parent meta hash: %w", err) + } //TODO adjust the Max value for _, txs := range txLists[:utils.Min(p.MaxProposedTxListsPerEpoch, uint64(len(txLists)))] { diff --git a/packages/taiko-client/proposer/transaction_builder/blob.go b/packages/taiko-client/proposer/transaction_builder/blob.go index 278d6e810e..18fa977d36 100644 --- a/packages/taiko-client/proposer/transaction_builder/blob.go +++ b/packages/taiko-client/proposer/transaction_builder/blob.go @@ -87,7 +87,7 @@ func (b *BlobTransactionBuilder) Build( // If the current proposer wants to include the parent meta hash, then fetch it from the protocol. var parentMetaHash = [32]byte{} if includeParentMetaHash { - if parentMetaHash, err = getParentMetaHash(ctx, b.rpc); err != nil { + if parentMetaHash, err = GetParentMetaHash(ctx, b.rpc); err != nil { return nil, err } } diff --git a/packages/taiko-client/proposer/transaction_builder/calldata.go b/packages/taiko-client/proposer/transaction_builder/calldata.go index a701e5da02..120d227e10 100644 --- a/packages/taiko-client/proposer/transaction_builder/calldata.go +++ b/packages/taiko-client/proposer/transaction_builder/calldata.go @@ -73,7 +73,7 @@ func (b *CalldataTransactionBuilder) Build( // If the current proposer wants to include the parent meta hash, then fetch it from the protocol. var parentMetaHash = [32]byte{} if includeParentMetaHash { - if parentMetaHash, err = getParentMetaHash(ctx, b.rpc); err != nil { + if parentMetaHash, err = GetParentMetaHash(ctx, b.rpc); err != nil { return nil, err } } diff --git a/packages/taiko-client/proposer/transaction_builder/common.go b/packages/taiko-client/proposer/transaction_builder/common.go index e3898d1100..f3e198bd58 100644 --- a/packages/taiko-client/proposer/transaction_builder/common.go +++ b/packages/taiko-client/proposer/transaction_builder/common.go @@ -10,8 +10,8 @@ import ( "github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/rpc" ) -// getParentMetaHash returns the meta hash of the parent block of the latest proposed block in protocol. -func getParentMetaHash(ctx context.Context, rpc *rpc.Client) (common.Hash, error) { +// GetParentMetaHash returns the meta hash of the parent block of the latest proposed block in protocol. +func GetParentMetaHash(ctx context.Context, rpc *rpc.Client) (common.Hash, error) { state, err := rpc.TaikoL1.State(&bind.CallOpts{Context: ctx}) if err != nil { return common.Hash{}, err diff --git a/packages/taiko-client/proposer/transaction_builder/common_test.go b/packages/taiko-client/proposer/transaction_builder/common_test.go index 81c1128058..7155bd3ef8 100644 --- a/packages/taiko-client/proposer/transaction_builder/common_test.go +++ b/packages/taiko-client/proposer/transaction_builder/common_test.go @@ -70,7 +70,7 @@ func (s *TransactionBuilderTestSuite) SetupTest() { } func (s *TransactionBuilderTestSuite) TestGetParentMetaHash() { - metahash, err := getParentMetaHash(context.Background(), s.RPCClient) + metahash, err := GetParentMetaHash(context.Background(), s.RPCClient) s.Nil(err) s.NotEmpty(metahash) }