From 103b08de84fcc25c09595d598fd28cfce5b8a4e3 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Mon, 18 Sep 2023 13:35:52 +0300 Subject: [PATCH] fix: requeue validation removal --- x/orderbook/keeper/bet_wager.go | 48 ++++++++------------- x/orderbook/keeper/bet_wager_test.go | 2 +- x/orderbook/keeper/orderbook_settle_test.go | 10 ++++- x/orderbook/types/errors.go | 1 - 4 files changed, 26 insertions(+), 35 deletions(-) diff --git a/x/orderbook/keeper/bet_wager.go b/x/orderbook/keeper/bet_wager.go index cfa1902e..99b1e7d0 100644 --- a/x/orderbook/keeper/bet_wager.go +++ b/x/orderbook/keeper/bet_wager.go @@ -191,15 +191,14 @@ func (k Keeper) initFulfillmentInfo( ) { fInfo = fulfillmentInfo{ // bet specs - betAmount: betAmount, - payoutProfit: payoutProfit, - betUID: betUID, - betID: betID, - oddsUID: oddsUID, - oddsType: oddsType, - oddsVal: oddsVal, - maxLossMultiplier: maxLossMultiplier, - totalAvailableLiquidity: sdk.NewInt(0), + betAmount: betAmount, + payoutProfit: payoutProfit, + betUID: betUID, + betID: betID, + oddsUID: oddsUID, + oddsType: oddsType, + oddsVal: oddsVal, + maxLossMultiplier: maxLossMultiplier, // in process maps fulfillmentMap: make(map[uint64]fulfillmentItem), @@ -237,9 +236,6 @@ func (k Keeper) initFulfillmentInfo( if found { item.participationExposure = pe fInfo.fulfillmentMap[pe.ParticipationIndex] = item - - fInfo.totalAvailableLiquidity = fInfo.totalAvailableLiquidity. - Add(item.calcAvailableLiquidity(maxLossMultiplier)) } } @@ -271,15 +267,6 @@ func (fInfo *fulfillmentInfo) validate() error { } } - if fInfo.totalAvailableLiquidity.LT(fInfo.payoutProfit.TruncateInt()) { - return sdkerrors.Wrapf( - types.ErrInsufficientFundToCoverPayout, - "total liquidity %s, payout %s", - fInfo.totalAvailableLiquidity, - fInfo.payoutProfit, - ) - } - return nil } @@ -417,16 +404,15 @@ func (k Keeper) refreshQueueAndState( } type fulfillmentInfo struct { - betUID string - betID uint64 - oddsUID string - oddsType bettypes.OddsType - oddsVal string - maxLossMultiplier sdk.Dec - betAmount sdkmath.Int - payoutProfit sdk.Dec - fulfilledBetAmount sdkmath.Int - totalAvailableLiquidity sdkmath.Int + betUID string + betID uint64 + oddsUID string + oddsType bettypes.OddsType + oddsVal string + maxLossMultiplier sdk.Dec + betAmount sdkmath.Int + payoutProfit sdk.Dec + fulfilledBetAmount sdkmath.Int fulfillmentQueue []uint64 fulfillmentMap fulfillmentMap diff --git a/x/orderbook/keeper/bet_wager_test.go b/x/orderbook/keeper/bet_wager_test.go index e46eced4..1191b9e9 100644 --- a/x/orderbook/keeper/bet_wager_test.go +++ b/x/orderbook/keeper/bet_wager_test.go @@ -248,7 +248,7 @@ func (ts *testBetSuite) placeBetsAndTest() ([]bettypes.Bet, sdk.Dec, sdk.Dec) { failedWinnerBetID, sdk.NewInt(100000000000), ts.betFee, - types.ErrInsufficientFundToCoverPayout, + types.ErrInternalProcessingBet, ) ///// loser bet placement diff --git a/x/orderbook/keeper/orderbook_settle_test.go b/x/orderbook/keeper/orderbook_settle_test.go index e5d1d97c..b0fc590f 100644 --- a/x/orderbook/keeper/orderbook_settle_test.go +++ b/x/orderbook/keeper/orderbook_settle_test.go @@ -73,10 +73,16 @@ func TestOrderBookSettlement(t *testing.T) { Sub(ts.participations[1].Fee), participant2BalanceAfterSettlement) + // In this case, in the orderbook we have a long loop of requeue + // and the payout is a large value. + // in the real scenario when the bet placement transaction fails duo to + // orderbook failure, the hole transaction would fail and no state change will happen. participant3BalanceAfterSettlement := ts.tApp.BankKeeper.GetBalance( ts.ctx, sdk.MustAccAddressFromBech32(ts.deposits[2].DepositorAddress), params.DefaultBondDenom).Amount require.Equal(t, - participant3BalanceBeforeDeposit.Int64(), - participant3BalanceAfterSettlement.Int64()) + participant3BalanceBeforeDeposit. + // subtract participation fee + Sub(ts.participations[2].Fee), + participant3BalanceAfterSettlement) } diff --git a/x/orderbook/types/errors.go b/x/orderbook/types/errors.go index f73373ef..195b26e2 100644 --- a/x/orderbook/types/errors.go +++ b/x/orderbook/types/errors.go @@ -31,7 +31,6 @@ var ( ErrMaxWithdrawableAmountIsZero = sdkerrors.Register(ModuleName, 6021, "maximum withdrawal amount is zero") ErrParticipationOnInactiveMarket = sdkerrors.Register(ModuleName, 6022, "participation is allowed on an active market only") ErrMarketNotFound = sdkerrors.Register(ModuleName, 6023, "market not found to initialize participation") - ErrInsufficientFundToCoverPayout = sdkerrors.Register(ModuleName, 6024, "insufficient fund in the participations to cover the payout") ErrUnknownMarketStatus = sdkerrors.Register(ModuleName, 6025, "unknown market status of orderbook settlement") ErrWithdrawalTooLarge = sdkerrors.Register(ModuleName, 6026, "withdrawal is more than unused amount") )