Skip to content

Commit

Permalink
Fix situation where progress in domain files is higher than progress …
Browse files Browse the repository at this point in the history
…in blocks snapshots (#10339)
  • Loading branch information
Giulio2002 authored May 15, 2024
1 parent 0397bb9 commit 5d6798b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion erigon-lib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ require (
github.com/pion/transport/v2 v2.0.0 // indirect
github.com/pion/turn/v2 v2.0.8 // indirect
github.com/pion/webrtc/v3 v3.1.42 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/common v0.48.0 // indirect
Expand Down
7 changes: 5 additions & 2 deletions erigon-lib/state/domain_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"unsafe"

"github.com/ledgerwatch/erigon-lib/common/cryptozerocopy"
"github.com/pkg/errors"
"golang.org/x/crypto/sha3"

btree2 "github.com/tidwall/btree"
Expand All @@ -30,6 +31,8 @@ import (
"github.com/ledgerwatch/log/v3"
)

var ErrBehindCommitment = fmt.Errorf("behind commitment")

// KvList sort.Interface to sort write list by keys
type KvList struct {
Keys []string
Expand Down Expand Up @@ -105,7 +108,7 @@ func NewSharedDomains(tx kv.Tx, logger log.Logger) (*SharedDomains, error) {
sd.sdCtx = NewSharedDomainsCommitmentContext(sd, commitment.ModeDirect, commitment.VariantHexPatriciaTrie)

if _, err := sd.SeekCommitment(context.Background(), tx); err != nil {
return nil, fmt.Errorf("SeekCommitment: %w", err)
return nil, err
}
return sd, nil
}
Expand Down Expand Up @@ -197,7 +200,7 @@ func (sd *SharedDomains) SeekCommitment(ctx context.Context, tx kv.Tx) (txsFromB
return 0, err
}
if lastBn < bn {
return 0, fmt.Errorf("TxNums index is at block %d and behind commitment %d. Likely it means that `domain snaps` are ahead of `block snaps`", lastBn, bn)
return 0, errors.WithMessage(ErrBehindCommitment, fmt.Sprintf("TxNums index is at block %d and behind commitment %d", lastBn, bn))
}
}
sd.SetBlockNum(bn)
Expand Down
9 changes: 6 additions & 3 deletions eth/stagedsync/exec3.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,19 @@ func ExecV3(ctx context.Context,
}()
}
}

var err error
inMemExec := txc.Doms != nil
var doms *state2.SharedDomains
if inMemExec {
doms = txc.Doms
} else {
var err error
doms, err = state2.NewSharedDomains(applyTx, log.New())
// if we are behind the commitment, we can't execute anything
// this can heppen if progress in domain is higher than progress in blocks
if errors.Is(err, state2.ErrBehindCommitment) {
return nil
}
if err != nil {
return err
}
Expand Down Expand Up @@ -291,8 +296,6 @@ func ExecV3(ctx context.Context,
initialBlockNum := blockNum
outputTxNum.Store(doms.TxNum())

var err error

if maxBlockNum-blockNum > 16 {
log.Info(fmt.Sprintf("[%s] starting", execStage.LogPrefix()),
"from", blockNum, "to", maxBlockNum, "fromTxNum", doms.TxNum(), "offsetFromBlockBeginning", offsetFromBlockBeginning, "initialCycle", initialCycle, "useExternalTx", useExternalTx)
Expand Down
6 changes: 6 additions & 0 deletions eth/stagedsync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package stagedsync

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -140,6 +141,11 @@ func (s *Sync) UnwindTo(unwindPoint uint64, reason UnwindReason, tx kv.Tx) error
if casted, ok := tx.(state.HasAggTx); ok {
// protect from too far unwind
unwindPointWithCommitment, ok, err := casted.AggTx().(*state.AggregatorRoTx).CanUnwindBeforeBlockNum(unwindPoint, tx)
// Ignore in the case that snapshots are ahead of commitment, it will be resolved later.
// This can be a problem if snapshots include a wrong chain so it is ok to ignore it.
if errors.Is(err, state.ErrBehindCommitment) {
return nil
}
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion turbo/execution/eth1/forkchoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ func (e *EthereumExecutionModule) updateForkChoice(ctx context.Context, original
sendForkchoiceErrorWithoutWaiting(outcomeCh, err)
return
}

if e.hook != nil {
if err = e.hook.BeforeRun(tx, isSynced); err != nil {
sendForkchoiceErrorWithoutWaiting(outcomeCh, err)
Expand All @@ -271,6 +270,7 @@ func (e *EthereumExecutionModule) updateForkChoice(ctx context.Context, original
sendForkchoiceErrorWithoutWaiting(outcomeCh, err)
return
}

if err := rawdbv3.TxNums.Truncate(tx, currentParentNumber+1); err != nil {
//if err := rawdbv3.TxNums.Truncate(tx, fcuHeader.Number.Uint64()); err != nil {
sendForkchoiceErrorWithoutWaiting(outcomeCh, err)
Expand Down Expand Up @@ -303,6 +303,7 @@ func (e *EthereumExecutionModule) updateForkChoice(ctx context.Context, original
return
}
}

if len(newCanonicals) > 0 {
if err := rawdbv3.TxNums.Truncate(tx, newCanonicals[0].number); err != nil {
sendForkchoiceErrorWithoutWaiting(outcomeCh, err)
Expand Down

0 comments on commit 5d6798b

Please sign in to comment.