Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle non staking tokens #1132

Merged
merged 35 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b3c00c7
test: update versions of external tools
Feb 8, 2024
1f48ff3
Always use helpers to increment/decrement/set withdrawal waitgroup in…
Feb 8, 2024
c3fc7b7
fix: race condition in non-staking denom reward dist
Feb 8, 2024
0773519
add non-staking denom test to bash tests
Feb 8, 2024
bd42bba
improve validateCoinsForZone, and handle non-staking coins airdropped…
Feb 10, 2024
5e89a14
test: add delegate account airdrops test to bash tests
Feb 10, 2024
3560fd7
fix: SendToWithdrawal shouldn't use fixed sender
Feb 10, 2024
8c8fc77
Ensure we have the same cases for failed messages
Feb 10, 2024
c6249c4
fix: handle race condition in delegation record update
Feb 10, 2024
7705109
update port for testzone
Feb 10, 2024
b6bdf51
lint
Feb 10, 2024
37b7d2a
Update x/interchainstaking/keeper/ibc_packet_handlers.go
Feb 10, 2024
4740264
tigy logging
Feb 10, 2024
05f7259
Merge branch 'main' into feature-1118-handle-non-staking-tokens
faddat Feb 10, 2024
e33120e
Merge branch 'main' into feature-1118-handle-non-staking-tokens
faddat Feb 10, 2024
7bf525a
run tests with go 1.22
faddat Feb 10, 2024
09681cb
update golang
faddat Feb 10, 2024
872c2fa
bump golangci-lint
faddat Feb 10, 2024
0ae72e9
update Makefile for go 1.22
faddat Feb 10, 2024
58c8c4e
Update Makefile
faddat Feb 10, 2024
dd80f7d
exclude amd64 for darwin, no one really has that anymore anyhow.
faddat Feb 11, 2024
acfbef3
fix test where error is no longer thrown
Feb 12, 2024
157d99d
revert bump to go1.22 until it is more mature
Feb 12, 2024
5aef227
add missed Dockerfile
Feb 12, 2024
3a70764
Bump makefile
Feb 12, 2024
29e5fe4
fix #1140; recreate redelegation record if long delays mean original …
Feb 13, 2024
ed81656
tests
Feb 13, 2024
3f9e3f3
change some error messages to info
Feb 13, 2024
ec4085d
sendToWithdrawal ack test
Feb 13, 2024
f4c9ef3
add test for redelegation record creation
Feb 13, 2024
dba928f
add test for 0 wg in DelegationAccountBalances
Feb 13, 2024
67d1f09
add tests (from cosmos-sdk) for decoder funcs
Feb 13, 2024
c94d2a7
lint
Feb 13, 2024
9572b8f
Merge branch 'main' into feature-1118-handle-non-staking-tokens
Feb 13, 2024
608447d
Merge branch 'main' into feature-1118-handle-non-staking-tokens
faddat Feb 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions Dockerfile.hermes

This file was deleted.

18 changes: 7 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ services:
- start
ports:
- 27657:26657
- 23137:1317
- 21317:1317
testzone1-2:
image: quicksilverzone/testzone:latest
hostname: testzone1-2
Expand Down Expand Up @@ -98,31 +98,27 @@ services:
- osmosisd
- start
hermes:
image: quicksilverzone/hermes:v1.5.0
image: informalsystems/hermes:v1.8.0
hostname: hermes
volumes:
- ./data/hermes:/hermes/.hermes
- ./data/hermes:/home/hermes/.hermes
command:
- hermes
- start
restart: always
build:
context: .
dockerfile: Dockerfile.hermes
icq:
image: quicksilverzone/interchain-queries:v0.9.1
image: quicksilverzone/interchain-queries:v0.10.0
volumes:
- ./data/icq:/icq/.icq
command:
- interchain-queries
- icq-relayer
- run
restart: always
icq2:
image: quicksilverzone/interchain-queries:v0.9.1
image: quicksilverzone/interchain-queries:v0.10.0
volumes:
- ./data/icq2:/icq/.icq
command:
- interchain-queries
- icq-relayer
- run
restart: always
relayer:
Expand Down
9 changes: 7 additions & 2 deletions scripts/config/hermes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enabled = true
enabled = true
clear_interval = 100
clear_on_start = true
tx_confirmation = true

