Skip to content

Commit

Permalink
caplin: use tmpdir inside datadir (#8041)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed Sep 6, 2023
1 parent f346e76 commit 3cb8a95
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
6 changes: 5 additions & 1 deletion cl/phase1/stages/clstages.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"time"

"github.com/ledgerwatch/erigon-lib/common/datadir"
"github.com/ledgerwatch/erigon/cl/clparams"
"github.com/ledgerwatch/erigon/cl/clstages"
"github.com/ledgerwatch/erigon/cl/cltypes"
Expand All @@ -30,6 +31,7 @@ type Cfg struct {
gossipManager *network2.GossipManager
forkChoice *forkchoice.ForkChoiceStore
beaconDB persistence.BeaconChainDatabase
dirs datadir.Dirs
}

type Args struct {
Expand All @@ -48,6 +50,7 @@ func ClStagesCfg(
gossipManager *network2.GossipManager,
forkChoice *forkchoice.ForkChoiceStore,
beaconDB persistence.BeaconChainDatabase,
dirs datadir.Dirs,
) *Cfg {
return &Cfg{
rpc: rpc,
Expand All @@ -58,6 +61,7 @@ func ClStagesCfg(
gossipManager: gossipManager,
forkChoice: forkChoice,
beaconDB: beaconDB,
dirs: dirs,
}
}

Expand Down Expand Up @@ -235,7 +239,7 @@ func ConsensusClStages(ctx context.Context,
startingSlot := cfg.state.LatestBlockHeader().Slot
downloader := network2.NewBackwardBeaconDownloader(ctx, cfg.rpc)

return SpawnStageHistoryDownload(StageHistoryReconstruction(downloader, cfg.beaconDB, cfg.executionClient, cfg.genesisCfg, cfg.beaconCfg, 0, startingRoot, startingSlot, "/tmp", logger), ctx, logger)
return SpawnStageHistoryDownload(StageHistoryReconstruction(downloader, cfg.beaconDB, cfg.executionClient, cfg.genesisCfg, cfg.beaconCfg, 0, startingRoot, startingSlot, cfg.dirs.Tmp, logger), ctx, logger)
},
},
CatchUpEpochs: {
Expand Down
9 changes: 5 additions & 4 deletions cmd/caplin-phase1/caplin1/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"time"

"github.com/ledgerwatch/erigon-lib/common/datadir"
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
"github.com/ledgerwatch/erigon/cl/freezer"
"github.com/ledgerwatch/erigon/cl/persistence"
Expand All @@ -24,7 +25,7 @@ import (
func RunCaplinPhase1(ctx context.Context, sentinel sentinel.SentinelClient,
beaconConfig *clparams.BeaconChainConfig, genesisConfig *clparams.GenesisConfig,
engine execution_client.ExecutionEngine, state *state.CachingBeaconState,
caplinFreezer freezer.Freezer, datadir string) error {
caplinFreezer freezer.Freezer, dirs datadir.Dirs) error {
ctx, cn := context.WithCancel(ctx)
defer cn()

Expand All @@ -51,7 +52,7 @@ func RunCaplinPhase1(ctx context.Context, sentinel sentinel.SentinelClient,
return true
})
gossipManager := network.NewGossipReceiver(sentinel, forkChoice, beaconConfig, genesisConfig, caplinFreezer)
dataDirFs := afero.NewBasePathFs(afero.NewOsFs(), datadir)
dataDirFs := afero.NewBasePathFs(afero.NewOsFs(), dirs.DataDir)

{ // start the gossip manager
go gossipManager.Start(ctx)
Expand Down Expand Up @@ -87,8 +88,8 @@ func RunCaplinPhase1(ctx context.Context, sentinel sentinel.SentinelClient,
}
}()
}
beaconDB := persistence.NewbeaconChainDatabaseFilesystem(afero.NewBasePathFs(dataDirFs, datadir), beaconConfig)
stageCfg := stages.ClStagesCfg(beaconRpc, genesisConfig, beaconConfig, state, engine, gossipManager, forkChoice, beaconDB)
beaconDB := persistence.NewbeaconChainDatabaseFilesystem(afero.NewBasePathFs(dataDirFs, dirs.DataDir), beaconConfig)
stageCfg := stages.ClStagesCfg(beaconRpc, genesisConfig, beaconConfig, state, engine, gossipManager, forkChoice, beaconDB, dirs)
sync := stages.ConsensusClStages(ctx, stageCfg)

logger.Info("[caplin] starting clstages loop")
Expand Down
2 changes: 1 addition & 1 deletion cmd/caplin-phase1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,5 @@ func runCaplinNode(cliCtx *cli.Context) error {
}
}

return caplin1.RunCaplinPhase1(ctx, sentinel, cfg.BeaconCfg, cfg.GenesisCfg, executionEngine, state, caplinFreezer, cfg.DataDir)
return caplin1.RunCaplinPhase1(ctx, sentinel, cfg.BeaconCfg, cfg.GenesisCfg, executionEngine, state, caplinFreezer, cfg.Dirs)
}
3 changes: 3 additions & 0 deletions cmd/sentinel/cli/cliSettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"time"

"github.com/ledgerwatch/erigon-lib/common/datadir"
"github.com/ledgerwatch/erigon/cl/phase1/core/rawdb"
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
"github.com/ledgerwatch/erigon/common"
Expand Down Expand Up @@ -54,6 +55,7 @@ type ConsensusClientCliCfg struct {
JwtSecret []byte

InitalState *state.CachingBeaconState
Dirs datadir.Dirs
}

func SetupConsensusClientCfg(ctx *cli.Context) (*ConsensusClientCliCfg, error) {
Expand Down Expand Up @@ -97,6 +99,7 @@ func SetupConsensusClientCfg(ctx *cli.Context) (*ConsensusClientCliCfg, error) {
cfg.RecordMode = ctx.Bool(flags.RecordModeFlag.Name)
cfg.RecordDir = ctx.String(flags.RecordModeDir.Name)
cfg.DataDir = ctx.String(utils.DataDirFlag.Name)
cfg.Dirs = datadir.New(cfg.DataDir)

cfg.RunEngineAPI = ctx.Bool(flags.RunEngineAPI.Name)
cfg.EngineAPIAddr = ctx.String(flags.EngineApiHostFlag.Name)
Expand Down
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
return nil, err
}
fmt.Println(engine)
go caplin1.RunCaplinPhase1(ctx, client, beaconCfg, genesisCfg, engine, state, nil, dirs.DataDir)
go caplin1.RunCaplinPhase1(ctx, client, beaconCfg, genesisCfg, engine, state, nil, dirs)
}

return backend, nil
Expand Down

0 comments on commit 3cb8a95

Please sign in to comment.