Skip to content

Commit

Permalink
fixup! fix everything that was depending on rm'd namada crate
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Jul 1, 2024
1 parent 9695d7b commit a04ad35
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions crates/node/src/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,9 @@ impl Client for BenchShell {

if request.path == RPC.shell().dry_run_tx_path() {
dry_run_tx(
// This is safe because nothing else is using `self.state`
// concurrently and the `TempWlState` will be dropped right
// after dry-run.
unsafe { self.state.read_only().with_static_temp_write_log() },
self.vp_wasm_cache.read_only(),
self.tx_wasm_cache.read_only(),
Expand Down
3 changes: 3 additions & 0 deletions crates/node/src/dry_run_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ mod test {
// than [`std::io::Error`]
if request.path == RPC.shell().dry_run_tx_path() {
dry_run_tx(
// This is safe because nothing else is using `self.state`
// concurrently and the `TempWlState` will be dropped right
// after dry-run.
unsafe {
self.state.read_only().with_static_temp_write_log()
},
Expand Down
5 changes: 5 additions & 0 deletions crates/node/src/shell/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ where
// Invoke the root RPC handler - returns borsh-encoded data on success
let result = if query.path == RPC.shell().dry_run_tx_path() {
dry_run_tx(
// This is safe as neither the inner `db` nor `in_mem` are
// actually mutable, only the `write_log` which is owned by
// the `TempWlState` struct. The `TempWlState` will be dropped
// right after dry-run and before any other ABCI request is
// processed.
unsafe { self.state.read_only().with_static_temp_write_log() },
self.vp_wasm_cache.read_only(),
self.tx_wasm_cache.read_only(),
Expand Down
3 changes: 3 additions & 0 deletions crates/node/src/shell/testing/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,9 @@ impl<'a> Client for &'a MockNode {
let borrowed = self.shell.lock().unwrap();
if request.path == RPC.shell().dry_run_tx_path() {
dry_run_tx(
// This is safe because nothing else is using `self.state`
// concurrently and the `TempWlState` will be dropped right
// after dry-run.
unsafe {
borrowed.state.read_only().with_static_temp_write_log()
},
Expand Down
11 changes: 6 additions & 5 deletions crates/state/src/wl_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,17 +653,18 @@ where

/// Borrow in-memory state and DB handle with a mutable temporary write-log.
///
/// # Safety
///
/// The lifetime of borrows is unsafely extended to `'static` to allow usage
/// in node's `dry_run_tx`, which needs a static lifetime to be able to call
/// protocol's API that is generic over the state with a bound `S: 'static +
/// State` with a mutable reference to this struct.
/// Because the lifetime of `S` is invariant w.r.t. `&mut S`
/// (<https://doc.rust-lang.org/nomicon/subtyping.html>) we are faking a
/// static lifetime of `S` for `TempWlState`. This should be safe as neither
/// `db` nor `in_mem` are actually mutable, only the `write_log` which is
/// owned by this struct.
/// static lifetime of `S` for `TempWlState`.
///
/// # Safety
///
/// The caller must guarantee that the source `WlState` is not being
/// accessed mutably before `TempWlState` gets dropped.
pub unsafe fn with_static_temp_write_log(
&self,
) -> TempWlState<'static, D, H> {
Expand Down

0 comments on commit a04ad35

Please sign in to comment.