[rest]
enabled = true
Expand All @@ -29,7 +30,7 @@ port = 3001
id = 'qstest-1'
rpc_addr = 'http://quicksilver:26657'
grpc_addr = 'http://quicksilver:9090'
websocket_addr = 'ws://quicksilver:26657/websocket'
event_source = { mode = "pull" }
rpc_timeout = '10s'
account_prefix = 'quick'
key_name = 'testkey'
Expand All @@ -45,12 +46,14 @@ max_block_time = '10s'
trusting_period = '3minutes'
trust_threshold = { numerator = '1', denominator = '3' }
address_type = { derivation = 'cosmos' }
trusted_node = true
sequential_batch_tx = true

[[chains]]
id = 'lstest-1'
rpc_addr = 'http://testzone1-1:26657'
grpc_addr = 'http://testzone1-1:9090'
websocket_addr = 'ws://testzone1-1:26657/websocket'
event_source = { mode = "pull" }
rpc_timeout = '10s'
account_prefix = 'cosmos'
key_name = 'testkey'
Expand All @@ -66,3 +69,5 @@ max_block_time = '10s'
trusting_period = '3minutes'
trust_threshold = { numerator = '1', denominator = '3' }
address_type = { derivation = 'cosmos' }
trusted_node = true
sequential_batch_tx = true
4 changes: 2 additions & 2 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ $QS1_RUN add-genesis-account ${DEMO_ADDRESS_7} 100000000000uqck
$QS2_RUN add-genesis-account ${VAL_ADDRESS_6} 100000000000uqck
$QS3_RUN add-genesis-account ${VAL_ADDRESS_7} 100000000000uqck

$TZ1_1_RUN add-genesis-account ${VAL_ADDRESS_2} 100000000000uatom
$TZ1_1_RUN add-genesis-account ${VAL_ADDRESS_2} 100000000000uatom,100000000uother
$TZ1_1_RUN add-genesis-account ${VAL_ADDRESS_3} 100000000000uatom
$TZ1_1_RUN add-genesis-account ${VAL_ADDRESS_4} 100000000000uatom
$TZ1_1_RUN add-genesis-account ${VAL_ADDRESS_5} 100000000000uatom
Expand Down Expand Up @@ -475,7 +475,7 @@ if [ "$IS_MULTI_ZONE_TEST" = true ]; then
fi

