Skip to content

Commit

Permalink
remove transaction whitelisting
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraccaman committed May 31, 2024
1 parent b6128b7 commit e6a7d41
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 77 deletions.
38 changes: 0 additions & 38 deletions block_party/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
use dec::Dec;
use hash::Hash as CodeHash;
use namada_tx_prelude::*;
use storage::Key;

use std::str::FromStr;

use namada_proof_of_stake::storage::{read_pos_params, write_pos_params};

const TX_CLAIM_REWARDS_NAME: &str = "tx_claim_rewards.wasm";
const TX_CLAIM_REWARDS_BYTES: &[u8] = include_bytes!("../../wasms/tx_claim_rewards.af4cd35b30f17cf2440be74bedeb74296aac21e4ab1ea7143f3a3dede722a0ed.wasm");

#[transaction]
fn apply_tx(ctx: &mut Ctx, _tx_data: BatchedTx) -> TxResult {
// PoS inflation
Expand All @@ -30,38 +25,5 @@ fn apply_tx(ctx: &mut Ctx, _tx_data: BatchedTx) -> TxResult {
let steward_inflation_rate = Dec::from_str("0.001").unwrap();
ctx.write(&steward_inflation_key, steward_inflation_rate)?;

// Read the current transaction allowlist from storage
let tx_allowlist_key = parameters_storage::get_tx_allowlist_storage_key();
let mut current_tx_allowlist = ctx
.read::<Vec<String>>(&tx_allowlist_key)?
.unwrap_or_default();

// Update the allowlist and write the addition wasm storage keys per transaction
for (wasm_name, wasm_bytes) in [(TX_CLAIM_REWARDS_NAME, TX_CLAIM_REWARDS_BYTES)] {
let tx_hash = CodeHash::sha256(wasm_bytes);

// make the update idempotent
if current_tx_allowlist.contains(&tx_hash.to_string()) {
continue;
}

let wasm_name_key = Key::wasm_code_name(wasm_name.to_string());
ctx.write(&wasm_name_key, tx_hash)?;

let wasm_hash_key = Key::wasm_hash(wasm_name);
ctx.write(&wasm_hash_key, tx_hash)?;

let code_key = Key::wasm_code(&tx_hash);
ctx.write(&code_key, wasm_bytes)?;

let len_key = Key::wasm_code_len(&tx_hash);
ctx.write(&len_key, wasm_bytes.len())?;

current_tx_allowlist.push(tx_hash.to_string());
}

// Write the update allowlist back to storage
ctx.write(&tx_allowlist_key, current_tx_allowlist)?;

Ok(())
}
39 changes: 0 additions & 39 deletions staking_party/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
use hash::Hash as CodeHash;
use namada_tx_prelude::*;
use storage::Key;

pub type ChannelId = &'static str;
pub type BaseToken = &'static str;

pub type MintTokenLimit = token::Amount;
pub type ThroughtputTokenLimit = token::Amount;

const TX_TRANSFER_NAME: &str = "tx_transfer.wasm";
const TX_TRANSFER_BYTES: &[u8] = include_bytes!(
"../../wasms/tx_transfer.8198890dbdf67bc93b16492496413c8140a273465f0f8f3ae091e5949a5ac4e0.wasm"
);

const IBC_TOKENS: [(ChannelId, BaseToken, MintTokenLimit, ThroughtputTokenLimit); 2] = [
(
"channel-0",
Expand Down Expand Up @@ -42,37 +35,5 @@ fn apply_tx(ctx: &mut Ctx, _tx_data: BatchedTx) -> TxResult {
ctx.write(&throughput_limit_token_key, throughput_limit)?;
}

// Read the current transaction allowlist from storage
let tx_allowlist_key = parameters_storage::get_tx_allowlist_storage_key();
let mut current_tx_allowlist = ctx
.read::<Vec<String>>(&tx_allowlist_key)?
.unwrap_or_default();

// Update the allowlist and write the addition wasm storage keys per transaction
for (wasm_name, wasm_bytes) in [(TX_TRANSFER_NAME, TX_TRANSFER_BYTES)] {
let tx_hash = CodeHash::sha256(wasm_bytes);

if current_tx_allowlist.contains(&tx_hash.to_string()) {
continue;
}

let wasm_name_key = Key::wasm_code_name(wasm_name.to_string());
ctx.write(&wasm_name_key, tx_hash)?;

let wasm_hash_key = Key::wasm_hash(wasm_name);
ctx.write(&wasm_hash_key, tx_hash)?;

let code_key = Key::wasm_code(&tx_hash);
ctx.write(&code_key, wasm_bytes)?;

let len_key = Key::wasm_code_len(&tx_hash);
ctx.write(&len_key, wasm_bytes.len())?;

current_tx_allowlist.push(tx_hash.to_string());
}

// Write the update allowlist back to storage
ctx.write(&tx_allowlist_key, current_tx_allowlist)?;

Ok(())
}

0 comments on commit e6a7d41

Please sign in to comment.