diff --git a/chain/gen/gen.go b/chain/gen/gen.go index e29c2b0e3..1f45147dc 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -306,8 +306,11 @@ func (cg *ChainGen) nextBlockProof(ctx context.Context, pts *types.TipSet, m add return nil, nil, nil, xerrors.Errorf("failed to cbor marshal address: %w", err) } - ticketRand, err := cg.cs.GetRandomness(ctx, pts.Cids(), crypto.DomainSeparationTag_TicketProduction, - round-build.TicketRandomnessLookback, buf.Bytes()) + if len(entries) == 0 { + buf.Write(pts.MinTicket().VRFProof) + } + + ticketRand, err := store.DrawRandomness(rbase.Data, crypto.DomainSeparationTag_TicketProduction, round-build.TicketRandomnessLookback, buf.Bytes()) if err != nil { return nil, nil, nil, err } diff --git a/chain/sync.go b/chain/sync.go index 92df7820f..19c3bf9d5 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -667,8 +667,14 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err return xerrors.Errorf("failed to marshal miner address to cbor: %w", err) } - vrfBase, err := syncer.sm.ChainStore().GetRandomness(ctx, baseTs.Cids(), - crypto.DomainSeparationTag_TicketProduction, h.Height-build.TicketRandomnessLookback, buf.Bytes()) + beaconBase := *prevBeacon + if len(h.BeaconEntries) == 0 { + buf.Write(baseTs.MinTicket().VRFProof) + } else { + beaconBase = h.BeaconEntries[len(h.BeaconEntries)-1] + } + + vrfBase, err := store.DrawRandomness(beaconBase.Data, crypto.DomainSeparationTag_TicketProduction, h.Height-build.TicketRandomnessLookback, buf.Bytes()) if err != nil { return xerrors.Errorf("failed to compute vrf base for ticket: %w", err) } diff --git a/miner/miner.go b/miner/miner.go index 78abb2691..fe3e04683 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -16,6 +16,7 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/beacon" "github.com/filecoin-project/lotus/chain/gen" + "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" logging "github.com/ipfs/go-log/v2" @@ -345,7 +346,7 @@ func (m *Miner) mineOne(ctx context.Context, addr address.Address, base *MiningB rbase = bvals[len(bvals)-1] } - ticket, err := m.computeTicket(ctx, addr, &rbase, base) + ticket, err := m.computeTicket(ctx, addr, &rbase, base, len(bvals) > 0) if err != nil { return nil, xerrors.Errorf("scratching ticket failed: %w", err) } @@ -393,7 +394,7 @@ func (m *Miner) mineOne(ctx context.Context, addr address.Address, base *MiningB return b, nil } -func (m *Miner) computeTicket(ctx context.Context, addr address.Address, brand *types.BeaconEntry, base *MiningBase) (*types.Ticket, error) { +func (m *Miner) computeTicket(ctx context.Context, addr address.Address, brand *types.BeaconEntry, base *MiningBase, haveNewEntries bool) (*types.Ticket, error) { mi, err := m.api.StateMinerInfo(ctx, addr, types.EmptyTSK) if err != nil { return nil, err @@ -407,8 +408,12 @@ func (m *Miner) computeTicket(ctx context.Context, addr address.Address, brand * if err := addr.MarshalCBOR(buf); err != nil { return nil, xerrors.Errorf("failed to marshal address to cbor: %w", err) } - input, err := m.api.ChainGetRandomness(ctx, base.TipSet.Key(), crypto.DomainSeparationTag_TicketProduction, - base.TipSet.Height()+base.NullRounds+1-build.TicketRandomnessLookback, buf.Bytes()) + + if !haveNewEntries { + buf.Write(base.TipSet.MinTicket().VRFProof) + } + + input, err := store.DrawRandomness(brand.Data, crypto.DomainSeparationTag_TicketProduction, base.TipSet.Height()+base.NullRounds+1-build.TicketRandomnessLookback, buf.Bytes()) if err != nil { return nil, err }