Skip to content

Commit

Permalink
Empty ChainName in snapshots (#13018)
Browse files Browse the repository at this point in the history
```
panic: ChainName is empty

goroutine 358 [running]:
github.com/erigontech/erigon/turbo/snapshotsync.NewCaplinStateSnapshots({_, _, _, _, _, {_, _}, {_, _}}, 0xc0bfcb6008, ...)
	github.com/erigontech/erigon/turbo/snapshotsync/caplin_state_snapshots.go:170 +0x39a
github.com/erigontech/erigon/cmd/caplin/caplin1.RunCaplinService({_, _}, {_, _}, {0x1, 0x1, 0x0, 0x1, 0x1, 0x1, ...}, ...)
	github.com/erigontech/erigon/cmd/caplin/caplin1/run.go:401 +0x2da5
github.com/erigontech/erigon/eth.New.func14()
	github.com/erigontech/erigon/eth/backend.go:990 +0x265
created by github.com/erigontech/erigon/eth.New in goroutine 1
	github.com/erigontech/erigon/eth/backend.go:988 +0x5849
```

- revert some changes done by:
#12995
- found that freezeCfg.ChainName is emtpy everywhere 
- not found ways to get ChainName in `RunCaplinService`
- added warnings for future
- created follow up: #13017
  • Loading branch information
AskAlexSharov authored Dec 6, 2024
1 parent 5561b7d commit e2d00e3
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 54 deletions.
41 changes: 30 additions & 11 deletions cmd/capcli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ func (c *Chain) Run(ctx *Context) error {

dirs := datadir.New(c.Datadir)

csn := freezeblocks.NewCaplinSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, log.Root())
freezingCfg := ethconfig.Defaults.Snapshot
freezingCfg.ChainName = c.Chain
csn := freezeblocks.NewCaplinSnapshots(freezingCfg, beaconConfig, dirs, log.Root())
bs, err := checkpoint_sync.NewRemoteCheckpointSync(beaconConfig, networkType).GetLatestBeaconState(ctx)
if err != nil {
return err
Expand Down Expand Up @@ -434,7 +436,9 @@ func (c *CheckSnapshots) Run(ctx *Context) error {

to = (to / snaptype.CaplinMergeLimit) * snaptype.CaplinMergeLimit

csn := freezeblocks.NewCaplinSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, log.Root())
freezingCfg := ethconfig.Defaults.Snapshot
freezingCfg.ChainName = c.Chain
csn := freezeblocks.NewCaplinSnapshots(freezingCfg, beaconConfig, dirs, log.Root())
if err := csn.OpenFolder(); err != nil {
return err
}
Expand Down Expand Up @@ -519,7 +523,9 @@ func (c *LoopSnapshots) Run(ctx *Context) error {

to = (to / snaptype.CaplinMergeLimit) * snaptype.CaplinMergeLimit

csn := freezeblocks.NewCaplinSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, log.Root())
freezingCfg := ethconfig.Defaults.Snapshot
freezingCfg.ChainName = c.Chain
csn := freezeblocks.NewCaplinSnapshots(freezingCfg, beaconConfig, dirs, log.Root())
if err := csn.OpenFolder(); err != nil {
return err
}
Expand Down Expand Up @@ -562,7 +568,9 @@ func (r *RetrieveHistoricalState) Run(ctx *Context) error {
}
defer tx.Rollback()

allSnapshots := freezeblocks.NewRoSnapshots(ethconfig.BlocksFreezing{}, dirs.Snap, 0, log.Root())
freezingCfg := ethconfig.Defaults.Snapshot
freezingCfg.ChainName = r.Chain
allSnapshots := freezeblocks.NewRoSnapshots(freezingCfg, dirs.Snap, 0, log.Root())
if err := allSnapshots.OpenFolder(); err != nil {
return err
}
Expand All @@ -573,7 +581,7 @@ func (r *RetrieveHistoricalState) Run(ctx *Context) error {
blockReader := freezeblocks.NewBlockReader(allSnapshots, nil, nil, nil)
eth1Getter := getters.NewExecutionSnapshotReader(ctx, blockReader, db)
eth1Getter.SetBeaconChainConfig(beaconConfig)
csn := freezeblocks.NewCaplinSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, log.Root())
csn := freezeblocks.NewCaplinSnapshots(freezingCfg, beaconConfig, dirs, log.Root())
if err := csn.OpenFolder(); err != nil {
return err
}
Expand All @@ -584,7 +592,7 @@ func (r *RetrieveHistoricalState) Run(ctx *Context) error {
}

snTypes := snapshotsync.MakeCaplinStateSnapshotsTypes(db)
stateSn := snapshotsync.NewCaplinStateSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, snTypes, log.Root())
stateSn := snapshotsync.NewCaplinStateSnapshots(freezingCfg, beaconConfig, dirs, snTypes, log.Root())
if err := stateSn.OpenFolder(); err != nil {
return err
}
Expand Down Expand Up @@ -914,7 +922,9 @@ func (b *BlobArchiveStoreCheck) Run(ctx *Context) error {
}
defer db.Close()

csn := freezeblocks.NewCaplinSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, log.Root())
freezingCfg := ethconfig.Defaults.Snapshot
freezingCfg.ChainName = b.Chain
csn := freezeblocks.NewCaplinSnapshots(freezingCfg, beaconConfig, dirs, log.Root())
if err := csn.OpenFolder(); err != nil {
return err
}
Expand Down Expand Up @@ -1029,7 +1039,9 @@ func (c *CheckBlobsSnapshots) Run(ctx *Context) error {
}
defer tx.Rollback()

