From 95000578ab06480c7e8234d397df2e1efd41bcc2 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Fri, 8 Dec 2023 18:12:11 +0800 Subject: [PATCH 01/10] skeleton --- eth/taiko_api_backend.go | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/eth/taiko_api_backend.go b/eth/taiko_api_backend.go index 49e8580b664f..4a340dbb3579 100644 --- a/eth/taiko_api_backend.go +++ b/eth/taiko_api_backend.go @@ -1,6 +1,7 @@ package eth import ( + "context" "math/big" "github.com/ethereum/go-ethereum" @@ -8,7 +9,9 @@ import ( "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/rpc" ) // TaikoAPIBackend handles l2 node related RPC calls. @@ -89,3 +92,44 @@ func (s *TaikoAPIBackend) TxPoolContent( maxTransactionsLists, ) } + +// Get L2ParentHashes retrieves the preceding 256 parent hashes given a block number. +func (s *TaikoAPIBackend) GetL2ParentHashes(blockID uint64) ([]common.Hash, error) { + var hashes []common.Hash + furthest := 256 + + if blockID < 257 { + furthest = int(blockID) + } + + for i := 1; i < furthest; i++ { + block, err := s.eth.APIBackend.BlockByNumber(context.Background(), rpc.BlockNumber(blockID-uint64(i))) + if err != nil { + return nil, err + } + + hashes = append(hashes, block.ParentHash()) + } + return hashes, nil +} + +// Get L2ParentBlocks retrieves the preceding 256 parent blocks given a block number. +func (s *TaikoAPIBackend) GetL2ParentBlocks(blockID uint64) ([]map[string]interface{}, error) { + var parents []map[string]interface{} + b := ethapi.NewBlockChainAPI(s.eth.APIBackend) + furthest := 256 + + if blockID < 257 { + furthest = int(blockID) + } + + for i := 1; i < furthest; i++ { + block, err := b.GetBlockByNumber(context.Background(), rpc.BlockNumber(blockID-uint64(i)), false) + if err != nil { + return nil, err + } + parents = append(parents, block) + } + + return parents, nil +} From 257e2c1b3edacd809001b366d0935623dadf69c8 Mon Sep 17 00:00:00 2001 From: Roger <50648015+RogerLamTd@users.noreply.github.com> Date: Fri, 8 Dec 2023 19:47:57 +0800 Subject: [PATCH 02/10] Update taiko_api_backend.go --- eth/taiko_api_backend.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth/taiko_api_backend.go b/eth/taiko_api_backend.go index 4a340dbb3579..d7a3beaac03e 100644 --- a/eth/taiko_api_backend.go +++ b/eth/taiko_api_backend.go @@ -108,7 +108,7 @@ func (s *TaikoAPIBackend) GetL2ParentHashes(blockID uint64) ([]common.Hash, erro return nil, err } - hashes = append(hashes, block.ParentHash()) + hashes = append(hashes, block.Hash()) } return hashes, nil } From 2d9272ee3bd866528ad2eecc9d9cae00995b26dd Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 11 Dec 2023 17:47:00 +0800 Subject: [PATCH 03/10] add getl2parenthashes test --- ethclient/taiko_api.go | 11 +++++++++++ ethclient/taiko_api_test.go | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/ethclient/taiko_api.go b/ethclient/taiko_api.go index 9637608d062f..e3245b2ee26a 100644 --- a/ethclient/taiko_api.go +++ b/ethclient/taiko_api.go @@ -4,6 +4,7 @@ import ( "context" "math/big" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/rawdb" ) @@ -29,3 +30,13 @@ func (ec *Client) L1OriginByID(ctx context.Context, blockID *big.Int) (*rawdb.L1 return res, nil } + +func (ec *Client) GetL2ParentHashes(ctx context.Context, blockID uint64) ([]common.Hash, error) { + var res []common.Hash + + if err := ec.c.CallContext(ctx, &res, "taiko_getL2ParentHashes", blockID); err != nil { + return nil, err + } + + return res, nil +} diff --git a/ethclient/taiko_api_test.go b/ethclient/taiko_api_test.go index 7a7cfc7dcd4c..8624f509c46d 100644 --- a/ethclient/taiko_api_test.go +++ b/ethclient/taiko_api_test.go @@ -104,6 +104,25 @@ func TestL1OriginByID(t *testing.T) { require.Equal(t, testL1Origin, l1OriginFound) } +func TestGetL2ParentHashes(t *testing.T) { + ec, _, _ := newTaikoAPITestClient(t) + + hashes, err := ec.GetL2ParentHashes(context.Background(), big.NewInt(4).Uint64()) + require.Nil(t, hashes) + require.NotNil(t, err) + // log.Info("error:", "errortype", err) + // fails since chain segment hasn't reached (?) + + test := common.Big3.Uint64() + + hashes, err = ec.GetL2ParentHashes(context.Background(), test) + require.Nil(t, err) + + require.Equal(t, len(hashes), int(test-1)) + require.Equal(t, hashes[test-3].String(), "0x4bab762ae8457561f28e3359a98e323c4f6ae5dce54442cd24eefd8886d2d838") + require.Equal(t, hashes[test-2].String(), "0x82b6413886df66f54c5e1de8689eb9a0dbcdd7c8fc6dbf32da8a081a353dc6ab") +} + // randomHash generates a random blob of data and returns it as a hash. func randomHash() common.Hash { var hash common.Hash From 14d8ab6ddc8d79481b31ed58d6911c9e9208ec57 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 11 Dec 2023 18:09:16 +0800 Subject: [PATCH 04/10] use blocks[i].hash instead of str --- ethclient/taiko_api_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ethclient/taiko_api_test.go b/ethclient/taiko_api_test.go index 8624f509c46d..4d81bcebe2e7 100644 --- a/ethclient/taiko_api_test.go +++ b/ethclient/taiko_api_test.go @@ -105,13 +105,13 @@ func TestL1OriginByID(t *testing.T) { } func TestGetL2ParentHashes(t *testing.T) { - ec, _, _ := newTaikoAPITestClient(t) + ec, blocks, _ := newTaikoAPITestClient(t) hashes, err := ec.GetL2ParentHashes(context.Background(), big.NewInt(4).Uint64()) require.Nil(t, hashes) require.NotNil(t, err) // log.Info("error:", "errortype", err) - // fails since chain segment hasn't reached (?) + // fails since chain segment hasn't reached test := common.Big3.Uint64() @@ -119,8 +119,8 @@ func TestGetL2ParentHashes(t *testing.T) { require.Nil(t, err) require.Equal(t, len(hashes), int(test-1)) - require.Equal(t, hashes[test-3].String(), "0x4bab762ae8457561f28e3359a98e323c4f6ae5dce54442cd24eefd8886d2d838") - require.Equal(t, hashes[test-2].String(), "0x82b6413886df66f54c5e1de8689eb9a0dbcdd7c8fc6dbf32da8a081a353dc6ab") + require.Equal(t, hashes[test-3], blocks[2].Hash()) + require.Equal(t, hashes[test-2], blocks[1].Hash()) } // randomHash generates a random blob of data and returns it as a hash. From ff476f45771f097f75ada688a12b86ff338e3705 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 11 Dec 2023 19:31:33 +0800 Subject: [PATCH 05/10] add getl2parentblocks test --- ethclient/taiko_api.go | 10 +++++++++ ethclient/taiko_api_test.go | 42 +++++++++++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/ethclient/taiko_api.go b/ethclient/taiko_api.go index e3245b2ee26a..3cfdaf701cdd 100644 --- a/ethclient/taiko_api.go +++ b/ethclient/taiko_api.go @@ -40,3 +40,13 @@ func (ec *Client) GetL2ParentHashes(ctx context.Context, blockID uint64) ([]comm return res, nil } + +func (ec *Client) GetL2ParentBlocks(ctx context.Context, blockID uint64) ([]map[string]interface{}, error) { + var res []map[string]interface{} + + if err := ec.c.CallContext(ctx, &res, "taiko_getL2ParentBlocks", blockID); err != nil { + return nil, err + } + + return res, nil +} diff --git a/ethclient/taiko_api_test.go b/ethclient/taiko_api_test.go index 4d81bcebe2e7..65dd30fa024b 100644 --- a/ethclient/taiko_api_test.go +++ b/ethclient/taiko_api_test.go @@ -110,7 +110,6 @@ func TestGetL2ParentHashes(t *testing.T) { hashes, err := ec.GetL2ParentHashes(context.Background(), big.NewInt(4).Uint64()) require.Nil(t, hashes) require.NotNil(t, err) - // log.Info("error:", "errortype", err) // fails since chain segment hasn't reached test := common.Big3.Uint64() @@ -118,9 +117,44 @@ func TestGetL2ParentHashes(t *testing.T) { hashes, err = ec.GetL2ParentHashes(context.Background(), test) require.Nil(t, err) - require.Equal(t, len(hashes), int(test-1)) - require.Equal(t, hashes[test-3], blocks[2].Hash()) - require.Equal(t, hashes[test-2], blocks[1].Hash()) + require.Equal(t, int(test-1), len(hashes)) + require.Equal(t, blocks[2].Hash(), hashes[test-3]) + require.Equal(t, blocks[1].Hash(), hashes[test-2]) + + // should work when shorter than length of chain + hashes, err = ec.GetL2ParentHashes(context.Background(), common.Big2.Uint64()) + require.Nil(t, err) + + require.Equal(t, 1, len(hashes)) + require.Equal(t, blocks[1].Hash(), hashes[0]) + + // empty when 1 since genesis has no parent + hashes, err = ec.GetL2ParentHashes(context.Background(), common.Big1.Uint64()) + require.Nil(t, err) + + require.Equal(t, 0, len(hashes)) +} + +func TestGetL2ParentBlocks(t *testing.T) { + ec, blocks, _ := newTaikoAPITestClient(t) + + res, err := ec.GetL2ParentBlocks(context.Background(), common.Big3.Uint64()) + require.Nil(t, err) + + require.Equal(t, 2, len(res)) + require.Equal(t, res[0]["hash"], blocks[2].Hash().String()) + require.Equal(t, res[1]["hash"], blocks[1].Hash().String()) + + res, err = ec.GetL2ParentBlocks(context.Background(), common.Big2.Uint64()) + require.Nil(t, err) + + require.Equal(t, 1, len(res)) + require.Equal(t, res[0]["hash"], blocks[1].Hash().String()) + + res, err = ec.GetL2ParentBlocks(context.Background(), common.Big1.Uint64()) + require.Nil(t, err) + + require.Equal(t, 0, len(res)) } // randomHash generates a random blob of data and returns it as a hash. From 23ab798e6f1be86f69d3204971cc023b5e6c2d55 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 11 Dec 2023 19:34:48 +0800 Subject: [PATCH 06/10] standardize --- ethclient/taiko_api_test.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ethclient/taiko_api_test.go b/ethclient/taiko_api_test.go index 65dd30fa024b..71cd440799ba 100644 --- a/ethclient/taiko_api_test.go +++ b/ethclient/taiko_api_test.go @@ -112,14 +112,12 @@ func TestGetL2ParentHashes(t *testing.T) { require.NotNil(t, err) // fails since chain segment hasn't reached - test := common.Big3.Uint64() - - hashes, err = ec.GetL2ParentHashes(context.Background(), test) + hashes, err = ec.GetL2ParentHashes(context.Background(), common.Big3.Uint64()) require.Nil(t, err) - require.Equal(t, int(test-1), len(hashes)) - require.Equal(t, blocks[2].Hash(), hashes[test-3]) - require.Equal(t, blocks[1].Hash(), hashes[test-2]) + require.Equal(t, 2, len(hashes)) + require.Equal(t, blocks[2].Hash(), hashes[0]) + require.Equal(t, blocks[1].Hash(), hashes[1]) // should work when shorter than length of chain hashes, err = ec.GetL2ParentHashes(context.Background(), common.Big2.Uint64()) From 4b29a30b7846c8beb1504bfa885d29811fc4136e Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 11 Dec 2023 20:06:09 +0800 Subject: [PATCH 07/10] changes according to comments --- eth/taiko_api_backend.go | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/eth/taiko_api_backend.go b/eth/taiko_api_backend.go index d7a3beaac03e..c0498827c4a2 100644 --- a/eth/taiko_api_backend.go +++ b/eth/taiko_api_backend.go @@ -96,19 +96,9 @@ func (s *TaikoAPIBackend) TxPoolContent( // Get L2ParentHashes retrieves the preceding 256 parent hashes given a block number. func (s *TaikoAPIBackend) GetL2ParentHashes(blockID uint64) ([]common.Hash, error) { var hashes []common.Hash - furthest := 256 - if blockID < 257 { - furthest = int(blockID) - } - - for i := 1; i < furthest; i++ { - block, err := s.eth.APIBackend.BlockByNumber(context.Background(), rpc.BlockNumber(blockID-uint64(i))) - if err != nil { - return nil, err - } - - hashes = append(hashes, block.Hash()) + for i := blockID; i == 0 && (blockID-i >= 256); i-- { + hashes = append(hashes, s.eth.blockchain.GetHeaderByNumber(i).Hash()) } return hashes, nil } @@ -117,14 +107,9 @@ func (s *TaikoAPIBackend) GetL2ParentHashes(blockID uint64) ([]common.Hash, erro func (s *TaikoAPIBackend) GetL2ParentBlocks(blockID uint64) ([]map[string]interface{}, error) { var parents []map[string]interface{} b := ethapi.NewBlockChainAPI(s.eth.APIBackend) - furthest := 256 - - if blockID < 257 { - furthest = int(blockID) - } - for i := 1; i < furthest; i++ { - block, err := b.GetBlockByNumber(context.Background(), rpc.BlockNumber(blockID-uint64(i)), false) + for i := blockID; i == 0 && (blockID-i >= 256); i-- { + block, err := b.GetBlockByNumber(context.Background(), rpc.BlockNumber(blockID-i), false) if err != nil { return nil, err } From 779decdfdc78cffad7a61fa1cd062c75d3cbfcc9 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 11 Dec 2023 21:49:15 +0800 Subject: [PATCH 08/10] refactor according to comments --- eth/taiko_api_backend.go | 6 +++--- ethclient/taiko_api_test.go | 34 ++++++++++++++++------------------ 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/eth/taiko_api_backend.go b/eth/taiko_api_backend.go index c0498827c4a2..d5e82e75deab 100644 --- a/eth/taiko_api_backend.go +++ b/eth/taiko_api_backend.go @@ -97,8 +97,8 @@ func (s *TaikoAPIBackend) TxPoolContent( func (s *TaikoAPIBackend) GetL2ParentHashes(blockID uint64) ([]common.Hash, error) { var hashes []common.Hash - for i := blockID; i == 0 && (blockID-i >= 256); i-- { - hashes = append(hashes, s.eth.blockchain.GetHeaderByNumber(i).Hash()) + for i := blockID; i != 0 && (blockID-i) < 256; i-- { + hashes = append(hashes, s.eth.blockchain.GetHeaderByNumber(blockID-i).Hash()) } return hashes, nil } @@ -108,7 +108,7 @@ func (s *TaikoAPIBackend) GetL2ParentBlocks(blockID uint64) ([]map[string]interf var parents []map[string]interface{} b := ethapi.NewBlockChainAPI(s.eth.APIBackend) - for i := blockID; i == 0 && (blockID-i >= 256); i-- { + for i := blockID; i != 0 && (blockID-i) < 256; i-- { block, err := b.GetBlockByNumber(context.Background(), rpc.BlockNumber(blockID-i), false) if err != nil { return nil, err diff --git a/ethclient/taiko_api_test.go b/ethclient/taiko_api_test.go index 71cd440799ba..5e44a0d48755 100644 --- a/ethclient/taiko_api_test.go +++ b/ethclient/taiko_api_test.go @@ -107,27 +107,23 @@ func TestL1OriginByID(t *testing.T) { func TestGetL2ParentHashes(t *testing.T) { ec, blocks, _ := newTaikoAPITestClient(t) - hashes, err := ec.GetL2ParentHashes(context.Background(), big.NewInt(4).Uint64()) - require.Nil(t, hashes) - require.NotNil(t, err) - // fails since chain segment hasn't reached - - hashes, err = ec.GetL2ParentHashes(context.Background(), common.Big3.Uint64()) + hashes, err := ec.GetL2ParentHashes(context.Background(), common.Big3.Uint64()) require.Nil(t, err) - require.Equal(t, 2, len(hashes)) - require.Equal(t, blocks[2].Hash(), hashes[0]) + log.Info("hashes", "a", hashes) + require.Equal(t, 3, len(hashes)) + require.Equal(t, blocks[0].Hash(), hashes[0]) require.Equal(t, blocks[1].Hash(), hashes[1]) + require.Equal(t, blocks[2].Hash(), hashes[2]) - // should work when shorter than length of chain hashes, err = ec.GetL2ParentHashes(context.Background(), common.Big2.Uint64()) require.Nil(t, err) - require.Equal(t, 1, len(hashes)) - require.Equal(t, blocks[1].Hash(), hashes[0]) + require.Equal(t, 2, len(hashes)) + require.Equal(t, blocks[0].Hash(), hashes[0]) + require.Equal(t, blocks[1].Hash(), hashes[1]) - // empty when 1 since genesis has no parent - hashes, err = ec.GetL2ParentHashes(context.Background(), common.Big1.Uint64()) + hashes, err = ec.GetL2ParentHashes(context.Background(), common.Big0.Uint64()) require.Nil(t, err) require.Equal(t, 0, len(hashes)) @@ -139,17 +135,19 @@ func TestGetL2ParentBlocks(t *testing.T) { res, err := ec.GetL2ParentBlocks(context.Background(), common.Big3.Uint64()) require.Nil(t, err) - require.Equal(t, 2, len(res)) - require.Equal(t, res[0]["hash"], blocks[2].Hash().String()) + require.Equal(t, 3, len(res)) + require.Equal(t, res[0]["hash"], blocks[0].Hash().String()) require.Equal(t, res[1]["hash"], blocks[1].Hash().String()) + require.Equal(t, res[2]["hash"], blocks[2].Hash().String()) res, err = ec.GetL2ParentBlocks(context.Background(), common.Big2.Uint64()) require.Nil(t, err) - require.Equal(t, 1, len(res)) - require.Equal(t, res[0]["hash"], blocks[1].Hash().String()) + require.Equal(t, 2, len(res)) + require.Equal(t, res[0]["hash"], blocks[0].Hash().String()) + require.Equal(t, res[1]["hash"], blocks[1].Hash().String()) - res, err = ec.GetL2ParentBlocks(context.Background(), common.Big1.Uint64()) + res, err = ec.GetL2ParentBlocks(context.Background(), common.Big0.Uint64()) require.Nil(t, err) require.Equal(t, 0, len(res)) From a21ba717d29d686107e29e32236691531c95e908 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Tue, 12 Dec 2023 00:44:14 +0800 Subject: [PATCH 09/10] refactor again --- eth/taiko_api_backend.go | 26 +++++++++++--------------- ethclient/taiko_api.go | 4 ++-- ethclient/taiko_api_test.go | 6 +++--- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/eth/taiko_api_backend.go b/eth/taiko_api_backend.go index d5e82e75deab..2ead80760426 100644 --- a/eth/taiko_api_backend.go +++ b/eth/taiko_api_backend.go @@ -1,7 +1,6 @@ package eth import ( - "context" "math/big" "github.com/ethereum/go-ethereum" @@ -9,9 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/log" - "github.com/ethereum/go-ethereum/rpc" ) // TaikoAPIBackend handles l2 node related RPC calls. @@ -97,24 +94,23 @@ func (s *TaikoAPIBackend) TxPoolContent( func (s *TaikoAPIBackend) GetL2ParentHashes(blockID uint64) ([]common.Hash, error) { var hashes []common.Hash - for i := blockID; i != 0 && (blockID-i) < 256; i-- { - hashes = append(hashes, s.eth.blockchain.GetHeaderByNumber(blockID-i).Hash()) + headers, err := s.GetL2ParentHeaders(blockID) + if err != nil { + return nil, err + } + + for _, x := range headers { + hashes = append(hashes, x.Hash()) } return hashes, nil } // Get L2ParentBlocks retrieves the preceding 256 parent blocks given a block number. -func (s *TaikoAPIBackend) GetL2ParentBlocks(blockID uint64) ([]map[string]interface{}, error) { - var parents []map[string]interface{} - b := ethapi.NewBlockChainAPI(s.eth.APIBackend) +func (s *TaikoAPIBackend) GetL2ParentHeaders(blockID uint64) ([]*types.Header, error) { + var headers []*types.Header for i := blockID; i != 0 && (blockID-i) < 256; i-- { - block, err := b.GetBlockByNumber(context.Background(), rpc.BlockNumber(blockID-i), false) - if err != nil { - return nil, err - } - parents = append(parents, block) + headers = append(headers, s.eth.blockchain.GetHeaderByNumber(blockID-i)) } - - return parents, nil + return headers, nil } diff --git a/ethclient/taiko_api.go b/ethclient/taiko_api.go index 3cfdaf701cdd..dd3372b121c2 100644 --- a/ethclient/taiko_api.go +++ b/ethclient/taiko_api.go @@ -41,10 +41,10 @@ func (ec *Client) GetL2ParentHashes(ctx context.Context, blockID uint64) ([]comm return res, nil } -func (ec *Client) GetL2ParentBlocks(ctx context.Context, blockID uint64) ([]map[string]interface{}, error) { +func (ec *Client) GetL2ParentHeaders(ctx context.Context, blockID uint64) ([]map[string]interface{}, error) { var res []map[string]interface{} - if err := ec.c.CallContext(ctx, &res, "taiko_getL2ParentBlocks", blockID); err != nil { + if err := ec.c.CallContext(ctx, &res, "taiko_getL2ParentHeaders", blockID); err != nil { return nil, err } diff --git a/ethclient/taiko_api_test.go b/ethclient/taiko_api_test.go index 5e44a0d48755..76b86b3263cd 100644 --- a/ethclient/taiko_api_test.go +++ b/ethclient/taiko_api_test.go @@ -132,7 +132,7 @@ func TestGetL2ParentHashes(t *testing.T) { func TestGetL2ParentBlocks(t *testing.T) { ec, blocks, _ := newTaikoAPITestClient(t) - res, err := ec.GetL2ParentBlocks(context.Background(), common.Big3.Uint64()) + res, err := ec.GetL2ParentHeaders(context.Background(), common.Big3.Uint64()) require.Nil(t, err) require.Equal(t, 3, len(res)) @@ -140,14 +140,14 @@ func TestGetL2ParentBlocks(t *testing.T) { require.Equal(t, res[1]["hash"], blocks[1].Hash().String()) require.Equal(t, res[2]["hash"], blocks[2].Hash().String()) - res, err = ec.GetL2ParentBlocks(context.Background(), common.Big2.Uint64()) + res, err = ec.GetL2ParentHeaders(context.Background(), common.Big2.Uint64()) require.Nil(t, err) require.Equal(t, 2, len(res)) require.Equal(t, res[0]["hash"], blocks[0].Hash().String()) require.Equal(t, res[1]["hash"], blocks[1].Hash().String()) - res, err = ec.GetL2ParentBlocks(context.Background(), common.Big0.Uint64()) + res, err = ec.GetL2ParentHeaders(context.Background(), common.Big0.Uint64()) require.Nil(t, err) require.Equal(t, 0, len(res)) From 49a0ecf796476d3d7ff68d8d6f509ac061a41d40 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Tue, 12 Dec 2023 00:45:43 +0800 Subject: [PATCH 10/10] spaces --- eth/taiko_api_backend.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/eth/taiko_api_backend.go b/eth/taiko_api_backend.go index 2ead80760426..404e88ae21c8 100644 --- a/eth/taiko_api_backend.go +++ b/eth/taiko_api_backend.go @@ -93,7 +93,6 @@ func (s *TaikoAPIBackend) TxPoolContent( // Get L2ParentHashes retrieves the preceding 256 parent hashes given a block number. func (s *TaikoAPIBackend) GetL2ParentHashes(blockID uint64) ([]common.Hash, error) { var hashes []common.Hash - headers, err := s.GetL2ParentHeaders(blockID) if err != nil { return nil, err @@ -108,7 +107,6 @@ func (s *TaikoAPIBackend) GetL2ParentHashes(blockID uint64) ([]common.Hash, erro // Get L2ParentBlocks retrieves the preceding 256 parent blocks given a block number. func (s *TaikoAPIBackend) GetL2ParentHeaders(blockID uint64) ([]*types.Header, error) { var headers []*types.Header - for i := blockID; i != 0 && (blockID-i) < 256; i-- { headers = append(headers, s.eth.blockchain.GetHeaderByNumber(blockID-i)) }