Skip to content

Commit

Permalink
Merge pull request #45 from siburu/channel-upgrade
Browse files Browse the repository at this point in the history
Channel upgrade
  • Loading branch information
siburu authored Sep 2, 2024
2 parents 52ae9eb + ff049d7 commit 924fe85
Show file tree
Hide file tree
Showing 43 changed files with 1,144 additions and 1,812 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ enclave:
.PHONY: clean
clean:
@rm -f $(RustEnclave_Name) $(Signed_RustEnclave_Name) enclave/*_t.* lib/*.a
@cd enclave && cargo clean && rm -f Cargo.lock
@cd enclave && cargo clean

.PHONY: fmt
fmt:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ This repository contains multiple modules:

## Supported Versions

- [ibc-solidity v0.3.29](https://github.com/hyperledger-labs/yui-ibc-solidity/releases/tag/v0.3.29)
- [ibc-solidity v0.3.35](https://github.com/hyperledger-labs/yui-ibc-solidity/releases/tag/v0.3.35)
- [lcp v0.2.9](https://github.com/datachainlab/lcp/releases/tag/v0.2.9)
- [ethereum-elc v0.0.16](https://github.com/datachainlab/ethereum-elc/releases/tag/v0.0.16)
- [lcp-go v0.2.10](https://github.com/datachainlab/lcp-go/releases/tag/v0.2.10)
- [lcp-solidity v0.1.14](https://github.com/datachainlab/lcp-solidity/releases/tag/v0.1.14)
- [yui-relayer v0.5.4](https://github.com/hyperledger-labs/yui-relayer/releases/tag/v0.5.4)
- [ethereum-ibc-relay-chain v0.3.4](https://github.com/datachainlab/ethereum-ibc-relay-chain/releases/tag/v0.3.4)
- [ethereum-ibc-relay-prover v0.3.1](https://github.com/datachainlab/ethereum-ibc-relay-prover/releases/tag/v0.3.1)
- [yui-relayer v0.5.8](https://github.com/hyperledger-labs/yui-relayer/releases/tag/v0.5.8)
- [ethereum-ibc-relay-chain v0.3.10](https://github.com/datachainlab/ethereum-ibc-relay-chain/releases/tag/v0.3.10)
- [ethereum-ibc-relay-prover v0.3.2](https://github.com/datachainlab/ethereum-ibc-relay-prover/releases/tag/v0.3.2)

## Build enclave and run E2E test

Expand Down
3 changes: 1 addition & 2 deletions enclave/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions enclave/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ getrandom = { git = "https://github.com/datachainlab/getrandom-sgx", branch = "v
# TODO these patches would be better as optional
sha2-0106 = { git = "https://github.com/bluele/hashes", branch = "0.10.6-sha256-hwa-disabled", package = "sha2" }
sha2-098 = { git = "https://github.com/bluele/hashes", branch = "0.9.8-sha256-hwa-disabled", package = "sha2" }
ibc = { git = "https://github.com/datachainlab/ibc-rs", rev = "v0.29.0-channel-upgrade-path" }

[profile.release]
opt-level = 3
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ module github.com/datachainlab/cosmos-ethereum-ibc-lcp
go 1.21

require (
github.com/datachainlab/ethereum-ibc-relay-chain v0.3.4
github.com/datachainlab/ethereum-ibc-relay-prover v0.3.1
github.com/datachainlab/ethereum-ibc-relay-chain v0.3.10
github.com/datachainlab/ethereum-ibc-relay-prover v0.3.2
github.com/datachainlab/ibc-hd-signer v0.1.0
github.com/datachainlab/lcp-go v0.2.10
github.com/hyperledger-labs/yui-relayer v0.5.4
github.com/hyperledger-labs/yui-relayer v0.5.8
)

require (
Expand Down
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,12 @@ github.com/d4l3k/messagediff v1.2.1 h1:ZcAIMYsUg0EAp9X+tt8/enBE/Q8Yd5kzPynLyKptt
github.com/d4l3k/messagediff v1.2.1/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo=
github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0=
github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0=
github.com/datachainlab/ethereum-ibc-relay-chain v0.3.4 h1:2mbvy6W/lm11SeQBgj1100A6D/70Wk9DooMoZfE8oXU=
github.com/datachainlab/ethereum-ibc-relay-chain v0.3.4/go.mod h1:PdSsegkRJiMWVGq+afDtXKRKg4p8hnmR1Yj5BgXkit0=
github.com/datachainlab/ethereum-ibc-relay-prover v0.3.1 h1:/a4O7oFDs3Crlm8VkOY8HCM+2eLCCSvTbGLHnFttlLY=
github.com/datachainlab/ethereum-ibc-relay-prover v0.3.1/go.mod h1:OfuufukSThjjZXQtFyZqwY9csQNrJ/wIm0VLAUw3l4g=
github.com/datachainlab/ethereum-ibc-relay-chain v0.3.10 h1:ce7/EiUZDjTWGHr8VGwP8Maqqur0koxK2qCOLty6gJs=
github.com/datachainlab/ethereum-ibc-relay-chain v0.3.10/go.mod h1:7goF50HLpKyL6bmisyY7t9QV338WC+68GqGpaZ9Te24=
github.com/datachainlab/ethereum-ibc-relay-prover v0.3.2 h1:E1gWclbzDoPMkZNSq7p0ifWrOTfv+p2RZ+CsZjUOPD0=
github.com/datachainlab/ethereum-ibc-relay-prover v0.3.2/go.mod h1:OfuufukSThjjZXQtFyZqwY9csQNrJ/wIm0VLAUw3l4g=
github.com/datachainlab/ibc-hd-signer v0.1.0 h1:dmnFTAwFpl0m7Lx6+b+N/rrNpHQnXpyJAYnM25GhDi0=
github.com/datachainlab/ibc-hd-signer v0.1.0/go.mod h1:wUbLb2EryMCY+GfEsziU0T032Gch04jmrN0D4XGAfOI=
github.com/datachainlab/lcp-go v0.2.10 h1:1c8C+HR+tC/4NjCjpuz+Nkk3I/uIQ3PNRcvJKsSU948=
github.com/datachainlab/lcp-go v0.2.10/go.mod h1:0ivRb4qUiZz5UQxsbRKygQyFz0XC6TIC6YpEUdOc1So=
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -809,8 +811,8 @@ github.com/huandu/skiplist v1.2.0/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXM
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
github.com/hyperledger-labs/yui-relayer v0.5.4 h1:yhvWI28Rcel55UsdmYWX0QE0W3P9aBSRetQh1k8VpZA=
github.com/hyperledger-labs/yui-relayer v0.5.4/go.mod h1:GeCb1dtZjtQdkBNw1L9+LAUHzNQQhQK+kkoOnZYffw0=
github.com/hyperledger-labs/yui-relayer v0.5.8 h1:rIgWXSyKIVg/xjbfYjQ2biQaoL7jAoGIjJFgqLWWanY=
github.com/hyperledger-labs/yui-relayer v0.5.8/go.mod h1:GeCb1dtZjtQdkBNw1L9+LAUHzNQQhQK+kkoOnZYffw0=
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down
2 changes: 1 addition & 1 deletion relayer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"os"

"github.com/datachainlab/ethereum-ibc-relay-chain/pkg/relay/ethereum"
"github.com/datachainlab/ethereum-ibc-relay-chain/pkg/relay/ethereum/signers/hd"
ethereumlc "github.com/datachainlab/ethereum-ibc-relay-prover/relay"
"github.com/datachainlab/ibc-hd-signer/pkg/hd"
lcp "github.com/datachainlab/lcp-go/relay"
rawsigner "github.com/datachainlab/lcp-go/relay/signers/raw"
lcptm "github.com/datachainlab/lcp-go/relay/tendermint"
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/cases/tm2eth/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ setup:
handshake:
RLY_BIN=$(RLY_BIN) ./scripts/handshake

.PHONY: test-channel-upgrade
test-channel-upgrade:
RLY_BIN=$(RLY_BIN) ./scripts/test-channel-upgrade

.PHONY: test
test:
RLY_BIN=$(RLY_BIN) ./scripts/test-tx
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/cases/tm2eth/configs/templates/ibc-1.json.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"eth_chain_id": 15,
"rpc_addr": "http://localhost:8546",
"signer": {
"@type": "/relayer.chains.ethereum.signers.hd.SignerConfig",
"@type": "/relayer.signers.hd.SignerConfig",
"mnemonic": "math razor capable expose worth grape metal sunset metal sudden usage scheme",
"path": "m/44'/60'/0'/0/0"
},
Expand Down
198 changes: 198 additions & 0 deletions tests/e2e/cases/tm2eth/scripts/test-channel-upgrade
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
#!/bin/bash

set -eux

SCRIPT_DIR=$(cd $(dirname $0); pwd)
source "$SCRIPT_DIR/../../../scripts/util"

RELAYER_CONF="$HOME/.yui-relayer"
RLY="${RLY_BIN} --debug"

PATH_NAME=ibc01

checkEq() {
typ=$1
a=$2
b=$3
if [ $a != $b ]
then
echo "${typ} mismatch: ${a} != ${b}"
exit 1
fi
echo $a
}

# back up the original channel fields
a=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].src."connection-id"')
b=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].dst."connection-id"')
origConnectionId=$(checkEq "original connection id" $a $b)

a=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].src."version"')
b=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].dst."version"')
origVersion=$(checkEq "original version" $a $b)

a=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].src."order"')
b=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].dst."order"')
origOrder=$(checkEq "original ordering" $a $b)

# back up the original config.json and make connection identifiers empty
origconfig=`mktemp`
cp "$RELAYER_CONF/config/config.json" $origconfig
$RLY paths edit $PATH_NAME src connection-id ''
$RLY paths edit $PATH_NAME dst connection-id ''

# create a new connection and save the new connection identifiers
retry 5 $RLY tx update-clients $PATH_NAME
sleep 60
retry 20 $RLY tx connection $PATH_NAME -o 20s
a=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].src."connection-id"')
b=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].dst."connection-id"')
altConnectionId=$(checkEq "alternative connection id" $a $b)
altOrder=ordered

# resume the original config.json
mv $origconfig "$RELAYER_CONF/config/config.json"

# the function that checks which of orig or alt the channel has finally settled
checkResult() {
expectedSide=$1
expectedVersion=$2

a=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].src."connection-id"')
b=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].dst."connection-id"')
connectionId=$(checkEq "path config connection id" $a $b)

a=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].src."version"')
b=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].dst."version"')
version=$(checkEq "path config version" $a $b)

a=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].src."order"')
b=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].dst."order"')
order=$(checkEq "path config ordering" $a $b)

if [ "$expectedSide" = orig ]
then
expectedConnectionId=$origConnectionId
expectedOrder=$origOrder
elif [ $expectedSide = alt ]
then
expectedConnectionId=$altConnectionId
expectedOrder=$altOrder
else
echo "expectedSide is invalid value: $expectedSide"
exit 1
fi

if [ "$connectionId" != "$expectedConnectionId" -o "$order" != "$expectedOrder" -o "$version" != "$expectedVersion" ]
then
echo "unexpected channel fields: $connectionId(expected: $expectedConnectionId), $order(expected: $expectedOrder), $version(expected: $expectedVersion)"
exit 1
fi

# confirm src chain is not upgrading
upg=$($RLY query channel-upgrade ibc01 ibc0)
if [ $(echo "$upg" | jq '.fields|length') -ne 0 ]
then
echo "src chain still in the process of upgrade: $upg"
exit 1
fi

# confirm dst chain is not upgrading
upg=$($RLY query channel-upgrade ibc01 ibc1)
if [ $(echo "$upg" | jq '.fields|length') -ne 0 ]
then
echo "dst chain is still in the process of upgrade: $upg"
exit 1
fi
}

# constant variables
#TIMEOUT_FLAGS="--timeout-height 0-0 --timeout-timestamp `date -d 2030/01/01 +%s`"
TIMEOUT_FLAGS="--timeout-height 0-100000000"
ORIG_FIELDS="--ordering $origOrder --connection-hops $origConnectionId"
ALT_FIELDS="--ordering $altOrder --connection-hops $altConnectionId"

echo '##### case 1 #####'
fields="$ALT_FIELDS --version mockapp-2"
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY eth upgrade propose ibc01 ibc1 $fields $TIMEOUT_FLAGS
$RLY tx channel-upgrade init ibc01 ibc1 $fields
retry 10 $RLY tx channel-upgrade execute ibc01 --target-src-state FLUSHCOMPLETE --target-dst-state FLUSHING
$RLY eth upgrade allow ibc01 ibc1 --upgrade-sequence 1
retry 10 $RLY tx channel-upgrade execute ibc01
checkResult alt mockapp-2

echo '##### case 2 #####'
fields="$ORIG_FIELDS --version mockapp-3"
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY eth upgrade propose ibc01 ibc1 $fields $TIMEOUT_FLAGS
$RLY tx channel-upgrade init ibc01 ibc1 $fields
retry 10 $RLY tx channel-upgrade execute ibc01
checkResult orig mockapp-3

echo '##### case 3 #####'
fields="$ALT_FIELDS --version mockapp-4"
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY eth upgrade propose ibc01 ibc1 $fields $TIMEOUT_FLAGS
$RLY tx channel-upgrade init ibc01 ibc1 $fields
retry 10 $RLY tx channel-upgrade cancel ibc01 ibc0 # create situation where ibc0.error_receipt.sequence >= ibc1.channel.upgrade_sequence
retry 10 $RLY tx channel-upgrade execute ibc01 # the channel upgrade of ibc1 should be cancelled
checkResult orig mockapp-3

echo '##### case 4 #####'
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY eth upgrade propose ibc01 ibc1 $fields $TIMEOUT_FLAGS
retry 10 $RLY tx channel-upgrade execute ibc01 --target-src-state INIT --target-dst-state FLUSHING
retry 10 $RLY tx channel-upgrade cancel ibc01 ibc0 # ibc0 returns to UNINIT. ibc1 is FLUSHING.
retry 10 $RLY tx channel-upgrade execute ibc01 # ibc1's upgrade should be cancelled
checkResult orig mockapp-3

echo '##### case 5 #####'
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY eth upgrade propose ibc01 ibc1 $fields $TIMEOUT_FLAGS
retry 10 $RLY tx channel-upgrade execute ibc01 --target-src-state INIT --target-dst-state FLUSHING
retry 10 $RLY tx channel-upgrade cancel ibc01 ibc0 # ibc0 returns to UNINIT. ibc1 is FLUSHING.
$RLY tx channel-upgrade init ibc01 ibc0 --unsafe $fields # ibc0 re-initiates new upgrade.
retry 10 $RLY tx channel-upgrade execute ibc01 --target-src-state FLUSHCOMPLETE --target-dst-state FLUSHING
$RLY eth upgrade allow ibc01 ibc1 --upgrade-sequence 7
retry 10 $RLY tx channel-upgrade execute ibc01 # The upgrade initiated by ibc0 should be completed after ibc1's one is cancelled.
checkResult alt mockapp-4

echo '##### case 6 #####'
fields="$ORIG_FIELDS --version mockapp-5"
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY eth upgrade propose ibc01 ibc1 $fields $TIMEOUT_FLAGS
retry 10 $RLY tx channel-upgrade execute ibc01 --target-src-state FLUSHCOMPLETE --target-dst-state FLUSHING
retry 10 $RLY tx channel-upgrade cancel ibc01 ibc1 # ibc1 returns to UNINIT. ibc0 is FLUSHCOMPLETE.
retry 10 $RLY tx channel-upgrade execute ibc01 # ibc0's upgrade (in FLUSHCOMPLETE) should be cancelled.
checkResult alt mockapp-4

echo '##### case 7 #####'
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY eth upgrade propose ibc01 ibc1 $fields $TIMEOUT_FLAGS
retry 10 $RLY tx channel-upgrade execute ibc01 --target-src-state FLUSHCOMPLETE --target-dst-state FLUSHING
retry 10 $RLY tx channel-upgrade cancel ibc01 ibc1 # ibc1 returns to UNINIT. ibc0 is FLUSHCOMPLETE.
$RLY eth upgrade propose ibc01 ibc1 $fields $TIMEOUT_FLAGS
$RLY tx channel-upgrade init ibc01 ibc1 --unsafe $fields # ibc1 re-initiates new upgrade.
retry 10 $RLY tx channel-upgrade execute ibc01 # The upgrade initiated by ibc1 should be completed after ibc0's one is cancelled.
checkResult orig mockapp-5

echo '##### case 8 #####'
fields="$ALT_FIELDS --version mockapp-6"
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY eth upgrade propose ibc01 ibc1 $fields $TIMEOUT_FLAGS
$RLY tx channel-upgrade init ibc01 ibc1 $fields
retry 10 $RLY tx channel-upgrade execute ibc01 --target-src-state FLUSHCOMPLETE --target-dst-state FLUSHING
sleep 480 # ibc1 exceeds upgrade.timeout.timestamp
retry 10 $RLY tx channel-upgrade execute ibc01 # ibc0 <= chanUpgradeTimeout, ibc1 <= chanUpgradeCancel
checkResult orig mockapp-5

echo '##### case 9 #####'
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY eth upgrade propose ibc01 ibc1 $fields $TIMEOUT_FLAGS --timeout-height 0-0 --timeout-timestamp `date -d 480sec +%s%N`
$RLY tx channel-upgrade init ibc01 ibc1 $fields
retry 10 $RLY tx channel-upgrade execute ibc01 --target-src-state FLUSHING --target-dst-state FLUSHING
sleep 480 # Both chains exceed upgrade.timeout.timestamp
retry 10 $RLY tx channel-upgrade execute ibc01 # ibc0,ibc1 <= chanUpgradeTimeout
checkResult orig mockapp-5
2 changes: 1 addition & 1 deletion tests/e2e/cases/tm2eth/scripts/test-tx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ retry() {

echo "!!! ibc0 -> ibc1 !!!"

docker exec -it tendermint-chain sh -c "simd --home /root/data/ibc0 tx --keyring-backend=test --from ${TM_USER_ADDRESS} --chain-id ibc0 mockapp send mockapp channel-0 msg0 --yes"
docker exec tendermint-chain sh -c "simd --home /root/data/ibc0 tx --keyring-backend=test --from ${TM_USER_ADDRESS} --chain-id ibc0 mockapp send mockapp channel-0 'mock packet data' --yes"
sleep 5
retry 10 ${RLY} tx relay --do-refresh ibc01
sleep ${TX_INTERNAL}
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/chains/ethereum/contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ cache/
node_modules/
abis/
addresses/
.openzeppelin/
Loading

0 comments on commit 924fe85

Please sign in to comment.