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

Client: add VM execution #1028

Merged
merged 26 commits into from
Jan 7, 2021
Merged

Client: add VM execution #1028

merged 26 commits into from
Jan 7, 2021

Conversation

holgerd77
Copy link
Member

Continuation of #1017

This has been rebased on top of #1023 and is working apart from one integration test failing (FullSync, this is going into an endless loop in the while loop in sync.start()).

Will give some more comments on the changes later the day.

We should merge relatively soon otherwise this is getting a bit out of hands. 😋

@codecov
Copy link

codecov bot commented Jan 2, 2021

Codecov Report

Merging #1028 (dc2c99e) into master (01031f2) will increase coverage by 0.45%.
The diff coverage is 90.78%.

Impacted file tree graph

Flag Coverage Δ
block 77.92% <ø> (+0.27%) ⬆️
blockchain 77.92% <ø> (ø)
client 88.38% <90.56%> (+1.06%) ⬆️
common 91.87% <ø> (ø)
devp2p 82.34% <88.88%> (-0.01%) ⬇️
ethash 82.08% <ø> (ø)
tx 86.25% <ø> (ø)
vm 83.05% <92.85%> (ø)

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

@holgerd77
Copy link
Member Author

Some more debugging: integration test failure is due to FullSynchronizer.best() not delivering a peer on the sync() call.

@holgerd77
Copy link
Member Author

This difficulty check (!best && td.gte(this.chain.blocks.td)) in best() is failing now (in contrast to before).

@holgerd77
Copy link
Member Author

Ok, tests are passing and client run is working both initially and resumed upon an existing chain state, so this is now ready for review. 😄

The devp2p changes from 8bfec9d are technically independent from this PR, I did this yesterday because sync start did take so long and often was unreliable so it got very much a hazzle to further debug the PR. The change is subdividing the peer findNeighboursrefresh calls, so now calls for all the peers are not done any more at the same time (given by the interval option) but calls are distributed (still keeping the interval time for a dedicated peer) throughout the time period with a segregation by a peer.id derived selector, I had this change in mind already for quite some time. This leads to a more distributed networking traffic (avoiding networking spikes switching with no-activity periods) and leads to a faster sync pick-up.

@holgerd77 holgerd77 force-pushed the client-add-vm-execution-rebase branch from 8f506ae to fb2826d Compare January 5, 2021 10:17
@holgerd77
Copy link
Member Author

Rebased this.

@holgerd77
Copy link
Member Author

This is now open for review (and merge), #1030 should subsequently automatically update its base.

@holgerd77 holgerd77 force-pushed the client-add-vm-execution-rebase branch from a8d7cca to 1d4ca4f Compare January 5, 2021 14:25
@holgerd77
Copy link
Member Author

Rebased this on top of #1026

@holgerd77
Copy link
Member Author

Hi @jochem-brouwer, good morning 😀 , then only thing I would insist upon: can we please get this merged before you start rewriting the cache mechanism for trie? This is otherwise getting a bit hairy.

This PR shouldn't be too hard to review, especially since the core logic was rewritten by yourself, some explanations:


After rebasing upon your fetcher type improvements in 1fe5e03 I did the following:

  • The state DB is properly closed d984684 (line 248 in fullsync.ts, actually needs to be expanded to the the close() line, addition seems to have been done in a commit before that) in FullSynchronizer.stop(), follow-up correction in c7e32c8
  • State and chain DBs are better differentiated by renaming the original db -> chainDB and aligning state DB to also be an option in node.ts analog to db, 67aaf12 and baf5c33
  • There is now a more consistent and chain/state separating directory layout with c7079d9 so that we have the network data in folders like:
    • /[HOME_DIR]/Ethereum/ethereumjs/mainnet/chain
    • /[HOME_DIR]/Ethereum/ethereumjs/mainnet/state
    • /[HOME_DIR]/Ethereum/ethereumjs/rinkeby/chain
    • /[HOME_DIR]/Ethereum/ethereumjs/rinkeby/state
    • ...
  • Devp2p DPT changes from d3b5856 are already explained in Client: add VM execution #1028 (comment). This is in the peer discovery mechanism, findNeighbours() looks for others peers to connect to based on the existing (initially: bootstrap) peers. The call to refresh() is now done 10 times more often with a subdivided refresh interval by const refreshIntervalSubdivided = Math.floor((options.refreshInterval || ms('60s')) / 10). In refresh() there is then a selector extracted from the peer ID with const selector = buffer2int(peer.id.slice(0, 1)) % 10, so this just gives a number 0..9 for each peer. On a refresh call there are then only peers called where this selector matches a looping 0..9 counter, selector === this._refreshIntervalSelectionCounter. All this is just to distribute the network traffic a bit better, before there were all calls together in one moment in time (every refreshInterval seconds). Hope this is a sufficient explanation for review. Peer discovery in the client is still working as before with this (actually: substantially better, therefore the change)
  • The remaining commits are just some added tests and some minor fixes

