Integrate Poisson Sortition into chain sync
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
parent
97088e3109
commit
156a14eeeb
@ -559,11 +559,15 @@ func IsRoundWinner(ctx context.Context, ts *types.TipSet, round abi.ChainEpoch,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: wire in real power
|
// TODO: wire in real power
|
||||||
if !types.IsTicketWinner(vrfout, mbi.MinerPower, mbi.NetworkPower) {
|
// TODO: is above TODO still applicable?
|
||||||
|
ep := &types.ElectionProof{VRFProof: vrfout}
|
||||||
|
j := ep.ComputeWinCount(mbi.MinerPower, mbi.NetworkPower)
|
||||||
|
ep.WinCount = j
|
||||||
|
if j < 1 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.ElectionProof{VRFProof: vrfout}, nil
|
return ep, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type SignFunc func(context.Context, address.Address, []byte) (*crypto.Signature, error)
|
type SignFunc func(context.Context, address.Address, []byte) (*crypto.Signature, error)
|
||||||
|
@ -21,11 +21,11 @@ func (cs *ChainStore) Weight(ctx context.Context, ts *types.TipSet) (types.BigIn
|
|||||||
if ts == nil {
|
if ts == nil {
|
||||||
return types.NewInt(0), nil
|
return types.NewInt(0), nil
|
||||||
}
|
}
|
||||||
// >>> w[r] <<< + wFunction(totalPowerAtTipset(ts)) * 2^8 + (wFunction(totalPowerAtTipset(ts)) * len(ts.blocks) * wRatio_num * 2^8) / (e * wRatio_den)
|
// >>> w[r] <<< + wFunction(totalPowerAtTipset(ts)) * 2^8 + (wFunction(totalPowerAtTipset(ts)) * sum(ts.blocks.ElectionProof.WinCount) * wRatio_num * 2^8) / (e * wRatio_den)
|
||||||
|
|
||||||
var out = new(big.Int).Set(ts.Blocks()[0].ParentWeight.Int)
|
var out = new(big.Int).Set(ts.Blocks()[0].ParentWeight.Int)
|
||||||
|
|
||||||
// >>> wFunction(totalPowerAtTipset(ts)) * 2^8 <<< + (wFunction(totalPowerAtTipset(ts)) * len(ts.blocks) * wRatio_num * 2^8) / (e * wRatio_den)
|
// >>> wFunction(totalPowerAtTipset(ts)) * 2^8 <<< + (wFunction(totalPowerAtTipset(ts)) * sum(ts.blocks.ElectionProof.WinCount) * wRatio_num * 2^8) / (e * wRatio_den)
|
||||||
|
|
||||||
tpow := big2.Zero()
|
tpow := big2.Zero()
|
||||||
{
|
{
|
||||||
@ -57,11 +57,19 @@ func (cs *ChainStore) Weight(ctx context.Context, ts *types.TipSet) (types.BigIn
|
|||||||
|
|
||||||
out.Add(out, big.NewInt(log2P<<8))
|
out.Add(out, big.NewInt(log2P<<8))
|
||||||
|
|
||||||
// (wFunction(totalPowerAtTipset(ts)) * len(ts.blocks) * wRatio_num * 2^8) / (e * wRatio_den)
|
// (wFunction(totalPowerAtTipset(ts)) * sum(ts.blocks.ElectionProof.WinCount) * wRatio_num * 2^8) / (e * wRatio_den)
|
||||||
|
|
||||||
eWeight := big.NewInt((log2P * int64(len(ts.Blocks())) * build.WRatioNum) << 8)
|
totalJ := uint64(0)
|
||||||
eWeight.Div(eWeight, big.NewInt(int64(build.BlocksPerEpoch*build.WRatioDen)))
|
for _, b := range ts.Blocks() {
|
||||||
out.Add(out, eWeight)
|
totalJ += b.ElectionProof.WinCount
|
||||||
|
}
|
||||||
|
|
||||||
|
eWeight := big.NewInt((log2P * build.WRatioNum))
|
||||||
|
eWeight = eWeight.Lsh(eWeight, 8)
|
||||||
|
eWeight = eWeight.Mul(eWeight, new(big.Int).SetUint64(totalJ))
|
||||||
|
eWeight = eWeight.Div(eWeight, big.NewInt(int64(build.BlocksPerEpoch*build.WRatioDen)))
|
||||||
|
|
||||||
|
out = out.Add(out, eWeight)
|
||||||
|
|
||||||
return types.BigInt{Int: out}, nil
|
return types.BigInt{Int: out}, nil
|
||||||
}
|
}
|
||||||
|
@ -210,6 +210,12 @@ func (bv *BlockValidator) Validate(ctx context.Context, pid peer.ID, msg *pubsub
|
|||||||
return pubsub.ValidationReject
|
return pubsub.ValidationReject
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if blk.Header.ElectionProof.WinCount < 1 {
|
||||||
|
log.Errorf("block is not claiming to be winning")
|
||||||
|
recordFailure("not_winning")
|
||||||
|
return pubsub.ValidationReject
|
||||||
|
}
|
||||||
|
|
||||||
// it's a good block! make sure we've only seen it once
|
// it's a good block! make sure we've only seen it once
|
||||||
if bv.recvBlocks.add(blk.Header.Cid()) > 0 {
|
if bv.recvBlocks.add(blk.Header.Cid()) > 0 {
|
||||||
// TODO: once these changes propagate to the network, we can consider
|
// TODO: once these changes propagate to the network, we can consider
|
||||||
|
@ -651,6 +651,10 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) (er
|
|||||||
}
|
}
|
||||||
|
|
||||||
winnerCheck := async.Err(func() error {
|
winnerCheck := async.Err(func() error {
|
||||||
|
if h.ElectionProof.WinCount < 1 {
|
||||||
|
return xerrors.Errorf("block is not claiming to be a winner")
|
||||||
|
}
|
||||||
|
|
||||||
rBeacon := *prevBeacon
|
rBeacon := *prevBeacon
|
||||||
if len(h.BeaconEntries) != 0 {
|
if len(h.BeaconEntries) != 0 {
|
||||||
rBeacon = h.BeaconEntries[len(h.BeaconEntries)-1]
|
rBeacon = h.BeaconEntries[len(h.BeaconEntries)-1]
|
||||||
@ -660,7 +664,6 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) (er
|
|||||||
return xerrors.Errorf("failed to marshal miner address to cbor: %w", err)
|
return xerrors.Errorf("failed to marshal miner address to cbor: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: DST from spec actors when it is there
|
|
||||||
vrfBase, err := store.DrawRandomness(rBeacon.Data, crypto.DomainSeparationTag_ElectionProofProduction, h.Height, buf.Bytes())
|
vrfBase, err := store.DrawRandomness(rBeacon.Data, crypto.DomainSeparationTag_ElectionProofProduction, h.Height, buf.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("could not draw randomness: %w", err)
|
return xerrors.Errorf("could not draw randomness: %w", err)
|
||||||
@ -684,8 +687,9 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) (er
|
|||||||
return xerrors.Errorf("failed getting power: %w", err)
|
return xerrors.Errorf("failed getting power: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !types.IsTicketWinner(h.ElectionProof.VRFProof, mpow.QualityAdjPower, tpow.QualityAdjPower) {
|
j := h.ElectionProof.ComputeWinCount(mpow.QualityAdjPower, tpow.QualityAdjPower)
|
||||||
return xerrors.Errorf("miner created a block but was not a winner")
|
if h.ElectionProof.WinCount != j {
|
||||||
|
return xerrors.Errorf("miner claims wrong number of wins: miner: %d, computed: %d", h.ElectionProof.WinCount, j)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user