Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,6 @@ var (
Usage: "Enable WRITE_MAP feature for fast database writes and fast commit times",
Value: true,
}

HealthCheckFlag = cli.BoolFlag{
Name: "healthcheck",
Usage: "Enabling grpc health check",
Expand Down
4 changes: 3 additions & 1 deletion eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ var Defaults = Config{
BodyCacheLimit: 256 * 1024 * 1024,
BodyDownloadTimeoutSeconds: 2,
//LoopBlockLimit: 100_000,
PruneLimit: 100,
PruneLimit: 100,
ParallelStateFlushing: true,
},
Ethash: ethashcfg.Config{
CachesInMem: 2,
Expand Down Expand Up @@ -271,6 +272,7 @@ type Sync struct {
PruneLimit int //the maximum records to delete from the DB during pruning
BreakAfterStage string
LoopBlockLimit uint
ParallelStateFlushing bool

UploadLocation string
UploadFrom rpc.BlockNumber
Expand Down
1 change: 1 addition & 0 deletions turbo/cli/default_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,5 @@ var DefaultFlags = []cli.Flag{
&SyncLoopBlockLimitFlag,
&SyncLoopBreakAfterFlag,
&SyncLoopPruneLimitFlag,
&SyncParallelStateFlushing,
}
7 changes: 7 additions & 0 deletions turbo/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ var (
Value: 5_000,
}

SyncParallelStateFlushing = cli.BoolFlag{
Name: "sync.parallel-state-flushing",
Usage: "Enables parallel state flushing",
Value: true,
}

UploadLocationFlag = cli.StringFlag{
Name: "upload.location",
Usage: "Location to upload snapshot segments to",
Expand Down Expand Up @@ -353,6 +359,7 @@ func ApplyFlagsForEthConfig(ctx *cli.Context, cfg *ethconfig.Config, logger log.
if limit := ctx.Uint(SyncLoopBlockLimitFlag.Name); limit > 0 {
cfg.Sync.LoopBlockLimit = limit
}
cfg.Sync.ParallelStateFlushing = ctx.Bool(SyncParallelStateFlushing.Name)

if location := ctx.String(UploadLocationFlag.Name); len(location) > 0 {
cfg.Sync.UploadLocation = location
Expand Down
43 changes: 26 additions & 17 deletions turbo/execution/eth1/forkchoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,16 +397,19 @@ func (e *EthereumExecutionModule) updateForkChoice(ctx context.Context, original
}

flushExtendingFork := blockHash == e.forkValidator.ExtendingForkHeadHash()
stateFlushingInParallel := flushExtendingFork && e.syncCfg.ParallelStateFlushing
if flushExtendingFork {
e.logger.Debug("[updateForkchoice] Fork choice update: flushing in-memory state (built by previous newPayload)")
// Send forkchoice early (We already know the fork is valid)
sendForkchoiceReceiptWithoutWaiting(outcomeCh, &execution.ForkChoiceReceipt{
LatestValidHash: gointerfaces.ConvertHashToH256(blockHash),
Status: execution.ExecutionStatus_Success,
ValidationError: validationError,
}, false)
if stateFlushingInParallel {
// Send forkchoice early (We already know the fork is valid)
sendForkchoiceReceiptWithoutWaiting(outcomeCh, &execution.ForkChoiceReceipt{
LatestValidHash: gointerfaces.ConvertHashToH256(blockHash),
Status: execution.ExecutionStatus_Success,
ValidationError: validationError,
}, false)
}
if err := e.forkValidator.FlushExtendingFork(tx, e.accumulator); err != nil {
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, flushExtendingFork)
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, stateFlushingInParallel)
return
}
}
Expand All @@ -416,15 +419,15 @@ func (e *EthereumExecutionModule) updateForkChoice(ctx context.Context, original
if _, err := e.executionPipeline.Run(e.db, wrap.TxContainer{Tx: tx}, initialCycle, firstCycle); err != nil {
err = fmt.Errorf("updateForkChoice: %w", err)
e.logger.Warn("Cannot update chain head", "hash", blockHash, "err", err)
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, flushExtendingFork)
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, stateFlushingInParallel)
return
}

// if head hash was set then success otherwise no
headHash := rawdb.ReadHeadBlockHash(tx)
headNumber, err := e.blockReader.HeaderNumber(ctx, tx, headHash)
if err != nil {
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, flushExtendingFork)
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, stateFlushingInParallel)
return
}

Expand All @@ -442,28 +445,28 @@ func (e *EthereumExecutionModule) updateForkChoice(ctx context.Context, original
} else {
valid, err := e.verifyForkchoiceHashes(ctx, tx, blockHash, finalizedHash, safeHash)
if err != nil {
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, flushExtendingFork)
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, stateFlushingInParallel)
return
}
if !valid {
sendForkchoiceReceiptWithoutWaiting(outcomeCh, &execution.ForkChoiceReceipt{
Status: execution.ExecutionStatus_InvalidForkchoice,
LatestValidHash: gointerfaces.ConvertHashToH256(common.Hash{}),
}, flushExtendingFork)
}, stateFlushingInParallel)
return
}
if err := rawdb.TruncateCanonicalChain(ctx, tx, *headNumber+1); err != nil {
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, flushExtendingFork)
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, stateFlushingInParallel)
return
}