Copy link
Member

@jochem-brouwer jochem-brouwer left a comment

Choose a reason for hiding this comment

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

I got some questions, but nothing alarming. Looks good! 😄

packages/client/lib/client.ts Outdated Show resolved Hide resolved
packages/client/lib/config.ts Show resolved Hide resolved
packages/client/lib/config.ts Show resolved Hide resolved
packages/client/lib/config.ts Show resolved Hide resolved
packages/client/lib/sync/fullsync.ts Show resolved Hide resolved
@@ -47,6 +52,7 @@ export abstract class Synchronizer extends EventEmitter {

this.pool = options.pool
this.chain = options.chain
this.stateDB = options.stateDB
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need stateDB here, since it does not seem we use it anywhere?

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 put it there and not directly in FullSynchronizer since I thought this might be more flexible if we want to use stateDB in other synchronizers. Do you want me to move over to FullSynchronizer directly? Don't have a strong opinion on this myself, think these are all things which can be easily evolved and adopted further down the road.

Copy link
Member

Choose a reason for hiding this comment

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

I have no strong opinion either, it is OK to keep it here for now, if we focus on the light client then we can remove it if it turns out it is unnecessary.

packages/vm/lib/runBlock.ts Outdated Show resolved Hide resolved
packages/vm/lib/runBlock.ts Outdated Show resolved Hide resolved
packages/vm/lib/runBlock.ts Outdated Show resolved Hide resolved
holgerd77 and others added 7 commits January 6, 2021 18:18
…ance for a clear synchronizer object association
…ded state persistence by introducing StateManager
vm: add maxBlocks option to runBlockchain
client: fullsync: ensure VM executes final block upon shutdown
…uest) along import/execution decoupling, added tx number in block to execution message
…ed missed out test base directory tests (e.g. test/client.spec.ts) to test:unit package.json command
…ls for improved discovery performance and to avoid network traffic spikes
…r flow internet connections, fixed rebase bug in DPT.refresh()
…sh coalescent operator for options.refreshInterval selection in DPT
…, removed checkpointing exception for zero tx blocks in VM.runBlocks()
@holgerd77 holgerd77 force-pushed the client-add-vm-execution-rebase branch from 1d4ca4f to dc2c99e Compare January 6, 2021 17:56
@holgerd77
Copy link
Member Author

@jochem-brouwer ok, just pushed the changes, ready for re-review. 😀


// Tracking vars for log msg condensation on zero tx blocks
private NUM_ZERO_TXS_PER_LOG_MSG = 50
public zeroTxsBlockLogMsgCounter: number = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I don't think need the number type annotation since it's being initialized with 0

@@ -55,6 +55,7 @@ export class DPT extends EventEmitter {
private _kbucket: KBucket
private _server: DPTServer
private _refreshIntervalId: NodeJS.Timeout
private _refreshIntervalSelectionCounter: number = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

same nit here for number type annotation, I believe not needed when already initialized with a number

Copy link
Member

@jochem-brouwer jochem-brouwer left a comment

Choose a reason for hiding this comment

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

Yup, great!! 😄

@jochem-brouwer
Copy link
Member

I assume that first this one gets moved into master and then the checkpoint one immediately after?

@holgerd77
Copy link
Member Author

@jochem-brouwer thanks for the review 😄 , yes, I will now first merge here.

@holgerd77 holgerd77 merged commit ec0f059 into master Jan 7, 2021
@holgerd77 holgerd77 deleted the client-add-vm-execution-rebase branch January 7, 2021 16:02
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.

3 participants