Fix windowpost test
This commit is contained in:
parent
5ea61abfe1
commit
71cf358ee3
@ -132,6 +132,9 @@ type FullNode interface {
|
|||||||
GasEstimateGasPremium(_ context.Context, nblocksincl uint64,
|
GasEstimateGasPremium(_ context.Context, nblocksincl uint64,
|
||||||
sender address.Address, gaslimit int64, tsk types.TipSetKey) (types.BigInt, error)
|
sender address.Address, gaslimit int64, tsk types.TipSetKey) (types.BigInt, error)
|
||||||
|
|
||||||
|
// GasEstimateMessageGas estimates gas values unset message gas fields
|
||||||
|
GasEstimateMessageGas(context.Context, *types.Message, *MessageSendSpec, types.TipSetKey) (*types.Message, error)
|
||||||
|
|
||||||
// MethodGroup: Sync
|
// MethodGroup: Sync
|
||||||
// The Sync method group contains methods for interacting with and
|
// The Sync method group contains methods for interacting with and
|
||||||
// observing the lotus sync service.
|
// observing the lotus sync service.
|
||||||
|
@ -90,9 +90,10 @@ type FullNodeStruct struct {
|
|||||||
|
|
||||||
BeaconGetEntry func(ctx context.Context, epoch abi.ChainEpoch) (*types.BeaconEntry, error) `perm:"read"`
|
BeaconGetEntry func(ctx context.Context, epoch abi.ChainEpoch) (*types.BeaconEntry, error) `perm:"read"`
|
||||||
|
|
||||||
GasEstimateGasPremium func(context.Context, uint64, address.Address, int64, types.TipSetKey) (types.BigInt, error) `perm:"read"`
|
GasEstimateGasPremium func(context.Context, uint64, address.Address, int64, types.TipSetKey) (types.BigInt, error) `perm:"read"`
|
||||||
GasEstimateGasLimit func(context.Context, *types.Message, types.TipSetKey) (int64, error) `perm:"read"`
|
GasEstimateGasLimit func(context.Context, *types.Message, types.TipSetKey) (int64, error) `perm:"read"`
|
||||||
GasEstimateFeeCap func(context.Context, *types.Message, int64, types.TipSetKey) (types.BigInt, error) `perm:"read"`
|
GasEstimateFeeCap func(context.Context, *types.Message, int64, types.TipSetKey) (types.BigInt, error) `perm:"read"`
|
||||||
|
GasEstimateMessageGas func(context.Context, *types.Message, *api.MessageSendSpec, types.TipSetKey) (*types.Message, error) `perm:"read"`
|
||||||
|
|
||||||
SyncState func(context.Context) (*api.SyncState, error) `perm:"read"`
|
SyncState func(context.Context) (*api.SyncState, error) `perm:"read"`
|
||||||
SyncSubmitBlock func(ctx context.Context, blk *types.BlockMsg) error `perm:"write"`
|
SyncSubmitBlock func(ctx context.Context, blk *types.BlockMsg) error `perm:"write"`
|
||||||
@ -459,17 +460,19 @@ func (c *FullNodeStruct) ClientDataTransferUpdates(ctx context.Context) (<-chan
|
|||||||
return c.Internal.ClientDataTransferUpdates(ctx)
|
return c.Internal.ClientDataTransferUpdates(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) GasEstimateGasPremium(ctx context.Context, nblocksincl uint64,
|
func (c *FullNodeStruct) GasEstimateGasPremium(ctx context.Context, nblocksincl uint64, sender address.Address, gaslimit int64, tsk types.TipSetKey) (types.BigInt, error) {
|
||||||
sender address.Address, gaslimit int64, tsk types.TipSetKey) (types.BigInt, error) {
|
|
||||||
return c.Internal.GasEstimateGasPremium(ctx, nblocksincl, sender, gaslimit, tsk)
|
return c.Internal.GasEstimateGasPremium(ctx, nblocksincl, sender, gaslimit, tsk)
|
||||||
}
|
}
|
||||||
func (c *FullNodeStruct) GasEstimateFeeCap(ctx context.Context, msg *types.Message,
|
|
||||||
maxqueueblks int64, tsk types.TipSetKey) (types.BigInt, error) {
|
func (c *FullNodeStruct) GasEstimateFeeCap(ctx context.Context, msg *types.Message, maxqueueblks int64, tsk types.TipSetKey) (types.BigInt, error) {
|
||||||
return c.Internal.GasEstimateFeeCap(ctx, msg, maxqueueblks, tsk)
|
return c.Internal.GasEstimateFeeCap(ctx, msg, maxqueueblks, tsk)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) GasEstimateGasLimit(ctx context.Context, msg *types.Message,
|
func (c *FullNodeStruct) GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, tsk types.TipSetKey) (*types.Message, error) {
|
||||||
tsk types.TipSetKey) (int64, error) {
|
return c.Internal.GasEstimateMessageGas(ctx, msg, spec, tsk)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *FullNodeStruct) GasEstimateGasLimit(ctx context.Context, msg *types.Message, tsk types.TipSetKey) (int64, error) {
|
||||||
return c.Internal.GasEstimateGasLimit(ctx, msg, tsk)
|
return c.Internal.GasEstimateGasLimit(ctx, msg, tsk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/messagepool"
|
"github.com/filecoin-project/lotus/chain/messagepool"
|
||||||
"github.com/filecoin-project/lotus/chain/stmgr"
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
||||||
@ -176,3 +177,33 @@ func (a *GasAPI) GasEstimateGasLimit(ctx context.Context, msgIn *types.Message,
|
|||||||
|
|
||||||
return res.MsgRct.GasUsed, nil
|
return res.MsgRct.GasUsed, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *GasAPI) GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, _ types.TipSetKey) (*types.Message, error) {
|
||||||
|
if msg.GasLimit == 0 {
|
||||||
|
gasLimit, err := a.GasEstimateGasLimit(ctx, msg, types.TipSetKey{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("estimating gas used: %w", err)
|
||||||
|
}
|
||||||
|
msg.GasLimit = int64(float64(gasLimit) * a.Mpool.GetConfig().GasLimitOverestimation)
|
||||||
|
}
|
||||||
|
|
||||||
|
if msg.GasPremium == types.EmptyInt || types.BigCmp(msg.GasPremium, types.NewInt(0)) == 0 {
|
||||||
|
gasPremium, err := a.GasEstimateGasPremium(ctx, 2, msg.From, msg.GasLimit, types.TipSetKey{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("estimating gas price: %w", err)
|
||||||
|
}
|
||||||
|
msg.GasPremium = gasPremium
|
||||||
|
}
|
||||||
|
|
||||||
|
if msg.GasFeeCap == types.EmptyInt || types.BigCmp(msg.GasFeeCap, types.NewInt(0)) == 0 {
|
||||||
|
feeCap, err := a.GasEstimateFeeCap(ctx, msg, 10, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("estimating fee cap: %w", err)
|
||||||
|
}
|
||||||
|
msg.GasFeeCap = big.Add(feeCap, msg.GasPremium)
|
||||||
|
}
|
||||||
|
|
||||||
|
capGasFee(msg, spec.Get().MaxFee)
|
||||||
|
|
||||||
|
return msg, nil
|
||||||
|
}
|
||||||
|
@ -146,32 +146,12 @@ func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, spe
|
|||||||
if msg.Nonce != 0 {
|
if msg.Nonce != 0 {
|
||||||
return nil, xerrors.Errorf("MpoolPushMessage expects message nonce to be 0, was %d", msg.Nonce)
|
return nil, xerrors.Errorf("MpoolPushMessage expects message nonce to be 0, was %d", msg.Nonce)
|
||||||
}
|
}
|
||||||
if msg.GasLimit == 0 {
|
|
||||||
gasLimit, err := a.GasEstimateGasLimit(ctx, msg, types.TipSetKey{})
|
|
||||||
if err != nil {
|
|
||||||
return nil, xerrors.Errorf("estimating gas used: %w", err)
|
|
||||||
}
|
|
||||||
msg.GasLimit = int64(float64(gasLimit) * a.Mpool.GetConfig().GasLimitOverestimation)
|
|
||||||
}
|
|
||||||
|
|
||||||
if msg.GasPremium == types.EmptyInt || types.BigCmp(msg.GasPremium, types.NewInt(0)) == 0 {
|
msg, err := a.GasAPI.GasEstimateMessageGas(ctx, msg, spec, types.EmptyTSK)
|
||||||
gasPremium, err := a.GasEstimateGasPremium(ctx, 2, msg.From, msg.GasLimit, types.TipSetKey{})
|
if err != nil {
|
||||||
if err != nil {
|
return nil, xerrors.Errorf("GasEstimateMessageGas error: %w", err)
|
||||||
return nil, xerrors.Errorf("estimating gas price: %w", err)
|
|
||||||
}
|
|
||||||
msg.GasPremium = gasPremium
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.GasFeeCap == types.EmptyInt || types.BigCmp(msg.GasFeeCap, types.NewInt(0)) == 0 {
|
|
||||||
feeCap, err := a.GasEstimateFeeCap(ctx, msg, 10, types.EmptyTSK)
|
|
||||||
if err != nil {
|
|
||||||
return nil, xerrors.Errorf("estimating fee cap: %w", err)
|
|
||||||
}
|
|
||||||
msg.GasFeeCap = big.Add(feeCap, msg.GasPremium)
|
|
||||||
}
|
|
||||||
|
|
||||||
capGasFee(msg, spec.Get().MaxFee)
|
|
||||||
|
|
||||||
sign := func(from address.Address, nonce uint64) (*types.SignedMessage, error) {
|
sign := func(from address.Address, nonce uint64) (*types.SignedMessage, error) {
|
||||||
msg.Nonce = nonce
|
msg.Nonce = nonce
|
||||||
if msg.From.Protocol() == address.ID {
|
if msg.From.Protocol() == address.ID {
|
||||||
@ -192,7 +172,6 @@ func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, spe
|
|||||||
}
|
}
|
||||||
|
|
||||||
var m *types.SignedMessage
|
var m *types.SignedMessage
|
||||||
var err error
|
|
||||||
again:
|
again:
|
||||||
m, err = a.Mpool.PushWithNonce(ctx, msg.From, sign)
|
m, err = a.Mpool.PushWithNonce(ctx, msg.From, sign)
|
||||||
if err == messagepool.ErrTryAgain {
|
if err == messagepool.ErrTryAgain {
|
||||||
|
@ -71,6 +71,8 @@ type storageMinerApi interface {
|
|||||||
|
|
||||||
MpoolPushMessage(context.Context, *types.Message, *api.MessageSendSpec) (*types.SignedMessage, error)
|
MpoolPushMessage(context.Context, *types.Message, *api.MessageSendSpec) (*types.SignedMessage, error)
|
||||||
|
|
||||||
|
GasEstimateMessageGas(context.Context, *types.Message, *api.MessageSendSpec, types.TipSetKey) (*types.Message, error)
|
||||||
|
|
||||||
ChainHead(context.Context) (*types.TipSet, error)
|
ChainHead(context.Context) (*types.TipSet, error)
|
||||||
ChainNotify(context.Context) (<-chan []*api.HeadChange, error)
|
ChainNotify(context.Context) (<-chan []*api.HeadChange, error)
|
||||||
ChainGetRandomnessFromTickets(ctx context.Context, tsk types.TipSetKey, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) (abi.Randomness, error)
|
ChainGetRandomnessFromTickets(ctx context.Context, tsk types.TipSetKey, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) (abi.Randomness, error)
|
||||||
|
@ -173,11 +173,13 @@ func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uin
|
|||||||
|
|
||||||
msg := &types.Message{
|
msg := &types.Message{
|
||||||
To: s.actor,
|
To: s.actor,
|
||||||
|
From: s.worker,
|
||||||
Method: builtin.MethodsMiner.DeclareFaultsRecovered,
|
Method: builtin.MethodsMiner.DeclareFaultsRecovered,
|
||||||
Params: enc,
|
Params: enc,
|
||||||
Value: types.NewInt(0),
|
Value: types.NewInt(0),
|
||||||
}
|
}
|
||||||
s.setSender(ctx, msg)
|
spec := &api.MessageSendSpec{MaxFee: abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)}
|
||||||
|
s.setSender(ctx, msg, spec)
|
||||||
|
|
||||||
sm, err := s.api.MpoolPushMessage(ctx, msg, &api.MessageSendSpec{MaxFee: abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)})
|
sm, err := s.api.MpoolPushMessage(ctx, msg, &api.MessageSendSpec{MaxFee: abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -255,13 +257,15 @@ func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64,
|
|||||||
|
|
||||||
msg := &types.Message{
|
msg := &types.Message{
|
||||||
To: s.actor,
|
To: s.actor,
|
||||||
|
From: s.worker,
|
||||||
Method: builtin.MethodsMiner.DeclareFaults,
|
Method: builtin.MethodsMiner.DeclareFaults,
|
||||||
Params: enc,
|
Params: enc,
|
||||||
Value: types.NewInt(0), // TODO: Is there a fee?
|
Value: types.NewInt(0), // TODO: Is there a fee?
|
||||||
}
|
}
|
||||||
s.setSender(ctx, msg)
|
spec := &api.MessageSendSpec{MaxFee: abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)}
|
||||||
|
s.setSender(ctx, msg, spec)
|
||||||
|
|
||||||
sm, err := s.api.MpoolPushMessage(ctx, msg, &api.MessageSendSpec{MaxFee: abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)})
|
sm, err := s.api.MpoolPushMessage(ctx, msg, spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("pushing message to mpool: %w", err)
|
return xerrors.Errorf("pushing message to mpool: %w", err)
|
||||||
}
|
}
|
||||||
@ -461,14 +465,16 @@ func (s *WindowPoStScheduler) submitPost(ctx context.Context, proof *miner.Submi
|
|||||||
|
|
||||||
msg := &types.Message{
|
msg := &types.Message{
|
||||||
To: s.actor,
|
To: s.actor,
|
||||||
|
From: s.worker,
|
||||||
Method: builtin.MethodsMiner.SubmitWindowedPoSt,
|
Method: builtin.MethodsMiner.SubmitWindowedPoSt,
|
||||||
Params: enc,
|
Params: enc,
|
||||||
Value: types.NewInt(1000), // currently hard-coded late fee in actor, returned if not late
|
Value: types.NewInt(1000), // currently hard-coded late fee in actor, returned if not late
|
||||||
}
|
}
|
||||||
s.setSender(ctx, msg)
|
spec := &api.MessageSendSpec{MaxFee: abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)}
|
||||||
|
s.setSender(ctx, msg, spec)
|
||||||
|
|
||||||
// TODO: consider maybe caring about the output
|
// TODO: consider maybe caring about the output
|
||||||
sm, err := s.api.MpoolPushMessage(ctx, msg, &api.MessageSendSpec{MaxFee: abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)})
|
sm, err := s.api.MpoolPushMessage(ctx, msg, spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("pushing message to mpool: %w", err)
|
return xerrors.Errorf("pushing message to mpool: %w", err)
|
||||||
}
|
}
|
||||||
@ -492,7 +498,7 @@ func (s *WindowPoStScheduler) submitPost(ctx context.Context, proof *miner.Submi
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *WindowPoStScheduler) setSender(ctx context.Context, msg *types.Message) {
|
func (s *WindowPoStScheduler) setSender(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec) {
|
||||||
mi, err := s.api.StateMinerInfo(ctx, s.actor, types.EmptyTSK)
|
mi, err := s.api.StateMinerInfo(ctx, s.actor, types.EmptyTSK)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorw("error getting miner info", "error", err)
|
log.Errorw("error getting miner info", "error", err)
|
||||||
@ -502,6 +508,14 @@ func (s *WindowPoStScheduler) setSender(ctx context.Context, msg *types.Message)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gm, err := s.api.GasEstimateMessageGas(ctx, msg, spec, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorw("estimating gas", "error", err)
|
||||||
|
msg.From = s.worker
|
||||||
|
return
|
||||||
|
}
|
||||||
|
*msg = *gm
|
||||||
|
|
||||||
minFunds := big.Add(msg.RequiredFunds(), msg.Value)
|
minFunds := big.Add(msg.RequiredFunds(), msg.Value)
|
||||||
|
|
||||||
pa, err := AddressFor(ctx, s.api, mi, PoStAddr, minFunds)
|
pa, err := AddressFor(ctx, s.api, mi, PoStAddr, minFunds)
|
||||||
|
Loading…
Reference in New Issue
Block a user