Skip to content
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

Test Claim rewards upgrade on Campfire #36

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ members = [ "increase_target_staked_ratio",
"phase3",
"phase4",
"phase5",
"increase_target_staked_ratio"
"increase_target_staked_ratio",
"update-tx-claim-rewards",
]

default-members = [
"phase2",
"phase3",
"phase4",
"phase5",
"increase_target_staked_ratio"
"increase_target_staked_ratio",
"update-tx-claim-rewards",
]

[workspace.package]
Expand Down
4 changes: 2 additions & 2 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -53,4 +53,4 @@ all:
BUILD +build
BUILD +test
BUILD +fmt
BUILD +check
BUILD +check
15 changes: 15 additions & 0 deletions builder/parameters/update-tx-claim-rewards.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"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"
}
17 changes: 17 additions & 0 deletions update-tx-claim-rewards/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
53 changes: 53 additions & 0 deletions update-tx-claim-rewards/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<String> = ctx.read(&tx_allowlist_key)?.unwrap();
assert!(tx_allowlist.iter().any(|hash_str| hash_str == OLD_TX_HASH));
let tx_allowlist: Vec<String> = 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"
);
Binary file not shown.