csn := freezeblocks.NewCaplinSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, log.Root())
freezingCfg := ethconfig.Defaults.Snapshot
freezingCfg.ChainName = c.Chain
csn := freezeblocks.NewCaplinSnapshots(freezingCfg, beaconConfig, dirs, log.Root())
if err := csn.OpenFolder(); err != nil {
return err
}
Expand Down Expand Up @@ -1090,7 +1102,9 @@ func (c *CheckBlobsSnapshotsCount) Run(ctx *Context) error {
}
defer tx.Rollback()

csn := freezeblocks.NewCaplinSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, log.Root())
freezingCfg := ethconfig.Defaults.Snapshot
freezingCfg.ChainName = c.Chain
csn := freezeblocks.NewCaplinSnapshots(freezingCfg, beaconConfig, dirs, log.Root())
if err := csn.OpenFolder(); err != nil {
return err
}
Expand Down Expand Up @@ -1157,7 +1171,9 @@ func (c *DumpBlobsSnapshotsToStore) Run(ctx *Context) error {
}
defer tx.Rollback()

csn := freezeblocks.NewCaplinSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, log.Root())
freezingCfg := ethconfig.Defaults.Snapshot
freezingCfg.ChainName = c.Chain
csn := freezeblocks.NewCaplinSnapshots(freezingCfg, beaconConfig, dirs, log.Root())
if err := csn.OpenFolder(); err != nil {
return err
}
Expand Down Expand Up @@ -1218,13 +1234,16 @@ func (c *DumpStateSnapshots) Run(ctx *Context) error {
return
})

freezingCfg := ethconfig.Defaults.Snapshot
freezingCfg.ChainName = c.Chain

salt, err := snaptype.GetIndexSalt(dirs.Snap)

if err != nil {
return err
}
snTypes := snapshotsync.MakeCaplinStateSnapshotsTypes(db)
stateSn := snapshotsync.NewCaplinStateSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, snTypes, log.Root())
stateSn := snapshotsync.NewCaplinStateSnapshots(freezingCfg, beaconConfig, dirs, snTypes, log.Root())
if err := stateSn.OpenFolder(); err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/caplin/caplin1/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ func RunCaplinService(ctx context.Context, engine execution_client.ExecutionEngi

logger := log.New("app", "caplin")

csn := freezeblocks.NewCaplinSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, logger)
config.NetworkId = clparams.CustomNetwork // Force custom network
freezeCfg := ethconfig.Defaults.Snapshot
freezeCfg.ChainName = beaconConfig.ConfigName
csn := freezeblocks.NewCaplinSnapshots(freezeCfg, beaconConfig, dirs, logger)
rcsn := freezeblocks.NewBeaconSnapshotReader(csn, eth1Getter, beaconConfig)

pool := pool.NewOperationsPool(beaconConfig)
Expand Down
17 changes: 10 additions & 7 deletions cmd/hack/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ func printCurrentBlockNumber(chaindata string) {
}