## set the 'epoch' epoch to 5m interval
jq '.app_state.epochs.epochs = [{"identifier": "epoch","start_time": "0001-01-01T00:00:00Z","duration": "240s","current_epoch": "0","current_epoch_start_time": "0001-01-01T00:00:00Z","epoch_counting_started": false,"current_epoch_start_height": "0"}]' ./${CHAIN_DIR}/${CHAINID_0}/config/genesis.json > ./${CHAIN_DIR}/${CHAINID_0}/config/genesis.json.new && mv ./${CHAIN_DIR}/${CHAINID_0}/config/genesis.json{.new,}
jq '.app_state.epochs.epochs = [{"identifier": "epoch","start_time": "0001-01-01T00:00:00Z","duration": "360s","current_epoch": "0","current_epoch_start_time": "0001-01-01T00:00:00Z","epoch_counting_started": false,"current_epoch_start_height": "0"},{"identifier": "day","start_time": "0001-01-01T00:00:00Z","duration": "120s","current_epoch": "0","current_epoch_start_time": "0001-01-01T00:00:00Z","epoch_counting_started": false,"current_epoch_start_height": "0"}]' ./${CHAIN_DIR}/${CHAINID_0}/config/genesis.json > ./${CHAIN_DIR}/${CHAINID_0}/config/genesis.json.new && mv ./${CHAIN_DIR}/${CHAINID_0}/config/genesis.json{.new,}
jq '.app_state.interchainstaking.params.deposit_interval = 25' ./${CHAIN_DIR}/${CHAINID_0}/config/genesis.json > ./${CHAIN_DIR}/${CHAINID_0}/config/genesis.json.new && mv ./${CHAIN_DIR}/${CHAINID_0}/config/genesis.json{.new,}
jq '.app_state.mint.params.epoch_identifier = "epoch"' ./${CHAIN_DIR}/${CHAINID_0}/config/genesis.json > ./${CHAIN_DIR}/${CHAINID_0}/config/genesis.json.new && mv ./${CHAIN_DIR}/${CHAINID_0}/config/genesis.json{.new,}
jq '.app_state.gov.deposit_params.min_deposit = [{"denom": "uqck", "amount": "100"}]' ./${CHAIN_DIR}/${CHAINID_0}/config/genesis.json > ./${CHAIN_DIR}/${CHAINID_0}/config/genesis.json.new && mv ./${CHAIN_DIR}/${CHAINID_0}/config/genesis.json{.new,}
Expand Down
19 changes: 18 additions & 1 deletion scripts/simple-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,32 @@ while [[ "$PERFORMANCE_ACCOUNT" == "null" ]]; do
PERFORMANCE_ACCOUNT=$($QS1_EXEC q interchainstaking zones --output=json | jq .zones[0].performance_address.address -r)
done

$TZ1_1_EXEC tx bank send val2 $PERFORMANCE_ACCOUNT 40000uatom --chain-id $CHAINID_1 -y --keyring-backend=test
WITHDRAWAL_ACCOUNT=$($QS1_EXEC q interchainstaking zones --output=json | jq .zones[0].withdrawal_address.address -r)
while [[ "$WITHDRAWAL_ACCOUNT" == "null" ]]; do
sleep 2
WITHDRAWAL_ACCOUNT=$($QS1_EXEC q interchainstaking zones --output=json | jq .zones[0].withdrawal_address.address -r)
done

DELEGATE_ACCOUNT=$($QS1_EXEC q interchainstaking zones --output=json | jq .zones[0].delegation_address.address -r)
while [[ "DELEGATE_ACCOUNT" == "null" ]]; do
sleep 2
DELEGATE_ACCOUNT=$($QS1_EXEC q interchainstaking zones --output=json | jq .zones[0].delegation_address.address -r)
done

$TZ1_1_EXEC tx bank send val2 $PERFORMANCE_ACCOUNT 40000uatom --chain-id $CHAINID_1 -y --keyring-backend=test
sleep 3
#$TZ1_1_EXEC tx bank send val2 $DEPOSIT_ACCOUNT 10000000${VAL_VALOPER_2}1 --chain-id $CHAINID_1 -y --keyring-backend=test
#sleep 5
#$TZ1_2_EXEC tx bank send val3 $DEPOSIT_ACCOUNT 15000000${VAL_VALOPER_3}2 --chain-id $CHAINID_1 -y --keyring-backend=test
#sleep 5
$TZ1_1_EXEC tx bank send demowallet2 $DEPOSIT_ACCOUNT 333333uatom --chain-id $CHAINID_1 -y --keyring-backend=test
sleep 5
$TZ1_1_EXEC tx bank send val2 $DEPOSIT_ACCOUNT 5000000uother --chain-id $CHAINID_1 -y --keyring-backend=test
sleep 5
$TZ1_1_EXEC tx bank send val2 $WITHDRAWAL_ACCOUNT 8000000uother --chain-id $CHAINID_1 -y --keyring-backend=test
sleep 5
$TZ1_1_EXEC tx bank send val2 $DELEGATE_ACCOUNT 10000000uother --chain-id $CHAINID_1 -y --keyring-backend=test
sleep 5
$TZ1_1_EXEC tx bank send demowallet2 $DEPOSIT_ACCOUNT 20000000uatom --chain-id $CHAINID_1 -y --keyring-backend=test --note MgTUzEjWVVYoDZBarqFL1akb38mxlgTsqdZ/sFxTJBNf+tv6rtckvn3T
sleep 5
$TZ1_1_EXEC tx bank send demowallet2 $DEPOSIT_ACCOUNT 33000000uatom --chain-id $CHAINID_1 -y --keyring-backend=test
Expand Down
6 changes: 3 additions & 3 deletions scripts/vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ TZ2_2_RUN="docker-compose $DC --ansi never run --rm -T testzone2-2 osmosisd"
TZ2_3_RUN="docker-compose $DC --ansi never run --rm -T testzone2-3 osmosisd"
TZ2_4_RUN="docker-compose $DC --ansi never run --rm -T testzone2-4 osmosisd"
RLY_RUN="docker-compose $DC --ansi never run --rm -T relayer rly"
HERMES_RUN="docker-compose $DC --ansi never run --rm -T hermes hermes"
HERMES_RUN="docker-compose $DC --ansi never run --rm -T hermes"

