-
Notifications
You must be signed in to change notification settings - Fork 782
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
VM: Add vm.buildBlock() and BlockBuilder API #1158
Conversation
Codecov Report
Flags with carried forward coverage won't be shown. Click here to find out more. |
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.
Hi @ryanio, thanks for opening this, this looks really great, the API on this is really beautiful! 😄
I've stumbled upon one bigger thing (the miner
reward question on runTx()
) which would have caused the post-txs state root to be wrong, this would need some addressing.
I think we can't integrate this PR into the berlin
releases any more, this is just too much in the open so close to the releases, hope that's ok. But also considering the complexity of the introduced code here I generally think it makes sense to first test this code in the client (which just is a super-natural fit) before releasing, then we can really be pretty sure that everything is working properly.
We can then target another minor VM release with these changes together with an eventual first client release in 2-4 weeks or so. How does that sound?
6057137
to
ac73685
Compare
ok this should be ready for review now :) I noticed that if a PoA block wasn't instantiated with the |
13776ab
to
679717e
Compare
if (consensusType === 'pow') { | ||
await this.rewardMiner() | ||
} | ||
|
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.
If we use clique, is the miner rewarded?
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.
there are no block rewards in clique poa. the signer will get the txs amount spent on gas (applied in runTx
)
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.
Some comments and questions
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.
This looks great, @ryanio! We'll use it as soon as it's released!
I mostly focused this review on the new API and the fix to runBlock
. Didn't get into the tests, nor the Clique things.
/** | ||
* Adds the block miner reward to the coinbase account. | ||
*/ | ||
private async rewardMiner() { |
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 hadn't realized that this was necessary here 🤯
throw new Error('tx has a higher gas limit than the remaining gas in the block') | ||
} | ||
|
||
const blockData = { header: this.headerData, transactions: this.transactions } |
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.
The transactions list is not really necessary here, as the EVM can't observe it. Not that it's bad having it either, but I'm just making this comment in case this can lead to some kind of optimization or something.
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.
got it, yeah, i wanted to pass in the most representative block in case runTx
gets updated in the future and uses something that wasn't anticipated.
const bloom = result.bloom.bitvector | ||
const gasUsed = result.gasUsed |
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.
Thanks for this fix! Looks good.
block: ensure extraData is at least length vanity + seal
eb197ab
to
7836fdc
Compare
Note: please do not merge before #1170, we can discuss, but atm I am planning to release access list generation as a bugfix release very soon, since I think this is relatively time pressing and should be out before the mainnet HF and at the same time I think it would be good to give the PR here some additional days of practical application test and integration within the client. |
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.
Ok, had another look at the code changes, this looks good to me, also the test cases are really excellent foster trust in the implementation, since they really read very well on how to use the library and things behave. 😄 👍 Will merge and prepare for release.
This PR adds
vm.buildBlock()
for building a block and adding transactions one at a time.It can be used like so:
It creates a checkpoint on the StateManager and modifies the state as transactions are run. The checkpoint is committed on
build()
or discarded withrevert()
.Closes #1018.
This PR also:
runBlock
withgenerate: true
by setting the header fields for gasUsed, logs bloom, receiptTrie, and transactionsTrie. (closes Generate receipt roots in runBlock #1037)runBlock
to a function inside the same file calledgenerateTxReceipt
, which is then exported and used in BlockBuilder for generating the receiptTrie.WIP, still finishing some last spec tests but sharing for initial review.