WIP: working on winning post integration
This commit is contained in:
parent
4153f128ef
commit
708988244d
@ -386,12 +386,13 @@ type MiningBaseInfo struct {
|
||||
}
|
||||
|
||||
type BlockTemplate struct {
|
||||
Miner address.Address
|
||||
Parents types.TipSetKey
|
||||
Ticket *types.Ticket
|
||||
Eproof *types.ElectionProof
|
||||
BeaconValues []types.BeaconEntry
|
||||
Messages []*types.SignedMessage
|
||||
Epoch abi.ChainEpoch
|
||||
Timestamp uint64
|
||||
Miner address.Address
|
||||
Parents types.TipSetKey
|
||||
Ticket *types.Ticket
|
||||
Eproof *types.ElectionProof
|
||||
BeaconValues []types.BeaconEntry
|
||||
Messages []*types.SignedMessage
|
||||
Epoch abi.ChainEpoch
|
||||
Timestamp uint64
|
||||
WinningPoStProof []abi.PoStProof
|
||||
}
|
||||
|
@ -324,8 +324,6 @@ func (cg *ChainGen) nextBlockProof(ctx context.Context, pts *types.TipSet, m add
|
||||
return nil, nil, nil, xerrors.Errorf("compute VRF: %w", err)
|
||||
}
|
||||
|
||||
// TODO winning post return?
|
||||
|
||||
return entries, eproof, &types.Ticket{VRFProof: vrfout}, nil
|
||||
}
|
||||
|
||||
@ -502,7 +500,7 @@ func (mca mca) WalletSign(ctx context.Context, a address.Address, v []byte) (*cr
|
||||
|
||||
type WinningPoStProver interface {
|
||||
GenerateCandidates(context.Context, abi.PoStRandomness, uint64) ([]uint64, error)
|
||||
ComputeProof(context.Context, []abi.SectorInfo, []byte) ([]abi.PoStProof, error)
|
||||
ComputeProof(context.Context, []abi.SectorInfo, abi.PoStRandomness) ([]abi.PoStProof, error)
|
||||
}
|
||||
|
||||
type wppProvider struct{}
|
||||
@ -511,7 +509,7 @@ func (wpp *wppProvider) GenerateCandidates(ctx context.Context, _ abi.PoStRandom
|
||||
return []uint64{0}, nil
|
||||
}
|
||||
|
||||
func (wpp *wppProvider) ComputeProof(context.Context, []abi.SectorInfo, []byte) ([]abi.PoStProof, error) {
|
||||
func (wpp *wppProvider) ComputeProof(context.Context, []abi.SectorInfo, abi.PoStRandomness) ([]abi.PoStProof, error) {
|
||||
return []abi.PoStProof{{
|
||||
ProofBytes: []byte("valid proof"),
|
||||
}}, nil
|
||||
|
@ -130,6 +130,10 @@ func GetMinerSectorSet(ctx context.Context, sm *StateManager, ts *types.TipSet,
|
||||
return LoadSectorsFromSet(ctx, sm.ChainStore().Blockstore(), mas.Sectors, filter)
|
||||
}
|
||||
|
||||
func GetSectorsForWinningPoSt(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) ([]*api.ChainSectorInfo, error) {
|
||||
panic("TODO")
|
||||
}
|
||||
|
||||
func StateMinerInfo(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (miner.MinerInfo, error) {
|
||||
var mas miner.State
|
||||
_, err := sm.LoadActorStateRaw(ctx, maddr, &mas, ts.ParentState())
|
||||
|
114
chain/sync.go
114
chain/sync.go
@ -27,6 +27,8 @@ import (
|
||||
bls "github.com/filecoin-project/filecoin-ffi"
|
||||
"github.com/filecoin-project/go-address"
|
||||
amt "github.com/filecoin-project/go-amt-ipld/v2"
|
||||
"github.com/filecoin-project/sector-storage/ffiwrapper"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/power"
|
||||
"github.com/filecoin-project/specs-actors/actors/crypto"
|
||||
@ -661,19 +663,19 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
|
||||
return nil
|
||||
})
|
||||
|
||||
//eproofCheck := async.Err(func() error {
|
||||
//if err := syncer.VerifyElectionPoStProof(ctx, h, waddr); err != nil {
|
||||
//return xerrors.Errorf("invalid election post: %w", err)
|
||||
//}
|
||||
//return nil
|
||||
//})
|
||||
wproofCheck := async.Err(func() error {
|
||||
if err := syncer.VerifyWinningPoStProof(ctx, h, waddr); err != nil {
|
||||
return xerrors.Errorf("invalid election post: %w", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
await := []async.ErrorFuture{
|
||||
minerCheck,
|
||||
tktsCheck,
|
||||
blockSigCheck,
|
||||
beaconValuesCheck,
|
||||
//eproofCheck,
|
||||
wproofCheck,
|
||||
winnerCheck,
|
||||
msgsCheck,
|
||||
}
|
||||
@ -705,109 +707,61 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
|
||||
return merr
|
||||
}
|
||||
|
||||
/*
|
||||
func (syncer *Syncer) VerifyElectionPoStProof(ctx context.Context, h *types.BlockHeader, waddr address.Address) error {
|
||||
func (syncer *Syncer) VerifyWinningPoStProof(ctx context.Context, h *types.BlockHeader, waddr address.Address) error {
|
||||
if build.InsecurePoStValidation {
|
||||
if len(h.WinPoStProof) == 0 {
|
||||
return xerrors.Errorf("[TESTING] No election post proof given")
|
||||
}
|
||||
|
||||
if string(h.WinPoStProof[0].ProofBytes) == "valid proof" {
|
||||
return nil
|
||||
}
|
||||
return xerrors.Errorf("[TESTING] election post was invalid")
|
||||
}
|
||||
|
||||
curTs, err := types.NewTipSet([]*types.BlockHeader{h})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
if err := h.Miner.MarshalCBOR(buf); err != nil {
|
||||
return xerrors.Errorf("failed to marshal miner to cbor: %w", err)
|
||||
}
|
||||
rand, err := syncer.sm.ChainStore().GetRandomness(ctx, curTs.Cids(), crypto.DomainSeparationTag_ElectionPoStChallengeSeed, h.Height-build.EcRandomnessLookback, buf.Bytes())
|
||||
// TODO: use proper DST
|
||||
rand, err := syncer.sm.ChainStore().GetRandomness(ctx, curTs.Cids(), crypto.DomainSeparationTag_ElectionPoStChallengeSeed, h.Height-1, nil)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to get randomness for verifying election proof: %w", err)
|
||||
}
|
||||
|
||||
if err := VerifyElectionPoStVRF(ctx, h.EPostProof.PostRand, rand, waddr); err != nil {
|
||||
return xerrors.Errorf("checking eproof failed: %w", err)
|
||||
}
|
||||
|
||||
ssize, err := stmgr.GetMinerSectorSize(ctx, syncer.sm, curTs, h.Miner)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to get sector size for miner: %w", err)
|
||||
}
|
||||
|
||||
mid, err := address.IDFromAddress(h.Miner)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to get ID from miner address %s: %w", h.Miner, err)
|
||||
}
|
||||
|
||||
var winners []abi.PoStCandidate
|
||||
for _, t := range h.EPostProof.Candidates {
|
||||
winners = append(winners, abi.PoStCandidate{
|
||||
PartialTicket: t.Partial,
|
||||
SectorID: abi.SectorID{
|
||||
Number: t.SectorID,
|
||||
Miner: abi.ActorID(mid),
|
||||
},
|
||||
ChallengeIndex: int64(t.ChallengeIndex),
|
||||
})
|
||||
}
|
||||
|
||||
if len(winners) == 0 {
|
||||
return xerrors.Errorf("no candidates")
|
||||
}
|
||||
|
||||
sectorInfo, err := stmgr.GetSectorsForElectionPost(ctx, syncer.sm, curTs, h.Miner)
|
||||
sectors, err := stmgr.GetSectorsForWinningPoSt(ctx, syncer.sm, curTs, h.Miner)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("getting election post sector set: %w", err)
|
||||
}
|
||||
|
||||
if build.InsecurePoStValidation {
|
||||
if len(h.EPostProof.Proofs) == 0 {
|
||||
return xerrors.Errorf("[TESTING] No election post proof given")
|
||||
}
|
||||
panic("NEED TO GET CHALLENGE epp.GenerateWinningPoStSectorChallenge")
|
||||
challenge := 0
|
||||
|
||||
if string(h.EPostProof.Proofs[0].ProofBytes) == "valid proof" {
|
||||
return nil
|
||||
}
|
||||
return xerrors.Errorf("[TESTING] election post was invalid")
|
||||
}
|
||||
sector := sectors[challenge]
|
||||
|
||||
rt, _, err := ffiwrapper.ProofTypeFromSectorSize(ssize)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
candidates := make([]abi.PoStCandidate, 0, len(h.EPostProof.Candidates))
|
||||
for _, c := range h.EPostProof.Candidates {
|
||||
candidates = append(candidates, abi.PoStCandidate{
|
||||
RegisteredProof: rt,
|
||||
PartialTicket: c.Partial,
|
||||
SectorID: abi.SectorID{Number: c.SectorID}, // this should not be an ID, we already know who the miner is...
|
||||
ChallengeIndex: int64(c.ChallengeIndex),
|
||||
})
|
||||
}
|
||||
|
||||
// TODO: why do we need this here?
|
||||
challengeCount := ffiwrapper.ElectionPostChallengeCount(uint64(len(sectorInfo)), 0)
|
||||
|
||||
hvrf := blake2b.Sum256(h.EPostProof.PostRand)
|
||||
pvi := abi.PoStVerifyInfo{
|
||||
Randomness: hvrf[:],
|
||||
Candidates: candidates,
|
||||
Proofs: h.EPostProof.Proofs,
|
||||
EligibleSectors: sectorInfo,
|
||||
Prover: abi.ActorID(mid),
|
||||
ChallengeCount: challengeCount,
|
||||
}
|
||||
|
||||
ok, err := ffiwrapper.ProofVerifier.VerifyElectionPost(ctx, pvi)
|
||||
ok, err := ffiwrapper.ProofVerifier.VerifyWinningPoSt(ctx, abi.WinningPoStVerifyInfo{
|
||||
Randomness: rand,
|
||||
Proofs: h.WinPoStProof,
|
||||
ChallengedSectors: []abi.SectorInfo{sector.Info.AsSectorInfo()},
|
||||
Prover: abi.ActorID(mid),
|
||||
})
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to verify election post: %w", err)
|
||||
}
|
||||
|
||||
if !ok {
|
||||
log.Errorf("invalid election post (%x; %v)", pvi.Randomness, candidates)
|
||||
log.Errorf("invalid election post (%x; %v)", rand, challenge)
|
||||
return xerrors.Errorf("election post was invalid")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
*/
|
||||
|
||||
func (syncer *Syncer) checkBlockMessages(ctx context.Context, b *types.FullBlock, baseTs *types.TipSet) error {
|
||||
{
|
||||
|
@ -40,6 +40,8 @@ type BlockHeader struct {
|
||||
|
||||
BeaconEntries []BeaconEntry
|
||||
|
||||
WinPoStProof []abi.PoStProof
|
||||
|
||||
Parents []cid.Cid // 3
|
||||
|
||||
ParentWeight BigInt // 4
|
||||
|
@ -339,6 +339,26 @@ func (m *Miner) mineOne(ctx context.Context, addr address.Address, base *MiningB
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// TODO: use the right dst, also NB: not using any 'entropy' in this call because nicola really didnt want it
|
||||
rand, err := m.api.ChainGetRandomness(ctx, base.ts.Key(), crypto.DomainSeparationTag_ElectionPoStChallengeSeed, base.ts.Height()+base.nullRounds, nil)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to get randomness for winning post: %w", err)
|
||||
}
|
||||
|
||||
prand := abi.PoStRandomness(rand)
|
||||
|
||||
sx, err := m.epp.GenerateCandidates(ctx, prand, uint64(len(mbi.Sectors)))
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to generate candidates for winning post: %w", err)
|
||||
}
|
||||
|
||||
si := mbi.Sectors[sx[0]]
|
||||
postInp := []abi.SectorInfo{si.Info.AsSectorInfo()}
|
||||
postProof, err := m.epp.ComputeProof(ctx, postInp, prand)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to compute winning post proof: %w", err)
|
||||
}
|
||||
|
||||
// get pending messages early,
|
||||
pending, err := m.api.MpoolPending(context.TODO(), base.ts.Key())
|
||||
if err != nil {
|
||||
@ -346,7 +366,7 @@ func (m *Miner) mineOne(ctx context.Context, addr address.Address, base *MiningB
|
||||
}
|
||||
|
||||
// TODO: winning post proof
|
||||
b, err := m.createBlock(base, addr, ticket, winner, bvals, pending)
|
||||
b, err := m.createBlock(base, addr, ticket, winner, bvals, postProof, pending)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to create block: %w", err)
|
||||
}
|
||||
@ -391,7 +411,7 @@ func (m *Miner) computeTicket(ctx context.Context, addr address.Address, brand *
|
||||
}
|
||||
|
||||
func (m *Miner) createBlock(base *MiningBase, addr address.Address, ticket *types.Ticket,
|
||||
eproof *types.ElectionProof, bvals []types.BeaconEntry, pending []*types.SignedMessage) (*types.BlockMsg, error) {
|
||||
eproof *types.ElectionProof, bvals []types.BeaconEntry, wpostProof []abi.PoStProof, pending []*types.SignedMessage) (*types.BlockMsg, error) {
|
||||
msgs, err := SelectMessages(context.TODO(), m.api.StateGetActor, base.ts, pending)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("message filtering failed: %w", err)
|
||||
@ -408,14 +428,15 @@ func (m *Miner) createBlock(base *MiningBase, addr address.Address, ticket *type
|
||||
|
||||
// why even return this? that api call could just submit it for us
|
||||
return m.api.MinerCreateBlock(context.TODO(), &api.BlockTemplate{
|
||||
Miner: addr,
|
||||
Parents: base.ts.Key(),
|
||||
Ticket: ticket,
|
||||
Eproof: eproof,
|
||||
BeaconValues: bvals,
|
||||
Messages: msgs,
|
||||
Epoch: nheight,
|
||||
Timestamp: uts,
|
||||
Miner: addr,
|
||||
Parents: base.ts.Key(),
|
||||
Ticket: ticket,
|
||||
Eproof: eproof,
|
||||
BeaconValues: bvals,
|
||||
Messages: msgs,
|
||||
Epoch: nheight,
|
||||
Timestamp: uts,
|
||||
WinningPoStProof: wpostProof,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -391,7 +391,8 @@ func mockSbBuilder(t *testing.T, nFull int, storage []int) ([]test.TestNode, []t
|
||||
node.Override(new(sectorstorage.SectorManager), func() (sectorstorage.SectorManager, error) {
|
||||
return mock.NewMockSectorMgr(5, build.SectorSizes[0]), nil
|
||||
}),
|
||||
node.Override(new(ffiwrapper.Verifier), mock.MockVerifier),
|
||||
node.Override(new(ffiwrapper.Verifier), ffiwrapper.ProofVerifier),
|
||||
//node.Override(new(ffiwrapper.Verifier), mock.MockVerifier),
|
||||
node.Unset(new(*sectorstorage.Manager)),
|
||||
))
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ func (wpp *StorageWpp) GenerateCandidates(ctx context.Context, randomness abi.Po
|
||||
return cds, nil
|
||||
}
|
||||
|
||||
func (wpp *StorageWpp) ComputeProof(ctx context.Context, ssi []abi.SectorInfo, rand []byte) ([]abi.PoStProof, error) {
|
||||
func (wpp *StorageWpp) ComputeProof(ctx context.Context, ssi []abi.SectorInfo, rand abi.PoStRandomness) ([]abi.PoStProof, error) {
|
||||
if build.InsecurePoStValidation {
|
||||
log.Warn("Generating fake EPost proof! You should only see this while running tests!")
|
||||
return []abi.PoStProof{{ProofBytes: []byte("valid proof")}}, nil
|
||||
|
Loading…
Reference in New Issue
Block a user