QS1_EXEC="docker-compose $DC --ansi never exec -T quicksilver quicksilverd"
QS2_EXEC="docker-compose $DC --ansi never exec -T quicksilver2 quicksilverd"
Expand All @@ -65,8 +65,8 @@ TZ2_3_EXEC="docker-compose $DC --ansi never exec -T testzone2-3 osmosisd"
TZ2_4_EXEC="docker-compose $DC --ansi never exec -T testzone2-4 osmosisd"
RLY_EXEC="docker-compose $DC --ansi never exec -T relayer"

ICQ_RUN="docker-compose $DC --ansi never run --rm -T icq interchain-queries"
ICQ2_RUN="docker-compose $DC --ansi never run --rm -T icq2 interchain-queries"
ICQ_RUN="docker-compose $DC --ansi never run --rm -T icq icq-relayer"
ICQ2_RUN="docker-compose $DC --ansi never run --rm -T icq2 icq-relayer"

VAL_MNEMONIC_1="clock post desk civil pottery foster expand merit dash seminar song memory figure uniform spice circle try happy obvious trash crime hybrid hood cushion"
VAL_MNEMONIC_2="angry twist harsh drastic left brass behave host shove marriage fall update business leg direct reward object ugly security warm tuna model broccoli choice"
Expand Down
22 changes: 16 additions & 6 deletions x/interchainstaking/keeper/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ func RewardsCallback(k *Keeper, ctx sdk.Context, args []byte, query icqtypes.Que

// decrement waitgroup as we have received back the query
// (initially incremented in AfterEpochEnd)
err = zone.DecrementWithdrawalWaitgroup()
err = zone.DecrementWithdrawalWaitgroup(k.Logger(ctx), 1, "rewards callback")
joe-bowman marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}

k.Logger(ctx).Debug("QueryDelegationRewards callback", "wg", zone.WithdrawalWaitgroup, "delegatorAddress", rewardsQuery.DelegatorAddress, "zone", query.ChainId)
k.Logger(ctx).Debug("QueryDelegationRewards callback", "wg", zone.GetWithdrawalWaitgroup(), "delegatorAddress", rewardsQuery.DelegatorAddress, "zone", query.ChainId)
joe-bowman marked this conversation as resolved.
Show resolved Hide resolved

return k.WithdrawDelegationRewardsForResponse(ctx, &zone, rewardsQuery.DelegatorAddress, args)
}
Expand Down Expand Up @@ -622,7 +622,7 @@ func DelegationAccountBalanceCallback(k *Keeper, ctx sdk.Context, args []byte, q
}

