Revert cached "available" amount if the AddFunds message send fails
This commit is contained in:
parent
9d8932d395
commit
d80e7eda93
@ -120,9 +120,10 @@ 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()
|
||||||
|
defer fm.lk.Unlock()
|
||||||
|
|
||||||
bal, err := fm.api.StateMarketBalance(ctx, addr, types.EmptyTSK)
|
bal, err := fm.api.StateMarketBalance(ctx, addr, types.EmptyTSK)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fm.lk.Unlock()
|
|
||||||
return cid.Undef, err
|
return cid.Undef, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +139,6 @@ func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr, wallet address.Add
|
|||||||
toAdd = types.NewInt(0)
|
toAdd = types.NewInt(0)
|
||||||
}
|
}
|
||||||
fm.available[idAddr] = big.Add(avail, toAdd)
|
fm.available[idAddr] = big.Add(avail, toAdd)
|
||||||
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())
|
log.Infof("Funds operation w/ Expected Balance: %s, In State: %s, Requested: %s, Adding: %s", avail.String(), stateAvail.String(), amt.String(), toAdd.String())
|
||||||
|
|
||||||
@ -148,6 +148,7 @@ func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr, wallet address.Add
|
|||||||
|
|
||||||
params, err := actors.SerializeParams(&addr)
|
params, err := actors.SerializeParams(&addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fm.available[idAddr] = avail
|
||||||
return cid.Undef, err
|
return cid.Undef, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,6 +160,7 @@ func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr, wallet address.Add
|
|||||||
Params: params,
|
Params: params,
|
||||||
}, nil)
|
}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fm.available[idAddr] = avail
|
||||||
return cid.Undef, err
|
return cid.Undef, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,9 +57,10 @@ func addFundsMsg(toAdd abi.TokenAmount, addr address.Address, wallet address.Add
|
|||||||
}
|
}
|
||||||
|
|
||||||
type expectedResult struct {
|
type expectedResult struct {
|
||||||
addAmt abi.TokenAmount
|
addAmt abi.TokenAmount
|
||||||
shouldAdd bool
|
shouldAdd bool
|
||||||
err error
|
err error
|
||||||
|
cachedAvailable abi.TokenAmount
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddFunds(t *testing.T) {
|
func TestAddFunds(t *testing.T) {
|
||||||
@ -88,8 +89,9 @@ func TestAddFunds(t *testing.T) {
|
|||||||
addAmounts: []abi.TokenAmount{abi.NewTokenAmount(100)},
|
addAmounts: []abi.TokenAmount{abi.NewTokenAmount(100)},
|
||||||
expectedResults: []expectedResult{
|
expectedResults: []expectedResult{
|
||||||
{
|
{
|
||||||
shouldAdd: false,
|
shouldAdd: false,
|
||||||
err: nil,
|
err: nil,
|
||||||
|
cachedAvailable: abi.NewTokenAmount(100),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -102,18 +104,21 @@ func TestAddFunds(t *testing.T) {
|
|||||||
err: nil,
|
err: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
addAmt: abi.NewTokenAmount(100),
|
addAmt: abi.NewTokenAmount(100),
|
||||||
shouldAdd: true,
|
shouldAdd: true,
|
||||||
err: nil,
|
err: nil,
|
||||||
|
cachedAvailable: abi.NewTokenAmount(200),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
addAmt: abi.NewTokenAmount(50),
|
addAmt: abi.NewTokenAmount(50),
|
||||||
shouldAdd: true,
|
shouldAdd: true,
|
||||||
err: nil,
|
err: nil,
|
||||||
|
cachedAvailable: abi.NewTokenAmount(250),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shouldAdd: false,
|
shouldAdd: false,
|
||||||
err: nil,
|
err: nil,
|
||||||
|
cachedAvailable: abi.NewTokenAmount(250),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -132,7 +137,8 @@ func TestAddFunds(t *testing.T) {
|
|||||||
addAmounts: []abi.TokenAmount{abi.NewTokenAmount(100)},
|
addAmounts: []abi.TokenAmount{abi.NewTokenAmount(100)},
|
||||||
expectedResults: []expectedResult{
|
expectedResults: []expectedResult{
|
||||||
{
|
{
|
||||||
err: errors.New("something went wrong"),
|
err: errors.New("something went wrong"),
|
||||||
|
cachedAvailable: abi.NewTokenAmount(0),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -183,6 +189,10 @@ func TestAddFunds(t *testing.T) {
|
|||||||
} else {
|
} else {
|
||||||
require.EqualError(t, err, expected.err.Error())
|
require.EqualError(t, err, expected.err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !expected.cachedAvailable.Nil() {
|
||||||
|
require.Equal(t, expected.cachedAvailable, fundMgr.available[addr])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user