Skip to content

Commit

Permalink
fix scripts for Namada v0.25.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yito88 committed Nov 7, 2023
1 parent 53868c4 commit 19d76d3
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 97 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ ibc-proto = { version = "0.38.0", features = ["serde"] }
ibc-telemetry = { version = "0.26.0", path = "../telemetry", optional = true }
ibc-relayer-types = { version = "0.26.0", path = "../relayer-types", features = ["mocks"] }

namada = { git = "https://github.com/anoma/namada", rev = "63f2e4be022ded03ce0639f4a2a20945c3719080" }
namada_sdk = { git = "https://github.com/anoma/namada", rev = "63f2e4be022ded03ce0639f4a2a20945c3719080", features = ["std", "async-client"] }
namada = { git = "https://github.com/anoma/namada", rev = "7116b6aa916026e97f3f871f291c6ba1c7b427d2" }
namada_sdk = { git = "https://github.com/anoma/namada", rev = "7116b6aa916026e97f3f871f291c6ba1c7b427d2", features = ["std", "async-client"] }

subtle-encoding = "0.5"
humantime-serde = "1.1.1"
Expand Down
6 changes: 3 additions & 3 deletions crates/relayer/src/chain/namada.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ impl ChainEndpoint for NamadaChain {
let key_name = key_name.unwrap_or(&self.config.key_name);
let denom = denom.unwrap_or("NAM");
let token = match self.wallet.find_address(denom) {
Some(addr) => addr.clone(),
Some(addr) => addr.into_owned(),
None => Address::decode(denom)
.map_err(|_| Error::namada_address_not_found(denom.to_string()))?,
};
Expand All @@ -414,7 +414,7 @@ impl ChainEndpoint for NamadaChain {
.find_address(key_name)
.ok_or_else(|| Error::namada_address_not_found(key_name.to_string()))?;

let balance_key = token::balance_key(&token, owner);
let balance_key = token::balance_key(&token, &owner);
let (value, _) = self.query(balance_key, QueryHeight::Latest, IncludeProof::No)?;
if value.is_empty() {
return Ok(Balance {
Expand Down Expand Up @@ -456,7 +456,7 @@ impl ChainEndpoint for NamadaChain {
let prefix = Key::from(Address::Internal(InternalAddress::Multitoken).to_db_key());
for PrefixValue { key, value } in self.query_prefix(prefix)? {
if let Some([token, owner]) = token::is_any_token_balance_key(&key) {
if key_owner == owner {
if key_owner.as_ref() == owner {
let amount =
token::Amount::try_from_slice(&value[..]).map_err(Error::borsh_decode)?;
let denom_key = token::denom_key(token);
Expand Down
4 changes: 2 additions & 2 deletions crates/relayer/src/chain/namada/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl NamadaChain {
.wallet
.find_address(&fee_token)
.ok_or_else(|| Error::namada_address_not_found(fee_token))?
.clone();
.into_owned();

// fee
let gas_limit_key = parameter_storage::get_fee_unshielding_gas_limit_key();
Expand All @@ -55,7 +55,7 @@ impl NamadaChain {
.wallet
.find_address(&self.config.key_name)
.expect("The relayer doesn't exist in the wallet")
.clone();
.into_owned();

let tx_args = TxArgs {
dry_run: false,
Expand Down
20 changes: 12 additions & 8 deletions e2e/namada-simple-transfers
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ fi
cd $(dirname $0)
HERMES_DIR=${PWD%/e2e*}

NAMADAC="${NAMADA_DIR}/target/release/namadac"
NAMADAW="${NAMADA_DIR}/target/release/namadaw"
NAMADAC="${NAMADA_DIR}/target/debug/namadac"
NAMADAW="${NAMADA_DIR}/target/debug/namadaw"
DATA_DIR="${HERMES_DIR}/data"
# IbcToken from `transfer/channel-0/#apfel`
IBC_TOKEN="atest1d93xxw36xqckvdn9vgcxyv3jvyurqdrr89jrwvmxxcexxdnpx5cnyv3ex93kvepnxdjnqvrzucsc73"

LEDGER_ADDR_A="127.0.0.1:27657"
LEDGER_ADDR_B="127.0.0.1:28657"
Expand All @@ -29,7 +27,7 @@ function init_relayer_balance() {
local suffix=$1
local ledger_addr=$2

local base_dir=${DATA_DIR}/namada-${suffix}/.namada
local base_dir=${DATA_DIR}/namada-${suffix}

${NAMADAC} --base-dir ${base_dir} \
transfer \
Expand Down Expand Up @@ -64,7 +62,7 @@ cargo run --bin hermes -- --config config_for_namada.toml \
--new-client-connection --yes

# faucet apfel on chain_a
base_dir_a=${DATA_DIR}/namada-a/.namada
base_dir_a=${DATA_DIR}/namada-a
${NAMADAC} --base-dir ${base_dir_a} transfer \
--source albert \
--target relayer \
Expand All @@ -75,7 +73,7 @@ ${NAMADAC} --base-dir ${base_dir_a} transfer \

# Get the receiver addresses
receiver_a=$(${NAMADAW} --base-dir ${base_dir_a} address find --alias relayer | awk '{print $4}')
base_dir_b=${DATA_DIR}/namada-b/.namada
base_dir_b=${DATA_DIR}/namada-b
receiver_b=$(${NAMADAW} --base-dir ${base_dir_b} address find --alias relayer | awk '{print $4}')

# transfer 100 apfel from chain_a to chain_b
Expand Down Expand Up @@ -113,12 +111,18 @@ echo "Balances on chain B"
${NAMADAC} --base-dir ${base_dir_b} balance \
--owner relayer \
--node ${LEDGER_ADDR_B}
# get token address
received_token=$(${NAMADAC} --base-dir ${base_dir_b} balance \
--owner relayer \
--node ${LEDGER_ADDR_B} \
| sed -e s/://g \
| awk '$1 ~ /transfer\/channel-0/ {print $1}')

# transfer back 50 apfel from chain_b to chain_a
${NAMADAC} --base-dir ${base_dir_b} ibc-transfer \
--source relayer \
--receiver ${receiver_a} \
--token ${IBC_TOKEN} \
--token ${received_token} \
--amount 50 \
--signing-keys relayer \
--channel-id channel-0 \
Expand Down
116 changes: 77 additions & 39 deletions scripts/setup-namada
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@ fi
HERMES_DIR=${PWD%/scripts*}

# edit for your environment
NAMADAC="${NAMADA_DIR}/target/release/namadac"
NAMADAN="${NAMADA_DIR}/target/release/namadan"
NAMADAW="${NAMADA_DIR}/target/release/namadaw"
BASE_GENESIS_PATH="${NAMADA_DIR}/genesis/e2e-tests-single-node.toml"
NAMADAC="${NAMADA_DIR}/target/debug/namadac"
NAMADAN="${NAMADA_DIR}/target/debug/namadan"
NAMADAW="${NAMADA_DIR}/target/debug/namadaw"
BASE_GENESIS_DIR="${NAMADA_DIR}/genesis/localnet"
CHECKSUM_PATH="${NAMADA_DIR}/wasm/checksums.json"
DATA_DIR="${HERMES_DIR}/data"
GENESIS_PATH_A="${DATA_DIR}/e2e-tests-single-node-a.toml"
GENESIS_PATH_B="${DATA_DIR}/e2e-tests-single-node-b.toml"

NET_ADDR_A="127.0.0.1:27656"
NET_ADDR_B="127.0.0.1:28656"
LEDGER_ADDR_A="127.0.0.1:27657"
LEDGER_ADDR_B="127.0.0.1:28657"

Expand Down Expand Up @@ -87,53 +83,67 @@ gas_price = { price = 0.001, denom = 'nam' }

function make_genesis() {
local suffix=$1
local base_dir=${DATA_DIR}/namada-${suffix}

if [ "${suffix}" == "a" ]
then
sed "s/epochs_per_year = .*/epochs_per_year = 31536/g" \
${BASE_GENESIS_PATH} > ${GENESIS_PATH_A}
else
sed -e "s/${NET_ADDR_A}/${NET_ADDR_B}/g" \
-e "s/epochs_per_year = .*/epochs_per_year = 31536/g" \
${BASE_GENESIS_PATH} > ${GENESIS_PATH_B}
fi
mkdir -p ${base_dir}/templates
cp ${BASE_GENESIS_DIR}/*.toml ${base_dir}/templates
sed -i .bak "s/epochs_per_year = .*/epochs_per_year = 31536/g" ${base_dir}/templates/parameters.toml

mkdir ${base_dir}/pre-genesis
cp -r ${BASE_GENESIS_DIR}/src/pre-genesis/* ${base_dir}/pre-genesis
}

function init_network() {
local suffix=$1
local genesis_path=$2

mkdir -p ${DATA_DIR}/namada-${suffix}
NAMADA_BASE_DIR=${DATA_DIR}/namada-${suffix}/.namada \
${NAMADAC} utils init-network \
--unsafe-dont-encrypt \
--genesis-path ${genesis_path} \
--chain-prefix namada-test \
--localhost \
--dont-archive \
local base_dir=${DATA_DIR}/namada-${suffix}
local validator_base_dir=${base_dir}/setup/validator-0

mkdir -p ${base_dir}/genesis
local chain_id=$(NAMADA_BASE_DIR=${base_dir} \
${NAMADAC} utils init-network \
--chain-prefix namada-${suffix} \
--genesis-time "2023-01-01T00:00:00Z" \
--templates-path ${base_dir}/templates \
--wasm-checksums-path ${CHECKSUM_PATH} \
| awk '$1 == "Derived" {print $4}'
--archive-dir ${base_dir}/genesis \
| awk '$1 == "Derived" {print $4}')

NAMADA_NETWORK_CONFIGS_DIR=${base_dir}/genesis \
${NAMADAC} --base-dir ${validator_base_dir} \
utils join-network \
--chain-id ${chain_id} \
--genesis-validator validator-0 \
--pre-genesis-path \
${base_dir}/pre-genesis/validator-0 \
--dont-prefetch-wasm

rm -rf ${base_dir}/${chain_id}
# for non-validator
NAMADA_NETWORK_CONFIGS_DIR=${base_dir}/genesis \
${NAMADAC} --base-dir ${base_dir} \
utils join-network \
--chain-id ${chain_id} \
--dont-prefetch-wasm
}

function copy_wasm() {
local suffix=$1
local chain_id=$2

local base_dir=${DATA_DIR}/namada-${suffix}/.namada
local base_dir=${DATA_DIR}/namada-${suffix}

cp ${NAMADA_DIR}/wasm/checksums.json ${base_dir}/${chain_id}/setup/validator-0/.namada/${chain_id}/wasm/
cp ${NAMADA_DIR}/wasm/*.wasm ${base_dir}/${chain_id}/setup/validator-0/.namada/${chain_id}/wasm/
cp ${NAMADA_DIR}/wasm/*.wasm ${base_dir}/setup/validator-0/${chain_id}/wasm/
}

function init_relayer_acc() {
local suffix=$1
local chain_id=$2
local ledger_addr=$3

local base_dir=${DATA_DIR}/namada-${suffix}/.namada
local base_dir=${DATA_DIR}/namada-${suffix}
local wallet_dir=${HERMES_DIR}/namada_wallet/${chain_id}

cp ${base_dir}/${chain_id}/setup/other/wallet.toml ${base_dir}/${chain_id}/wallet.toml
#cp ${base_dir}/${chain_id}/setup/other/wallet.toml ${base_dir}/${chain_id}/wallet.toml

${NAMADAW} --base-dir ${base_dir} \
key gen --alias relayer --unsafe-dont-encrypt
Expand All @@ -148,29 +158,57 @@ mkdir -p ${DATA_DIR}

# for chain A
make_genesis "a"
chain_id_a=$(init_network "a" ${GENESIS_PATH_A})
result=$(init_network "a")
chain_id_a=$(echo "${result}" | awk '$5 == "ID" {id = $6} END {print id}')

copy_wasm "a" ${chain_id_a}

${NAMADAN} --base-dir ${DATA_DIR}/namada-a/.namada/${chain_id_a}/setup/validator-0/.namada/ \
${NAMADAN} --base-dir ${DATA_DIR}/namada-a/setup/validator-0 \
ledger run > ${DATA_DIR}/namada-a/namada.log 2>&1 &
echo "Namada chain A's PID = $!"
sleep 5

init_relayer_acc "a" ${chain_id_a} ${LEDGER_ADDR_A}
# shutdown temporarily to bootstrap chain-b
killall namadan

# for chain B
make_genesis "b"
chain_id_b=$(init_network "b" ${GENESIS_PATH_B})
result=$(init_network "b")
chain_id_b=$(echo "${result}" | awk '$5 == "ID" {id = $6} END {print id}')

copy_wasm "b" ${chain_id_b}

${NAMADAN} --base-dir ${DATA_DIR}/namada-b/setup/validator-0 \
ledger run > ${DATA_DIR}/namada-b/namada.log 2>&1 &
sleep 5

# shutdown temporarily to bootstrap chain-b
killall namadan

# Edit chain-b addresses
sed -i .bak \
-e "s/:27656/:28656/" \
-e "s/:27657/:28657/" \
-e "s/:27658/:28658/" \
${DATA_DIR}/namada-b/setup/validator-0/${chain_id_b}/config.toml
sed -i .bak \
-e "s/:27656/:28656/" \
-e "s/:27657/:28657/" \
-e "s/:27658/:28658/" \
${DATA_DIR}/namada-b/setup/validator-0/${chain_id_b}/cometbft/config/config.toml

# Restart each chain
${NAMADAN} --base-dir ${DATA_DIR}/namada-a/setup/validator-0 \
ledger run > ${DATA_DIR}/namada-a/namada.log 2>&1 &
echo "Namada chain A's PID = $!"

${NAMADAN} --base-dir ${DATA_DIR}/namada-b/.namada/${chain_id_b}/setup/validator-0/.namada/ \
${NAMADAN} --base-dir ${DATA_DIR}/namada-b/setup/validator-0 \
ledger run > ${DATA_DIR}/namada-b/namada.log 2>&1 &
echo "Namada chain B's PID = $!"

sleep 5

# create "relayer" account on each chain
init_relayer_acc "a" ${chain_id_a} ${LEDGER_ADDR_A}
init_relayer_acc "b" ${chain_id_b} ${LEDGER_ADDR_B}

# for the relayer
Expand Down
Loading

0 comments on commit 19d76d3

Please sign in to comment.