diff --git a/api/api_full.go b/api/api_full.go index 184805698..42c5017de 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -159,7 +159,7 @@ type FullNode interface { MpoolPending(context.Context, types.TipSetKey) ([]*types.SignedMessage, error) // MpoolSelect returns a list of pending messages for inclusion in the next block - MpoolSelect(context.Context, types.TipSetKey) ([]*types.SignedMessage, error) + MpoolSelect(context.Context, types.TipSetKey, float64) ([]*types.SignedMessage, error) // MpoolPush pushes a signed message to mempool. MpoolPush(context.Context, *types.SignedMessage) (cid.Cid, error) diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index a571e4564..c7f1314fd 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -97,9 +97,11 @@ type FullNodeStruct struct { SyncMarkBad func(ctx context.Context, bcid cid.Cid) error `perm:"admin"` SyncCheckBad func(ctx context.Context, bcid cid.Cid) (string, error) `perm:"read"` - MpoolGetConfig func(context.Context) (*types.MpoolConfig, error) `perm:"read"` - MpoolSetConfig func(context.Context, *types.MpoolConfig) error `perm:"write"` - MpoolSelect func(context.Context, types.TipSetKey) ([]*types.SignedMessage, error) `perm:"read"` + MpoolGetConfig func(context.Context) (*types.MpoolConfig, error) `perm:"read"` + MpoolSetConfig func(context.Context, *types.MpoolConfig) error `perm:"write"` + + MpoolSelect func(context.Context, types.TipSetKey, float64) ([]*types.SignedMessage, error) `perm:"read"` + MpoolPending func(context.Context, types.TipSetKey) ([]*types.SignedMessage, error) `perm:"read"` MpoolPush func(context.Context, *types.SignedMessage) (cid.Cid, error) `perm:"write"` MpoolPushMessage func(context.Context, *types.Message) (*types.SignedMessage, error) `perm:"sign"` @@ -456,8 +458,8 @@ func (c *FullNodeStruct) MpoolSetConfig(ctx context.Context, cfg *types.MpoolCon return c.Internal.MpoolSetConfig(ctx, cfg) } -func (c *FullNodeStruct) MpoolSelect(ctx context.Context, tsk types.TipSetKey) ([]*types.SignedMessage, error) { - return c.Internal.MpoolSelect(ctx, tsk) +func (c *FullNodeStruct) MpoolSelect(ctx context.Context, tsk types.TipSetKey, tq float64) ([]*types.SignedMessage, error) { + return c.Internal.MpoolSelect(ctx, tsk, tq) } func (c *FullNodeStruct) MpoolPending(ctx context.Context, tsk types.TipSetKey) ([]*types.SignedMessage, error) { diff --git a/cli/state.go b/cli/state.go index 3072d4c01..5b8a10a7a 100644 --- a/cli/state.go +++ b/cli/state.go @@ -858,7 +858,7 @@ var stateComputeStateCmd = &cli.Command{ var msgs []*types.Message if cctx.Bool("apply-mpool-messages") { - pmsgs, err := api.MpoolSelect(ctx, ts.Key()) + pmsgs, err := api.MpoolSelect(ctx, ts.Key(), 1) if err != nil { return err } diff --git a/cmd/lotus-shed/mpool.go b/cmd/lotus-shed/mpool.go index c7a2e9b39..d3660db69 100644 --- a/cmd/lotus-shed/mpool.go +++ b/cmd/lotus-shed/mpool.go @@ -20,6 +20,12 @@ var mpoolCmd = &cli.Command{ var minerSelectMsgsCmd = &cli.Command{ Name: "miner-select-msgs", + Flags: []cli.Flag{ + &cli.Float64Flag{ + Name: "ticket-quality", + Value: 1, + }, + }, Action: func(cctx *cli.Context) error { api, closer, err := lcli.GetFullNodeAPI(cctx) if err != nil { @@ -34,7 +40,7 @@ var minerSelectMsgsCmd = &cli.Command{ return err } - msgs, err := api.MpoolSelect(ctx, head.Key()) + msgs, err := api.MpoolSelect(ctx, head.Key(), cctx.Float64("ticket-quality")) if err != nil { return err } diff --git a/cmd/lotus/debug_advance.go b/cmd/lotus/debug_advance.go index 17d63b6de..72c833bb6 100644 --- a/cmd/lotus/debug_advance.go +++ b/cmd/lotus/debug_advance.go @@ -33,7 +33,7 @@ func init() { if err != nil { return err } - msgs, err := api.MpoolSelect(ctx, head.Key()) + msgs, err := api.MpoolSelect(ctx, head.Key(), 1) if err != nil { return err } diff --git a/miner/miner.go b/miner/miner.go index b8bb9e562..077e18638 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -6,10 +6,12 @@ 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" @@ -390,8 +392,14 @@ 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()) + msgs, err := m.api.MpoolSelect(context.TODO(), base.TipSet.Key(), tq) 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 346f3e2c6..20ca271c0 100644 --- a/node/impl/full/mpool.go +++ b/node/impl/full/mpool.go @@ -40,14 +40,14 @@ func (a *MpoolAPI) MpoolSetConfig(ctx context.Context, cfg *types.MpoolConfig) e return nil } -func (a *MpoolAPI) MpoolSelect(ctx context.Context, tsk types.TipSetKey) ([]*types.SignedMessage, error) { +func (a *MpoolAPI) MpoolSelect(ctx context.Context, tsk types.TipSetKey, ticketQuality float64) ([]*types.SignedMessage, error) { ts, err := a.Chain.GetTipSetFromKey(tsk) if err != nil { 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, 1.0) + return a.Mpool.SelectMessages(ts, ticketQuality) } func (a *MpoolAPI) MpoolPending(ctx context.Context, tsk types.TipSetKey) ([]*types.SignedMessage, error) {