reuse GetTipsetByHeight in GetRandomness
This commit is contained in:
parent
8aa158d4e6
commit
2fdcf5347b
@ -909,25 +909,26 @@ func (cs *ChainStore) GetRandomness(ctx context.Context, blks []cid.Cid, pers cr
|
|||||||
defer span.End()
|
defer span.End()
|
||||||
span.AddAttributes(trace.Int64Attribute("round", int64(round)))
|
span.AddAttributes(trace.Int64Attribute("round", int64(round)))
|
||||||
|
|
||||||
//defer func() {
|
ts, err := cs.LoadTipSet(types.NewTipSetKey(blks...))
|
||||||
//log.Infof("getRand %v %d %d %x -> %x", blks, pers, round, entropy, out)
|
if err != nil {
|
||||||
//}()
|
return nil, err
|
||||||
for {
|
|
||||||
nts, err := cs.LoadTipSet(types.NewTipSetKey(blks...))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
mtb := nts.MinTicketBlock()
|
|
||||||
|
|
||||||
// if at (or just past -- for null epochs) appropriate epoch
|
|
||||||
// or at genesis (works for negative epochs)
|
|
||||||
if nts.Height() <= round || mtb.Height == 0 {
|
|
||||||
return DrawRandomness(nts.MinTicketBlock().Ticket.VRFProof, pers, round, entropy)
|
|
||||||
}
|
|
||||||
|
|
||||||
blks = mtb.Parents
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
searchHeight := round
|
||||||
|
if searchHeight < 0 {
|
||||||
|
searchHeight = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
randTs, err := cs.GetTipsetByHeight(ctx, searchHeight, ts, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
mtb := randTs.MinTicketBlock()
|
||||||
|
|
||||||
|
// if at (or just past -- for null epochs) appropriate epoch
|
||||||
|
// or at genesis (works for negative epochs)
|
||||||
|
return DrawRandomness(mtb.Ticket.VRFProof, pers, round, entropy)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTipsetByHeight returns the tipset on the chain behind 'ts' at the given
|
// GetTipsetByHeight returns the tipset on the chain behind 'ts' at the given
|
||||||
|
Loading…
Reference in New Issue
Block a user