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

merge queue: embarking main (c6ec091) and #3807 together #3813

Closed
wants to merge 11 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
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/3807-env-agnostic-vps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Refactored most native VPs to be agnostic to VP environment (WASM or native).
([\#3807](https://github.com/anoma/namada/pull/3807))
9 changes: 6 additions & 3 deletions Cargo.lock

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

141 changes: 75 additions & 66 deletions crates/benches/native_vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ use namada_node::bench_utils::{
TX_BRIDGE_POOL_WASM, TX_IBC_WASM, TX_INIT_PROPOSAL_WASM, TX_RESIGN_STEWARD,
TX_TRANSFER_WASM, TX_UPDATE_STEWARD_COMMISSION, TX_VOTE_PROPOSAL_WASM,
};
use namada_vp::native_vp::{Ctx, NativeVp};
use namada_vm::wasm::run::VpEvalWasm;
use namada_vm::wasm::VpCache;
use namada_vp::native_vp::{self, NativeVp};
use rand_core::OsRng;

type Ctx<'ctx, S, D, H, CA> =
native_vp::Ctx<'ctx, S, VpCache<CA>, VpEvalWasm<D, H, CA>>;

fn governance(c: &mut Criterion) {
let mut group = c.benchmark_group("vp_governance");

Expand Down Expand Up @@ -215,7 +220,7 @@ fn governance(c: &mut Criterion) {
let gas_meter = RefCell::new(VpGasMeter::new_from_tx_meter(
&TxGasMeter::new(u64::MAX),
));
let governance = GovernanceVp::new(Ctx::new(
let ctx = Ctx::new(
&Address::Internal(InternalAddress::Governance),
&shell.state,
&signed_tx.tx,
Expand All @@ -225,18 +230,18 @@ fn governance(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell.vp_wasm_cache.clone(),
));
);

group.bench_function(bench_name, |b| {
b.iter(|| {
assert!(
governance
.validate_tx(
&signed_tx.to_ref(),
governance.ctx.keys_changed,
governance.ctx.verifiers,
)
.is_ok()
GovernanceVp::validate_tx(
&ctx,
&signed_tx.to_ref(),
ctx.keys_changed,
ctx.verifiers,
)
.is_ok()
)
})
});
Expand Down Expand Up @@ -508,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 @@ -518,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 Expand Up @@ -629,7 +634,7 @@ fn masp(c: &mut Criterion) {
let gas_meter = RefCell::new(VpGasMeter::new_from_tx_meter(
&TxGasMeter::new(u64::MAX),
));
let masp = MaspVp::new(Ctx::new(
let ctx = Ctx::new(
&Address::Internal(InternalAddress::Masp),
&shell_read.state,
&signed_tx.tx,
Expand All @@ -639,14 +644,15 @@ fn masp(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell_read.vp_wasm_cache.clone(),
));
);

b.iter(|| {
assert!(
masp.validate_tx(
MaspVp::validate_tx(
&ctx,
&signed_tx.to_ref(),
masp.ctx.keys_changed,
masp.ctx.verifiers,
ctx.keys_changed,
ctx.verifiers,
)
.is_ok()
);
Expand Down Expand Up @@ -1241,7 +1247,7 @@ fn pgf(c: &mut Criterion) {
let gas_meter = RefCell::new(VpGasMeter::new_from_tx_meter(
&TxGasMeter::new(u64::MAX),
));
let pgf = PgfVp::new(Ctx::new(
let ctx = Ctx::new(
&Address::Internal(InternalAddress::Pgf),
&shell.state,
&signed_tx.tx,
Expand All @@ -1251,15 +1257,16 @@ fn pgf(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell.vp_wasm_cache.clone(),
));
);

group.bench_function(bench_name, |b| {
b.iter(|| {
assert!(
pgf.validate_tx(
PgfVp::validate_tx(
&ctx,
&signed_tx.to_ref(),
pgf.ctx.keys_changed,
pgf.ctx.verifiers,
ctx.keys_changed,
ctx.verifiers,
)
.is_ok()
)
Expand Down Expand Up @@ -1316,7 +1323,7 @@ fn eth_bridge_nut(c: &mut Criterion) {
Address::Internal(InternalAddress::Nut(native_erc20_addres));
let gas_meter =
RefCell::new(VpGasMeter::new_from_tx_meter(&TxGasMeter::new(u64::MAX)));
let nut = EthBridgeNutVp::new(Ctx::new(
let ctx = Ctx::new(
&vp_address,
&shell.state,
&signed_tx.tx,
Expand All @@ -1326,15 +1333,16 @@ fn eth_bridge_nut(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell.vp_wasm_cache.clone(),
));
);

c.bench_function("vp_eth_bridge_nut", |b| {
b.iter(|| {
assert!(
nut.validate_tx(
EthBridgeNutVp::validate_tx(
&ctx,
&signed_tx.to_ref(),
nut.ctx.keys_changed,
nut.ctx.verifiers,
ctx.keys_changed,
ctx.verifiers,
)
.is_ok()
)
Expand Down Expand Up @@ -1387,7 +1395,7 @@ fn eth_bridge(c: &mut Criterion) {
let vp_address = Address::Internal(InternalAddress::EthBridge);
let gas_meter =
RefCell::new(VpGasMeter::new_from_tx_meter(&TxGasMeter::new(u64::MAX)));
let eth_bridge = EthBridgeVp::new(Ctx::new(
let ctx = Ctx::new(
&vp_address,
&shell.state,
&signed_tx.tx,
Expand All @@ -1397,18 +1405,18 @@ fn eth_bridge(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell.vp_wasm_cache.clone(),
));
);

c.bench_function("vp_eth_bridge", |b| {
b.iter(|| {
assert!(
eth_bridge
.validate_tx(
&signed_tx.to_ref(),
eth_bridge.ctx.keys_changed,
eth_bridge.ctx.verifiers,
)
.is_ok()
EthBridgeVp::validate_tx(
&ctx,
&signed_tx.to_ref(),
ctx.keys_changed,
ctx.verifiers,
)
.is_ok()
)
})
});
Expand Down Expand Up @@ -1484,7 +1492,7 @@ fn eth_bridge_pool(c: &mut Criterion) {
let vp_address = Address::Internal(InternalAddress::EthBridgePool);
let gas_meter =
RefCell::new(VpGasMeter::new_from_tx_meter(&TxGasMeter::new(u64::MAX)));
let bridge_pool = EthBridgePoolVp::new(Ctx::new(
let ctx = Ctx::new(
&vp_address,
&shell.state,
&signed_tx.tx,
Expand All @@ -1494,18 +1502,18 @@ fn eth_bridge_pool(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell.vp_wasm_cache.clone(),
));
);

c.bench_function("vp_eth_bridge_pool", |b| {
b.iter(|| {
assert!(
bridge_pool
.validate_tx(
&signed_tx.to_ref(),
bridge_pool.ctx.keys_changed,
bridge_pool.ctx.verifiers,
)
.is_ok()
EthBridgePoolVp::validate_tx(
&ctx,
&signed_tx.to_ref(),
ctx.keys_changed,
ctx.verifiers,
)
.is_ok()
)
})
});
Expand Down Expand Up @@ -1557,7 +1565,7 @@ fn parameters(c: &mut Criterion) {
let gas_meter = RefCell::new(VpGasMeter::new_from_tx_meter(
&TxGasMeter::new(u64::MAX),
));
let parameters = ParametersVp::new(Ctx::new(
let ctx = Ctx::new(
&vp_address,
&shell.state,
&signed_tx.tx,
Expand All @@ -1567,18 +1575,18 @@ fn parameters(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell.vp_wasm_cache.clone(),
));
);

group.bench_function(bench_name, |b| {
b.iter(|| {
assert!(
parameters
.validate_tx(
&signed_tx.to_ref(),
parameters.ctx.keys_changed,
parameters.ctx.verifiers,
)
.is_ok()
ParametersVp::validate_tx(
&ctx,
&signed_tx.to_ref(),
ctx.keys_changed,
ctx.verifiers,
)
.is_ok()
)
})
});
Expand Down Expand Up @@ -1633,7 +1641,7 @@ fn pos(c: &mut Criterion) {
let gas_meter = RefCell::new(VpGasMeter::new_from_tx_meter(
&TxGasMeter::new(u64::MAX),
));
let pos = PosVp::new(Ctx::new(
let ctx = Ctx::new(
&vp_address,
&shell.state,
&signed_tx.tx,
Expand All @@ -1643,15 +1651,16 @@ fn pos(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell.vp_wasm_cache.clone(),
));
);

group.bench_function(bench_name, |b| {
b.iter(|| {
assert!(
pos.validate_tx(
PosVp::validate_tx(
&ctx,
&signed_tx.to_ref(),
pos.ctx.keys_changed,
pos.ctx.verifiers,
ctx.keys_changed,
ctx.verifiers,
)
.is_ok()
)
Expand Down
3 changes: 2 additions & 1 deletion crates/ethereum_bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namada_systems = { path = "../systems" }
namada_trans_token = {path = "../trans_token"}
namada_tx = {path = "../tx"}
namada_vote_ext = {path = "../vote_ext"}
namada_vp = {path = "../vp"}
namada_vp_env = {path = "../vp_env"}

borsh.workspace = true
ethers.workspace = true
Expand All @@ -64,6 +64,7 @@ namada_state = { path = "../state", features = ["testing"] }
namada_token = {path = "../token", features = ["testing"]}
namada_tx = {path = "../tx", features = ["testing"]}
namada_vm = {path = "../vm", features = ["testing"]}
namada_vp = {path = "../vp"}

assert_matches.workspace = true
data-encoding.workspace = true
Expand Down
Loading
Loading