fix winning post inputs

This commit is contained in:
Jeromy 2020-04-30 11:27:22 -07:00
parent d7d2b12a32
commit 4b3cc2ca7e
2 changed files with 7 additions and 8 deletions

View File

@ -687,7 +687,7 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
}) })
wproofCheck := async.Err(func() error { 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 xerrors.Errorf("invalid election post: %w", err)
} }
return nil return nil
@ -730,7 +730,7 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
return merr 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 build.InsecurePoStValidation {
if len(h.WinPoStProof) == 0 { if len(h.WinPoStProof) == 0 {
return xerrors.Errorf("[TESTING] No winning post proof given") 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") return xerrors.Errorf("[TESTING] winning post was invalid")
} }
curTs, err := types.NewTipSet([]*types.BlockHeader{h}) rbase := prevBeacon
if err != nil { if len(h.BeaconEntries) > 0 {
return err rbase = h.BeaconEntries[len(h.BeaconEntries)-1]
} }
// TODO: use proper DST rand, err := store.DrawRandomness(rbase.Data, crypto.DomainSeparationTag_WinningPoStChallengeSeed, h.Height-1, nil)
rand, err := syncer.sm.ChainStore().GetRandomness(ctx, curTs.Cids(), crypto.DomainSeparationTag_WinningPoStChallengeSeed, h.Height-1, nil)
if err != nil { if err != nil {
return xerrors.Errorf("failed to get randomness for verifying winningPost proof: %w", err) return xerrors.Errorf("failed to get randomness for verifying winningPost proof: %w", err)
} }

View File

@ -361,7 +361,7 @@ func (m *Miner) mineOne(ctx context.Context, addr address.Address, base *MiningB
return nil, nil 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 { if err != nil {
return nil, xerrors.Errorf("failed to get randomness for winning post: %w", err) return nil, xerrors.Errorf("failed to get randomness for winning post: %w", err)
} }