Skip to content

Commit

Permalink
Added sentry simulator implementation (#9087)
Browse files Browse the repository at this point in the history
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: 

```go
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:

```go
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
  • Loading branch information
mh0lt authored Dec 27, 2023
1 parent a48db43 commit df0699a
Show file tree
Hide file tree
Showing 8 changed files with 1,024 additions and 129 deletions.
2 changes: 1 addition & 1 deletion cmd/silkworm_api/snapshot_idx.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func buildIndex(cliCtx *cli.Context, dataDir string, snapshotPaths []string) err
jobProgress := &background.Progress{}
ps.Add(jobProgress)
defer ps.Delete(jobProgress)
return freezeblocks.HeadersIdx(ctx, chainConfig, segment.Path, segment.From, dirs.Tmp, jobProgress, logLevel, logger)
return freezeblocks.HeadersIdx(ctx, segment.Path, segment.From, dirs.Tmp, jobProgress, logLevel, logger)
})
case snaptype.Bodies:
g.Go(func() error {
Expand Down
Loading

0 comments on commit df0699a

Please sign in to comment.