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

Added sentry simulator implementation #9087

Merged
merged 2 commits into from
Dec 27, 2023
Merged

Added sentry simulator implementation #9087

merged 2 commits into from
Dec 27, 2023

Conversation

mh0lt
Copy link
Contributor

@mh0lt mh0lt commented Dec 27, 2023

This adds a simulator object with implements the SentryServer api but takes objects from a pre-existing snapshot file.

If the snapshot is not available locally it will download and index the .seg file for the header range being asked for.

It is created as follows:

sim, err := simulator.NewSentry(ctx, "mumbai", dataDir, 1, logger)

Where the arguments are:

  • ctx - a callable context where cancel will close the simulator torrent and file connections (it also has a Close method)
  • chain - the name of the chain to take the snapshots from
  • datadir - a directory potentially containing snapshot .seg files. If not files exist in this directory they will be downloaded
  • num peers - the number of peers the simulator should create
  • logger - the loger to log actions to

It can be attached to a client as follows:

simClient := direct.NewSentryClientDirect(66, sim)

At the moment only very basic functionality is implemented:

  • get headers will return headers by range or hash (hash assumes a pre-downloaded .seg as it needs an index
  • the header replay semantics need to be confirmed
  • eth 65 and 66(+) messaging is supported
  • For details see: `simulator_test.go

More advanced peer behavior (e.g. header rewriting) can be added
Bodies/Transactions handling can be added

"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/downloader/snaptype"
"github.com/ledgerwatch/erigon-lib/gointerfaces"
sentry_if "github.com/ledgerwatch/erigon-lib/gointerfaces/sentry"
Copy link
Member

Choose a reason for hiding this comment

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

fyi we were chatting with @battlmonstr about trying to stick to some common code style, like google's code style guide

one example was to stick to unbroken lowercase imports e.g. https://google.github.io/styleguide/go/decisions#package-names

we are only starting the conversation now though (no action needed), will probably be best to introduce some linter changes later on once we have some alignment with everyone

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not a package name its a disambiguation.

I think you get better code readability if you use this model for name disambiguation because:

  • its clear its not a package
  • it gives some clue as to where the package came from

I think its better than the package1, package2 etc.

Copy link
Member

Choose a reason for hiding this comment

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

I agree, it is better than package1, package2 to disambiguate, however it could be sentryif or sentryinterfaces - ie avoiding snake case

@mh0lt mh0lt merged commit df0699a into devel Dec 27, 2023
7 checks passed
@mh0lt mh0lt deleted the sentry_snap_simolator branch December 27, 2023 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants