diff --git a/chain/gen/gen.go b/chain/gen/gen.go index d75215083..34e9b9bd0 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -28,6 +28,7 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/beacon" + "github.com/filecoin-project/lotus/chain/beacon/drand" genesis2 "github.com/filecoin-project/lotus/chain/gen/genesis" "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/store" @@ -188,7 +189,7 @@ func NewGenerator() (*ChainGen, error) { *genm2, }, NetworkName: "", - Timestamp: 100000, + Timestamp: uint64(time.Now().Add(-500 * build.BlockDelay * time.Second).Unix()), } genb, err := genesis2.MakeGenesisBlock(context.TODO(), bs, sys, tpl) @@ -214,7 +215,11 @@ func NewGenerator() (*ChainGen, error) { miners := []address.Address{maddr1, maddr2} - beac := beacon.NewMockBeacon(time.Second) + //beac := beacon.NewMockBeacon(time.Second) + beac, err := drand.NewDrandBeacon(tpl.Timestamp, build.BlockDelay) + if err != nil { + return nil, xerrors.Errorf("could not create beacon: %w", err) + } gen := &ChainGen{ bs: bs, diff --git a/chain/sync.go b/chain/sync.go index 11bfa97af..68e118594 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "sort" "strings" "sync" "time" @@ -980,35 +981,32 @@ func (syncer *Syncer) collectHeaders(ctx context.Context, from *types.TipSet, to } } - /* - { - // TODO: Not sure what this check is aiming to do exactly, but it doesnt quite work - // ensure consistency of beacon entires - targetBE := from.Blocks()[0].BeaconEntries - - for _, e := range targetBE[1:] { - if cur >= e.Round { - syncer.bad.Add(from.Cids()[0], "wrong order of beacon entires") - return nil, xerrors.Errorf("wrong order of beacon entires") - } - - } - for _, bh := range from.Blocks()[1:] { - beacon.ValidateBlockValues() - if len(targetBE) != len(bh.BeaconEntries) { - // cannot mark bad, I think @Kubuxu - return nil, xerrors.Errorf("tipset contained different number for beacon entires") - } - for i, be := range bh.BeaconEntries { - if targetBE[i].Round != be.Round || !bytes.Equal(targetBE[i].Data, be.Data) { - // cannot mark bad, I think @Kubuxu - return nil, xerrors.Errorf("tipset contained different number for beacon entires") - } - } - - } + { + // TODO: Not sure what this check is aiming to do exactly, but it doesnt quite work + // ensure consistency of beacon entires + targetBE := from.Blocks()[0].BeaconEntries + sorted := sort.SliceIsSorted(targetBE, func(i, j int) bool { + return targetBE[i].Round < targetBE[j].Round + }) + if !sorted { + syncer.bad.Add(from.Cids()[0], "wrong order of beacon entires") + return nil, xerrors.Errorf("wrong order of beacon entires") } - */ + + for _, bh := range from.Blocks()[1:] { + if len(targetBE) != len(bh.BeaconEntries) { + // cannot mark bad, I think @Kubuxu + return nil, xerrors.Errorf("tipset contained different number for beacon entires") + } + for i, be := range bh.BeaconEntries { + if targetBE[i].Round != be.Round || !bytes.Equal(targetBE[i].Data, be.Data) { + // cannot mark bad, I think @Kubuxu + return nil, xerrors.Errorf("tipset contained different beacon entires") + } + } + + } + } blockSet := []*types.TipSet{from}