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

Blockchain client requests #965

Merged
merged 3 commits into from Dec 17, 2020
Merged

Blockchain client requests #965

merged 3 commits into from Dec 17, 2020

Conversation

jochem-brouwer
Copy link
Member

@jochem-brouwer jochem-brouwer commented Nov 24, 2020

Related: #960

This PR introduces some handy things: afterBlock and afterTx now get access to which block/tx is finished. Blockchain iterator gets an optional parameter which specifies how many blocks should (at most) be ran. It also adds a setHead method which allows updating the head of a certain tag, and this is saved in the DB. Related issue: #691.

@codecov
Copy link

codecov bot commented Nov 24, 2020

Codecov Report

Merging #965 (5497bc0) into master (a06ebde) will decrease coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

Flag Coverage Δ
block 77.65% <100.00%> (-0.04%) ⬇️
blockchain 77.92% <100.00%> (+0.52%) ⬆️
client 87.02% <ø> (-0.40%) ⬇️
common 92.11% <ø> (+0.24%) ⬆️
devp2p 82.88% <ø> (+0.25%) ⬆️
ethash 82.08% <ø> (ø)
tx 86.25% <ø> (+0.21%) ⬆️
vm 83.05% <100.00%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@holgerd77
Copy link
Member

Please don't merge until Thursday (eventually I will just do the releases itself already on Wednesday and do only the announcements on Thursday, then we can proceed with the other stuff one day earlier, should be ok I guess).

@jochem-brouwer
Copy link
Member Author

Yeah, I did not intend to merge anything until we release 😄 I also need to add some stuff here.

@holgerd77
Copy link
Member

Rebased this.

@jochem-brouwer
Copy link
Member Author

Hi @holgerd77, thanks for the rebase, I intend to keep this WIP until we have integrated the client, then this PR will also remove the blockchain wrapper from the client 👍

@holgerd77
Copy link
Member

@jochem-brouwer yeah, this was rather a test if a rebase (in general) still works well with the devp2p integration PR merged, since rebase went through without problems I thought I could as well push hehe 😁

@jochem-brouwer
Copy link
Member Author

Rebased on master. This PR will remove the blockchain wrapper from the client.

@jochem-brouwer
Copy link
Member Author

Removing this blockchain wrapper in client is a bit more work than anticipated, so I will open a subsequent PR for that one. Ready for review.

@jochem-brouwer jochem-brouwer marked this pull request as ready for review December 17, 2020 15:31
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.

Events look good.

I've two comments in the code. Apart from that I would say that the new maxBlocks option in the iterator() function as well as the new setHead() functionality should each get at least one additional test case.

@@ -770,6 +772,10 @@ export default class Blockchain implements BlockchainInterface {
lastBlock = block
await onBlock(block, reorg)
blockNumber.iaddn(1)
blocksRanCounter++
if (maxBlocks && blocksRanCounter == maxBlocks) {
Copy link
Member

Choose a reason for hiding this comment

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

Two things here:

  1. I guess this would be the only place in our whole codebase where the double equals would be used 😛, can we update to the standard triple equals?

  2. The break condition is unnecessarily late in the loop (correct me if I am wrong), this gets most obvious when ran on an edge case (maxBlocks === 0) where code is executed which shouldn't be executed which could lead to side effects. This should be placed at the top (eventually just directly integrate into the while condition, something like while (maxBlocks === undefined || maxBlocks && blocksRanCounter == maxBlocks))? Can also be done separately as well though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should be fixed in 833264f 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Have re-fixed in 5497bc0

@jochem-brouwer
Copy link
Member Author

Ah yes, you are right, I should've added some tests. Will fix (your comments also), thanks! 😄

st.equals(i, 0)
st.end()
}
)
Copy link
Member

Choose a reason for hiding this comment

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

Nice tests. 👍

blockchain: add setHead / iterator tests

blockchain: remove unnecessary iterator logic
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.

LGTM

@holgerd77 holgerd77 merged commit a855765 into master Dec 17, 2020
@holgerd77 holgerd77 deleted the blockchain-client-requests branch December 17, 2020 21:21
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

3 participants