Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Beam Sync v0.1 #641

Merged
merged 1 commit into from
Jun 14, 2019
Merged

Beam Sync v0.1 #641

merged 1 commit into from
Jun 14, 2019

Conversation

carver
Copy link
Contributor

@carver carver commented May 20, 2019

What was wrong?

It takes too long to sync. Beam sync is an experiment to see if we can direct fast sync to choose the nodes we need in order to execute the latest blocks in the chain. If we can download the needed state fast enough, then we can keep up with the tip of the chain as soon as we find the right header tip. (Right now, we still have to commit all headers before starting beam sync, which would become the new longest part of sync).

How was it fixed?

Depends on ethereum/py-evm#1783

A lot of hacked stuff. This is never intended to be merged as is, except for a few pieces that I'll split off to independent PRs. It's got some horrendous code, that was just built for prototyping. The reason for publishing the PR is to provide some context to where Beam Sync is headed.

There is a beam sync test added, with a custom database. That should likely make it into a final Beam Sync PR.

Next steps are to re-implement in a different approach: Subclass VM, catch exceptions while getting state, pause execution until the state is added to the DB, then resume. That should provide some speed benefits, plus require less custom stuff in py-evm (like MidBlockState).

Ripping pieces out, into:

TODO

  • Update test_sync to the new request server and peer pool approach
  • stop using the hacked-in verify_uncles=False flag
  • Handle that BeamSyncService needs the event_bus
  • Add lots of comments
  • Running against the full suite of beam tests (not just the 4 selected ones that I intend to commit)
  • lint roll
  • Mark ready for review
  • figure out why pytest (sometimes) doesn't exit properly in the new beam sync test
  • review fixups
  • extract out the reverted changes for future branches of work
  • squash
  • Add to release notes

Probably later, at least write up an issue:

  • bugfix: properly handle uncle validation in beam sync (download/import previous six blocks?) Beam Sync: Uncle Validation #717
  • upgrade to lahja 0.14 API?
  • add statistics of beam execution data downloads and timing, by block Beam Sync: stats #718
  • move beam sync run_in_executor to its own process instead of thread? (not critical, because only one block imported at a time right now)

Cute Animal Picture

put a cute animal picture link inside the parentheses

@carver
Copy link
Contributor Author

carver commented May 20, 2019

cc @pipermerriam for some context on beam sync

@@ -148,7 +155,7 @@ def load_mining_chain(db):