k.Logger(ctx).Info("Received balance response for denom", "denom", coin.Denom)
err = zone.DecrementWithdrawalWaitgroup()
err = zone.DecrementWithdrawalWaitgroup(k.Logger(ctx), 1, "delegationaccountbalance callback")
joe-bowman marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
Expand All @@ -642,6 +642,12 @@ func DelegationAccountBalanceCallback(k *Keeper, ctx sdk.Context, args []byte, q

k.SetZone(ctx, &zone)

// if token is not valid for staking, then send to withdrawal account.
if valid, _ := zone.ValidateCoinsForZone(sdk.NewCoins(coin), k.GetValidatorAddressesAsMap(ctx, zone.ChainId)); !valid {
k.Logger(ctx).Info("token is not a valid staking token, so sending to withdrawal account for disbursal", "chain", zone.ChainId, "assets", coin)
return k.SendToWithdrawal(ctx, &zone, zone.DelegationAddress, sdk.NewCoins(coin))
}

joe-bowman marked this conversation as resolved.
Show resolved Hide resolved
return k.FlushOutstandingDelegations(ctx, &zone, coin)
}

Expand All @@ -653,7 +659,9 @@ func DelegationAccountBalancesCallback(k *Keeper, ctx sdk.Context, args []byte,
result := banktypes.QueryAllBalancesResponse{}
k.cdc.MustUnmarshal(args, &result)

zone.WithdrawalWaitgroup--
if err := zone.DecrementWithdrawalWaitgroup(k.Logger(ctx), 1, "delegationaccountbalances callback"); err != nil {
return err
}
joe-bowman marked this conversation as resolved.
Show resolved Hide resolved

addressBytes, err := addressutils.AccAddressFromBech32(zone.DelegationAddress.Address, zone.AccountPrefix)
if err != nil {
Expand All @@ -677,8 +685,10 @@ func DelegationAccountBalancesCallback(k *Keeper, ctx sdk.Context, args []byte,
0,
)

k.Logger(ctx).Info("Emitting balance request for denom", "denom", coin.Denom)
zone.WithdrawalWaitgroup++
if err = zone.IncrementWithdrawalWaitgroup(k.Logger(ctx), 1, fmt.Sprintf("delegation account balance for %s", coin.Denom)); err != nil {
return err
}
k.Logger(ctx).Info("Emitting balance request for denom", "denom", coin.Denom, "waitgroup", zone.GetWithdrawalWaitgroup())
}
k.SetZone(ctx, &zone)

Expand Down
23 changes: 13 additions & 10 deletions x/interchainstaking/keeper/callbacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ func (suite *KeeperTestSuite) TestHandleRewardsCallbackNonDelegator() {
ctx := suite.chainA.GetContext()

zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
zone.WithdrawalWaitgroup++
suite.NoError(zone.IncrementWithdrawalWaitgroup(quicksilver.Logger(), 1, "test rewards callback handler"))
quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone)

user := addressutils.GenerateAccAddressForTest()
Expand Down Expand Up @@ -757,7 +757,8 @@ func (suite *KeeperTestSuite) TestHandleRewardsCallbackEmptyResponse() {
ctx := suite.chainA.GetContext()

zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
zone.WithdrawalWaitgroup++
suite.NoError(zone.IncrementWithdrawalWaitgroup(quicksilver.Logger(), 1, "test rewards callback handler"))

quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone)

queryReq := distrtypes.QueryDelegationTotalRewardsRequest{
Expand Down Expand Up @@ -786,7 +787,8 @@ func (suite *KeeperTestSuite) TestHandleValideRewardsCallback() {
ctx := suite.chainA.GetContext()

zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
zone.WithdrawalWaitgroup++
suite.NoError(zone.IncrementWithdrawalWaitgroup(quicksilver.Logger(), 1, "test rewards callback handler"))

quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone)

queryReq := distrtypes.QueryDelegationTotalRewardsRequest{
Expand Down Expand Up @@ -2445,7 +2447,8 @@ func (suite *KeeperTestSuite) TestDepositLsmTxCallbackFailOnNonMatchingValidator
// trigger the callback
err = keeper.DepositTxCallback(quicksilver.InterchainstakingKeeper, ctx, payloadBytes, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: resDataBz})

suite.ErrorContains(err, "unable to validate coins. Ignoring.")
// we used to error here, but now we don't to avoid blocking queues.
suite.NoError(err)

// expect quick1a2zht8x2j0dqvuejr8pxpu7due3qmk405vakg9 to have 0 uqatoms, as the deposit failed.
addrBytes, _ := addressutils.AccAddressFromBech32("cosmos1a2zht8x2j0dqvuejr8pxpu7due3qmk40lgdy3h", "")
Expand Down Expand Up @@ -2527,7 +2530,7 @@ func (suite *KeeperTestSuite) TestDelegationAccountBalancesCallback() {
ctx := suite.chainA.GetContext()

zone, _ := app.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
zone.WithdrawalWaitgroup = 1
zone.SetWithdrawalWaitgroup(app.Logger(), 1, "init")
zone.DelegationAddress.Balance = t.PreviousBalance
app.InterchainstakingKeeper.SetZone(ctx, &zone)

Expand All @@ -2546,7 +2549,7 @@ func (suite *KeeperTestSuite) TestDelegationAccountBalancesCallback() {

// refetch zone
zone, _ = app.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
suite.Require().Equal(t.ExpectedWaitgroup, zone.WithdrawalWaitgroup)
suite.Require().Equal(t.ExpectedWaitgroup, zone.GetWithdrawalWaitgroup())

_, addr, err := bech32.DecodeAndConvert(zone.DelegationAddress.Address)
suite.Require().NoError(err)
Expand Down Expand Up @@ -2581,7 +2584,7 @@ func (suite *KeeperTestSuite) TestDelegationAccountBalanceCallback() {
ctx := suite.chainA.GetContext()

zone, _ := app.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
zone.WithdrawalWaitgroup = 2
zone.SetWithdrawalWaitgroup(app.Logger(), 2, "init")
zone.DelegationAddress.Balance = sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(500_000_000)))
app.InterchainstakingKeeper.SetZone(ctx, &zone)

Expand All @@ -2598,7 +2601,7 @@ func (suite *KeeperTestSuite) TestDelegationAccountBalanceCallback() {

ctx = suite.chainA.GetContext()
zone, _ = app.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
suite.Equal(uint32(5), zone.WithdrawalWaitgroup) // initial 2 is reduced to 1, but incremented by 4 (4x delegation messages) == 5
suite.Equal(uint32(5), zone.GetWithdrawalWaitgroup()) // initial 2 is reduced to 1, but incremented by 4 (4x delegation messages) == 5
suite.Equal(sdk.NewInt(500_000_000), zone.DelegationAddress.Balance.AmountOf("uatom"))
})
}
Expand All @@ -2616,7 +2619,7 @@ func (suite *KeeperTestSuite) TestDelegationAccountBalanceCallbackLSM() {

valOper := app.InterchainstakingKeeper.GetValidatorAddresses(ctx, suite.chainB.ChainID)[0]
denom := valOper + "/1"
zone.WithdrawalWaitgroup = 2
zone.SetWithdrawalWaitgroup(app.Logger(), 2, "init")
zone.DelegationAddress.Balance = sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(500)))
app.InterchainstakingKeeper.SetZone(ctx, &zone)