if err := rawdbv3.TxNums.Truncate(tx, *headNumber+1); err != nil {
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, flushExtendingFork)
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, stateFlushingInParallel)
return
}
commitStart := time.Now()
if err := tx.Commit(); err != nil {
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, flushExtendingFork)
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, stateFlushingInParallel)
return
}
commitTime := time.Since(commitStart)
Expand All @@ -472,7 +475,7 @@ func (e *EthereumExecutionModule) updateForkChoice(ctx context.Context, original
if err := e.db.View(ctx, func(tx kv.Tx) error {
return e.hook.AfterRun(tx, finishProgressBefore)
}); err != nil {
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, flushExtendingFork)
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, stateFlushingInParallel)
return
}
}
Expand All @@ -481,7 +484,7 @@ func (e *EthereumExecutionModule) updateForkChoice(ctx context.Context, original
if err := e.db.Update(ctx, func(tx kv.RwTx) error {
return kv.IncrementKey(tx, kv.DatabaseInfo, []byte("chaindata_force"))
}); err != nil {
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, flushExtendingFork)
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, stateFlushingInParallel)
return
}

Expand All @@ -491,11 +494,17 @@ func (e *EthereumExecutionModule) updateForkChoice(ctx context.Context, original
logArgs := []interface{}{"head", headHash, "hash", blockHash}
if flushExtendingFork {
totalTime := blockTimings[engine_helpers.BlockTimingsValidationIndex]
if !e.syncCfg.ParallelStateFlushing {
totalTime += blockTimings[engine_helpers.BlockTimingsFlushExtendingFork]
}
gasUsedMgas := float64(fcuHeader.GasUsed) / 1e6
mgasPerSec := gasUsedMgas / totalTime.Seconds()
e.avgMgasSec = ((e.avgMgasSec * (float64(e.recordedMgasSec))) + mgasPerSec) / float64(e.recordedMgasSec+1)
e.recordedMgasSec++
logArgs = append(logArgs, "number", fcuHeader.Number.Uint64(), "execution", blockTimings[engine_helpers.BlockTimingsValidationIndex], "mgas/s", fmt.Sprintf("%.2f", mgasPerSec), "average mgas/s", fmt.Sprintf("%.2f", e.avgMgasSec))
if !e.syncCfg.ParallelStateFlushing {
logArgs = append(logArgs, "flushing", blockTimings[engine_helpers.BlockTimingsFlushExtendingFork])
}
}
logArgs = append(logArgs, "commit", commitTime, "alloc", common.ByteCount(m.Alloc), "sys", common.ByteCount(m.Sys))
if log {
Expand All @@ -510,7 +519,7 @@ func (e *EthereumExecutionModule) updateForkChoice(ctx context.Context, original
LatestValidHash: gointerfaces.ConvertHashToH256(headHash),
Status: status,
ValidationError: validationError,
}, flushExtendingFork)
}, stateFlushingInParallel)
}

func (e *EthereumExecutionModule) runPostForkchoiceInBackground(initialCycle bool) {
Expand Down