func blocksIO(db kv.RoDB) (services.FullBlockReader, *blockio.BlockWriter) {
br := freezeblocks.NewBlockReader(freezeblocks.NewRoSnapshots(ethconfig.BlocksFreezing{}, "", 0, log.New()), nil, nil, nil)
cc := tool.ChainConfigFromDB(db)
freezeCfg := ethconfig.Defaults.Snapshot
freezeCfg.ChainName = cc.ChainName
br := freezeblocks.NewBlockReader(freezeblocks.NewRoSnapshots(freezeCfg, "", 0, log.New()), nil, nil, nil)
bw := blockio.NewBlockWriter()
return br, bw
}
Expand Down Expand Up @@ -277,10 +280,12 @@ func extractHeaders(chaindata string, block uint64, blockTotalOrOffset int64) er
}

func extractBodies(datadir string) error {
snaps := freezeblocks.NewRoSnapshots(ethconfig.BlocksFreezing{
KeepBlocks: true,
ProduceE2: false,
}, filepath.Join(datadir, "snapshots"), 0, log.New())
db := mdbx.MustOpen(filepath.Join(datadir, "chaindata"))
defer db.Close()
cc := tool.ChainConfigFromDB(db)
freezeCfg := ethconfig.Defaults.Snapshot
freezeCfg.ChainName = cc.ChainName
snaps := freezeblocks.NewRoSnapshots(freezeCfg, filepath.Join(datadir, "snapshots"), 0, log.New())
snaps.OpenFolder()

/* method Iterate was removed, need re-implement
Expand Down Expand Up @@ -317,8 +322,6 @@ func extractBodies(datadir string) error {
return nil
})
*/
db := mdbx.MustOpen(filepath.Join(datadir, "chaindata"))
defer db.Close()
br, _ := blocksIO(db)

tx, err := db.BeginRo(context.Background())
Expand Down
30 changes: 14 additions & 16 deletions cmd/snapshots/cmp/cmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@ func (c comparitor) compareHeaders(ctx context.Context, f1ents []fs.DirEntry, f2
var downloadTime uint64
var compareTime uint64

freezeCfg := ethconfig.Defaults.Snapshot
freezeCfg.NoDownloader = true
freezeCfg.ProduceE2 = false
freezeCfg.ChainName = c.chain

g, ctx := errgroup.WithContext(ctx)
g.SetLimit(workers)

Expand Down Expand Up @@ -477,19 +482,13 @@ func (c comparitor) compareHeaders(ctx context.Context, f1ents []fs.DirEntry, f2

info1, _, _ := snaptype.ParseFileName(c.session1.LocalFsRoot(), ent1.Name())

f1snaps := freezeblocks.NewRoSnapshots(ethconfig.BlocksFreezing{
ProduceE2: false,
NoDownloader: true,
}, info1.Dir(), info1.From, logger)
f1snaps := freezeblocks.NewRoSnapshots(freezeCfg, info1.Dir(), info1.From, logger)

f1snaps.OpenList([]string{ent1.Name()}, false)

info2, _, _ := snaptype.ParseFileName(c.session2.LocalFsRoot(), ent1.Name())

f2snaps := freezeblocks.NewRoSnapshots(ethconfig.BlocksFreezing{
ProduceE2: false,
NoDownloader: true,
}, info2.Dir(), info2.From, logger)
f2snaps := freezeblocks.NewRoSnapshots(freezeCfg, info2.Dir(), info2.From, logger)

f2snaps.OpenList([]string{ent2.Name()}, false)

Expand Down Expand Up @@ -581,6 +580,11 @@ func (c comparitor) compareBodies(ctx context.Context, f1ents []*BodyEntry, f2en
var indexTime uint64
var compareTime uint64

freezeCfg := ethconfig.Defaults.Snapshot
freezeCfg.NoDownloader = true
freezeCfg.ProduceE2 = false
freezeCfg.ChainName = c.chain

g, ctx := errgroup.WithContext(ctx)
g.SetLimit(workers)

Expand Down Expand Up @@ -756,19 +760,13 @@ func (c comparitor) compareBodies(ctx context.Context, f1ents []*BodyEntry, f2en

info1, _, _ := snaptype.ParseFileName(c.session1.LocalFsRoot(), ent1.Body.Name())

f1snaps := freezeblocks.NewRoSnapshots(ethconfig.BlocksFreezing{
ProduceE2: false,
NoDownloader: true,
}, info1.Dir(), info1.From, logger)
f1snaps := freezeblocks.NewRoSnapshots(freezeCfg, info1.Dir(), info1.From, logger)

f1snaps.OpenList([]string{ent1.Body.Name(), ent1.Transactions.Name()}, false)

info2, _, _ := snaptype.ParseFileName(c.session2.LocalFsRoot(), ent2.Body.Name())

f2snaps := freezeblocks.NewRoSnapshots(ethconfig.BlocksFreezing{
ProduceE2: false,
NoDownloader: true,
}, info2.Dir(), info2.From, logger)
f2snaps := freezeblocks.NewRoSnapshots(freezeCfg, info2.Dir(), info2.From, logger)

f2snaps.OpenList([]string{ent2.Body.Name(), ent2.Transactions.Name()}, false)

Expand Down
4 changes: 3 additions & 1 deletion cmd/state/commands/opcode_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,9 @@ func OpcodeTracer(genesis *types.Genesis, blockNum uint64, chaindata string, num
defer historyTx.Rollback()

dirs := datadir2.New(filepath.Dir(chainDb.(*mdbx.MdbxKV).Path()))
blockReader := freezeblocks.NewBlockReader(freezeblocks.NewRoSnapshots(ethconfig.BlocksFreezing{}, dirs.Snap, 0, log.New()), nil, nil, nil)
freezeCfg := ethconfig.Defaults.Snapshot
freezeCfg.ChainName = genesis.Config.ChainName
blockReader := freezeblocks.NewBlockReader(freezeblocks.NewRoSnapshots(freezeCfg, dirs.Snap, 0, log.New()), nil, nil, nil)

chainConfig := genesis.Config
vmConfig := vm.Config{Tracer: ot, Debug: true}
Expand Down
6 changes: 5 additions & 1 deletion cmd/state/verify/verify_txlookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/erigontech/erigon-lib/kv"
"github.com/erigontech/erigon-lib/kv/mdbx"
"github.com/erigontech/erigon-lib/log/v3"
"github.com/erigontech/erigon/cmd/hack/tool"
"github.com/erigontech/erigon/core/rawdb/blockio"
"github.com/erigontech/erigon/eth/ethconfig"
"github.com/erigontech/erigon/turbo/services"
Expand All @@ -39,7 +40,10 @@ import (

func blocksIO(db kv.RoDB) (services.FullBlockReader, *blockio.BlockWriter) {
dirs := datadir2.New(filepath.Dir(db.(*mdbx.MdbxKV).Path()))
br := freezeblocks.NewBlockReader(freezeblocks.NewRoSnapshots(ethconfig.BlocksFreezing{}, dirs.Snap, 0, log.New()), nil, nil, nil)
cc := tool.ChainConfigFromDB(db)
freezeCfg := ethconfig.Defaults.Snapshot
freezeCfg.ChainName = cc.ChainName
br := freezeblocks.NewBlockReader(freezeblocks.NewRoSnapshots(freezeCfg, dirs.Snap, 0, log.New()), nil, nil, nil)
bw := blockio.NewBlockWriter()
return br, bw
}
Expand Down
1 change: 1 addition & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,7 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C
cfg.Snapshot.NoDownloader = ctx.Bool(NoDownloaderFlag.Name)
cfg.Snapshot.Verify = ctx.Bool(DownloaderVerifyFlag.Name)
cfg.Snapshot.DownloaderAddr = strings.TrimSpace(ctx.String(DownloaderAddrFlag.Name))
cfg.Snapshot.ChainName = chain
if cfg.Snapshot.DownloaderAddr == "" {
downloadRateStr := ctx.String(TorrentDownloadRateFlag.Name)
uploadRateStr := ctx.String(TorrentUploadRateFlag.Name)
Expand Down
7 changes: 7 additions & 0 deletions erigon-lib/chain/snapcfg/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,13 @@ func MergeStepsFromCfg(cfg *Cfg, snapType snaptype.Enum, fromBlock uint64) []uin
return snaptype.MergeSteps
}

func IsFrozen(networkName string, info snaptype.FileInfo) bool {
if networkName == "" {
return false
}
return KnownCfg(networkName).IsFrozen(info)
}

// KnownCfg return list of preverified hashes for given network, but apply whiteList filter if it's not empty
func KnownCfg(networkName string) *Cfg {
c, ok := knownPreverified[networkName]
Expand Down
15 changes: 7 additions & 8 deletions p2p/sentry/simulator/sentry_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ func NewSentry(ctx context.Context, chain string, snapshotLocation string, peerC
cfg := snapcfg.KnownCfg(chain)
torrentDir := filepath.Join(snapshotLocation, "torrents", chain)

knownSnapshots := freezeblocks.NewRoSnapshots(ethconfig.BlocksFreezing{
ProduceE2: false,
NoDownloader: true,
}, "", 0, logger)
freezeCfg := ethconfig.Defaults.Snapshot
freezeCfg.NoDownloader = true
freezeCfg.ProduceE2 = false
freezeCfg.ProduceE3 = false
freezeCfg.ChainName = chain
knownSnapshots := freezeblocks.NewRoSnapshots(freezeCfg, "", 0, logger)

files := make([]string, 0, len(cfg.Preverified))

Expand All @@ -99,10 +101,7 @@ func NewSentry(ctx context.Context, chain string, snapshotLocation string, peerC
knownSnapshots.InitSegments(files)

//s.knownSnapshots.OpenList([]string{ent2.Name()}, false)
activeSnapshots := freezeblocks.NewRoSnapshots(ethconfig.BlocksFreezing{
ProduceE2: false,
NoDownloader: true,
}, torrentDir, 0, logger)
activeSnapshots := freezeblocks.NewRoSnapshots(freezeCfg, torrentDir, 0, logger)

if err := activeSnapshots.OpenFolder(); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion tests/bor/helper/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func InitMiner(ctx context.Context, dirName string, genesis *types.Genesis, priv
DeprecatedTxPool: ethconfig.Defaults.DeprecatedTxPool,
RPCGasCap: 50000000,
RPCTxFeeCap: 1, // 1 ether
Snapshot: ethconfig.BlocksFreezing{NoDownloader: true},
Snapshot: ethconfig.BlocksFreezing{NoDownloader: true, ChainName: genesis.Config.ChainName},
StateStream: true,
}
ethCfg.TxPool.DBDir = nodeCfg.Dirs.TxPool
Expand Down
9 changes: 6 additions & 3 deletions turbo/snapshotsync/caplin_state_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"sync/atomic"
"time"

"github.com/erigontech/erigon-lib/common/dbg"
"github.com/tidwall/btree"

"github.com/erigontech/erigon-lib/log/v3"
Expand Down Expand Up @@ -166,6 +167,10 @@ type SnapshotTypes struct {
// - gaps are not allowed
// - segment have [from:to) semantic
func NewCaplinStateSnapshots(cfg ethconfig.BlocksFreezing, beaconCfg *clparams.BeaconChainConfig, dirs datadir.Dirs, snapshotTypes SnapshotTypes, logger log.Logger) *CaplinStateSnapshots {
if cfg.ChainName == "" {
log.Debug("[dbg] NewCaplinSnapshots created with empty ChainName", "stack", dbg.Stack())
}

// BeaconBlocks := &segments{
// DirtySegments: btree.NewBTreeGOptions[*DirtySegment](DirtySegmentLess, btree.Options{Degree: 128, NoLocks: false}),
// }
Expand Down Expand Up @@ -269,8 +274,6 @@ func (s *CaplinStateSnapshots) OpenList(fileNames []string, optimistic bool) err
s.dirtySegmentsLock.Lock()
defer s.dirtySegmentsLock.Unlock()

snConfig := snapcfg.KnownCfg(s.cfg.ChainName)

s.closeWhatNotInList(fileNames)
var segmentsMax uint64
var segmentsMaxSet bool
Expand Down Expand Up @@ -305,7 +308,7 @@ Loop:
// segType: f.Type, Unsupported
version: f.Version,
Range: Range{f.From, f.To},
frozen: snConfig.IsFrozen(f),
frozen: snapcfg.IsFrozen(s.cfg.ChainName, f),
filePath: filePath,
}
}
Expand Down
Loading

0 comments on commit e2d00e3

Please sign in to comment.