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

eth/stagedsync: implement stage polygon sync forward #10124

Merged
merged 39 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6537574
eth/stagedsync: add init code for stage_polygon_sync
taratorio Apr 29, 2024
cffeb5e
polygon/heimdall: refactor heimdall with store option
taratorio Apr 29, 2024
ca1665f
Merge branch 'e35' of github.com:ledgerwatch/erigon into e35-astrid-h…
taratorio Apr 29, 2024
f8d899e
polygon/sync: rename storage to store for consistency with heimdall p…
taratorio Apr 29, 2024
d1b9b03
polygon/heimdall: refactor heimdall with store option
taratorio Apr 29, 2024
032a9d6
add comment
taratorio Apr 29, 2024
21342f1
Merge branch 'e35-astrid-heimdall-store-refac' of github.com:ledgerwa…
taratorio Apr 29, 2024
dfc8fe2
Merge branch 'e35-astrid-store-renames' of github.com:ledgerwatch/eri…
taratorio Apr 29, 2024
84f00d2
pass dependencies
taratorio Apr 29, 2024
611a343
polygon/heimdall: refactor into roTxStore and rwTxStore
taratorio Apr 29, 2024
805ba6e
tidy
taratorio Apr 29, 2024
eff0e7d
Merge branch 'e35' of github.com:ledgerwatch/erigon into e35-astrid-r…
taratorio Apr 29, 2024
de250fa
Merge branch 'e35-astrid-refactor-heimdall-tx-stores' of github.com:l…
taratorio Apr 29, 2024
17bd94a
reverse dependency - fixes import cycle with InMemorySignatures
taratorio Apr 29, 2024
8e6b859
use heimdall.NewRwTxStore
taratorio Apr 29, 2024
aa99235
Merge branch 'e35' of github.com:ledgerwatch/erigon into e35-astring-…
taratorio May 1, 2024
d90b36e
Merge branch 'main' of github.com:ledgerwatch/erigon into e35-astring…
taratorio May 1, 2024
ea002b4
fix merge conflict
taratorio May 1, 2024
e23b47e
plug in block reader
taratorio May 1, 2024
1d0d213
Merge branch 'main' of github.com:ledgerwatch/erigon into e35-astring…
taratorio May 6, 2024
f8ceafc
add stopNode and interruptingExecutionClient
taratorio May 6, 2024
ca95d46
Merge branch 'main' of github.com:ledgerwatch/erigon into e35-astring…
taratorio May 9, 2024
329aca2
implement final stage logic
taratorio May 9, 2024
1cfe666
Merge branch 'main' of github.com:ledgerwatch/erigon into e35-astring…
taratorio May 9, 2024
92dd8f6
fix useExternalTx
taratorio May 9, 2024
83f04d9
Merge branch 'main' of github.com:ledgerwatch/erigon into e35-astring…
taratorio May 18, 2024
7c04b4e
Merge branch 'main' of github.com:ledgerwatch/erigon into e35-astring…
taratorio May 22, 2024
7134867
current header to use snapshots and stage hash progress
taratorio May 22, 2024
8a80d61
Merge branch 'main' of github.com:ledgerwatch/erigon into e35-astring…
taratorio May 23, 2024
3188042
add flag to default flags
taratorio May 23, 2024
b23afc4
rewrite due to mdbx tx usage on multiple threads
taratorio May 23, 2024
29751c4
fix sentry disable block download for polygon sync stage
taratorio May 23, 2024
54770d2
Merge branch 'main' of github.com:ledgerwatch/erigon into e35-astring…
taratorio May 23, 2024
220ba44
fix accidental err swallow
taratorio May 23, 2024
eae738d
improve logging
taratorio May 23, 2024
7514934
improve logging
taratorio May 23, 2024
89f9288
fix checkpoint marshalling issue
taratorio May 23, 2024
3334492
remove chatty log
taratorio May 23, 2024
ec50aa0
remove chatty log
taratorio May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ import (
"sync/atomic"
"time"

"github.com/ledgerwatch/erigon-lib/common/dir"
"github.com/ledgerwatch/erigon-lib/common/disk"
"github.com/ledgerwatch/erigon-lib/common/mem"

"github.com/erigontech/mdbx-go/mdbx"
lru "github.com/hashicorp/golang-lru/arc/v2"
"github.com/holiman/uint256"
Expand All @@ -54,6 +50,9 @@ import (
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/datadir"
"github.com/ledgerwatch/erigon-lib/common/dbg"
"github.com/ledgerwatch/erigon-lib/common/dir"
"github.com/ledgerwatch/erigon-lib/common/disk"
"github.com/ledgerwatch/erigon-lib/common/mem"
"github.com/ledgerwatch/erigon-lib/config3"
"github.com/ledgerwatch/erigon-lib/direct"
"github.com/ledgerwatch/erigon-lib/downloader"
Expand Down Expand Up @@ -847,6 +846,7 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
if config.PolygonSyncStage {
backend.syncStages = stages2.NewPolygonSyncStages(
backend.sentryCtx,
logger,
backend.chainDB,
config,
backend.chainConfig,
Expand All @@ -859,6 +859,10 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
backend.silkworm,
backend.forkValidator,
heimdallClient,
polygonSyncSentry(sentries),
p2pConfig.MaxPeers,
statusDataProvider,
backend.stopNode,
)
backend.syncUnwindOrder = stagedsync.PolygonSyncUnwindOrder
backend.syncPruneOrder = stagedsync.PolygonSyncPruneOrder
Expand Down Expand Up @@ -966,27 +970,12 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
}

if config.PolygonSync {
// TODO - pending sentry multi client refactor
// - sentry multi client should conform to the SentryClient interface and internally
// multiplex
// - for now we just use 1 sentry
var sentryClient direct.SentryClient
for _, client := range sentries {
if client.Protocol() == direct.ETH68 {
sentryClient = client
break
}
}
if sentryClient == nil {
return nil, errors.New("nil sentryClient for polygon sync")
}

backend.polygonSyncService = polygonsync.NewService(
logger,
chainConfig,
dirs.DataDir,
tmpdir,
sentryClient,
polygonSyncSentry(sentries),
p2pConfig.MaxPeers,
statusDataProvider,
config.HeimdallURL,
Expand Down Expand Up @@ -1741,3 +1730,23 @@ func setBorDefaultTxPoolPriceLimit(chainConfig *chain.Config, config txpoolcfg.C
config.MinFeeCap = txpoolcfg.BorDefaultTxPoolPriceLimit
}
}

func polygonSyncSentry(sentries []direct.SentryClient) direct.SentryClient {
// TODO - pending sentry multi client refactor
// - sentry multi client should conform to the SentryClient interface and internally
// multiplex
// - for now we just use 1 sentry
var sentryClient direct.SentryClient
for _, client := range sentries {
if client.Protocol() == direct.ETH68 {
sentryClient = client
break
}
}

if sentryClient == nil {
panic("nil sentryClient for polygon sync")
}

return sentryClient
}
30 changes: 21 additions & 9 deletions eth/stagedsync/bor_heimdall_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
"github.com/ledgerwatch/log/v3"

"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/accounts/abi"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/polygon/bor/borcfg"
"github.com/ledgerwatch/erigon/polygon/heimdall"
"github.com/ledgerwatch/erigon/rlp"
"github.com/ledgerwatch/erigon/turbo/services"
Expand Down Expand Up @@ -299,7 +301,7 @@ func fetchAndWriteHeimdallMilestonesIfNeeded(
}

for milestoneId := lastId + 1; milestoneId <= uint64(count) && (lastMilestone == nil || lastMilestone.EndBlock().Uint64() < toBlockNum); milestoneId++ {
if _, lastMilestone, err = fetchAndWriteHeimdallMilestone(ctx, milestoneId, uint64(count), tx, cfg.heimdallClient, logPrefix, logger); err != nil {
if _, lastMilestone, err = fetchAndWriteHeimdallMilestone(ctx, milestoneId, tx, cfg.heimdallClient, logPrefix, logger); err != nil {
if !errors.Is(err, heimdall.ErrNotInMilestoneList) {
return 0, err
}
Expand All @@ -318,7 +320,6 @@ var activeMilestones uint64 = 100
func fetchAndWriteHeimdallMilestone(
ctx context.Context,
milestoneId uint64,
count uint64,
tx kv.RwTx,
heimdallClient heimdall.HeimdallClient,
logPrefix string,
Expand Down Expand Up @@ -368,24 +369,35 @@ func fetchRequiredHeimdallStateSyncEventsIfNeeded(
return lastStateSyncEventID, 0, 0, nil
}

return fetchAndWriteHeimdallStateSyncEvents(ctx, header, lastStateSyncEventID, tx, cfg, logPrefix, logger)
return fetchAndWriteHeimdallStateSyncEvents(
ctx,
header,
lastStateSyncEventID,
tx,
cfg.borConfig,
cfg.blockReader,
cfg.heimdallClient,
cfg.chainConfig.ChainID.String(),
cfg.stateReceiverABI,
logPrefix,
logger,
)
}

func fetchAndWriteHeimdallStateSyncEvents(
ctx context.Context,
header *types.Header,
lastStateSyncEventID uint64,
tx kv.RwTx,
cfg BorHeimdallCfg,
config *borcfg.BorConfig,
blockReader services.FullBlockReader,
heimdallClient heimdall.HeimdallClient,
chainID string,
stateReceiverABI abi.ABI,
logPrefix string,
logger log.Logger,
) (uint64, int, time.Duration, error) {
fetchStart := time.Now()
config := cfg.borConfig
blockReader := cfg.blockReader
heimdallClient := cfg.heimdallClient
chainID := cfg.chainConfig.ChainID.String()
stateReceiverABI := cfg.stateReceiverABI
// Find out the latest eventId
var (
from uint64
Expand Down
3 changes: 2 additions & 1 deletion eth/stagedsync/default_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ func StateStages(ctx context.Context, headers HeadersCfg, bodies BodiesCfg, bloc
func PolygonSyncStages(
ctx context.Context,
snapshots SnapshotsCfg,
polygonSyncStageCfg PolygonSyncStageCfg,
blockHashCfg BlockHashesCfg,
senders SendersCfg,
exec ExecuteBlockCfg,
Expand Down Expand Up @@ -766,7 +767,7 @@ func PolygonSyncStages(
ID: stages.PolygonSync,
Description: "Use polygon sync component to sync headers, bodies and heimdall data",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, unwinder Unwinder, txc wrap.TxContainer, logger log.Logger) error {
return SpawnPolygonSyncStage()
return SpawnPolygonSyncStage(ctx, txc.Tx, s, polygonSyncStageCfg)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
return UnwindPolygonSyncStage()
Expand Down
4 changes: 2 additions & 2 deletions eth/stagedsync/stage_bor_heimdall.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ import (
"github.com/ledgerwatch/erigon/polygon/bor/finality/whitelist"
"github.com/ledgerwatch/erigon/polygon/bor/valset"
"github.com/ledgerwatch/erigon/polygon/heimdall"
"github.com/ledgerwatch/erigon/polygon/sync"
"github.com/ledgerwatch/erigon/turbo/services"
"github.com/ledgerwatch/erigon/turbo/stages/headerdownload"
)

const (
InMemorySignatures = 4096 // Number of recent block signatures to keep in memory
inmemorySnapshots = 128 // Number of recent vote snapshots to keep in memory
snapshotPersistInterval = 1024 // Number of blocks after which to persist the vote snapshot to the database
)
Expand Down Expand Up @@ -172,7 +172,7 @@ func BorHeimdallForward(
return err
}

signatures, err := lru.NewARC[libcommon.Hash, libcommon.Address](InMemorySignatures)
signatures, err := lru.NewARC[libcommon.Hash, libcommon.Address](sync.InMemorySignatures)
if err != nil {
return err
}
Expand Down
Loading
Loading