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

refactor storage prefix iter #335

Merged
merged 33 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 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
abd10c1
ledger: factor out TxEnv write methods into a new StorageWrite trait
tzemanovic Aug 12, 2022
08b0a8f
ledger: impl StorageWrite for Storage
tzemanovic Aug 12, 2022
773033d
add <'iter> lifetime to StorageRead trait to get around lack of GATs
tzemanovic Aug 16, 2022
28b4307
add more comments for StorageRead lifetime with an example usage
tzemanovic Aug 16, 2022
8bc5816
storage: remove unnecessary clone
tzemanovic Aug 16, 2022
7decfab
fix missing StorageWrite for Storage merkle tree update
tzemanovic Aug 16, 2022
b92edd4
update wasm checksums
tzemanovic Aug 20, 2022
ace6716
changelog: add #331
tzemanovic Aug 21, 2022
d737acd
storage_api: build a nicer `iter_prefix` function on top of StorageRead
tzemanovic Aug 15, 2022
4558dfa
test/vm_host_env: refactor prefix iter tests with new `iter_prefix` fn
tzemanovic Aug 15, 2022
d32d7af
wasm checksums update
github-actions[bot] Aug 15, 2022
fec7220
changelog: add #335
tzemanovic Aug 22, 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,2 @@
- Added a StorageWrite trait for a common interface for transactions and direct
storage access for protocol ([#331](https://github.com/anoma/namada/pull/331))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Added a simpler prefix iterator API that returns `std::iter::Iterator` with
the storage keys parsed and a variant that also decodes stored values with
Borsh ([#335](https://github.com/anoma/namada/pull/335))
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
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