finish addressing review
This commit is contained in:
parent
7ee6388686
commit
ac271b021d
@ -386,6 +386,7 @@ type MiningBaseInfo struct {
|
|||||||
Sectors []*ChainSectorInfo
|
Sectors []*ChainSectorInfo
|
||||||
Worker address.Address
|
Worker address.Address
|
||||||
SectorSize abi.SectorSize
|
SectorSize abi.SectorSize
|
||||||
|
PrevBeaconEntry types.BeaconEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
type BlockTemplate struct {
|
type BlockTemplate struct {
|
||||||
|
@ -31,9 +31,19 @@ func NewDrandBeacon() *DrandBeacon {
|
|||||||
func (db *DrandBeacon) Entry(ctx context.Context, round uint64) <-chan beacon.Response {
|
func (db *DrandBeacon) Entry(ctx context.Context, round uint64) <-chan beacon.Response {
|
||||||
// check cache, it it if there, otherwise query the endpoint
|
// check cache, it it if there, otherwise query the endpoint
|
||||||
resp, err := db.client.PublicRand(nil, &dproto.PublicRandRequest{Round: round})
|
resp, err := db.client.PublicRand(nil, &dproto.PublicRandRequest{Round: round})
|
||||||
_, _ = resp, err
|
|
||||||
|
|
||||||
return nil
|
var br beacon.Response
|
||||||
|
if err != nil {
|
||||||
|
br.Err = err
|
||||||
|
} else {
|
||||||
|
br.Entry.Round = resp.GetRound()
|
||||||
|
br.Entry.Data = resp.GetSignature()
|
||||||
|
}
|
||||||
|
|
||||||
|
out := make(chan beacon.Response, 1)
|
||||||
|
out <- br
|
||||||
|
|
||||||
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DrandBeacon) VerifyEntry(types.BeaconEntry, types.BeaconEntry) error {
|
func (db *DrandBeacon) VerifyEntry(types.BeaconEntry, types.BeaconEntry) error {
|
||||||
|
@ -279,22 +279,25 @@ func CarWalkFunc(nd format.Node) (out []*format.Link, err error) {
|
|||||||
|
|
||||||
func (cg *ChainGen) nextBlockProof(ctx context.Context, pts *types.TipSet, m address.Address, round abi.ChainEpoch) ([]types.BeaconEntry, *types.ElectionProof, *types.Ticket, error) {
|
func (cg *ChainGen) nextBlockProof(ctx context.Context, pts *types.TipSet, m address.Address, round abi.ChainEpoch) ([]types.BeaconEntry, *types.ElectionProof, *types.Ticket, error) {
|
||||||
mc := &mca{w: cg.w, sm: cg.sm}
|
mc := &mca{w: cg.w, sm: cg.sm}
|
||||||
prev, err := cg.cs.GetLatestBeaconEntry(pts)
|
|
||||||
|
mbi, err := mc.MinerGetBaseInfo(ctx, m, pts.Key())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, xerrors.Errorf("getLatestBeaconEntry: %w", err)
|
return nil, nil, nil, xerrors.Errorf("get miner base info: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
entries, err := beacon.BeaconEntriesForBlock(ctx, cg.beacon, round, *prev)
|
prev := mbi.PrevBeaconEntry
|
||||||
|
|
||||||
|
entries, err := beacon.BeaconEntriesForBlock(ctx, cg.beacon, round, prev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, xerrors.Errorf("get beacon entries for block: %w", err)
|
return nil, nil, nil, xerrors.Errorf("get beacon entries for block: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rbase := *prev
|
rbase := prev
|
||||||
if len(entries) > 0 {
|
if len(entries) > 0 {
|
||||||
rbase = entries[len(entries)-1]
|
rbase = entries[len(entries)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
eproof, err := IsRoundWinner(ctx, pts, round, m, rbase, mc)
|
eproof, err := IsRoundWinner(ctx, pts, round, m, rbase, mbi, mc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, xerrors.Errorf("checking round winner failed: %w", err)
|
return nil, nil, nil, xerrors.Errorf("checking round winner failed: %w", err)
|
||||||
}
|
}
|
||||||
@ -534,7 +537,7 @@ type ProofInput struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsRoundWinner(ctx context.Context, ts *types.TipSet, round abi.ChainEpoch,
|
func IsRoundWinner(ctx context.Context, ts *types.TipSet, round abi.ChainEpoch,
|
||||||
miner address.Address, brand types.BeaconEntry, a MiningCheckAPI) (*types.ElectionProof, error) {
|
miner address.Address, brand types.BeaconEntry, mbi *api.MiningBaseInfo, a MiningCheckAPI) (*types.ElectionProof, error) {
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
if err := miner.MarshalCBOR(buf); err != nil {
|
if err := miner.MarshalCBOR(buf); err != nil {
|
||||||
@ -546,11 +549,6 @@ func IsRoundWinner(ctx context.Context, ts *types.TipSet, round abi.ChainEpoch,
|
|||||||
return nil, xerrors.Errorf("failed to draw randomness: %w", err)
|
return nil, xerrors.Errorf("failed to draw randomness: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
mbi, err := a.MinerGetBaseInfo(ctx, miner, ts.Key())
|
|
||||||
if err != nil {
|
|
||||||
return nil, xerrors.Errorf("failed to get mining base info: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
vrfout, err := ComputeVRF(ctx, a.WalletSign, mbi.Worker, electionRand)
|
vrfout, err := ComputeVRF(ctx, a.WalletSign, mbi.Worker, electionRand)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("failed to compute VRF: %w", err)
|
return nil, xerrors.Errorf("failed to compute VRF: %w", err)
|
||||||
|
@ -2,6 +2,7 @@ package stmgr
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
amt "github.com/filecoin-project/go-amt-ipld/v2"
|
amt "github.com/filecoin-project/go-amt-ipld/v2"
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
||||||
@ -418,11 +419,17 @@ func MinerGetBaseInfo(ctx context.Context, sm *StateManager, tsk types.TipSetKey
|
|||||||
return nil, xerrors.Errorf("failed to get miner sector size: %w", err)
|
return nil, xerrors.Errorf("failed to get miner sector size: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prev, err := sm.ChainStore().GetLatestBeaconEntry(ts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("failed to get latest beacon entry: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return &api.MiningBaseInfo{
|
return &api.MiningBaseInfo{
|
||||||
MinerPower: mpow,
|
MinerPower: mpow,
|
||||||
NetworkPower: tpow,
|
NetworkPower: tpow,
|
||||||
Sectors: provset,
|
Sectors: provset,
|
||||||
Worker: worker,
|
Worker: worker,
|
||||||
SectorSize: ssize,
|
SectorSize: ssize,
|
||||||
|
PrevBeaconEntry: *prev,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -317,13 +317,15 @@ func (m *Miner) mineOne(ctx context.Context, addr address.Address, base *MiningB
|
|||||||
log.Debugw("attempting to mine a block", "tipset", types.LogCids(base.ts.Cids()))
|
log.Debugw("attempting to mine a block", "tipset", types.LogCids(base.ts.Cids()))
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
beaconPrev, err := m.getLatestBeaconEntry(ctx, base.ts)
|
mbi, err := m.api.MinerGetBaseInfo(ctx, addr, base.ts.Key())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("getLatestBeaconEntry: %w", err)
|
return nil, xerrors.Errorf("failed to get mining base info: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
beaconPrev := mbi.PrevBeaconEntry
|
||||||
|
|
||||||
round := base.ts.Height() + base.nullRounds + 1
|
round := base.ts.Height() + base.nullRounds + 1
|
||||||
bvals, err := beacon.BeaconEntriesForBlock(ctx, m.beacon, round, *beaconPrev)
|
bvals, err := beacon.BeaconEntriesForBlock(ctx, m.beacon, round, beaconPrev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("get beacon entries failed: %w", err)
|
return nil, xerrors.Errorf("get beacon entries failed: %w", err)
|
||||||
}
|
}
|
||||||
@ -340,7 +342,7 @@ func (m *Miner) mineOne(ctx context.Context, addr address.Address, base *MiningB
|
|||||||
|
|
||||||
log.Infof("Time delta between now and our mining base: %ds (nulls: %d)", uint64(time.Now().Unix())-base.ts.MinTimestamp(), base.nullRounds)
|
log.Infof("Time delta between now and our mining base: %ds (nulls: %d)", uint64(time.Now().Unix())-base.ts.MinTimestamp(), base.nullRounds)
|
||||||
|
|
||||||
rbase := *beaconPrev
|
rbase := beaconPrev
|
||||||
if len(bvals) > 0 {
|
if len(bvals) > 0 {
|
||||||
rbase = bvals[len(bvals)-1]
|
rbase = bvals[len(bvals)-1]
|
||||||
}
|
}
|
||||||
@ -350,7 +352,7 @@ func (m *Miner) mineOne(ctx context.Context, addr address.Address, base *MiningB
|
|||||||
return nil, xerrors.Errorf("scratching ticket failed: %w", err)
|
return nil, xerrors.Errorf("scratching ticket failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
winner, err := gen.IsRoundWinner(ctx, base.ts, round, addr, rbase, m.api)
|
winner, err := gen.IsRoundWinner(ctx, base.ts, round, addr, rbase, mbi, m.api)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("failed to check if we win next round: %w", err)
|
return nil, xerrors.Errorf("failed to check if we win next round: %w", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user