From 6082a2da56141d936c1cd3134e779497989879d7 Mon Sep 17 00:00:00 2001 From: blindchaser Date: Mon, 23 Sep 2024 12:23:11 -0400 Subject: [PATCH] revert block.go to v.5.8.0-hot-fix-2 --- evmrpc/block.go | 48 +++++++------------------------------------- evmrpc/block_test.go | 10 +++------ 2 files changed, 10 insertions(+), 48 deletions(-) diff --git a/evmrpc/block.go b/evmrpc/block.go index 45dc4914b..186b8d955 100644 --- a/evmrpc/block.go +++ b/evmrpc/block.go @@ -69,37 +69,13 @@ func (a *BlockAPI) GetBlockByHash(ctx context.Context, blockHash common.Hash, fu if err != nil { return nil, err } - return EncodeTmBlock(a.ctxProvider(LatestCtxHeight), block, blockRes, a.keeper, a.txConfig.TxDecoder(), fullTx) + blockBloom := a.keeper.GetBlockBloom(a.ctxProvider(block.Block.Height)) + return EncodeTmBlock(a.ctxProvider(LatestCtxHeight), block, blockRes, blockBloom, a.keeper, a.txConfig.TxDecoder(), fullTx) } func (a *BlockAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (result map[string]interface{}, returnErr error) { startTime := time.Now() defer recordMetrics("eth_getBlockByNumber", a.connectionType, startTime, returnErr == nil) - if number == 0 { - // always return genesis block - return map[string]interface{}{ - "number": (*hexutil.Big)(big.NewInt(0)), - "hash": common.HexToHash("F9D3845DF25B43B1C6926F3CEDA6845C17F5624E12212FD8847D0BA01DA1AB9E"), - "parentHash": common.Hash{}, - "nonce": ethtypes.BlockNonce{}, // inapplicable to Sei - "mixHash": common.Hash{}, // inapplicable to Sei - "sha3Uncles": ethtypes.EmptyUncleHash, // inapplicable to Sei - "logsBloom": ethtypes.Bloom{}, - "stateRoot": common.Hash{}, - "miner": common.Address{}, - "difficulty": (*hexutil.Big)(big.NewInt(0)), // inapplicable to Sei - "extraData": hexutil.Bytes{}, // inapplicable to Sei - "gasLimit": hexutil.Uint64(0), - "gasUsed": hexutil.Uint64(0), - "timestamp": hexutil.Uint64(0), - "transactionsRoot": common.Hash{}, - "receiptsRoot": common.Hash{}, - "size": hexutil.Uint64(0), - "uncles": []common.Hash{}, // inapplicable to Sei - "transactions": []interface{}{}, - "baseFeePerGas": (*hexutil.Big)(big.NewInt(0)), - }, nil - } numberPtr, err := getBlockNumber(ctx, a.tmClient, number) if err != nil { return nil, err @@ -112,7 +88,8 @@ func (a *BlockAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, if err != nil { return nil, err } - return EncodeTmBlock(a.ctxProvider(LatestCtxHeight), block, blockRes, a.keeper, a.txConfig.TxDecoder(), fullTx) + blockBloom := a.keeper.GetBlockBloom(a.ctxProvider(block.Block.Height)) + return EncodeTmBlock(a.ctxProvider(LatestCtxHeight), block, blockRes, blockBloom, a.keeper, a.txConfig.TxDecoder(), fullTx) } func (a *BlockAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (result []map[string]interface{}, returnErr error) { @@ -153,12 +130,6 @@ func (a *BlockAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc.Block mtx.Unlock() } } else { - if len(receipt.Logs) > 0 && receipt.Logs[0].Synthetic { - return - } - if receipt.EffectiveGasPrice == 0 { - return - } encodedReceipt, err := encodeReceipt(receipt, a.txConfig.TxDecoder(), block, func(h common.Hash) bool { _, err := a.keeper.GetReceipt(a.ctxProvider(height), h) return err == nil @@ -173,22 +144,17 @@ func (a *BlockAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc.Block }(i, hash) } wg.Wait() - compactReceipts := make([]map[string]interface{}, 0) - for _, r := range allReceipts { - if len(r) > 0 { - compactReceipts = append(compactReceipts, r) - } - } if returnErr != nil { return nil, returnErr } - return compactReceipts, nil + return allReceipts, nil } func EncodeTmBlock( ctx sdk.Context, block *coretypes.ResultBlock, blockRes *coretypes.ResultBlockResults, + blockBloom ethtypes.Bloom, k *keeper.Keeper, txDecoder sdk.TxDecoder, fullTx bool, @@ -245,7 +211,7 @@ func EncodeTmBlock( "nonce": ethtypes.BlockNonce{}, // inapplicable to Sei "mixHash": common.Hash{}, // inapplicable to Sei "sha3Uncles": ethtypes.EmptyUncleHash, // inapplicable to Sei - "logsBloom": k.GetBlockBloom(ctx, block.Block.Height), + "logsBloom": blockBloom, "stateRoot": appHash, "miner": miner, "difficulty": (*hexutil.Big)(big.NewInt(0)), // inapplicable to Sei diff --git a/evmrpc/block_test.go b/evmrpc/block_test.go index 256312f9b..c91798026 100644 --- a/evmrpc/block_test.go +++ b/evmrpc/block_test.go @@ -103,11 +103,7 @@ func verifyBlockResult(t *testing.T, resObj map[string]interface{}) { require.Equal(t, "0x5", resObj["gasUsed"]) require.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000001", resObj["hash"]) // see setup_tests.go, which have one transaction for block 0x8 (latest) - if resObj["number"] == "0x8" { - require.Equal(t, "0x00002000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000200000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000", resObj["logsBloom"]) - } else { - require.Equal(t, "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", resObj["logsBloom"]) - } + require.Equal(t, "0x00002000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000200000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000", resObj["logsBloom"]) require.Equal(t, "0x0000000000000000000000000000000000000005", resObj["miner"]) require.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000000", resObj["mixHash"]) require.Equal(t, "0x0000000000000000", resObj["nonce"]) @@ -167,7 +163,7 @@ func TestEncodeTmBlock_EmptyTransactions(t *testing.T) { } // Call EncodeTmBlock with empty transactions - result, err := evmrpc.EncodeTmBlock(ctx, block, blockRes, k, Decoder, true) + result, err := evmrpc.EncodeTmBlock(ctx, block, blockRes, ethtypes.Bloom{}, k, Decoder, true) require.Nil(t, err) // Assert txHash is equal to ethtypes.EmptyTxsHash @@ -213,7 +209,7 @@ func TestEncodeBankMsg(t *testing.T) { }, }, } - res, err := evmrpc.EncodeTmBlock(ctx, &resBlock, &resBlockRes, k, Decoder, true) + res, err := evmrpc.EncodeTmBlock(ctx, &resBlock, &resBlockRes, ethtypes.Bloom{}, k, Decoder, true) require.Nil(t, err) txs := res["transactions"].([]interface{}) require.Equal(t, 0, len(txs))