Skip to content

Commit

Permalink
removed autopilot support for metadata in receiver and increased memo…
Browse files Browse the repository at this point in the history
… lengths (#1273)
  • Loading branch information
sampocs authored Aug 28, 2024
1 parent 274c103 commit 930d4eb
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 175 deletions.
2 changes: 1 addition & 1 deletion deps/gaia
Submodule gaia updated 582 files
2 changes: 1 addition & 1 deletion dockernet/config/relayer_config_stride.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ chains:
account-prefix: cosmos
keyring-backend: test
gas-adjustment: 1.3
gas-prices: 0.02uatom
gas-prices: 1ufee
coin-type: 118
debug: false
timeout: 20s
Expand Down
19 changes: 13 additions & 6 deletions dockernet/dockerfiles/Dockerfile.gaia
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
FROM golang:1.20-alpine3.16 AS builder
FROM golang:1.22-alpine AS builder

WORKDIR /opt

RUN apk add --update curl make git libc-dev bash gcc linux-headers eudev-dev python3
RUN apk add --update curl make git libc-dev bash gcc linux-headers eudev-dev ca-certificates build-base git

ENV COMMIT_HASH=v12.0.0-rc0
ENV COMMIT_HASH=v18.1.0

RUN git clone https://github.com/cosmos/gaia \
&& cd gaia \
&& git checkout $COMMIT_HASH \
&& CGO_ENABLED=0 make install
&& git checkout $COMMIT_HASH

FROM alpine:3.16
WORKDIR /opt/gaia

RUN WASMVM_VERSION=$(cat go.mod | grep github.com/CosmWasm/wasmvm | awk '{print $2}') \
&& wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$(uname -m).a \
-O /lib/libwasmvm_muslc.a

RUN CGO_ENABLED=1 BUILD_TAGS="muslc linkstatic" LINK_STATICALLY=true LEDGER_ENABLED=false make install

FROM alpine:3.17
COPY --from=builder /go/bin/gaiad /usr/local/bin/
RUN apk add bash vim \
&& addgroup -g 1000 gaia \
Expand Down
21 changes: 13 additions & 8 deletions dockernet/src/init_chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ STAKE_TOKENS=${STAKE_TOKENS}${MICRO_DENOM_UNITS}
ADMIN_TOKENS=${ADMIN_TOKENS}${MICRO_DENOM_UNITS}
USER_TOKENS=${USER_TOKENS}${MICRO_DENOM_UNITS}

FEES=1000000000ufee
GENESIS_CMD=$($BINARY 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "")

set_stride_epochs() {
genesis_config=$1

Expand Down Expand Up @@ -127,11 +130,13 @@ set_host_genesis() {
sed -i -E 's|"downtime_jail_duration": "600s"|"downtime_jail_duration": "10s"|g' $genesis_config
sed -i -E 's|"slash_fraction_downtime": "0.010000000000000000"|"slash_fraction_downtime": "0.050000000000000000"|g' $genesis_config

# LSM params
# LSM and feemarket params
if [[ "$CHAIN" == "GAIA" ]]; then
jq '.app_state.staking.params.validator_bond_factor = $newVal' --arg newVal "$LSM_VALIDATOR_BOND_FACTOR" $genesis_config > json.tmp && mv json.tmp $genesis_config
jq '.app_state.staking.params.validator_liquid_staking_cap = $newVal' --arg newVal "$LSM_VALIDATOR_LIQUID_STAKING_CAP" $genesis_config > json.tmp && mv json.tmp $genesis_config
jq '.app_state.staking.params.global_liquid_staking_cap = $newVal' --arg newVal "$LSM_GLOBAL_LIQUID_STAKING_CAP" $genesis_config > json.tmp && mv json.tmp $genesis_config

jq '.app_state.feemarket.params.fee_denom = $newVal' --arg newVal "ufee" $genesis_config > json.tmp && mv json.tmp $genesis_config
fi
}

Expand Down Expand Up @@ -161,7 +166,7 @@ add_genesis_account() {

create_account "$account_name" "$mnemonic"
address=$($MAIN_CMD keys show $account_name --keyring-backend test -a | tr -cd '[:alnum:]._-')
$MAIN_CMD add-genesis-account ${address} ${amount}${DENOM}
$MAIN_CMD $GENESIS_CMD add-genesis-account ${address} ${amount}${DENOM},${FEES}
}

MAIN_ID=1 # Node responsible for genesis and persistent_peers
Expand Down Expand Up @@ -225,7 +230,7 @@ for (( i=1; i <= $NUM_NODES; i++ )); do
if [[ "$CHAIN" == "NOBLE" ]]; then
genesis_coins=${genesis_coins},${VAL_TOKENS}${USDC_DENOM}
fi
$cmd add-genesis-account ${val_addr} ${genesis_coins}
$cmd $GENESIS_CMD add-genesis-account ${val_addr} ${genesis_coins},${FEES}

# Copy over the provider stride validator keys to the provider (in the event
# that we are testing ICS)
Expand All @@ -238,7 +243,7 @@ for (( i=1; i <= $NUM_NODES; i++ )); do

# Only generate the validator txs for host chains
if [[ "$CHAIN" != "STRIDE" && "$CHAIN" != "HOST" ]]; then
$cmd gentx $val_acct ${STAKE_TOKENS}${DENOM} --chain-id $CHAIN_ID --keyring-backend test &> /dev/null
$cmd $GENESIS_CMD gentx $val_acct ${STAKE_TOKENS}${DENOM} --chain-id $CHAIN_ID --keyring-backend test &> /dev/null
fi

# Get the endpoint and node ID
Expand All @@ -257,7 +262,7 @@ for (( i=1; i <= $NUM_NODES; i++ )); do
MAIN_GENESIS=$genesis_json
else
# also add this account and it's genesis tx to the main node
$MAIN_CMD add-genesis-account ${val_addr} ${VAL_TOKENS}${DENOM}
$MAIN_CMD $GENESIS_CMD add-genesis-account ${val_addr} ${VAL_TOKENS}${DENOM},${FEES}
if [ -d "${STATE}/${node_name}/config/gentx" ]; then
cp ${STATE}/${node_name}/config/gentx/*.json ${STATE}/${MAIN_NODE_NAME}/config/gentx/
fi
Expand Down Expand Up @@ -319,7 +324,7 @@ else
if [ "$CHAIN" == "NOBLE" ]; then
echo "$NOBLE_AUTHORITHY_MNEMONIC" | $MAIN_CMD keys add authority --recover --keyring-backend test >> $KEYS_LOGS 2>&1
AUTHORITHY_ADDRESS=$($MAIN_CMD keys show authority --keyring-backend test -a | tr -cd '[:alnum:]._-')
$MAIN_CMD add-genesis-account ${AUTHORITHY_ADDRESS} ${VAL_TOKENS}${DENOM},${VAL_TOKENS}${USDC_DENOM}
$MAIN_CMD $GENESIS_CMD add-genesis-account ${AUTHORITHY_ADDRESS} ${VAL_TOKENS}${DENOM},${VAL_TOKENS}${USDC_DENOM}

sed -i -E 's|"authority": ""|"authority":"'${AUTHORITHY_ADDRESS}'"|g' $genesis_json
sed -i -E 's|"mintingDenom": null|"mintingDenom":{"denom":"'${DENOM}'"}|g' $genesis_json
Expand All @@ -335,12 +340,12 @@ fi
# the account should live on both stride and the host chain
echo "$USER_MNEMONIC" | $MAIN_CMD keys add $USER_ACCT --recover --keyring-backend=test >> $KEYS_LOGS 2>&1
USER_ADDRESS=$($MAIN_CMD keys show $USER_ACCT --keyring-backend test -a)
$MAIN_CMD add-genesis-account ${USER_ADDRESS} ${USER_TOKENS}${DENOM}
$MAIN_CMD $GENESIS_CMD add-genesis-account ${USER_ADDRESS} ${USER_TOKENS}${DENOM},${FEES}

# Only collect the validator genesis txs for host chains
if [[ "$CHAIN" != "STRIDE" && "$CHAIN" != "HOST" ]]; then
# now we process gentx txs on the main node
$MAIN_CMD collect-gentxs &> /dev/null
$MAIN_CMD $GENESIS_CMD collect-gentxs &> /dev/null
fi

# wipe out the persistent peers for the main node (these are incorrectly autogenerated for each validator during collect-gentxs)
Expand Down
2 changes: 1 addition & 1 deletion dockernet/src/register_host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ for (( i=1; i <= $NUM_VALS; i++ )); do
if [[ "$i" == "1" ]]; then
echo "$CHAIN - Submitting validator bonds..."
fi
$GAIA_MAIN_CMD tx staking validator-bond $delegate_val --from ${VAL_PREFIX}${i} -y | TRIM_TX
$GAIA_MAIN_CMD tx staking validator-bond $delegate_val --from ${VAL_PREFIX}${i} -y --fees 1000000ufee | TRIM_TX
fi
done

Expand Down
46 changes: 17 additions & 29 deletions dockernet/tests/integration_tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ setup_file() {
REDEEM_AMOUNT=10000
PACKET_FORWARD_STAKE_AMOUNT=300000

HOST_FEES="--fees 1000000ufee"

# HELPER FUNCTIONS
DECADD () {
echo "scale=2; $1+$2" | bc
Expand Down Expand Up @@ -98,7 +100,7 @@ setup_file() {

# do IBC transfer
$STRIDE_MAIN_CMD tx ibc-transfer transfer transfer $STRIDE_TRANSFER_CHANNEL $HOST_VAL_ADDRESS ${TRANSFER_AMOUNT}${STRIDE_DENOM} --from $STRIDE_VAL -y
$HOST_MAIN_CMD tx ibc-transfer transfer transfer $HOST_TRANSFER_CHANNEL $(STRIDE_ADDRESS) ${TRANSFER_AMOUNT}${HOST_DENOM} --from $HOST_VAL -y
$HOST_MAIN_CMD tx ibc-transfer transfer transfer $HOST_TRANSFER_CHANNEL $(STRIDE_ADDRESS) ${TRANSFER_AMOUNT}${HOST_DENOM} --from $HOST_VAL -y $HOST_FEES

WAIT_FOR_BLOCK $STRIDE_LOGS 8

Expand Down Expand Up @@ -177,11 +179,11 @@ setup_file() {
validator_address=$(GET_VAL_ADDR $CHAIN_NAME 1)

# delegate on the host chain
$HOST_MAIN_CMD tx staking delegate $validator_address ${TRANSFER_AMOUNT}${HOST_DENOM} --from $USER_ACCT -y
$HOST_MAIN_CMD tx staking delegate $validator_address ${TRANSFER_AMOUNT}${HOST_DENOM} --from $USER_ACCT -y $HOST_FEES
WAIT_FOR_BLOCK $STRIDE_LOGS 2

# tokenize shares
$HOST_MAIN_CMD tx staking tokenize-share $validator_address ${TRANSFER_AMOUNT}${HOST_DENOM} $staker_address_on_host --from $USER_ACCT -y --gas 1000000
$HOST_MAIN_CMD tx staking tokenize-share $validator_address ${TRANSFER_AMOUNT}${HOST_DENOM} $staker_address_on_host --from $USER_ACCT -y --gas 1000000 $HOST_FEES
WAIT_FOR_BLOCK $STRIDE_LOGS 2

# get the record id from the tokenized share record
Expand All @@ -190,7 +192,7 @@ setup_file() {
# transfer LSM tokens to stride
lsm_token_denom=${validator_address}/${record_id}
$HOST_MAIN_CMD tx ibc-transfer transfer transfer $HOST_TRANSFER_CHANNEL \
$staker_address_on_stride ${TRANSFER_AMOUNT}${lsm_token_denom} --from $USER_ACCT -y
$staker_address_on_stride ${TRANSFER_AMOUNT}${lsm_token_denom} --from $USER_ACCT -y $HOST_FEES

WAIT_FOR_BLOCK $STRIDE_LOGS 8

Expand Down Expand Up @@ -257,14 +259,8 @@ setup_file() {
sttoken_balance_start=$($STRIDE_MAIN_CMD q bank balances $(STRIDE_ADDRESS) --denom st$HOST_DENOM | GETBAL)

# Send the IBC transfer with the JSON memo
transfer_msg_prefix="$HOST_MAIN_CMD tx ibc-transfer transfer transfer $HOST_TRANSFER_CHANNEL"
if [[ "$CHAIN_NAME" == "GAIA" ]]; then
# For GAIA (ibc-v3), pass the memo into the receiver field
$transfer_msg_prefix "$memo" ${PACKET_FORWARD_STAKE_AMOUNT}${HOST_DENOM} --from $HOST_VAL -y
else
# For all other hosts (ibc-v5), pass an address for a receiver and the memo in the --memo field
$transfer_msg_prefix $(STRIDE_ADDRESS) ${PACKET_FORWARD_STAKE_AMOUNT}${HOST_DENOM} --memo "$memo" --from $HOST_VAL -y
fi
$HOST_MAIN_CMD tx ibc-transfer transfer transfer $HOST_TRANSFER_CHANNEL \
$(STRIDE_ADDRESS) ${PACKET_FORWARD_STAKE_AMOUNT}${HOST_DENOM} --memo "$memo" --from $HOST_VAL -y $HOST_FEES

# Wait for the transfer to complete
WAIT_FOR_BALANCE_CHANGE STRIDE $(STRIDE_ADDRESS) st$HOST_DENOM
Expand All @@ -282,14 +278,8 @@ setup_file() {
stibctoken_balance_start=$($HOST_MAIN_CMD q bank balances $HOST_VAL_ADDRESS --denom $IBC_STTOKEN 2>/dev/null | GETBAL)

# Send the IBC transfer with the JSON memo
transfer_msg_prefix="$HOST_MAIN_CMD tx ibc-transfer transfer transfer $HOST_TRANSFER_CHANNEL"
if [[ "$CHAIN_NAME" == "GAIA" ]]; then
# For GAIA (ibc-v3), pass the memo into the receiver field
$transfer_msg_prefix "$memo" ${PACKET_FORWARD_STAKE_AMOUNT}${HOST_DENOM} --from $HOST_VAL -y
else
# For all other hosts (ibc-v5), pass an address for a receiver and the memo in the --memo field
$transfer_msg_prefix $(STRIDE_ADDRESS) ${PACKET_FORWARD_STAKE_AMOUNT}${HOST_DENOM} --memo "$memo" --from $HOST_VAL -y
fi
$HOST_MAIN_CMD tx ibc-transfer transfer transfer $HOST_TRANSFER_CHANNEL \
$(STRIDE_ADDRESS) ${PACKET_FORWARD_STAKE_AMOUNT}${HOST_DENOM} --memo "$memo" --from $HOST_VAL -y $HOST_FEES

# Wait for the transfer to complete
WAIT_FOR_BALANCE_CHANGE $CHAIN_NAME $HOST_VAL_ADDRESS $IBC_STTOKEN
Expand All @@ -312,14 +302,10 @@ setup_file() {
memo='{ "autopilot": { "receiver": "'"$(STRIDE_ADDRESS)"'", "stakeibc": { "action": "RedeemStake", "ibc_receiver": "'$HOST_RECEIVER_ADDRESS'" } } }'

# do IBC transfer
transfer_msg_prefix="$HOST_MAIN_CMD tx ibc-transfer transfer transfer $HOST_TRANSFER_CHANNEL"
if [[ "$CHAIN_NAME" == "GAIA" ]]; then
# For GAIA (ibc-v3), pass the memo into the receiver field
$transfer_msg_prefix "$memo" ${REDEEM_AMOUNT}${IBC_STTOKEN} --from $HOST_VAL -y
else
# For all other hosts (ibc-v5), pass an address for a receiver and the memo in the --memo field
$transfer_msg_prefix $(STRIDE_ADDRESS) ${REDEEM_AMOUNT}${IBC_STTOKEN} --memo "$memo" --from $HOST_VAL -y
fi
# For all other hosts (ibc-v5), pass an address for a receiver and the memo in the --memo field
$HOST_MAIN_CMD tx ibc-transfer transfer transfer $HOST_TRANSFER_CHANNEL \
$(STRIDE_ADDRESS) ${REDEEM_AMOUNT}${IBC_STTOKEN} --memo "$memo" --from $HOST_VAL -y $HOST_FEES

WAIT_FOR_BLOCK $STRIDE_LOGS 2

# make sure stATOM balance decreased
Expand All @@ -336,7 +322,9 @@ setup_file() {

# attempt to redeem with an invalid receiver address to invoke a failure
invalid_memo='{ "autopilot": { "receiver": "'"$(STRIDE_ADDRESS)"'", "stakeibc": { "action": "RedeemStake", "ibc_receiver": "XXX" } } }'
$transfer_msg_prefix "$invalid_memo" ${REDEEM_AMOUNT}${IBC_STTOKEN} --from $HOST_VAL -y
$HOST_MAIN_CMD tx ibc-transfer transfer transfer $HOST_TRANSFER_CHANNEL \
$(STRIDE_ADDRESS) ${REDEEM_AMOUNT}${IBC_STTOKEN} --memo "$invalid_memo" --from $HOST_VAL -y $HOST_FEES

WAIT_FOR_BLOCK $STRIDE_LOGS 10

# Confirm the stATOM balance was refunded
Expand Down
42 changes: 25 additions & 17 deletions x/autopilot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,48 @@ With current implementation of Autopilot module, it supports:
Note: This will support more functions that can reduce number of users' operations.

## Memo
### Format

### Format

```json
{
"autopilot": {
"receiver": "strideXXX",
"{module_name}": { "{additiional_field}": "{value}" }
}
{
"autopilot": {
"receiver": "strideXXX",
"{module_name}": { "{additiional_field}": "{value}" }
}
}
```

### Example (1-Click Liquid Stake)

```json
{
"autopilot": {
"receiver": "strideXXX",
"stakeibc": {
"action": "LiquidStake",
}
{
"autopilot": {
"receiver": "strideXXX",
"stakeibc": {
"action": "LiquidStake"
}
}
}
```

### Example (Update Airdrop Address)

```json
{
"autopilot": {
"receiver": "strideXXX",
"claim": {}
}
{
"autopilot": {
"receiver": "strideXXX",
"claim": {}
}
}
```

### A Note on Parsing

Since older versions of IBC do not have a `Memo` field, they must pass the routing information in the `Receiver` attribute of the IBC packet. To make autopilot backwards compatible with all older IBC versions, the receiver address must be specified in the JSON string. Before passing the packet down the stack to the transfer module, the address in the JSON string will replace the `Receiver` field in the packet data, regardless of the IBC version.

The module also enforces a maximum length for both the `Memo` and `Receiver` fields of 4000 and 100 characters respectively.

## Params

```
Expand Down
Loading

0 comments on commit 930d4eb

Please sign in to comment.