-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
eth_getBalance with block parameter returns incorrect value in fork mode #1004
Comments
So the problem is that when you fork a block in node X, and then check the balance of one of the test accounts (that start with 10000 ETH each) at block X - 1, the result is 0, is that correct? I'm not 100% sure if this is a bug or if it should be the desired behavior. |
So when you fork a node at block X, the balance for test accounts is 10k ETH at block X, but after you send a transaction the balance for test accounts at block X is 0. This is happening due to inconsistency in _runInBlockContext function, in the first case, the function will just early return since |
Oh, I see. But I think we should decide what the correct behavior should be. Should they have 10000 ETH at block X? Or only after X+1 (that is, after the first transaction in the fork)? What about block X-1 and before? cc @alcuadrado |
I think the correct way is to have 10k ETH at block X and 0 at block X-1 and before. If you have 10k ETH only after X+1, then the transaction that occurred in block X+1 wouldn't be valid since the sender balance is 0 given that the sender is one of the test accounts. |
Yeah, I agree with that reasoning 👍 |
Steps for reproducing:
npx hardhat node --fork https://fork_node
curl --data '{"id":6185245701164,"jsonrpc":"2.0","params":[{"from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","to":"0x70997970c51812dc3a010c7d01b50e0d17dc79c8","gas":"0x5208","gasPrice":"0x3B9ACA00","value":"0x1","data":"0x","nonce": "0x0"}],"method":"eth_sendTransaction"}' -H "Content-Type: application/json"
curl --data '{"method":"eth_getBalance","params":["0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", "{current_block - 1}"],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST http://127.0.0.1:8545
The third step should return
0x21e19e0c9bab2400000
but instead, the result is0x0
, another odd thing is that the third step will return the correct value if called before the second step, even with the block parameter.This issue is not reproducible in normal mode.
The text was updated successfully, but these errors were encountered: