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,13 +53,16 @@ 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()
if toAdd.LessThanEqual(big.Zero()) {
return cid.Undef, nil
} else {
var err error var err error
params, err := actors.SerializeParams(&addr) params, err := actors.SerializeParams(&addr)
if err != nil { if err != nil {
@ -77,4 +81,5 @@ func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr, wallet address.Add
} }
return smsg.Cid(), nil return smsg.Cid(), nil
}
} }