Skip to content

Commit

Permalink
stage_txn_lookup: don't grind all blocks at initial sync (#12770)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Nov 19, 2024
1 parent 8392957 commit 50ce34e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 3 additions & 2 deletions eth/stagedsync/exec3_serial.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"context"
"errors"
"fmt"
chaos_monkey "github.com/erigontech/erigon/tests/chaos-monkey"
"sync/atomic"
"time"

chaos_monkey "github.com/erigontech/erigon/tests/chaos-monkey"

"github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/kv"
"github.com/erigontech/erigon-lib/log/v3"
Expand Down Expand Up @@ -104,7 +105,7 @@ func (se *serialExecutor) execute(ctx context.Context, tasks []*state.TxTask) (c
return false, err
}
se.logger.Warn(fmt.Sprintf("[%s] Execution failed", se.execStage.LogPrefix()),
"block", txTask.BlockNum, "txNum", txTask.TxNum, "hash", txTask.Header.Hash().String(), "err", err)
"block", txTask.BlockNum, "txNum", txTask.TxNum, "hash", txTask.Header.Hash().String(), "err", err, "inMem", se.inMemExec)
if se.cfg.hd != nil && se.cfg.hd.POSSync() && errors.Is(err, consensus.ErrInvalidBlock) {
se.cfg.hd.ReportBadHeaderPoS(txTask.Header.Hash(), txTask.Header.ParentHash)
}
Expand Down
19 changes: 18 additions & 1 deletion eth/stagedsync/stage_txlookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import (
"math/big"
"time"

"github.com/erigontech/erigon-lib/kv/rawdbv3"
"github.com/erigontech/erigon-lib/log/v3"
"github.com/erigontech/erigon/eth/stagedsync/stages"

"github.com/erigontech/erigon-lib/chain"
libcommon "github.com/erigontech/erigon-lib/common"
Expand Down Expand Up @@ -242,6 +244,21 @@ func PruneTxLookup(s *PruneState, tx kv.RwTx, cfg TxLookupCfg, ctx context.Conte
defer tx.Rollback()
}
blockFrom := s.PruneProgress
if blockFrom == 0 {
firstNonGenesisHeader, err := rawdbv3.SecondKey(tx, kv.Headers)
if err != nil {
return err
}
if firstNonGenesisHeader != nil {
blockFrom = binary.BigEndian.Uint64(firstNonGenesisHeader)
} else {
execProgress, err := stageProgress(tx, nil, stages.Senders)
if err != nil {
return err
}
blockFrom = execProgress
}
}
var blockTo uint64

var pruneBor bool
Expand Down Expand Up @@ -269,7 +286,7 @@ func PruneTxLookup(s *PruneState, tx kv.RwTx, cfg TxLookupCfg, ctx context.Conte
for ; pruneBlockNum < blockTo; pruneBlockNum++ {
select {
case <-logEvery.C:
logger.Info(fmt.Sprintf("[%s] pruning tx lookup periodic progress", logPrefix), "blockNum", pruneBlockNum)
logger.Info(fmt.Sprintf("[%s] progress", logPrefix), "blockNum", pruneBlockNum)
default:
}

Expand Down

0 comments on commit 50ce34e

Please sign in to comment.