Skip to content

Commit

Permalink
trans_token: env agnostic VP
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Sep 12, 2024
1 parent bc62e43 commit a75ad66
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 147 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

18 changes: 9 additions & 9 deletions crates/benches/native_vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ fn vp_multitoken(c: &mut Criterion) {
let gas_meter = RefCell::new(VpGasMeter::new_from_tx_meter(
&TxGasMeter::new(u64::MAX),
));
let multitoken = MultitokenVp::new(Ctx::new(
let ctx = Ctx::new(
&Address::Internal(InternalAddress::Multitoken),
&shell.state,
&signed_tx.tx,
Expand All @@ -523,18 +523,18 @@ fn vp_multitoken(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell.vp_wasm_cache.clone(),
));
);

group.bench_function(bench_name, |b| {
b.iter(|| {
assert!(
multitoken
.validate_tx(
&signed_tx.to_ref(),
multitoken.ctx.keys_changed,
multitoken.ctx.verifiers,
)
.is_ok()
MultitokenVp::validate_tx(
&ctx,
&signed_tx.to_ref(),
ctx.keys_changed,
ctx.verifiers,
)
.is_ok()
)
})
});
Expand Down
15 changes: 7 additions & 8 deletions crates/node/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,14 +1266,13 @@ where
)
.map_err(Error::NativeVpError),
InternalAddress::Multitoken => {
let multitoken = MultitokenVp::new(ctx);
multitoken
.validate_tx(
batched_tx,
&keys_changed,
&verifiers,
)
.map_err(Error::NativeVpError)
MultitokenVp::validate_tx(
&ctx,
batched_tx,
&keys_changed,
&verifiers,
)
.map_err(Error::NativeVpError)
}
InternalAddress::Masp => {
let masp = MaspVp::new(ctx);
Expand Down
12 changes: 5 additions & 7 deletions crates/sdk/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,11 @@ pub type GovernanceVp<'ctx, CTX> = governance::vp::GovernanceVp<
pub type PgfVp<'ctx, CTX> = governance::vp::pgf::PgfVp<'ctx, CTX>;

/// Native multitoken VP
pub type MultitokenVp<'a, S, CA> = token::vp::MultitokenVp<
'a,
S,
VpCache<CA>,
Eval<S, CA>,
ParamsPreStore<'a, S, CA>,
GovPreStore<'a, S, CA>,
pub type MultitokenVp<'ctx, CTX> = token::vp::MultitokenVp<
'ctx,
CTX,
parameters::Store<<CTX as VpEnv<'ctx>>::Pre>,
governance::Store<<CTX as VpEnv<'ctx>>::Pre>,
>;

/// Native MASP VP
Expand Down
22 changes: 4 additions & 18 deletions crates/tests/src/vm_host_env/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ use namada_sdk::{ibc, proof_of_stake, token};
use namada_test_utils::TestWasms;
use namada_tx_env::TxEnv;
use namada_tx_prelude::BorshSerializeExt;
use namada_vm::wasm::run::VpEvalWasm;
use namada_vm::{wasm, WasmCacheRwAccess};
use namada_vp::native_vp;
use namada_vp::native_vp::{Ctx, NativeVp};
Expand All @@ -100,20 +101,6 @@ impl<'a> TestIbcVp<'a> {
}
}

pub struct TestMultitokenVp<'a> {
pub multitoken_vp: MultitokenVp<'a, TestState, WasmCacheRwAccess>,
}

impl<'a> TestMultitokenVp<'a> {
pub fn validate(&self, batched_tx: &BatchedTxRef) -> native_vp::Result<()> {
self.multitoken_vp.validate_tx(
batched_tx,
self.multitoken_vp.ctx.keys_changed,
self.multitoken_vp.ctx.verifiers,
)
}
}

/// Validate an IBC transaction with IBC VP.
pub fn validate_ibc_vp_from_tx<'a>(
tx_env: &'a TestTxEnv,
Expand Down Expand Up @@ -170,12 +157,12 @@ pub fn validate_multitoken_vp_from_tx<'a>(
);
}
let (vp_wasm_cache, _vp_cache_dir) =
wasm::compilation_cache::common::testing::cache();
wasm::compilation_cache::common::testing::vp_cache();

let gas_meter = RefCell::new(VpGasMeter::new_from_tx_meter(
&TxGasMeter::new(10_000_000_000),
));
let ctx = Ctx::new(
let ctx = Ctx::<_, _, VpEvalWasm<_, _, _>>::new(
&ADDRESS,
&tx_env.state,
batched_tx.tx,
Expand All @@ -186,9 +173,8 @@ pub fn validate_multitoken_vp_from_tx<'a>(
&verifiers,
vp_wasm_cache,
);
let multitoken_vp = MultitokenVp::new(ctx);

TestMultitokenVp { multitoken_vp }.validate(batched_tx)
MultitokenVp::validate_tx(&ctx, batched_tx, ctx.keys_changed, ctx.verifiers)
}

/// Initialize the test storage. Requires initialized [`tx_host_env::ENV`].
Expand Down
3 changes: 2 additions & 1 deletion crates/trans_token/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namada_events = { path = "../events", default-features = false }
namada_state = { path = "../state" }
namada_systems = { path = "../systems" }
namada_tx = { path = "../tx" }
namada_vp = { path = "../vp" }
namada_vp_env = { path = "../vp_env" }

konst.workspace = true
linkme = {workspace = true, optional = true}
Expand All @@ -40,5 +40,6 @@ namada_parameters = { path = "../parameters", features = ["testing"] }
namada_state = { path = "../state", features = ["testing"] }
namada_tx = { path = "../tx", features = ["testing"] }
namada_vm = { path = "../vm", features = ["testing"] }
namada_vp = { path = "../vp" }

assert_matches.workspace = true
Loading

0 comments on commit a75ad66

Please sign in to comment.