Merge pull request #3070 from filecoin-project/next
Merge in fundmgr workaround
This commit is contained in:
commit
bbb419b4f4
@ -14,7 +14,6 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/build"
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors"
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
"github.com/filecoin-project/lotus/chain/events"
|
"github.com/filecoin-project/lotus/chain/events"
|
||||||
"github.com/filecoin-project/lotus/chain/events/state"
|
"github.com/filecoin-project/lotus/chain/events/state"
|
||||||
@ -52,7 +51,7 @@ func StartFundManager(lc fx.Lifecycle, api API) *FundMgr {
|
|||||||
match := func(oldTs, newTs *types.TipSet) (bool, events.StateChange, error) {
|
match := func(oldTs, newTs *types.TipSet) (bool, events.StateChange, error) {
|
||||||
return dealDiffFn(ctx, oldTs.Key(), newTs.Key())
|
return dealDiffFn(ctx, oldTs.Key(), newTs.Key())
|
||||||
}
|
}
|
||||||
return ev.StateChanged(fm.checkFunc, fm.stateChanged, fm.revert, int(build.MessageConfidence), events.NoTimeout, match)
|
return ev.StateChanged(fm.checkFunc, fm.stateChanged, fm.revert, 0, events.NoTimeout, match)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return fm
|
return fm
|
||||||
@ -92,6 +91,10 @@ func (fm *FundMgr) stateChanged(ts *types.TipSet, ts2 *types.TipSet, states even
|
|||||||
// overwrite our in memory cache with new values from chain (chain is canonical)
|
// overwrite our in memory cache with new values from chain (chain is canonical)
|
||||||
fm.lk.Lock()
|
fm.lk.Lock()
|
||||||
for addr, balanceChange := range changedBalances {
|
for addr, balanceChange := range changedBalances {
|
||||||
|
if fm.available[addr].Int != nil {
|
||||||
|
log.Infof("State balance change recorded, prev: %s, new: %s", fm.available[addr].String(), balanceChange.To.String())
|
||||||
|
}
|
||||||
|
|
||||||
fm.available[addr] = balanceChange.To
|
fm.available[addr] = balanceChange.To
|
||||||
}
|
}
|
||||||
fm.lk.Unlock()
|
fm.lk.Unlock()
|
||||||
@ -116,15 +119,17 @@ func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr, wallet address.Add
|
|||||||
return cid.Undef, err
|
return cid.Undef, err
|
||||||
}
|
}
|
||||||
fm.lk.Lock()
|
fm.lk.Lock()
|
||||||
|
bal, err := fm.api.StateMarketBalance(ctx, addr, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
fm.lk.Unlock()
|
||||||
|
return cid.Undef, err
|
||||||
|
}
|
||||||
|
|
||||||
|
stateAvail := types.BigSub(bal.Escrow, bal.Locked)
|
||||||
|
|
||||||
avail, ok := fm.available[idAddr]
|
avail, ok := fm.available[idAddr]
|
||||||
if !ok {
|
if !ok {
|
||||||
bal, err := fm.api.StateMarketBalance(ctx, addr, types.EmptyTSK)
|
avail = stateAvail
|
||||||
if err != nil {
|
|
||||||
fm.lk.Unlock()
|
|
||||||
return cid.Undef, err
|
|
||||||
}
|
|
||||||
|
|
||||||
avail = types.BigSub(bal.Escrow, bal.Locked)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toAdd := types.BigSub(amt, avail)
|
toAdd := types.BigSub(amt, avail)
|
||||||
@ -134,6 +139,8 @@ func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr, wallet address.Add
|
|||||||
fm.available[idAddr] = big.Add(avail, toAdd)
|
fm.available[idAddr] = big.Add(avail, toAdd)
|
||||||
fm.lk.Unlock()
|
fm.lk.Unlock()
|
||||||
|
|
||||||
|
log.Infof("Funds operation w/ Expected Balance: %s, In State: %s, Requested: %s, Adding: %s", avail.String(), stateAvail.String(), amt.String(), toAdd.String())
|
||||||
|
|
||||||
if toAdd.LessThanEqual(big.Zero()) {
|
if toAdd.LessThanEqual(big.Zero()) {
|
||||||
return cid.Undef, nil
|
return cid.Undef, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user