mpool: check origin balance before actually pushing to mpool

This commit is contained in:
Łukasz Magiera
2019-10-08 15:09:07 +09:00
committed by whyrusleeping
parent 8618e724ed
commit 2b04a9b6be
3 changed files with 15 additions and 25 deletions
+10
View File
@@ -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)
})
}