Fundmanager shouldn't try to add zero

This commit is contained in:
Aayush Rajasekaran 2020-07-29 20:27:22 -04:00
parent 7b567c77e9
commit 74dd01a8db

View File

@ -2,6 +2,7 @@ package market
import ( import (
"context" "context"
"github.com/filecoin-project/specs-actors/actors/abi/big"
"sync" "sync"
"github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin"
@ -52,29 +53,33 @@ func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr, wallet address.Add
if avail.LessThan(types.NewInt(0)) { if avail.LessThan(types.NewInt(0)) {
// TODO: some rules around adding more to avoid doing stuff on-chain // TODO: some rules around adding more to avoid doing stuff on-chain
// all the time // all the time
toAdd = types.BigSub(toAdd, avail) toAdd = avail.Neg()
avail = types.NewInt(0) avail = types.NewInt(0)
} }
fm.available[addr] = avail fm.available[addr] = avail
fm.lk.Unlock() fm.lk.Unlock()
var err error if toAdd.LessThanEqual(big.Zero()) {
params, err := actors.SerializeParams(&addr) return cid.Undef, nil
if err != nil { } else {
return cid.Undef, err var err error
} params, err := actors.SerializeParams(&addr)
if err != nil {
return cid.Undef, err
}
smsg, err := fm.mpool.MpoolPushMessage(ctx, &types.Message{ smsg, err := fm.mpool.MpoolPushMessage(ctx, &types.Message{
To: builtin.StorageMarketActorAddr, To: builtin.StorageMarketActorAddr,
From: wallet, From: wallet,
Value: toAdd, Value: toAdd,
Method: builtin.MethodsMarket.AddBalance, Method: builtin.MethodsMarket.AddBalance,
Params: params, Params: params,
}) })
if err != nil { if err != nil {
return cid.Undef, err return cid.Undef, err
} }
return smsg.Cid(), nil return smsg.Cid(), nil
}
} }