8000 fix: IBC attestation ordering (backport #505) by mergify[bot] · Pull Request #519 · evmos/evmos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: IBC attestation ordering (backport #505) #519

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

Merged
merged 2 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (claims) [\#381](https://github.com/tharsis/evmos/pull/381) Fix claim migration and deletion for EVM chains via IBC attestation.
- (claims) [\#374](https://github.com/tharsis/evmos/pull/374) Fix balance invariant in Claims `InitGenesis`
- (erc20) [\#366](https://github.com/tharsis/evmos/issues/366) Delete ERC20 denom map when deleting pair.
- (claims) [\#505](https://github.com/tharsis/evmos/pull/505) Fix IBC attestation ordering

### Improvements

Expand Down
29 changes: 10 additions & 19 deletions x/claims/keeper/claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ import (
"github.com/tharsis/evmos/v3/x/claims/types"
)

func (suite *KeeperTestSuite) SetupClaimTest() {
suite.SetupTest()
params := suite.app.ClaimsKeeper.GetParams(suite.ctx)

coins := sdk.NewCoins(sdk.NewCoin(params.ClaimsDenom, sdk.NewInt(10000000)))
err := testutil.FundModuleAccount(suite.app.BankKeeper, suite.ctx, types.ModuleName, coins)
suite.Require().NoError(err)
}

func (suite *KeeperTestSuite) TestGetClaimableAmountForAction() {
testCases := []struct {
name string
Expand Down Expand Up @@ -610,7 +601,7 @@ func (suite *KeeperTestSuite) TestMergeClaimRecords() {
}

func (suite *KeeperTestSuite) TestHookOfUnclaimableAccount() {
suite.SetupClaimTest()
suite.SetupTestWithEscrow()
addr1 := sdk.AccAddress(tests.GenerateAddress().Bytes())
suite.app.AccountKeeper.SetAccount(suite.ctx, authtypes.NewBaseAccount(addr1, nil, 0, 0))

Expand All @@ -628,7 +619,7 @@ func (suite *KeeperTestSuite) TestHookOfUnclaimableAccount() {
}

func (suite *KeeperTestSuite) TestHookBeforeAirdropStart() {
suite.SetupClaimTest()
suite.SetupTestWithEscrow()

airdropStartTime := suite.ctx.BlockTime().Add(time.Hour)
params := suite.app.ClaimsKeeper.GetParams(suite.ctx)
Expand Down Expand Up @@ -669,7 +660,7 @@ func (suite *KeeperTestSuite) TestHookBeforeAirdropStart() {
}

func (suite *KeeperTestSuite) TestHookAfterAirdropEnd() {
suite.SetupClaimTest()
suite.SetupTestWithEscrow()

// airdrop recipient address
addr1 := sdk.AccAddress(tests.GenerateAddress().Bytes())
Expand All @@ -693,7 +684,7 @@ func (suite *KeeperTestSuite) TestHookAfterAirdropEnd() {
}

func (suite *KeeperTestSuite) TestDuplicatedActionNotWithdrawRepeatedly() {
suite.SetupClaimTest()
suite.SetupTestWithEscrow()
addr1 := sdk.AccAddress(tests.GenerateAddress().Bytes())

params := suite.app.ClaimsKeeper.GetParams(suite.ctx)
Expand Down Expand Up @@ -728,7 +719,7 @@ func (suite *KeeperTestSuite) TestDuplicatedActionNotWithdrawRepeatedly() {
}

func (suite *KeeperTestSuite) TestDelegationAutoWithdrawAndDelegateMore() {
suite.SetupClaimTest()
suite.SetupTestWithEscrow()

pub1, _ := ethsecp256k1.GenerateKey()
pub2, _ := ethsecp256k1.GenerateKey()
Expand Down Expand Up @@ -784,7 +775,7 @@ func (suite *KeeperTestSuite) TestDelegationAutoWithdrawAndDelegateMore() {
}

func (suite *KeeperTestSuite) TestAirdropFlow() {
suite.SetupClaimTest()
suite.SetupTestWithEscrow()

addrs := []sdk.AccAddress{
sdk.AccAddress(tests.GenerateAddress().Bytes()),
Expand Down Expand Up @@ -883,7 +874,7 @@ func (suite *KeeperTestSuite) TestAirdropFlow() {
}

func (suite *KeeperTestSuite) TestClaimOfDecayed() {
suite.SetupClaimTest()
suite.SetupTestWithEscrow()

airdropStartTime := time.Now().UTC()
durationUntilDecay := time.Hour
Expand Down Expand Up @@ -965,7 +956,7 @@ func (suite *KeeperTestSuite) TestClaimOfDecayed() {
}

for _, test := range t {
suite.SetupClaimTest()
suite.SetupTestWithEscrow()

claimsRecord = types.ClaimsRecord{
InitialClaimableAmount: sdk.NewInt(100),
Expand All @@ -988,7 +979,7 @@ func (suite *KeeperTestSuite) TestClaimOfDecayed() {
}

func (suite *KeeperTestSuite) TestClawbackEscrowedTokens() {
suite.SetupClaimTest()
suite.SetupTestWithEscrow()
params := suite.app.ClaimsKeeper.GetParams(suite.ctx)

ctx := suite.ctx.WithBlockTime(params.GetAirdropStartTime())
Expand Down Expand Up @@ -1044,7 +1035,7 @@ func (suite *KeeperTestSuite) TestClawbackEscrowedTokens() {
}

func (suite *KeeperTestSuite) TestClawbackEmptyAccountsAirdrop() {
suite.SetupClaimTest()
suite.SetupTestWithEscrow()

params := suite.app.ClaimsKeeper.GetParams(suite.ctx)
tests := []struct {
Expand Down
20 changes: 17 additions & 3 deletions x/claims/keeper/ibc_callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ func (k Keeper) OnRecvPacket(

senderClaimsRecord, senderRecordFound := k.GetClaimsRecord(ctx, sender)

if senderRecordFound && senderClaimsRecord.HasClaimedAction(types.ActionIBCTransfer) {
// short-circuit, perform no-op if the IBC action has already been completed
return ack
}

sameAddress := sender.Equals(recipient)
fromEVMChain := params.IsEVMChannel(packet.DestinationChannel)

Expand Down Expand Up @@ -134,10 +139,12 @@ func (k Keeper) OnRecvPacket(
}

recipientClaimsRecord, recipientRecordFound := k.GetClaimsRecord(ctx, recipient)

amt, err := ibc.GetTransferAmount(packet)
if err != nil {
return channeltypes.NewErrorAcknowledgement(err.Error())
}

isTriggerAmt := amt == types.IBCTriggerAmt

switch {
Expand Down Expand Up @@ -167,6 +174,16 @@ func (k Keeper) OnRecvPacket(
case senderRecordFound && !recipientRecordFound && isTriggerAmt:
// case 2: only the sender has a claims record
// -> migrate the sender record to the recipient address and claim IBC action

claimedAmt := sdk.ZeroInt() // nolint: ineffassign
claimedAmt, err = k.ClaimCoinsForAction(ctx, recipient, senderClaimsRecord, types.ActionIBCTransfer, params)

// if the transfer fails or the claimable amount is 0 (eg: action already
// completed), don't perform a state migration
if err != nil || claimedAmt.IsZero() {
break
}

k.SetClaimsRecord(ctx, recipient, senderClaimsRecord)
k.DeleteClaimsRecord(ctx, sender)

Expand All @@ -176,9 +193,6 @@ func (k Keeper) OnRecvPacket(
"receiver", recipientBech32,
"total-claimable", senderClaimsRecord.InitialClaimableAmount.String(),
)

_, err = k.ClaimCoinsForAction(ctx, recipient, senderClaimsRecord, types.ActionIBCTransfer, params)

// Cases without SenderRecordFound
case !senderRecordFound && recipientRecordFound,
sameAddress && fromEVMChain && recipientRecordFound:
Expand Down
Loading
0