Expand All @@ -2633,7 +2636,7 @@ func (suite *KeeperTestSuite) TestDelegationAccountBalanceCallbackLSM() {

ctx = suite.chainA.GetContext()
zone, _ = app.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
suite.Equal(uint32(2), zone.WithdrawalWaitgroup) // initial 2 is reduced to 1, but incremented by 1 (1x redeem token messages) == 2
suite.Equal(uint32(2), zone.GetWithdrawalWaitgroup()) // initial 2 is reduced to 1, but incremented by 1 (1x redeem token messages) == 2
suite.Equal(sdk.NewInt(500), zone.DelegationAddress.Balance.AmountOf("uatom"))
suite.Equal(sdk.NewInt(10), zone.DelegationAddress.Balance.AmountOf(denom))
})
Expand Down
21 changes: 16 additions & 5 deletions x/interchainstaking/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,11 @@ func (k *Keeper) WithdrawDelegationRewardsForResponse(ctx sdk.Context, zone *typ
// this allows us to track individual msg responses and ensure all
// responses have been received and handled...
// HandleWithdrawRewards contains the opposing decrement.
zone.WithdrawalWaitgroup += uint32(len(msgs))
if err = zone.IncrementWithdrawalWaitgroup(k.Logger(ctx), uint32(len(msgs)), "WithdrawDelegationRewardsForResponse"); err != nil {
return err
}
k.SetZone(ctx, zone)
k.Logger(ctx).Info("Received WithdrawDelegationRewardsForResponse acknowledgement", "wg", zone.WithdrawalWaitgroup, "address", delegator)
k.Logger(ctx).Info("Received WithdrawDelegationRewardsForResponse acknowledgement", "wg", zone.GetWithdrawalWaitgroup(), "address", delegator)

return k.SubmitTx(ctx, msgs, zone.DelegationAddress, "", zone.MessagesPerTx)
}
Expand Down Expand Up @@ -316,20 +318,27 @@ func (k *Keeper) FlushOutstandingDelegations(ctx sdk.Context, zone *types.Zone,
exclusionTime := ctx.BlockTime().AddDate(0, 0, -1)
k.IterateZoneReceipts(ctx, zone.ChainId, func(_ int64, receiptInfo types.Receipt) (stop bool) {
if (receiptInfo.FirstSeen.After(exclusionTime) || receiptInfo.FirstSeen.Equal(exclusionTime)) && receiptInfo.Completed == nil && receiptInfo.Amount[0].Denom == delAddrBalance.Denom {
k.Logger(ctx).Error("adding to pending amount", "pending receipt", receiptInfo)
joe-bowman marked this conversation as resolved.
Show resolved Hide resolved
pendingAmount = pendingAmount.Add(receiptInfo.Amount...)
}
return false
})

coinsToFlush, hasNeg := sdk.NewCoins(delAddrBalance).SafeSub(pendingAmount...)
if hasNeg || coinsToFlush.IsZero() {
k.Logger(ctx).Debug("delegate account balance negative, setting outdated reciepts")
k.Logger(ctx).Error("delegate account balance negative, or nothing to flush, setting outdated receipts")
joe-bowman marked this conversation as resolved.
Show resolved Hide resolved
k.SetReceiptsCompleted(ctx, zone.ChainId, exclusionTime, ctx.BlockTime(), delAddrBalance.Denom)
if zone.GetWithdrawalWaitgroup() == 0 {
k.Logger(ctx).Info("Triggering redemption rate calc in lieu of delegation flush")
if err := k.TriggerRedemptionRate(ctx, zone); err != nil {
return err
}
}
return nil
}

// set the zone amount to the coins to be flushed.
k.Logger(ctx).Info("flush delegations ", "total", coinsToFlush)
k.Logger(ctx).Error("flush delegations ", "total", coinsToFlush)
joe-bowman marked this conversation as resolved.
Show resolved Hide resolved

sendMsg := banktypes.MsgSend{
FromAddress: "",
Expand All @@ -340,7 +349,9 @@ func (k *Keeper) FlushOutstandingDelegations(ctx sdk.Context, zone *types.Zone,
if err != nil {
return err
}
zone.WithdrawalWaitgroup += uint32(numMsgs)
if err = zone.IncrementWithdrawalWaitgroup(k.Logger(ctx), uint32(numMsgs), "sending flush messages"); err != nil {
return err
}
k.SetZone(ctx, zone)
return nil
}
Loading
Loading