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

StateManager interface simplification #388

Merged
merged 1 commit into from Nov 15, 2018

Conversation

mattdean-digicatapult
Copy link
Contributor

@mattdean-digicatapult mattdean-digicatapult commented Nov 14, 2018

This PR is based on discussions in #268 and simplifies the stateManager interface used by the VM by removing dependencies on the following methods:

  • getAccountBalance
  • putAccountBalance
  • copy

As per the discussion in #268 the balance methods have been removed as they are superfluously supported by both ethereumjs-account and by stateManager.

The dependency on the copy was introduced by #367 but this method in it's current form would be very difficult to document for an external interface. I've therefore removed this usage replacing it with a storageReader class which provides the necessary original value lookup caching.

Simplifies the stateManager interface used by the VM by removing dependencies on the following methods:
* getAccountBalance
* putAccountBalance
* copy
@holgerd77 holgerd77 force-pushed the state-manager-interface-simplification branch from 03de1b0 to c346a04 Compare November 15, 2018 12:42
@holgerd77
Copy link
Member

Rebased this.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 90.967% when pulling c346a04 on state-manager-interface-simplification into 7de7a5b on master.

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

Thanks Matthew, since this is also passing all previously passed tests (actually: even let some additional tests on Constantinople pass), I think I can merge this now! 👍

if (err) {
return cb(err)
}
cb(null, new BN(value))
cb(null, new BN(account.balance))
Copy link
Member

Choose a reason for hiding this comment

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

Ok.

Copy link
Member

Choose a reason for hiding this comment

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

Also double-checked that all occurences of getAccountBalance have been caught.

} catch (e) {
done(e.error)
return
}
Copy link
Member

Choose a reason for hiding this comment

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

empty is not needed here, so this can be simplified, ok.

function (account, cb) {
account.balance = new BN(0)
stateManager.putAccount(contractAddress, account, cb)
}
Copy link
Member

Choose a reason for hiding this comment

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

For my own understanding, is this switch from series to waterfall just to make things faster?

@@ -196,7 +199,7 @@ module.exports = function (opts, cb) {
.add(new BN(fromAccount.balance))
fromAccount.balance = finalFromBalance

self.stateManager.putAccountBalance(utils.toBuffer(tx.from), finalFromBalance, next)
self.stateManager.putAccount(utils.toBuffer(tx.from), fromAccount, next)
Copy link
Member

Choose a reason for hiding this comment

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

Double-checked here as well that there are no occurrences of putAccountBalance() left.

current
})
})
}
Copy link
Member

Choose a reason for hiding this comment

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

Ok, think I've gotten the concept, this is also well additionally covered by tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants