From 7c729f542b052779b8990c099c556187b5e9d1f3 Mon Sep 17 00:00:00 2001 From: Anshal Shukla <53994948+anshalshukla@users.noreply.github.com> Date: Mon, 6 May 2024 20:04:02 +0530 Subject: [PATCH 1/5] Fix state sync hash (#1207) * fix: hashing of statesync txn * add: state sync txn in getBlockReceipts, testcase to check hashing of state sync txn in GetTransactonReceiptsByBlock --- internal/ethapi/api.go | 21 +++++++++++++++++---- tests/bor/bor_api_test.go | 11 ++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 2d988ac94e83..8acc6a39b3f3 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1092,7 +1092,13 @@ func (s *BlockChainAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc. result := make([]map[string]interface{}, len(receipts)) for i, receipt := range receipts { - result[i] = marshalReceipt(receipt, block.Hash(), block.NumberU64(), signer, txs[i], i) + result[i] = marshalReceipt(receipt, block.Hash(), block.NumberU64(), signer, txs[i], i, false) + } + + stateSyncReceipt := rawdb.ReadBorReceipt(s.b.ChainDb(), block.Hash(), block.NumberU64(), s.b.ChainConfig()) + if stateSyncReceipt != nil { + tx, _, _, _ := rawdb.ReadBorTransaction(s.b.ChainDb(), stateSyncReceipt.TxHash) + result = append(result, marshalReceipt(stateSyncReceipt, block.Hash(), block.NumberU64(), signer, tx, len(result), true)) } return result, nil @@ -2225,17 +2231,24 @@ func (s *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash common. // Derive the sender. signer := types.MakeSigner(s.b.ChainConfig(), header.Number, header.Time) - return marshalReceipt(receipt, blockHash, blockNumber, signer, tx, int(index)), nil + return marshalReceipt(receipt, blockHash, blockNumber, signer, tx, int(index), borTx), nil } // marshalReceipt marshals a transaction receipt into a JSON object. -func marshalReceipt(receipt *types.Receipt, blockHash common.Hash, blockNumber uint64, signer types.Signer, tx *types.Transaction, txIndex int) map[string]interface{} { +func marshalReceipt(receipt *types.Receipt, blockHash common.Hash, blockNumber uint64, signer types.Signer, tx *types.Transaction, txIndex int, borTx bool) map[string]interface{} { from, _ := types.Sender(signer, tx) + txHash := common.Hash{} + if borTx { + txHash = types.GetDerivedBorTxHash(types.BorReceiptKey(blockNumber, blockHash)) + } else { + txHash = tx.Hash() + } + fields := map[string]interface{}{ "blockHash": blockHash, "blockNumber": hexutil.Uint64(blockNumber), - "transactionHash": tx.Hash(), + "transactionHash": txHash, "transactionIndex": hexutil.Uint64(txIndex), "from": from, "to": tx.To(), diff --git a/tests/bor/bor_api_test.go b/tests/bor/bor_api_test.go index cd4119c0e954..8d314193a7b6 100644 --- a/tests/bor/bor_api_test.go +++ b/tests/bor/bor_api_test.go @@ -98,6 +98,15 @@ func testGetTransactionReceiptsByBlock(t *testing.T, publicBlockchainAPI *ethapi assert.Equal(t, 2, len(receiptsOut)) assert.True(t, areDifferentHashes(receiptsOut)) + // check 5: Tx hash for state sync txn + block, err := publicBlockchainAPI.GetBlockByNumber(context.Background(), rpc.BlockNumber(4), false) + assert.Nil(t, err) + blockHash := block["hash"].(common.Hash) + txHash := types.GetDerivedBorTxHash(types.BorReceiptKey(4, blockHash)) + // Compare tx hash from GetTransactionReceiptsByBlock with hash computed above + txReceipts, err := publicBlockchainAPI.GetTransactionReceiptsByBlock(context.Background(), rpc.BlockNumberOrHashWithNumber(4)) + assert.Nil(t, err) + assert.Equal(t, txHash, txReceipts[1]["transactionHash"].(common.Hash)) } // Test for GetTransactionByBlockNumberAndIndex @@ -122,7 +131,7 @@ func testGetTransactionByBlockNumberAndIndex(t *testing.T, publicTransactionPool tx = publicTransactionPoolAPI.GetTransactionByBlockNumberAndIndex(context.Background(), rpc.BlockNumber(4), 0) assert.Equal(t, common.HexToAddress("0x1000"), *tx.To) - // check 5 : Normal Transaction + // check 5 : State Sync Transaction tx = publicTransactionPoolAPI.GetTransactionByBlockNumberAndIndex(context.Background(), rpc.BlockNumber(4), 1) assert.Equal(t, common.HexToAddress("0x0"), *tx.To) } From 3c284fa8afbf3fe8c06d09c55c751a293fd8cd92 Mon Sep 17 00:00:00 2001 From: Jerry Date: Thu, 2 May 2024 12:08:53 -0700 Subject: [PATCH 2/5] Cancel pending downloader tasks before rewinding --- eth/bor_checkpoint_verifier.go | 1 + 1 file changed, 1 insertion(+) diff --git a/eth/bor_checkpoint_verifier.go b/eth/bor_checkpoint_verifier.go index a0bdfeac8ee7..b2fd2c2d2193 100644 --- a/eth/bor_checkpoint_verifier.go +++ b/eth/bor_checkpoint_verifier.go @@ -162,6 +162,7 @@ func rewindBack(eth *Ethereum, head uint64, rewindTo uint64) { } func rewind(eth *Ethereum, head uint64, rewindTo uint64) { + eth.handler.downloader.Cancel() err := eth.blockchain.SetHead(rewindTo) if err != nil { From 0eceaca6f2e816d4a35a407cc7ad61780ffd3420 Mon Sep 17 00:00:00 2001 From: marcello33 Date: Mon, 6 May 2024 16:23:36 +0200 Subject: [PATCH 3/5] core/rawdb: add sanity-limit to header accessor --- core/rawdb/accessors_chain.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index aeed8da55c3e..25b7406e4ccf 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -362,8 +362,8 @@ func ReadHeaderRange(db ethdb.Reader, number uint64, count uint64) []rlp.RawValu if count == 0 { return rlpHeaders } - // read remaining from ancients - data, err := db.AncientRange(ChainFreezerHeaderTable, i+1-count, count, 0) + // read remaining from ancients, cap at 2M + data, err := db.AncientRange(ChainFreezerHeaderTable, i+1-count, count, 2*1024*1024) if err != nil { log.Error("Failed to read headers from freezer", "err", err) return rlpHeaders From 9e032090eb54357d87c116eccf9abcfc2396c7e3 Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Mon, 6 May 2024 20:57:09 +0530 Subject: [PATCH 4/5] release: v1.3.2-beta-2 --- packaging/templates/package_scripts/control | 2 +- packaging/templates/package_scripts/control.arm64 | 2 +- packaging/templates/package_scripts/control.profile.amd64 | 2 +- packaging/templates/package_scripts/control.profile.arm64 | 2 +- packaging/templates/package_scripts/control.validator | 2 +- .../templates/package_scripts/control.validator.arm64 | 2 +- params/version.go | 8 ++++---- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packaging/templates/package_scripts/control b/packaging/templates/package_scripts/control index b50b81e83e6a..be76fc83f01c 100644 --- a/packaging/templates/package_scripts/control +++ b/packaging/templates/package_scripts/control @@ -1,5 +1,5 @@ Source: bor -Version: 1.3.1 +Version: 1.3.2-beta-2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.arm64 b/packaging/templates/package_scripts/control.arm64 index 80831a8ef4a7..9cb00526f717 100644 --- a/packaging/templates/package_scripts/control.arm64 +++ b/packaging/templates/package_scripts/control.arm64 @@ -1,5 +1,5 @@ Source: bor -Version: 1.3.1 +Version: 1.3.2-beta-2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.amd64 b/packaging/templates/package_scripts/control.profile.amd64 index 907a1e20a9f3..3eb11fbefe37 100644 --- a/packaging/templates/package_scripts/control.profile.amd64 +++ b/packaging/templates/package_scripts/control.profile.amd64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.3.1 +Version: 1.3.2-beta-2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.arm64 b/packaging/templates/package_scripts/control.profile.arm64 index c456806bfabe..1d6fa090ae79 100644 --- a/packaging/templates/package_scripts/control.profile.arm64 +++ b/packaging/templates/package_scripts/control.profile.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.3.1 +Version: 1.3.2-beta-2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator b/packaging/templates/package_scripts/control.validator index 2a878e149d16..8e3abf6f4939 100644 --- a/packaging/templates/package_scripts/control.validator +++ b/packaging/templates/package_scripts/control.validator @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.3.1 +Version: 1.3.2-beta-2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator.arm64 b/packaging/templates/package_scripts/control.validator.arm64 index 3e6877ed3268..c78d77584742 100644 --- a/packaging/templates/package_scripts/control.validator.arm64 +++ b/packaging/templates/package_scripts/control.validator.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.3.1 +Version: 1.3.2-beta-2 Section: develop Priority: standard Maintainer: Polygon diff --git a/params/version.go b/params/version.go index f7658b9e69d1..45a5d50d5485 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 1 // Major version component of the current release - VersionMinor = 3 // Minor version component of the current release - VersionPatch = 1 // Patch version component of the current release - VersionMeta = "" // Version metadata to append to the version string + VersionMajor = 1 // Major version component of the current release + VersionMinor = 3 // Minor version component of the current release + VersionPatch = 2 // Patch version component of the current release + VersionMeta = "beta-2" // Version metadata to append to the version string ) var GitCommit string From 7543b5d87a5204e99e62e7b8e5b657d0f4d1ca08 Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Thu, 9 May 2024 11:30:34 +0530 Subject: [PATCH 5/5] release: v1.3.2 --- packaging/templates/package_scripts/control | 2 +- packaging/templates/package_scripts/control.arm64 | 2 +- packaging/templates/package_scripts/control.profile.amd64 | 2 +- packaging/templates/package_scripts/control.profile.arm64 | 2 +- packaging/templates/package_scripts/control.validator | 2 +- .../templates/package_scripts/control.validator.arm64 | 2 +- params/version.go | 8 ++++---- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packaging/templates/package_scripts/control b/packaging/templates/package_scripts/control index be76fc83f01c..f7fe99f821d0 100644 --- a/packaging/templates/package_scripts/control +++ b/packaging/templates/package_scripts/control @@ -1,5 +1,5 @@ Source: bor -Version: 1.3.2-beta-2 +Version: 1.3.2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.arm64 b/packaging/templates/package_scripts/control.arm64 index 9cb00526f717..2af8f0be6a54 100644 --- a/packaging/templates/package_scripts/control.arm64 +++ b/packaging/templates/package_scripts/control.arm64 @@ -1,5 +1,5 @@ Source: bor -Version: 1.3.2-beta-2 +Version: 1.3.2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.amd64 b/packaging/templates/package_scripts/control.profile.amd64 index 3eb11fbefe37..ea85bf094100 100644 --- a/packaging/templates/package_scripts/control.profile.amd64 +++ b/packaging/templates/package_scripts/control.profile.amd64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.3.2-beta-2 +Version: 1.3.2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.arm64 b/packaging/templates/package_scripts/control.profile.arm64 index 1d6fa090ae79..89facfc4ca43 100644 --- a/packaging/templates/package_scripts/control.profile.arm64 +++ b/packaging/templates/package_scripts/control.profile.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.3.2-beta-2 +Version: 1.3.2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator b/packaging/templates/package_scripts/control.validator index 8e3abf6f4939..823b9ed74229 100644 --- a/packaging/templates/package_scripts/control.validator +++ b/packaging/templates/package_scripts/control.validator @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.3.2-beta-2 +Version: 1.3.2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator.arm64 b/packaging/templates/package_scripts/control.validator.arm64 index c78d77584742..452051dbcbbf 100644 --- a/packaging/templates/package_scripts/control.validator.arm64 +++ b/packaging/templates/package_scripts/control.validator.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.3.2-beta-2 +Version: 1.3.2 Section: develop Priority: standard Maintainer: Polygon diff --git a/params/version.go b/params/version.go index 45a5d50d5485..35206e280e5c 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 1 // Major version component of the current release - VersionMinor = 3 // Minor version component of the current release - VersionPatch = 2 // Patch version component of the current release - VersionMeta = "beta-2" // Version metadata to append to the version string + VersionMajor = 1 // Major version component of the current release + VersionMinor = 3 // Minor version component of the current release + VersionPatch = 2 // Patch version component of the current release + VersionMeta = "" // Version metadata to append to the version string ) var GitCommit string