Skip to content

Commit

Permalink
Fix lookback for worker key when computing ticket
Browse files Browse the repository at this point in the history
We need to compute the ticket based on our worker key from the lookback epoch,
not the current epoch.
  • Loading branch information
Stebalien committed Oct 22, 2020
1 parent 4a550d1 commit e5fc307
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func (m *Miner) mineOne(ctx context.Context, base *MiningBase) (*types.BlockMsg,
rbase = bvals[len(bvals)-1]
}

ticket, err := m.computeTicket(ctx, &rbase, base)
ticket, err := m.computeTicket(ctx, &rbase, base, mbi)
if err != nil {
return nil, xerrors.Errorf("scratching ticket failed: %w", err)
}
Expand Down Expand Up @@ -456,16 +456,7 @@ func (m *Miner) mineOne(ctx context.Context, base *MiningBase) (*types.BlockMsg,
return b, nil
}

func (m *Miner) computeTicket(ctx context.Context, brand *types.BeaconEntry, base *MiningBase) (*types.Ticket, error) {
mi, err := m.api.StateMinerInfo(ctx, m.address, types.EmptyTSK)
if err != nil {
return nil, err
}
worker, err := m.api.StateAccountKey(ctx, mi.Worker, types.EmptyTSK)
if err != nil {
return nil, err
}

func (m *Miner) computeTicket(ctx context.Context, brand *types.BeaconEntry, base *MiningBase, mbi *api.MiningBaseInfo) (*types.Ticket, error) {
buf := new(bytes.Buffer)
if err := m.address.MarshalCBOR(buf); err != nil {
return nil, xerrors.Errorf("failed to marshal address to cbor: %w", err)
Expand All @@ -476,6 +467,11 @@ func (m *Miner) computeTicket(ctx context.Context, brand *types.BeaconEntry, bas
buf.Write(base.TipSet.MinTicket().VRFProof)
}

worker, err := m.api.StateAccountKey(ctx, mbi.WorkerKey, types.EmptyTSK)
if err != nil {
return nil, err
}

input, err := store.DrawRandomness(brand.Data, crypto.DomainSeparationTag_TicketProduction, round-build.TicketRandomnessLookback, buf.Bytes())
if err != nil {
return nil, err
Expand Down

0 comments on commit e5fc307

Please sign in to comment.