return build(
FakeAsyncChain,
byzantium_at(0),
petersburg_at(0),
Copy link
Member

Choose a reason for hiding this comment

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

side note

Might be nice to have a latest_mainnet_fork_at that keeps us from having to propagate these updates through the codebase.

Copy link
Member

@pipermerriam pipermerriam left a comment

Choose a reason for hiding this comment

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

😎

trinity/sync/beam/chain.py Outdated Show resolved Hide resolved
@pipermerriam
Copy link
Member

   ERROR  05-20 22:34:04  StateRetrievingBlockImporter  Unexpected exception during speculative execution
Traceback (most recent call last):
  File "/home/piper/projects/trinity/trinity/sync/beam/chain.py", line 383, in _execute_speculate_transaction
    vm.apply_all_transactions((transaction, ), base_header_for_import)
  File "/home/piper/projects/py-evm/eth/vm/base.py", line 553, in apply_all_transactions
    result_header = self.add_receipt_to_header(previous_header, receipt)
UnboundLocalError: local variable 'receipt' referenced before assignment

May be irrelevant depending on how you're refactoring but I ran into this last night.

@carver
Copy link
Contributor Author

carver commented May 21, 2019

   ERROR  05-20 22:34:04  StateRetrievingBlockImporter  Unexpected exception during speculative execution
Traceback (most recent call last):
  File "/home/piper/projects/trinity/trinity/sync/beam/chain.py", line 383, in _execute_speculate_transaction
    vm.apply_all_transactions((transaction, ), base_header_for_import)
  File "/home/piper/projects/py-evm/eth/vm/base.py", line 553, in apply_all_transactions
    result_header = self.add_receipt_to_header(previous_header, receipt)
UnboundLocalError: local variable 'receipt' referenced before assignment

May be irrelevant depending on how you're refactoring but I ran into this last night.

Maybe you weren't using the branch of py-evm from ethereum/py-evm#1783 ?

@pipermerriam
Copy link
Member

Yup, wrong py-evm branch. I clearely didn't look at that stack trace very closely because when I posted I thought it was trinity code...

self._transaction_completed[block.hash] = {}
for txn_idx in range(len(block.transactions)):
self._transaction_completed[block.hash][txn_idx] = asyncio.Event()
self._state_downloader.run_task(self._speculate_transaction(txn_idx, block))

This comment was marked as outdated.

@carver carver changed the title [Hacked Prototype] Beam Sync [WIP] Beam Sync Jun 7, 2019
@carver
Copy link
Contributor Author

carver commented Jun 8, 2019

Whelp, cut the PR down from +2.?k lines to +1.4k. -4 lines, lol

Currently failing the beam sync tests because I haven't updated to the new request server and peer pool approach in test_sync After that, and dealing with uncle validation, and maybe some other unknown lahja stuff (trying to put that off until 0.14), then I think it should be working again. After adding some docstrings and running against the full suite of beam tests (not just the 4 selected ones that I intend to commit) then this should ready for a final review.

I know it's huge. Sorry. Open to more ideas on how to break this up.

@carver carver marked this pull request as ready for review June 11, 2019 23:45
@carver
Copy link
Contributor Author

carver commented Jun 12, 2019

@pipermerriam okay, everything's passing. No major updates on functionality since the last run-through, just been working on getting it merge-ready. Can you take a look?

The biggest flaw right now is the uncle validation handling. It dies if you try syncing to a block with an uncle right now. It's fixable, but I think the fix belongs in its own PR, since this one is already huge.

@carver carver changed the title [WIP] Beam Sync Beam Sync v0.1 Jun 12, 2019
@carver carver requested a review from pipermerriam June 12, 2019 23:31
@carver
Copy link
Contributor Author

carver commented Jun 12, 2019

Okay, this one is really, actually passing this time. (Well it was before, but stochastically)

Copy link
Member

@pipermerriam pipermerriam left a comment

Choose a reason for hiding this comment

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

Frankly, this is large enough that I'm good moving it forward however you see fit and we can address any architectural issues iteratively. It's kind of in that "too big" range where I'm mostly inclined to trust you under the premise that I'll grow to understand it over time and we'll probably end up re-writing every piece of this iteratively both as it evolves and as we migrate to trio.

trinity/sync/beam/chain.py Outdated Show resolved Hide resolved
trinity/sync/beam/chain.py Show resolved Hide resolved
trinity/sync/beam/chain.py Outdated Show resolved Hide resolved
trinity/sync/beam/chain.py Outdated Show resolved Hide resolved
trinity/sync/beam/chain.py Show resolved Hide resolved
trinity/sync/beam/importer.py Outdated Show resolved Hide resolved
trinity/sync/beam/state.py Show resolved Hide resolved
trinity/sync/beam/state.py Outdated Show resolved Hide resolved
trinity/sync/beam/state.py Show resolved Hide resolved
@carver
Copy link
Contributor Author

carver commented Jun 13, 2019

Frankly, this is large enough that I'm good moving it forward however you see fit and we can address any architectural issues iteratively. It's kind of in that "too big" range where I'm mostly inclined to trust you under the premise that I'll grow to understand it over time and we'll probably end up re-writing every piece of this iteratively both as it evolves and as we migrate to trio.

Ok, cool. Totally understood. I'll see if I can pair review with @lithp for a bit for a second look. The good news is that everything is behind an opt-in sync-mode flag, so it's pretty low risk, even going into a release as-is.

@carver
Copy link
Contributor Author

carver commented Jun 14, 2019

Also from pair review with Brian:

Beam sync will fail if any of the first 6 blocks have uncles. A solution
for that is in progress and will be posted shortly.
carver added a commit that referenced this pull request Jun 14, 2019
@carver carver merged commit af4bc6b into ethereum:master Jun 14, 2019
@carver carver deleted the beam-sync branch June 14, 2019 14:08
@pipermerriam
Copy link
Member

HUZZAH!

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.

2 participants