-
Notifications
You must be signed in to change notification settings - Fork 94
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
introduce refund logic for ibc transfer if tx failed by timeout. #498
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,24 +17,24 @@ DENOM=${2:-ppica} | |
# remove existing daemon | ||
rm -rf ~/.banksy* | ||
|
||
centaurid config keyring-backend $KEYRING | ||
centaurid config chain-id $CHAINID | ||
picad config keyring-backend $KEYRING | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why change this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prefix change |
||
picad config chain-id $CHAINID | ||
|
||
# if $KEY exists it should be deleted | ||
echo "decorate bright ozone fork gallery riot bus exhaust worth way bone indoor calm squirrel merry zero scheme cotton until shop any excess stage laundry" | centaurid keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO --recover | ||
echo "decorate bright ozone fork gallery riot bus exhaust worth way bone indoor calm squirrel merry zero scheme cotton until shop any excess stage laundry" | picad keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO --recover | ||
|
||
centaurid init $MONIKER --chain-id $CHAINID | ||
picad init $MONIKER --chain-id $CHAINID | ||
|
||
update_test_genesis () { | ||
# update_test_genesis '.consensus_params["block"]["max_gas"]="100000000"' | ||
cat $HOME_DIR/config/genesis.json | jq "$1" > $HOME_DIR/config/tmp_genesis.json && mv $HOME_DIR/config/tmp_genesis.json $HOME_DIR/config/genesis.json | ||
} | ||
|
||
# Allocate genesis accounts (cosmos formatted addresses) | ||
centaurid add-genesis-account $KEY 100000000000000000000000000ppica --keyring-backend $KEYRING | ||
picad add-genesis-account $KEY 100000000000000000000000000ppica --keyring-backend $KEYRING | ||
|
||
# Sign genesis transaction | ||
centaurid gentx $KEY 10030009994127689ppica --keyring-backend $KEYRING --chain-id $CHAINID | ||
picad gentx $KEY 10030009994127689ppica --keyring-backend $KEYRING --chain-id $CHAINID | ||
|
||
update_test_genesis '.app_state["gov"]["params"]["voting_period"]="20s"' | ||
update_test_genesis '.app_state["mint"]["params"]["mint_denom"]="'$DENOM'"' | ||
|
@@ -43,10 +43,10 @@ update_test_genesis '.app_state["crisis"]["constant_fee"]={"denom":"'$DENOM'","a | |
update_test_genesis '.app_state["staking"]["params"]["bond_denom"]="'$DENOM'"' | ||
|
||
# Collect genesis tx | ||
centaurid collect-gentxs | ||
picad collect-gentxs | ||
|
||
# Run this to ensure everything worked and that the genesis file is setup correctly | ||
centaurid validate-genesis | ||
picad validate-genesis | ||
|
||
if [[ $1 == "pending" ]]; then | ||
echo "pending mode is on, please wait for the first block committed." | ||
|
@@ -57,4 +57,4 @@ fi | |
sed -i'' -e 's/max_body_bytes = /max_body_bytes = 1/g' ~/.banksy/config/config.toml | ||
|
||
# Start the node (remove the --pruning=nothing flag if historical queries are not needed) | ||
# centaurid start --pruning=nothing --minimum-gas-prices=0.0001ppica --rpc.laddr tcp://0.0.0.0:26657 | ||
picad start --pruning=nothing --minimum-gas-prices=0.0001ppica --rpc.laddr tcp://0.0.0.0:26657 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,41 @@ func (im IBCMiddleware) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Pac | |
return err | ||
} | ||
|
||
denom := data.Denom | ||
coin := im.keeper.IbcTransfermiddleware.GetCoin(ctx, packet.SourceChannel, denom) | ||
сhannelFeeAddress := im.keeper.IbcTransfermiddleware.GetChannelFeeAddress(ctx, packet.SourceChannel) | ||
if coin != nil { | ||
amount := data.Amount | ||
transferAmount, ok := sdk.NewIntFromString(amount) | ||
if !ok { | ||
return errors.Wrapf(transfertypes.ErrInvalidAmount, "unable to parse transfer amount: %s", amount) | ||
} | ||
|
||
// calculate the percentage charge | ||
/* | ||
coin.Percentage is 100 that means that we charge 1/100 of the transfer amount | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we charge 1%? Where does this number come from? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is example. |
||
coin.MinFee.Amount is the minimum fee that we charge | ||
the new amount is the transfer amount minus the percentage charge and the minimum fee | ||
transfer amount is a 99/100 of the original amount | ||
so to get the fee we charge transferAmount.QuoRaw(coin.Percentage - 1) + coin.MinFee.Amount | ||
*/ | ||
|
||
percentageCharge := sdk.NewInt(0) | ||
if coin.Percentage > 1 { | ||
percentageCharge = transferAmount.QuoRaw(coin.Percentage - 1) | ||
} | ||
percentageCharge = percentageCharge.Add(coin.MinFee.Amount) | ||
|
||
fee_address, err := sdk.AccAddressFromBech32(сhannelFeeAddress) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to decode receiver address: %s", сhannelFeeAddress) | ||
} | ||
|
||
refund_fee := sdk.NewCoin(denom, percentageCharge) | ||
im.keeper.RefundChannelCosmosFee(ctx, fee_address, sdk.AccAddress(data.Sender), []sdk.Coin{refund_fee}) | ||
|
||
} | ||
|
||
return nil | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this is for setting fees. this is for testnet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so it's an unrelated change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needed to make tests build success.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we introduce keeper to ibc hook
so we need to pass it now in tests.
this i why i added a IbcTransferMiddlewareKeeper to pass into ibc hook