-
Notifications
You must be signed in to change notification settings - Fork 873
chore (evmrpc): fix eth_getBlockTransactionCountByHash hash lookup consistency #3069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,35 @@ const ( | |
| Sei2Namespace = "sei2" | ||
| ) | ||
|
|
||
| // GenesisBlockHash is the block hash returned by GetBlockByNumber("0x0"). Hash-based lookups | ||
| // must recognize this so that count/block-by-hash stay consistent with block-by-number. | ||
| var GenesisBlockHash = common.HexToHash("0xF9D3845DF25B43B1C6926F3CEDA6845C17F5624E12212FD8847D0BA01DA1AB9E") | ||
|
|
||
| func encodeGenesisBlock() map[string]interface{} { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
| return map[string]interface{}{ | ||
| "number": (*hexutil.Big)(big.NewInt(0)), | ||
| "hash": "0xF9D3845DF25B43B1C6926F3CEDA6845C17F5624E12212FD8847D0BA01DA1AB9E", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extract the hash as a |
||
| "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)), | ||
| } | ||
| } | ||
|
|
||
| type BlockAPI struct { | ||
| tmClient rpcclient.Client | ||
| keeper *keeper.Keeper | ||
|
|
@@ -143,6 +172,9 @@ func (a *BlockAPI) GetBlockTransactionCountByNumber(ctx context.Context, number | |
| func (a *BlockAPI) GetBlockTransactionCountByHash(ctx context.Context, blockHash common.Hash) (result *hexutil.Uint, returnErr error) { | ||
| startTime := time.Now() | ||
| defer recordMetricsWithError(fmt.Sprintf("%s_getBlockTransactionCountByHash", a.namespace), a.connectionType, startTime, returnErr) | ||
| if blockHash == GenesisBlockHash { | ||
| return a.getEvmTxCount(nil, 0), nil | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is correct but i worry that it is fragile. a simple refactor in getEvmTxCount could cause panics given the nil txs passed in. Why not use |
||
| } | ||
| block, err := blockByHashRespectingWatermarks(ctx, a.tmClient, a.watermarks, blockHash[:], 1) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -158,6 +190,9 @@ func (a *BlockAPI) GetBlockByHash(ctx context.Context, blockHash common.Hash, fu | |
| func (a *BlockAPI) getBlockByHash(ctx context.Context, blockHash common.Hash, fullTx bool, includeSyntheticTxs bool, isPanicTx func(ctx context.Context, hash common.Hash) (bool, error)) (result map[string]interface{}, returnErr error) { | ||
| startTime := time.Now() | ||
| defer recordMetricsWithError(fmt.Sprintf("%s_getBlockByHash", a.namespace), a.connectionType, startTime, returnErr) | ||
| if blockHash == GenesisBlockHash { | ||
| return encodeGenesisBlock(), nil | ||
| } | ||
| block, err := blockByHashRespectingWatermarks(ctx, a.tmClient, a.watermarks, blockHash[:], 1) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -181,28 +216,7 @@ func (a *BlockAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, | |
| defer recordMetricsWithError(fmt.Sprintf("%s_getBlockByNumber", a.namespace), a.connectionType, startTime, returnErr) | ||
| if number == 0 { | ||
| // for compatibility with the graph, always return genesis block | ||
| return map[string]interface{}{ | ||
| "number": (*hexutil.Big)(big.NewInt(0)), | ||
| "hash": "0xF9D3845DF25B43B1C6926F3CEDA6845C17F5624E12212FD8847D0BA01DA1AB9E", | ||
| "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 | ||
| return encodeGenesisBlock(), nil | ||
| } | ||
| return a.getBlockByNumber(ctx, number, fullTx, a.includeShellReceipts, nil) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend not exporting this variable if we don't need to.