Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Feb 20, 2024
1 parent d44bf1e commit 4ec74dd
Show file tree
Hide file tree
Showing 107 changed files with 7,476 additions and 8,054 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

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

97 changes: 41 additions & 56 deletions crates/apps/src/lib/bench_utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Library code for benchmarks provides a wrapper of the ledger's shell
//! `BenchShell` and helper functions to generate transactions.
use std::cell::RefCell;
use std::collections::BTreeSet;
use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
Expand Down Expand Up @@ -78,6 +79,7 @@ use namada::{proof_of_stake, tendermint};
use namada_sdk::masp::{
self, ShieldedContext, ShieldedTransfer, ShieldedUtils,
};
use namada_sdk::storage::StorageWrite;
pub use namada_sdk::tx::{
TX_BECOME_VALIDATOR_WASM, TX_BOND_WASM, TX_BRIDGE_POOL_WASM,
TX_CHANGE_COMMISSION_WASM as TX_CHANGE_VALIDATOR_COMMISSION_WASM,
Expand Down Expand Up @@ -224,7 +226,7 @@ impl Default for BenchShell {
source: Some(defaults::albert_address()),
};
let params =
proof_of_stake::storage::read_pos_params(&bench_shell.wl_storage)
proof_of_stake::storage::read_pos_params(&bench_shell.state)

Check warning on line 229 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L229

Added line #L229 was not covered by tests
.unwrap();
let signed_tx = bench_shell.generate_tx(
TX_BOND_WASM,
Expand All @@ -235,7 +237,7 @@ impl Default for BenchShell {
);

bench_shell.execute_tx(&signed_tx);
bench_shell.wl_storage.commit_tx();
bench_shell.state.commit_tx();

Check warning on line 240 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L240

Added line #L240 was not covered by tests

// Initialize governance proposal
let content_section = Section::ExtraData(Code::new(
Expand All @@ -261,7 +263,7 @@ impl Default for BenchShell {
);

bench_shell.execute_tx(&signed_tx);
bench_shell.wl_storage.commit_tx();
bench_shell.state.commit_tx();

Check warning on line 266 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L266

Added line #L266 was not covered by tests
bench_shell.commit_block();

// Advance epoch for pos benches
Expand All @@ -270,7 +272,7 @@ impl Default for BenchShell {
}
// Must start after current epoch
debug_assert_eq!(
bench_shell.wl_storage.get_block_epoch().unwrap().next(),
bench_shell.state.get_block_epoch().unwrap().next(),

Check warning on line 275 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L275

Added line #L275 was not covered by tests
voting_start_epoch
);

Expand Down Expand Up @@ -386,10 +388,11 @@ impl BenchShell {
}

pub fn execute_tx(&mut self, tx: &Tx) {
let gas_meter =
RefCell::new(TxGasMeter::new_from_sub_limit(u64::MAX.into()));

Check warning on line 392 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L391-L392

Added lines #L391 - L392 were not covered by tests
run::tx(
&self.inner.wl_storage.storage,
&mut self.inner.wl_storage.write_log,
&mut TxGasMeter::new_from_sub_limit(u64::MAX.into()),
&mut self.inner.state,
&gas_meter,

Check warning on line 395 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L394-L395

Added lines #L394 - L395 were not covered by tests
&TxIndex(0),
tx,
&mut self.inner.vp_wasm_cache,
Expand All @@ -400,31 +403,29 @@ impl BenchShell {

pub fn advance_epoch(&mut self) {
let params =
proof_of_stake::storage::read_pos_params(&self.inner.wl_storage)
proof_of_stake::storage::read_pos_params(&self.inner.state)

Check warning on line 406 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L406

Added line #L406 was not covered by tests
.unwrap();

self.wl_storage.storage.block.epoch =
self.wl_storage.storage.block.epoch.next();
let current_epoch = self.wl_storage.storage.block.epoch;
self.state.in_mem_mut().block.epoch =
self.state.in_mem().block.epoch.next();
let current_epoch = self.state.in_mem().block.epoch;

Check warning on line 411 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L409-L411

Added lines #L409 - L411 were not covered by tests

proof_of_stake::validator_set_update::copy_validator_sets_and_positions(
&mut self.wl_storage,
&mut self.state,

Check warning on line 414 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L414

Added line #L414 was not covered by tests
&params,
current_epoch,
current_epoch + params.pipeline_len,
)
.unwrap();

namada::token::conversion::update_allowed_conversions(
&mut self.wl_storage,
)
.unwrap();
namada::token::conversion::update_allowed_conversions(&mut self.state)
.unwrap();

Check warning on line 422 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L420-L422

Added lines #L420 - L422 were not covered by tests
}

pub fn init_ibc_client_state(&mut self, addr_key: Key) -> ClientId {
// Set a dummy header
self.wl_storage
.storage
self.state
.in_mem_mut()

Check warning on line 428 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L427-L428

Added lines #L427 - L428 were not covered by tests
.set_header(get_dummy_header())
.unwrap();
// Set client state
Expand Down Expand Up @@ -453,8 +454,7 @@ impl BenchShell {
.unwrap()
.into();
let bytes = <ClientState as Protobuf<Any>>::encode_vec(client_state);
self.wl_storage
.storage
self.state

Check warning on line 457 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L457

Added line #L457 was not covered by tests
.write(&client_state_key, bytes)
.expect("write failed");

Expand All @@ -480,10 +480,7 @@ impl BenchShell {

let bytes =
<ConsensusState as Protobuf<Any>>::encode_vec(consensus_state);
self.wl_storage
.storage
.write(&consensus_key, bytes)
.unwrap();
self.state.write(&consensus_key, bytes).unwrap();

Check warning on line 483 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L483

Added line #L483 was not covered by tests

client_id
}
Expand All @@ -509,8 +506,7 @@ impl BenchShell {
.unwrap();

let connection_key = connection_key(&NamadaConnectionId::new(1));
self.wl_storage
.storage
self.state

Check warning on line 509 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L509

Added line #L509 was not covered by tests
.write(&connection_key, connection.encode_vec())
.unwrap();

Expand All @@ -519,18 +515,11 @@ impl BenchShell {

let index_key = addr_key
.join(&Key::from("capabilities/index".to_string().to_db_key()));
self.wl_storage
.storage
.write(&index_key, 1u64.to_be_bytes())
.unwrap();
self.wl_storage
.storage
.write(&port_key, 1u64.to_be_bytes())
.unwrap();
self.state.write(&index_key, 1u64.to_be_bytes()).unwrap();
self.state.write(&port_key, 1u64.to_be_bytes()).unwrap();

Check warning on line 519 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L518-L519

Added lines #L518 - L519 were not covered by tests
let cap_key =
addr_key.join(&Key::from("capabilities/1".to_string().to_db_key()));
self.wl_storage
.storage
self.state

Check warning on line 522 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L522

Added line #L522 was not covered by tests
.write(&cap_key, PortId::transfer().as_bytes())
.unwrap();

Expand All @@ -555,22 +544,19 @@ impl BenchShell {
.unwrap();
let channel_key =
channel_key(&NamadaPortId::transfer(), &NamadaChannelId::new(5));
self.wl_storage
.storage
self.state

Check warning on line 547 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L547

Added line #L547 was not covered by tests
.write(&channel_key, channel.encode_vec())
.unwrap();
}

// Update the block height in state to guarantee a valid response to the
// client queries
pub fn commit_block(&mut self) {
let last_height = self.inner.state.in_mem().get_last_block_height();

Check warning on line 555 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L555

Added line #L555 was not covered by tests
self.inner
.wl_storage
.storage
.begin_block(
Hash::default().into(),
self.inner.wl_storage.storage.get_last_block_height() + 1,
)
.state
.in_mem_mut()
.begin_block(Hash::default().into(), last_height + 1)

Check warning on line 559 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L557-L559

Added lines #L557 - L559 were not covered by tests
.unwrap();

self.inner.commit();
Expand All @@ -580,8 +566,8 @@ impl BenchShell {
// client queries
pub fn commit_masp_tx(&mut self, masp_tx: Tx) {
self.last_block_masp_txs
.push((masp_tx, self.wl_storage.write_log.get_keys()));
self.wl_storage.commit_tx();
.push((masp_tx, self.state.write_log().get_keys()));
self.state.commit_tx();

Check warning on line 570 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L569-L570

Added lines #L569 - L570 were not covered by tests
}
}

Expand Down Expand Up @@ -733,7 +719,7 @@ impl Client for BenchShell {
};

let ctx = RequestCtx {
wl_storage: &self.wl_storage,
state: &self.state,

Check warning on line 722 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L722

Added line #L722 was not covered by tests
event_log: self.event_log(),
vp_wasm_cache: self.vp_wasm_cache.read_only(),
tx_wasm_cache: self.tx_wasm_cache.read_only(),
Expand Down Expand Up @@ -774,13 +760,12 @@ impl Client for BenchShell {
// Given the way we setup and run benchmarks, the masp transactions can
// only present in the last block, we can mock the previous
// responses with an empty set of transactions
let last_block_txs = if height
== self.inner.wl_storage.storage.get_last_block_height()
{
self.last_block_masp_txs.clone()
} else {
vec![]
};
let last_block_txs =
if height == self.inner.state.in_mem().get_last_block_height() {
self.last_block_masp_txs.clone()

Check warning on line 765 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L763-L765

Added lines #L763 - L765 were not covered by tests
} else {
vec![]

Check warning on line 767 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L767

Added line #L767 was not covered by tests
};
Ok(tendermint_rpc::endpoint::block::Response {
block_id: tendermint::block::Id {
hash: tendermint::Hash::None,
Expand Down Expand Up @@ -839,7 +824,7 @@ impl Client for BenchShell {
// We can expect all the masp tranfers to have happened only in the last
// block
let end_block_events = if height.value()
== self.inner.wl_storage.storage.get_last_block_height().0
== self.inner.state.in_mem().get_last_block_height().0

Check warning on line 827 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L827

Added line #L827 was not covered by tests
{
Some(
self.last_block_masp_txs
Expand Down Expand Up @@ -991,7 +976,7 @@ impl BenchShieldedCtx {
&[],
))
.unwrap();
let native_token = self.shell.wl_storage.storage.native_token.clone();
let native_token = self.shell.state.in_mem().native_token.clone();

Check warning on line 979 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L979

Added line #L979 was not covered by tests
let namada = NamadaImpl::native_new(
self.shell,
self.wallet,
Expand Down
10 changes: 5 additions & 5 deletions crates/apps/src/lib/node/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use namada::core::storage::Key;
use namada::core::time::DateTimeUtc;
use namada::eth_bridge::ethers::providers::{Http, Provider};
use namada::governance::storage::keys as governance_storage;
use namada_sdk::tendermint::abci::request::CheckTxKind;
use namada::tendermint::abci::request::CheckTxKind;
use namada_sdk::state::StateRead;
use once_cell::unsync::Lazy;
use sysinfo::{RefreshKind, System, SystemExt};
use tokio::sync::mpsc;
Expand Down Expand Up @@ -66,16 +67,15 @@ const ENV_VAR_RAYON_THREADS: &str = "NAMADA_RAYON_THREADS";
impl Shell {
fn load_proposals(&mut self) {
let proposals_key = governance_storage::get_commiting_proposals_prefix(
self.wl_storage.storage.last_epoch.0,
self.state.in_mem().last_epoch.0,

Check warning on line 70 in crates/apps/src/lib/node/ledger/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/node/ledger/mod.rs#L70

Added line #L70 was not covered by tests
);

let (proposal_iter, _) =
self.wl_storage.storage.iter_prefix(&proposals_key);
let (proposal_iter, _) = self.state.db_iter_prefix(&proposals_key);

Check warning on line 73 in crates/apps/src/lib/node/ledger/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/node/ledger/mod.rs#L73

Added line #L73 was not covered by tests
for (key, _, _) in proposal_iter {
let key =
Key::from_str(key.as_str()).expect("Key should be parsable");
if governance_storage::get_commit_proposal_epoch(&key).unwrap()
!= self.wl_storage.storage.last_epoch.0
!= self.state.in_mem().last_epoch.0

Check warning on line 78 in crates/apps/src/lib/node/ledger/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/node/ledger/mod.rs#L78

Added line #L78 was not covered by tests
{
// NOTE: `iter_prefix` iterate over the matching prefix. In this
// case a proposal with grace_epoch 110 will be
Expand Down
6 changes: 3 additions & 3 deletions crates/apps/src/lib/node/ledger/shell/block_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub mod states;
use std::marker::PhantomData;

use namada::proof_of_stake::pos_queries::PosQueries;
use namada::state::{self, WlStorage};
use namada::state::{self, WlState};

#[allow(unused_imports)]
use crate::facade::tendermint_proto::abci::RequestPrepareProposal;
Expand Down Expand Up @@ -141,14 +141,14 @@ pub struct BlockAllocator<State> {
decrypted_txs: TxBin<BlockSpace>,
}

impl<D, H, M> From<&WlStorage<D, H>>
impl<D, H, M> From<&WlState<D, H>>
for BlockAllocator<states::BuildingEncryptedTxBatch<M>>
where
D: 'static + state::DB + for<'iter> state::DBIter<'iter>,
H: 'static + state::StorageHasher,
{
#[inline]
fn from(storage: &WlStorage<D, H>) -> Self {
fn from(storage: &WlState<D, H>) -> Self {
Self::init(
storage.pos_queries().get_max_proposal_bytes().get(),
namada::parameters::get_max_block_gas(storage).unwrap(),
Expand Down
Loading

0 comments on commit 4ec74dd

Please sign in to comment.