Skip to content

Commit 24f9fba

Browse files
authored
Merge pull request #3807 from anoma/tomas/env-agnostic-vps
env agnostic VPs
2 parents c6ec091 + 63d1113 commit 24f9fba

File tree

38 files changed

+1232
-1297
lines changed

38 files changed

+1232
-1297
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Refactored most native VPs to be agnostic to VP environment (WASM or native).
2+
([\#3807](https://github.com/anoma/namada/pull/3807))

Cargo.lock

+6-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/benches/native_vps.rs

+75-66
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@ use namada_node::bench_utils::{
6262
TX_BRIDGE_POOL_WASM, TX_IBC_WASM, TX_INIT_PROPOSAL_WASM, TX_RESIGN_STEWARD,
6363
TX_TRANSFER_WASM, TX_UPDATE_STEWARD_COMMISSION, TX_VOTE_PROPOSAL_WASM,
6464
};
65-
use namada_vp::native_vp::{Ctx, NativeVp};
65+
use namada_vm::wasm::run::VpEvalWasm;
66+
use namada_vm::wasm::VpCache;
67+
use namada_vp::native_vp::{self, NativeVp};
6668
use rand_core::OsRng;
6769

70+
type Ctx<'ctx, S, D, H, CA> =
71+
native_vp::Ctx<'ctx, S, VpCache<CA>, VpEvalWasm<D, H, CA>>;
72+
6873
fn governance(c: &mut Criterion) {
6974
let mut group = c.benchmark_group("vp_governance");
7075

@@ -215,7 +220,7 @@ fn governance(c: &mut Criterion) {
215220
let gas_meter = RefCell::new(VpGasMeter::new_from_tx_meter(
216221
&TxGasMeter::new(u64::MAX),
217222
));
218-
let governance = GovernanceVp::new(Ctx::new(
223+
let ctx = Ctx::new(
219224
&Address::Internal(InternalAddress::Governance),
220225
&shell.state,
221226
&signed_tx.tx,
@@ -225,18 +230,18 @@ fn governance(c: &mut Criterion) {
225230
&keys_changed,
226231
&verifiers,
227232
shell.vp_wasm_cache.clone(),
228-
));
233+
);
229234

230235
group.bench_function(bench_name, |b| {
231236
b.iter(|| {
232237
assert!(
233-
governance
234-
.validate_tx(
235-
&signed_tx.to_ref(),
236-
governance.ctx.keys_changed,
237-
governance.ctx.verifiers,
238-
)
239-
.is_ok()
238+
GovernanceVp::validate_tx(
239+
&ctx,
240+
&signed_tx.to_ref(),
241+
ctx.keys_changed,
242+
ctx.verifiers,
243+
)
244+
.is_ok()
240245
)
241246
})
242247
});
@@ -508,7 +513,7 @@ fn vp_multitoken(c: &mut Criterion) {
508513
let gas_meter = RefCell::new(VpGasMeter::new_from_tx_meter(
509514
&TxGasMeter::new(u64::MAX),
510515
));
511-
let multitoken = MultitokenVp::new(Ctx::new(
516+
let ctx = Ctx::new(
512517
&Address::Internal(InternalAddress::Multitoken),
513518
&shell.state,
514519
&signed_tx.tx,
@@ -518,18 +523,18 @@ fn vp_multitoken(c: &mut Criterion) {
518523
&keys_changed,
519524
&verifiers,
520525
shell.vp_wasm_cache.clone(),
521-
));
526+
);
522527

523528
group.bench_function(bench_name, |b| {
524529
b.iter(|| {
525530
assert!(
526-
multitoken
527-
.validate_tx(
528-
&signed_tx.to_ref(),
529-
multitoken.ctx.keys_changed,
530-
multitoken.ctx.verifiers,
531-
)
532-
.is_ok()
531+
MultitokenVp::validate_tx(
532+
&ctx,
533+
&signed_tx.to_ref(),
534+
ctx.keys_changed,
535+
ctx.verifiers,
536+
)
537+
.is_ok()
533538
)
534539
})
535540
});
@@ -629,7 +634,7 @@ fn masp(c: &mut Criterion) {
629634
let gas_meter = RefCell::new(VpGasMeter::new_from_tx_meter(
630635
&TxGasMeter::new(u64::MAX),
631636
));
632-
let masp = MaspVp::new(Ctx::new(
637+
let ctx = Ctx::new(
633638
&Address::Internal(InternalAddress::Masp),
634639
&shell_read.state,
635640
&signed_tx.tx,
@@ -639,14 +644,15 @@ fn masp(c: &mut Criterion) {
639644
&keys_changed,
640645
&verifiers,
641646
shell_read.vp_wasm_cache.clone(),
642-
));
647+
);
643648

644649
b.iter(|| {
645650
assert!(
646-
masp.validate_tx(
651+
MaspVp::validate_tx(
652+
&ctx,
647653
&signed_tx.to_ref(),
648-
masp.ctx.keys_changed,
649-
masp.ctx.verifiers,
654+
ctx.keys_changed,
655+
ctx.verifiers,
650656
)
651657
.is_ok()
652658
);
@@ -1241,7 +1247,7 @@ fn pgf(c: &mut Criterion) {
12411247
let gas_meter = RefCell::new(VpGasMeter::new_from_tx_meter(
12421248
&TxGasMeter::new(u64::MAX),
12431249
));
1244-
let pgf = PgfVp::new(Ctx::new(
1250+
let ctx = Ctx::new(
12451251
&Address::Internal(InternalAddress::Pgf),
12461252
&shell.state,
12471253
&signed_tx.tx,
@@ -1251,15 +1257,16 @@ fn pgf(c: &mut Criterion) {
12511257
&keys_changed,
12521258
&verifiers,
12531259
shell.vp_wasm_cache.clone(),
1254-
));
1260+
);
12551261

12561262
group.bench_function(bench_name, |b| {
12571263
b.iter(|| {
12581264
assert!(
1259-
pgf.validate_tx(
1265+
PgfVp::validate_tx(
1266+
&ctx,
12601267
&signed_tx.to_ref(),
1261-
pgf.ctx.keys_changed,
1262-
pgf.ctx.verifiers,
1268+
ctx.keys_changed,
1269+
ctx.verifiers,
12631270
)
12641271
.is_ok()
12651272
)
@@ -1316,7 +1323,7 @@ fn eth_bridge_nut(c: &mut Criterion) {
13161323
Address::Internal(InternalAddress::Nut(native_erc20_addres));
13171324
let gas_meter =
13181325
RefCell::new(VpGasMeter::new_from_tx_meter(&TxGasMeter::new(u64::MAX)));
1319-
let nut = EthBridgeNutVp::new(Ctx::new(
1326+
let ctx = Ctx::new(
13201327
&vp_address,
13211328
&shell.state,
13221329
&signed_tx.tx,
@@ -1326,15 +1333,16 @@ fn eth_bridge_nut(c: &mut Criterion) {
13261333
&keys_changed,
13271334
&verifiers,
13281335
shell.vp_wasm_cache.clone(),
1329-
));
1336+
);
13301337

13311338
c.bench_function("vp_eth_bridge_nut", |b| {
13321339
b.iter(|| {
13331340
assert!(
1334-
nut.validate_tx(
1341+
EthBridgeNutVp::validate_tx(
1342+
&ctx,
13351343
&signed_tx.to_ref(),
1336-
nut.ctx.keys_changed,
1337-
nut.ctx.verifiers,
1344+
ctx.keys_changed,
1345+
ctx.verifiers,
13381346
)
13391347
.is_ok()
13401348
)
@@ -1387,7 +1395,7 @@ fn eth_bridge(c: &mut Criterion) {
13871395
let vp_address = Address::Internal(InternalAddress::EthBridge);
13881396
let gas_meter =
13891397
RefCell::new(VpGasMeter::new_from_tx_meter(&TxGasMeter::new(u64::MAX)));
1390-
let eth_bridge = EthBridgeVp::new(Ctx::new(
1398+
let ctx = Ctx::new(
13911399
&vp_address,
13921400
&shell.state,
13931401
&signed_tx.tx,
@@ -1397,18 +1405,18 @@ fn eth_bridge(c: &mut Criterion) {
13971405
&keys_changed,
13981406
&verifiers,
13991407
shell.vp_wasm_cache.clone(),
1400-
));
1408+
);
14011409

14021410
c.bench_function("vp_eth_bridge", |b| {
14031411
b.iter(|| {
14041412
assert!(
1405-
eth_bridge
1406-
.validate_tx(
1407-
&signed_tx.to_ref(),
1408-
eth_bridge.ctx.keys_changed,
1409-
eth_bridge.ctx.verifiers,
1410-
)
1411-
.is_ok()
1413+
EthBridgeVp::validate_tx(
1414+
&ctx,
1415+
&signed_tx.to_ref(),
1416+
ctx.keys_changed,
1417+
ctx.verifiers,
1418+
)
1419+
.is_ok()
14121420
)
14131421
})
14141422
});
@@ -1484,7 +1492,7 @@ fn eth_bridge_pool(c: &mut Criterion) {
14841492
let vp_address = Address::Internal(InternalAddress::EthBridgePool);
14851493
let gas_meter =
14861494
RefCell::new(VpGasMeter::new_from_tx_meter(&TxGasMeter::new(u64::MAX)));
1487-
let bridge_pool = EthBridgePoolVp::new(Ctx::new(
1495+
let ctx = Ctx::new(
14881496
&vp_address,
14891497
&shell.state,
14901498
&signed_tx.tx,
@@ -1494,18 +1502,18 @@ fn eth_bridge_pool(c: &mut Criterion) {
14941502
&keys_changed,
14951503
&verifiers,
14961504
shell.vp_wasm_cache.clone(),
1497-
));
1505+
);
14981506

14991507
c.bench_function("vp_eth_bridge_pool", |b| {
15001508
b.iter(|| {
15011509
assert!(
1502-
bridge_pool
1503-
.validate_tx(
1504-
&signed_tx.to_ref(),
1505-
bridge_pool.ctx.keys_changed,
1506-
bridge_pool.ctx.verifiers,
1507-
)
1508-
.is_ok()
1510+
EthBridgePoolVp::validate_tx(
1511+
&ctx,
1512+
&signed_tx.to_ref(),
1513+
ctx.keys_changed,
1514+
ctx.verifiers,
1515+
)
1516+
.is_ok()
15091517
)
15101518
})
15111519
});
@@ -1557,7 +1565,7 @@ fn parameters(c: &mut Criterion) {
15571565
let gas_meter = RefCell::new(VpGasMeter::new_from_tx_meter(
15581566
&TxGasMeter::new(u64::MAX),
15591567
));
1560-
let parameters = ParametersVp::new(Ctx::new(
1568+
let ctx = Ctx::new(
15611569
&vp_address,
15621570
&shell.state,
15631571
&signed_tx.tx,
@@ -1567,18 +1575,18 @@ fn parameters(c: &mut Criterion) {
15671575
&keys_changed,
15681576
&verifiers,
15691577
shell.vp_wasm_cache.clone(),
1570-
));
1578+
);
15711579

15721580
group.bench_function(bench_name, |b| {
15731581
b.iter(|| {
15741582
assert!(
1575-
parameters
1576-
.validate_tx(
1577-
&signed_tx.to_ref(),
1578-
parameters.ctx.keys_changed,
1579-
parameters.ctx.verifiers,
1580-
)
1581-
.is_ok()
1583+
ParametersVp::validate_tx(
1584+
&ctx,
1585+
&signed_tx.to_ref(),
1586+
ctx.keys_changed,
1587+
ctx.verifiers,
1588+
)
1589+
.is_ok()
15821590
)
15831591
})
15841592
});
@@ -1633,7 +1641,7 @@ fn pos(c: &mut Criterion) {
16331641
let gas_meter = RefCell::new(VpGasMeter::new_from_tx_meter(
16341642
&TxGasMeter::new(u64::MAX),
16351643
));
1636-
let pos = PosVp::new(Ctx::new(
1644+
let ctx = Ctx::new(
16371645
&vp_address,
16381646
&shell.state,
16391647
&signed_tx.tx,
@@ -1643,15 +1651,16 @@ fn pos(c: &mut Criterion) {
16431651
&keys_changed,
16441652
&verifiers,
16451653
shell.vp_wasm_cache.clone(),
1646-
));
1654+
);
16471655

16481656
group.bench_function(bench_name, |b| {
16491657
b.iter(|| {
16501658
assert!(
1651-
pos.validate_tx(
1659+
PosVp::validate_tx(
1660+
&ctx,
16521661
&signed_tx.to_ref(),
1653-
pos.ctx.keys_changed,
1654-
pos.ctx.verifiers,
1662+
ctx.keys_changed,
1663+
ctx.verifiers,
16551664
)
16561665
.is_ok()
16571666
)

crates/ethereum_bridge/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namada_systems = { path = "../systems" }
4141
namada_trans_token = {path = "../trans_token"}
4242
namada_tx = {path = "../tx"}
4343
namada_vote_ext = {path = "../vote_ext"}
44-
namada_vp = {path = "../vp"}
44+
namada_vp_env = {path = "../vp_env"}
4545

4646
borsh.workspace = true
4747
ethers.workspace = true
@@ -64,6 +64,7 @@ namada_state = { path = "../state", features = ["testing"] }
6464
namada_token = {path = "../token", features = ["testing"]}
6565
namada_tx = {path = "../tx", features = ["testing"]}
6666
namada_vm = {path = "../vm", features = ["testing"]}
67+
namada_vp = {path = "../vp"}
6768

6869
assert_matches.workspace = true
6970
data-encoding.workspace = true

0 commit comments

Comments
 (0)