Skip to content
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

Fix how the state of the fork block is handled #1016

Merged
merged 2 commits into from
Nov 24, 2020

Conversation

fvictorio
Copy link
Member

Closes #1004.

Copy link

@msieczko msieczko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I think the fix is adequate and I would do it the same way 👍

Comment on lines 54 to 61
/**
* The forked block needs special handling because the genesis accounts are added to it.
* This is meant to be called when the initial state is final, so that _initialStateRoot
* points to this starting fork state.
*/
public updateInitialStateRoot() {
this._stateRootToState.set(this._initialStateRoot, this._state);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding this function and a long comment explaining its purpose I would put all of the initialization logic inside the FSM constructor. In other words, move this:
https://github.com/nomiclabs/hardhat/blob/b21474ce1df891edd7fb7b94f8bbc079c652b85a/packages/hardhat-core/src/internal/hardhat-network/provider/utils/putGenesisAccounts.ts#L10-L13
and make genesisAccounts a constructor parameter.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, putAccount is async only for the purpose of compliance with the PStateManager interface. I'd add a private synchronous _putAccount method and call it in the constructor and in the original public putAccount.

Comment on lines +332 to +335
if (blockNumber.eq(this._forkBlockNumber)) {
this._setStateRoot(toBuffer(this._initialStateRoot));
return;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +332 to +335
if (blockNumber.eq(this._forkBlockNumber)) {
this._setStateRoot(toBuffer(this._initialStateRoot));
return;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding this if statement, we could make the this._initialStateRoot equal to the actual stateRoot of the fork block. However this would require fetching the block before FSM construction and would slow down the HardhatNode creation. Having considered this I would leave this the way it is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did exactly the same reasoning, I'm glad that you agree 😅

@fvictorio fvictorio merged commit 930f7aa into master Nov 24, 2020
@fvictorio fvictorio deleted the test-accounts-forked-balance branch November 24, 2020 13:12
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

eth_getBalance with block parameter returns incorrect value in fork mode
3 participants