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

common read storage trait #324

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1a57908
ledger: add tx and VP traits with host env functions
tzemanovic Jul 20, 2022
5d8c61a
shared/vm: rename host_env TxEnv/VpEnv to TxVmEnv/VpVmEnv
tzemanovic Jul 20, 2022
fe365d9
shared/ledger/native_vp: implement VpEnv
tzemanovic Jul 20, 2022
4e46aca
shared: update native_vp implementations for VpEnv methods
tzemanovic Jul 20, 2022
e4b84a0
VM: move vm_env sub-mod into tx/vp_prelude and add Tx/VpEnv and Ctx
tzemanovic Jul 20, 2022
71820f6
tests: update for VM API changes
tzemanovic Jul 20, 2022
d7d0ef1
wasm: update for VM API changes
tzemanovic Jul 20, 2022
bf604a4
macros: add error handling to transaction and validity_predicate macros
tzemanovic Jul 20, 2022
d868424
wasm: improve error handling
tzemanovic Jul 21, 2022
221e9f2
changelog: add #1093
tzemanovic Jul 21, 2022
8bce915
Update shared/src/ledger/vp_env.rs
tzemanovic Jul 25, 2022
affa0b5
wasm_for_tests: make
tzemanovic Aug 11, 2022
14f638a
update wasm checksums
tzemanovic Aug 11, 2022
18526da
[ci skip] wasm checksums update
github-actions[bot] Aug 17, 2022
9a135eb
ledger: add StorageRead trait with extensible error type
tzemanovic Aug 12, 2022
97c6947
ledger/native_vp: implement StorageRead for pre and post state
tzemanovic Aug 12, 2022
7552c1e
ledger/vp: impl StorageRead for WASM VPs pre and post state
tzemanovic Aug 12, 2022
45f3f94
ledger/storage: impl StorageRead for Storage
tzemanovic Aug 12, 2022
5989412
ledger/tx: inherit StorageRead in TxEnv
tzemanovic Aug 12, 2022
10f94c2
ledger/pos: implement PosReadOnly using StorageRead trait
tzemanovic Aug 12, 2022
eeb1e8c
update wasm checksums
tzemanovic Aug 12, 2022
ff268e1
changelog: add #324
tzemanovic Aug 21, 2022
0b1d96f
rustdoc: resolve ambiguous link
tzemanovic Aug 30, 2022
e5e0486
rustdoc: fix more broken links
tzemanovic Sep 21, 2022
3a7d8c4
fixup! rustdoc: fix more broken links
tzemanovic Sep 21, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Added WASM transaction and validity predicate `Ctx` with methods for host
environment functions to unify the interface of native VPs and WASM VPs under
`trait VpEnv` ([#1093](https://github.com/anoma/anoma/pull/1093))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Added a StorageRead trait for a common interface for VPs prior and posterior
state, transactions and direct storage access for protocol and RPC handlers
([#324](https://github.com/anoma/namada/pull/324))
13 changes: 10 additions & 3 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions apps/src/lib/node/ledger/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,13 @@ where
}
Address::Internal(internal_addr) => {
let ctx = native_vp::Ctx::new(
addr,
storage,
write_log,
tx,
gas_meter,
&keys_changed,
&verifiers,
vp_wasm_cache.clone(),
);
let tx_data = match tx.data.as_ref() {
Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Any changes applied before [`Shell::finalize_block`] might have to be
//! reverted, so any changes applied in the methods `Shell::prepare_proposal`
//! (ABCI++), [`Shell::process_and_decode_proposal`] must be also reverted
//! (ABCI++), [`Shell::process_proposal`] must be also reverted
//! (unless we can simply overwrite them in the next block).
//! More info in <https://github.com/anoma/anoma/issues/362>.
mod finalize_block;
Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/node/ledger/shell/prepare_proposal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Implementation of the [`PrepareProposal`] ABCI++ method for the Shell
//! Implementation of the [`RequestPrepareProposal`] ABCI++ method for the Shell

use tendermint_proto::abci::TxRecord;

Expand Down
42 changes: 34 additions & 8 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use syn::{parse_macro_input, DeriveInput, ItemFn};
/// This macro expects a function with signature:
///
/// ```compiler_fail
/// fn apply_tx(tx_data: Vec<u8>)
/// fn apply_tx(
/// ctx: &mut Ctx,
/// tx_data: Vec<u8>
/// ) -> TxResult
/// ```
#[proc_macro_attribute]
pub fn transaction(_attr: TokenStream, input: TokenStream) -> TokenStream {
Expand All @@ -38,7 +41,19 @@ pub fn transaction(_attr: TokenStream, input: TokenStream) -> TokenStream {
)
};
let tx_data = slice.to_vec();
#ident(tx_data);

// The context on WASM side is only provided by the VM once its
// being executed (in here it's implicit). But because we want to
// have interface consistent with the VP interface, in which the
// context is explicit, in here we're just using an empty `Ctx`
// to "fake" it.
let mut ctx = unsafe { namada_tx_prelude::Ctx::new() };

if let Err(err) = #ident(&mut ctx, tx_data) {
namada_tx_prelude::debug_log!("Transaction error: {}", err);
// crash the transaction to abort
panic!();
}
}
};
TokenStream::from(gen)
Expand All @@ -50,11 +65,12 @@ pub fn transaction(_attr: TokenStream, input: TokenStream) -> TokenStream {
///
/// ```compiler_fail
/// fn validate_tx(
/// ctx: &Ctx,
/// tx_data: Vec<u8>,
/// addr: Address,
/// keys_changed: BTreeSet<storage::Key>,
/// verifiers: BTreeSet<Address>
/// ) -> bool
/// ) -> VpResult
/// ```
#[proc_macro_attribute]
pub fn validity_predicate(
Expand All @@ -74,7 +90,6 @@ pub fn validity_predicate(
#[no_mangle]
extern "C" fn _validate_tx(
// VP's account's address
// TODO Should the address be on demand (a call to host function?)
addr_ptr: u64,
addr_len: u64,
tx_data_ptr: u64,
Expand Down Expand Up @@ -113,11 +128,22 @@ pub fn validity_predicate(
};
let verifiers: BTreeSet<Address> = BTreeSet::try_from_slice(slice).unwrap();

// The context on WASM side is only provided by the VM once its
// being executed (in here it's implicit). But because we want to
// have interface identical with the native VPs, in which the
// context is explicit, in here we're just using an empty `Ctx`
// to "fake" it.
let ctx = unsafe { namada_vp_prelude::Ctx::new() };

// run validation with the concrete type(s)
if #ident(tx_data, addr, keys_changed, verifiers) {
1
} else {
0
match #ident(&ctx, tx_data, addr, keys_changed, verifiers)
{
Ok(true) => 1,
Ok(false) => 0,
Err(err) => {
namada_vp_prelude::debug_log!("Validity predicate error: {}", err);
0
},
}
}
};
Expand Down
Loading