diff --git a/chain/types/blockheader.go b/chain/types/blockheader.go index 8950fd91a..36b43c012 100644 --- a/chain/types/blockheader.go +++ b/chain/types/blockheader.go @@ -22,6 +22,16 @@ type Ticket struct { VRFProof []byte } +func (t *Ticket) Quality() float64 { + ticketHash := blake2b.Sum256(t.VRFProof) + ticketNum := BigFromBytes(ticketHash[:]).Int + ticketDenu := big.NewInt(1) + ticketDenu.Lsh(ticketDenu, 256) + tv, _ := new(big.Rat).SetFrac(ticketNum, ticketDenu).Float64() + tq := 1 - tv + return tq +} + type BeaconEntry struct { Round uint64 Data []byte diff --git a/miner/miner.go b/miner/miner.go index 077e18638..27d3c040d 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -6,12 +6,10 @@ import ( "crypto/rand" "encoding/binary" "fmt" - "math/big" "sync" "time" "github.com/filecoin-project/lotus/chain/gen/slashfilter" - "github.com/minio/blake2b-simd" "github.com/filecoin-project/go-address" "github.com/filecoin-project/specs-actors/actors/abi" @@ -392,14 +390,8 @@ func (m *Miner) mineOne(ctx context.Context, base *MiningBase) (*types.BlockMsg, return nil, xerrors.Errorf("failed to compute winning post proof: %w", err) } - ticketHash := blake2b.Sum256(ticket.VRFProof) - ticketNum := types.BigFromBytes(ticketHash[:]).Int - ticketDenu := big.NewInt(1) - ticketDenu.Lsh(ticketDenu, 256) - tq, _ := new(big.Rat).SetFrac(ticketNum, ticketDenu).Float64() - tq = 1 - tq // get pending messages early, - msgs, err := m.api.MpoolSelect(context.TODO(), base.TipSet.Key(), tq) + msgs, err := m.api.MpoolSelect(context.TODO(), base.TipSet.Key(), ticket.Quality()) if err != nil { return nil, xerrors.Errorf("failed to select messages for block: %w", err) } diff --git a/node/impl/full/mpool.go b/node/impl/full/mpool.go index b1d9a58cb..cd6adef6d 100644 --- a/node/impl/full/mpool.go +++ b/node/impl/full/mpool.go @@ -43,7 +43,6 @@ func (a *MpoolAPI) MpoolSelect(ctx context.Context, tsk types.TipSetKey, ticketQ return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err) } - // TODO FIXME compute (or pass in) the actual ticket quality! return a.Mpool.SelectMessages(ts, ticketQuality) }