From 4b3cc2ca7ebcb8a6d00788462657733209a63508 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Thu, 30 Apr 2020 11:27:22 -0700 Subject: [PATCH] fix winning post inputs --- chain/sync.go | 13 ++++++------- miner/miner.go | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/chain/sync.go b/chain/sync.go index 19c3bf9d5..6ca56b5b0 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -687,7 +687,7 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err }) wproofCheck := async.Err(func() error { - if err := syncer.VerifyWinningPoStProof(ctx, h, lbst, waddr); err != nil { + if err := syncer.VerifyWinningPoStProof(ctx, h, *prevBeacon, lbst, waddr); err != nil { return xerrors.Errorf("invalid election post: %w", err) } return nil @@ -730,7 +730,7 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err return merr } -func (syncer *Syncer) VerifyWinningPoStProof(ctx context.Context, h *types.BlockHeader, lbst cid.Cid, waddr address.Address) error { +func (syncer *Syncer) VerifyWinningPoStProof(ctx context.Context, h *types.BlockHeader, prevBeacon types.BeaconEntry, lbst cid.Cid, waddr address.Address) error { if build.InsecurePoStValidation { if len(h.WinPoStProof) == 0 { return xerrors.Errorf("[TESTING] No winning post proof given") @@ -742,13 +742,12 @@ func (syncer *Syncer) VerifyWinningPoStProof(ctx context.Context, h *types.Block return xerrors.Errorf("[TESTING] winning post was invalid") } - curTs, err := types.NewTipSet([]*types.BlockHeader{h}) - if err != nil { - return err + rbase := prevBeacon + if len(h.BeaconEntries) > 0 { + rbase = h.BeaconEntries[len(h.BeaconEntries)-1] } - // TODO: use proper DST - rand, err := syncer.sm.ChainStore().GetRandomness(ctx, curTs.Cids(), crypto.DomainSeparationTag_WinningPoStChallengeSeed, h.Height-1, nil) + rand, err := store.DrawRandomness(rbase.Data, crypto.DomainSeparationTag_WinningPoStChallengeSeed, h.Height-1, nil) if err != nil { return xerrors.Errorf("failed to get randomness for verifying winningPost proof: %w", err) } diff --git a/miner/miner.go b/miner/miner.go index fe3e04683..70c768fa4 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -361,7 +361,7 @@ func (m *Miner) mineOne(ctx context.Context, addr address.Address, base *MiningB return nil, nil } - rand, err := m.api.ChainGetRandomness(ctx, base.TipSet.Key(), crypto.DomainSeparationTag_WinningPoStChallengeSeed, base.TipSet.Height()+base.NullRounds, nil) + rand, err := store.DrawRandomness(rbase.Data, crypto.DomainSeparationTag_WinningPoStChallengeSeed, base.TipSet.Height()+base.NullRounds, nil) if err != nil { return nil, xerrors.Errorf("failed to get randomness for winning post: %w", err) }