Merge pull request #292 from filecoin-project/feat/mpool-precheck
mpool: check origin balance before actually pushing to mpool
This commit is contained in:
commit
cefd75be64
@ -65,7 +65,7 @@ type FullNode interface {
|
||||
// messages
|
||||
|
||||
MpoolPending(context.Context, *types.TipSet) ([]*types.SignedMessage, error)
|
||||
MpoolPush(context.Context, *types.SignedMessage) error
|
||||
MpoolPush(context.Context, *types.SignedMessage) error // TODO: remove
|
||||
MpoolPushMessage(context.Context, *types.Message) (*types.SignedMessage, error) // get nonce, sign, push
|
||||
MpoolGetNonce(context.Context, address.Address) (uint64, error)
|
||||
|
||||
|
@ -68,38 +68,18 @@ var createMinerCmd = &cli.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
nonce, err := api.MpoolGetNonce(ctx, addr)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to get account nonce: %w", err)
|
||||
}
|
||||
|
||||
msg := types.Message{
|
||||
msg := &types.Message{
|
||||
To: actors.StorageMarketAddress,
|
||||
From: addr,
|
||||
Method: actors.SMAMethods.CreateStorageMiner,
|
||||
Params: params,
|
||||
Value: types.NewInt(0),
|
||||
Nonce: nonce,
|
||||
GasPrice: types.NewInt(1),
|
||||
GasLimit: types.NewInt(1),
|
||||
GasPrice: types.NewInt(0),
|
||||
GasLimit: types.NewInt(10000),
|
||||
}
|
||||
|
||||
msgbytes, err := msg.Serialize()
|
||||
smsg, err := api.MpoolPushMessage(ctx, msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sig, err := api.WalletSign(ctx, addr, msgbytes)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to sign message: %w", err)
|
||||
}
|
||||
|
||||
smsg := &types.SignedMessage{
|
||||
Message: msg,
|
||||
Signature: *sig,
|
||||
}
|
||||
|
||||
if err := api.MpoolPush(ctx, smsg); err != nil {
|
||||
return xerrors.Errorf("failed to push signed message: %w", err)
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,16 @@ func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message) (*t
|
||||
|
||||
return a.Mpool.PushWithNonce(msg.From, func(nonce uint64) (*types.SignedMessage, error) {
|
||||
msg.Nonce = nonce
|
||||
|
||||
b, err := a.WalletBalance(ctx, msg.From)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("mpool push: getting origin balance: %w", err)
|
||||
}
|
||||
|
||||
if b.LessThan(msg.Value) {
|
||||
return nil, xerrors.Errorf("mpool push: not enough funds: %s < %s", b, msg.Value)
|
||||
}
|
||||
|
||||
return a.WalletSignMessage(ctx, msg.From, msg)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user