From 09b566dde1c3b44f2567679a2049ae8210f2ba1f Mon Sep 17 00:00:00 2001 From: Aayush Date: Sat, 15 Jul 2023 11:26:18 -0400 Subject: [PATCH] fix: daemon: set real beacon schedule when importing chain --- chain/beacon/drand/drand.go | 13 +++++++++++++ cmd/lotus-shed/gas-estimation.go | 24 +++++++----------------- cmd/lotus/daemon.go | 9 +++++++-- node/modules/services.go | 10 +++------- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/chain/beacon/drand/drand.go b/chain/beacon/drand/drand.go index 9b62a79287d..aa5e36717e9 100644 --- a/chain/beacon/drand/drand.go +++ b/chain/beacon/drand/drand.go @@ -235,3 +235,16 @@ func (db *DrandBeacon) maxBeaconRoundV2(latestTs uint64) uint64 { } var _ beacon.RandomBeacon = (*DrandBeacon)(nil) + +func BeaconScheduleFromDrandSchedule(dcs dtypes.DrandSchedule, genesisTime uint64, ps *pubsub.PubSub) (beacon.Schedule, error) { + shd := beacon.Schedule{} + for _, dc := range dcs { + bc, err := NewDrandBeacon(genesisTime, build.BlockDelaySecs, ps, dc.Config) + if err != nil { + return nil, xerrors.Errorf("creating drand beacon: %w", err) + } + shd = append(shd, beacon.BeaconPoint{Start: dc.Start, Beacon: bc}) + } + + return shd, nil +} diff --git a/cmd/lotus-shed/gas-estimation.go b/cmd/lotus-shed/gas-estimation.go index e02e2a722e1..5dc048f562c 100644 --- a/cmd/lotus-shed/gas-estimation.go +++ b/cmd/lotus-shed/gas-estimation.go @@ -16,7 +16,6 @@ import ( "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/build" - "github.com/filecoin-project/lotus/chain/beacon" "github.com/filecoin-project/lotus/chain/beacon/drand" "github.com/filecoin-project/lotus/chain/consensus" "github.com/filecoin-project/lotus/chain/consensus/filcns" @@ -100,15 +99,11 @@ var gasTraceCmd = &cli.Command{ return err } - dcs := build.DrandConfigSchedule() - shd := beacon.Schedule{} - for _, dc := range dcs { - bc, err := drand.NewDrandBeacon(MAINNET_GENESIS_TIME, build.BlockDelaySecs, nil, dc.Config) - if err != nil { - return xerrors.Errorf("creating drand beacon: %w", err) - } - shd = append(shd, beacon.BeaconPoint{Start: dc.Start, Beacon: bc}) + shd, err := drand.BeaconScheduleFromDrandSchedule(build.DrandConfigSchedule(), MAINNET_GENESIS_TIME, nil) + if err != nil { + return err } + cs := store.NewChainStore(bs, bs, mds, filcns.Weight, nil) defer cs.Close() //nolint:errcheck @@ -200,14 +195,9 @@ var replayOfflineCmd = &cli.Command{ return err } - dcs := build.DrandConfigSchedule() - shd := beacon.Schedule{} - for _, dc := range dcs { - bc, err := drand.NewDrandBeacon(MAINNET_GENESIS_TIME, build.BlockDelaySecs, nil, dc.Config) - if err != nil { - return xerrors.Errorf("creating drand beacon: %w", err) - } - shd = append(shd, beacon.BeaconPoint{Start: dc.Start, Beacon: bc}) + shd, err := drand.BeaconScheduleFromDrandSchedule(build.DrandConfigSchedule(), MAINNET_GENESIS_TIME, nil) + if err != nil { + return err } cs := store.NewChainStore(bs, bs, mds, filcns.Weight, nil) diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index 53d24553fb2..e58da78d1e1 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -40,6 +40,7 @@ import ( lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/beacon/drand" "github.com/filecoin-project/lotus/chain/consensus" "github.com/filecoin-project/lotus/chain/consensus/filcns" "github.com/filecoin-project/lotus/chain/gen/slashfilter" @@ -570,8 +571,12 @@ func ImportChain(ctx context.Context, r repo.Repo, fname string, snapshot bool) return err } - // TODO: We need to supply the actual beacon after v14 - stm, err := stmgr.NewStateManager(cst, consensus.NewTipSetExecutor(filcns.RewardFunc), vm.Syscalls(ffiwrapper.ProofVerifier), filcns.DefaultUpgradeSchedule(), nil, mds, index.DummyMsgIndex) + shd, err := drand.BeaconScheduleFromDrandSchedule(build.DrandConfigSchedule(), gb.MinTimestamp(), nil) + if err != nil { + return xerrors.Errorf("failed to construct beacon schedule: %w", err) + } + + stm, err := stmgr.NewStateManager(cst, consensus.NewTipSetExecutor(filcns.RewardFunc), vm.Syscalls(ffiwrapper.ProofVerifier), filcns.DefaultUpgradeSchedule(), shd, mds, index.DummyMsgIndex) if err != nil { return err } diff --git a/node/modules/services.go b/node/modules/services.go index 9acebd07105..bb1d41917b3 100644 --- a/node/modules/services.go +++ b/node/modules/services.go @@ -265,13 +265,9 @@ func RandomSchedule(lc fx.Lifecycle, mctx helpers.MetricsCtx, p RandomBeaconPara return nil, err } - shd := beacon.Schedule{} - for _, dc := range p.DrandConfig { - bc, err := drand.NewDrandBeacon(gen.Timestamp, build.BlockDelaySecs, p.PubSub, dc.Config) - if err != nil { - return nil, xerrors.Errorf("creating drand beacon: %w", err) - } - shd = append(shd, beacon.BeaconPoint{Start: dc.Start, Beacon: bc}) + shd, err := drand.BeaconScheduleFromDrandSchedule(p.DrandConfig, gen.Timestamp, p.PubSub) + if err != nil { + return nil, xerrors.Errorf("failed to create beacon schedule: %w", err) } return shd, nil