diff --git a/Cargo.lock b/Cargo.lock index 5d61771..4dafc58 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4295,6 +4295,15 @@ dependencies = [ "subtle", ] +[[package]] +name = "update-tx-claim-rewards" +version = "0.1.0" +dependencies = [ + "getrandom", + "namada_tx_prelude", + "rlsf", +] + [[package]] name = "usize-set" version = "0.10.3" diff --git a/Cargo.toml b/Cargo.toml index d7a0d52..e9ae677 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,8 @@ members = [ "increase_target_staked_ratio", "phase3", "phase4", "phase5", - "increase_target_staked_ratio" + "increase_target_staked_ratio", + "update-tx-claim-rewards", ] default-members = [ @@ -14,7 +15,8 @@ default-members = [ "phase3", "phase4", "phase5", - "increase_target_staked_ratio" + "increase_target_staked_ratio", + "update-tx-claim-rewards", ] [workspace.package] diff --git a/Earthfile b/Earthfile index f029ab6..e08a4de 100644 --- a/Earthfile +++ b/Earthfile @@ -18,7 +18,7 @@ source: COPY --keep-ts Cargo.toml Cargo.lock ./ COPY --keep-ts --chmod 755 docker/run-wasmopt.sh ./run-wasmopt.sh COPY --keep-ts --chmod 755 docker/download-wasmopt.sh ./download-wasmopt.sh - COPY --keep-ts --dir phase2 phase3 phase4 phase5 increase_target_staked_ratio ./ + COPY --keep-ts --dir phase2 phase3 phase4 phase5 increase_target_staked_ratio update-tx-claim-rewards ./ # lint runs cargo clippy on the source code lint: @@ -53,4 +53,4 @@ all: BUILD +build BUILD +test BUILD +fmt - BUILD +check \ No newline at end of file + BUILD +check diff --git a/builder/parameters/update-tx-claim-rewards.json b/builder/parameters/update-tx-claim-rewards.json new file mode 100644 index 0000000..9295b83 --- /dev/null +++ b/builder/parameters/update-tx-claim-rewards.json @@ -0,0 +1,15 @@ +{ + "title": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus eget ex id erat interdum dictum vel ac libero. Cras vitae porta velit, vel interdum odio. Phasellus quis sem finibus, luctus neque in, vestibulum lectus. Maecenas at nulla dapibus, condimentum sem vitae, ullamcorper nisi. Pellentesque tristique tempus tellus, nec sollicitudin velit facilisis at. Vivamus porta nibh sit amet eros tempor, vestibulum lacinia est pulvinar. Maecenas libero mauris, blandit sit amet tempus in, elementum quis nunc. ", + "authors": "Bob The Builer ", + "discussions-to": "www.bob-the-builder.forum.rock", + "license": "SPQR", + "abstract": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", + "motivation": " Vivamus eget ex id erat interdum dictum vel ac libero.", + "details": "Phasellus quis sem finibus, luctus neque in, vestibulum lectus.", + "requires": "-1", + "author": "tnam1qxfj3sf6a0meahdu9t6znp05g8zx4dkjtgyn9gfu", + "voting_start_epoch": 9, + "voting_end_epoch": 18, + "activation_epoch": 25, + "wasm_path": "artifacts/update-tx-claim-rewards.wasm" +} \ No newline at end of file diff --git a/update-tx-claim-rewards/Cargo.toml b/update-tx-claim-rewards/Cargo.toml new file mode 100644 index 0000000..a9aea7b --- /dev/null +++ b/update-tx-claim-rewards/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "update-tx-claim-rewards" +description = "WASM transaction to update tx_claim_rewards WASM from https://github.com/anoma/namada/pull/4283." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +rlsf.workspace = true +getrandom.workspace = true + +[lib] +crate-type = ["cdylib"] diff --git a/update-tx-claim-rewards/src/lib.rs b/update-tx-claim-rewards/src/lib.rs new file mode 100644 index 0000000..8619583 --- /dev/null +++ b/update-tx-claim-rewards/src/lib.rs @@ -0,0 +1,53 @@ +use std::str::FromStr; + +use namada_tx_prelude::hash::Hash; +use namada_tx_prelude::*; + +#[transaction] +fn apply_tx(ctx: &mut Ctx, _tx_data: BatchedTx) -> TxResult { + let new_code_hash = Hash::from_str(NEW_TX_HASH).unwrap(); + let new_code_len = u64::try_from(NEW_TX_CODE.len()).unwrap(); + let old_code_hash = Hash::from_str(OLD_TX_HASH).unwrap(); + + // Update the tx allowlist parameter + let tx_allowlist_key = parameters_storage::get_tx_allowlist_storage_key(); + let tx_allowlist: Vec = ctx.read(&tx_allowlist_key)?.unwrap(); + assert!(tx_allowlist.iter().any(|hash_str| hash_str == OLD_TX_HASH)); + let tx_allowlist: Vec = tx_allowlist + .into_iter() + .map(|hash_str| { + if hash_str == OLD_TX_HASH { + new_code_hash.to_string().to_lowercase() + } else { + hash_str + } + }) + .collect(); + ctx.write(&tx_allowlist_key, tx_allowlist)?; + + // Delete the old tx code + let old_code_key = storage::Key::wasm_code(&old_code_hash); + let old_code_len_key = storage::Key::wasm_code_len(&old_code_hash); + ctx.delete(&old_code_key)?; + ctx.delete(&old_code_len_key)?; + + // Write the new tx code into storage + let code_key = storage::Key::wasm_code(&new_code_hash); + let code_len_key = storage::Key::wasm_code_len(&new_code_hash); + let hash_key = storage::Key::wasm_hash(TX_NAME); + let code_name_key = storage::Key::wasm_code_name(TX_NAME.to_owned()); + + ctx.write(&code_key, NEW_TX_CODE)?; + ctx.write(&code_len_key, new_code_len)?; + ctx.write(&hash_key, new_code_hash)?; + ctx.write(&code_name_key, new_code_hash)?; + + Ok(()) +} + +const TX_NAME: &str = "tx_claim_rewards.wasm"; +const OLD_TX_HASH: &str = "b1224953556ae9e4f83bd2c9593cfbb04a08b5592d150bff2c158225f2dbbdd6"; +const NEW_TX_HASH: &str = "b74104949ac0c35ee922fdc3f3db454627742e2483d79550c12fcf31755c6d01"; +const NEW_TX_CODE: &[u8] = include_bytes!( + "tx_claim_rewards.b74104949ac0c35ee922fdc3f3db454627742e2483d79550c12fcf31755c6d01.wasm" +); diff --git a/update-tx-claim-rewards/src/tx_claim_rewards.b74104949ac0c35ee922fdc3f3db454627742e2483d79550c12fcf31755c6d01.wasm b/update-tx-claim-rewards/src/tx_claim_rewards.b74104949ac0c35ee922fdc3f3db454627742e2483d79550c12fcf31755c6d01.wasm new file mode 100755 index 0000000..1fe74b9 Binary files /dev/null and b/update-tx-claim-rewards/src/tx_claim_rewards.b74104949ac0c35ee922fdc3f3db454627742e2483d79550c12fcf31755c6d01.wasm differ