Skip to content

Commit 9d7c205

Browse files
philipglazmanomegablitz
authored andcommitted
Return triedb block number in ChainState
When using the buffer in getting latest block number, a race condition exists where the block number returned is not yet available in triedb. A common wallet workflow calling eth_getBlockNumber and then eth_getBalance will often catch this and encounter an error in the second method call.
1 parent 7fa44a4 commit 9d7c205

File tree

1 file changed

+5
-5
lines changed
  • monad-rpc/src/chainstate

1 file changed

+5
-5
lines changed

monad-rpc/src/chainstate/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ impl<T: Triedb> ChainState<T> {
101101
}
102102

103103
pub fn get_latest_block_number(&self) -> u64 {
104-
if let Some(buffer) = &self.buffer {
105-
buffer.get_latest_safe_voted_block_num()
106-
} else {
107-
self.triedb_env.get_latest_voted_block_key().seq_num().0
108-
}
104+
// Return triedb's latest block number.
105+
// There is a race condition between buffer and triedb for common wallet workflows.
106+
// For example, a wallet might call `eth_getBalance` after calling `eth_getBlockByNumber`
107+
// and the balance might not be updated in triedb yet.
108+
self.triedb_env.get_latest_voted_block_key().seq_num().0
109109
}
110110

111111
pub async fn get_transaction_receipt(

0 commit comments

Comments
 (0)