Skip to content

Commit

Permalink
fixup! converted more annoying was the schema changes
Browse files Browse the repository at this point in the history
they removed getting the btree... I added it back
  • Loading branch information
mariari committed Sep 21, 2023
1 parent 3de3342 commit c176701
Show file tree
Hide file tree
Showing 20 changed files with 125 additions and 109 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions apps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ bech32.workspace = true
bimap.workspace = true
blake2b-rs.workspace = true
borsh.workspace = true
borsh-ext.workspace = true
byte-unit.workspace = true
byteorder.workspace = true
clap.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ const TMP_FILE_NAME: &str = "shielded.tmp";

#[derive(Debug, BorshSerialize, BorshDeserialize, Clone)]
pub struct CLIShieldedUtils {
#[borsh_skip]
#[borsh(skip)]
context_dir: PathBuf,
}

Expand Down
157 changes: 86 additions & 71 deletions encoding_spec/src/main.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ethereum_bridge/src/vp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use borsh::BorshSerialize;

use borsh_ext::BorshSerializeExt;
use namada_core::ledger::storage::{self as ledger_storage, StorageHasher};
use namada_core::ledger::storage_api::StorageWrite;
Expand Down
2 changes: 1 addition & 1 deletion shared/src/ledger/native_vp/ethereum_bridge/nut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ mod test_nuts {
use std::env::temp_dir;

use assert_matches::assert_matches;
use borsh::BorshSerialize;
use namada_core::ledger::storage::testing::TestWlStorage;
use namada_core::ledger::storage_api::StorageWrite;
use namada_core::types::address::testing::arb_non_internal_address;
Expand All @@ -136,6 +135,7 @@ mod test_nuts {
use crate::ledger::gas::{TxGasMeter, VpGasMeter};
use crate::vm::wasm::VpCache;
use crate::vm::WasmCacheRwAccess;
use borsh_ext::BorshSerializeExt;

/// Run a VP check on a NUT transfer between the two provided addresses.
fn check_nut_transfer(src: Address, dst: Address) -> Option<bool> {
Expand Down
2 changes: 1 addition & 1 deletion shared/src/ledger/native_vp/ethereum_bridge/vp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ mod tests {
use std::default::Default;
use std::env::temp_dir;

use borsh::BorshSerialize;
use namada_core::ledger::eth_bridge;
use namada_core::ledger::eth_bridge::storage::bridge_pool::BRIDGE_POOL_ADDRESS;
use namada_core::ledger::eth_bridge::storage::wrapped_erc20s;
Expand All @@ -191,6 +190,7 @@ mod tests {
use crate::types::transaction::TxType;
use crate::vm::wasm::VpCache;
use crate::vm::WasmCacheRwAccess;
use borsh_ext::BorshSerializeExt;

const ARBITRARY_OWNER_A_ADDRESS: &str =
"atest1d9khqw36x9zyxwfhgfpygv2pgc65gse4gy6rjs34gfzr2v69gy6y23zpggurjv2yx5m52sesu6r4y4";
Expand Down
2 changes: 1 addition & 1 deletion shared/src/ledger/native_vp/multitoken.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ where
mod tests {
use std::collections::BTreeSet;

use borsh::BorshSerialize;
use namada_core::ledger::gas::TxGasMeter;

use super::*;
Expand All @@ -159,6 +158,7 @@ mod tests {
};
use crate::types::transaction::TxType;
use crate::vm::wasm::compilation_cache::common::testing::cache as wasm_cache;
use borsh_ext::BorshSerializeExt;

const ADDRESS: Address = Address::Internal(InternalAddress::Multitoken);

Expand Down
5 changes: 3 additions & 2 deletions shared/src/ledger/queries/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//! all the `println!`s in this module.
use thiserror::Error;
use borsh_ext::BorshSerializeExt;

/// Router error.
#[allow(missing_docs)]
Expand Down Expand Up @@ -834,7 +835,6 @@ macro_rules! router {
/// ```
#[cfg(test)]
mod test_rpc_handlers {
use borsh::BorshSerialize;

use crate::ledger::queries::{
EncodedResponseQuery, RequestCtx, RequestQuery, ResponseQuery,
Expand All @@ -843,6 +843,7 @@ mod test_rpc_handlers {
use crate::ledger::storage_api::{self, ResultExt};
use crate::types::storage::Epoch;
use crate::types::token;
use borsh_ext::BorshSerializeExt;

/// A little macro to generate boilerplate for RPC handler functions.
/// These are implemented to return their name as a String, joined by
Expand Down Expand Up @@ -949,7 +950,7 @@ mod test_rpc_handlers {
D: 'static + DB + for<'iter> DBIter<'iter> + Sync,
H: 'static + StorageHasher + Sync,
{
let data = "c".to_owned().serialize_to_vec().into_storage_result()?;
let data = "c".to_owned().serialize_to_vec();
Ok(ResponseQuery {
data,
..ResponseQuery::default()
Expand Down
5 changes: 3 additions & 2 deletions shared/src/ledger/queries/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ where
data.gas_used = cumulated_gas;
// NOTE: the keys changed by the wrapper transaction (if any) are not
// returned from this function
let data = data.serialize_to_vec().into_storage_result()?;
let data = data.serialize_to_vec();
Ok(EncodedResponseQuery {
data,
proof: None,
Expand Down Expand Up @@ -428,7 +428,7 @@ where
} else {
None
};
let data = data.serialize_to_vec().into_storage_result()?;
let data = data.serialize_to_vec();
Ok(EncodedResponseQuery {
data,
proof,
Expand Down Expand Up @@ -586,6 +586,7 @@ mod test {
use crate::types::transaction::decrypted::DecryptedTx;
use crate::types::transaction::TxType;
use crate::types::{address, token};
use borsh_ext::BorshSerializeExt;

#[test]
fn test_shell_queries_router_paths() {
Expand Down
2 changes: 1 addition & 1 deletion shared/src/ledger/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::collections::{BTreeMap, HashMap};
use std::path::PathBuf;

use borsh::{BorshDeserialize, BorshSerialize};
use borsh::BorshDeserialize;
use borsh_ext::BorshSerializeExt;
use data_encoding::HEXLOWER;
use itertools::Itertools;
Expand Down
4 changes: 1 addition & 3 deletions shared/src/ledger/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2110,8 +2110,6 @@ where
}

fn proposal_to_vec(proposal: OnChainProposal) -> Result<Vec<u8>> {
proposal
.content
.serialize_to_vec()
borsh::to_vec(&proposal.content)
.map_err(|e| Error::from(EncodingError::Conversion(e.to_string())))
}
1 change: 1 addition & 0 deletions shared/src/ledger/wallet/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use thiserror::Error;
use zeroize::Zeroizing;

use crate::ledger::wallet::WalletUtils;
use borsh_ext::BorshSerializeExt;

const ENCRYPTED_KEY_PREFIX: &str = "encrypted:";
const UNENCRYPTED_KEY_PREFIX: &str = "unencrypted:";
Expand Down
29 changes: 11 additions & 18 deletions shared/src/vm/host_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::types::token::{
use crate::vm::memory::VmMemory;
use crate::vm::prefix_iter::{PrefixIteratorId, PrefixIterators};
use crate::vm::{HostRef, MutHostRef};
use borsh_ext::BorshSerializeExt;

/// These runtime errors will abort tx WASM execution immediately
#[allow(missing_docs)]
Expand Down Expand Up @@ -734,11 +735,10 @@ where
tx_charge_gas(env, iter_gas + log_gas)?;
match log_val {
Some(write_log::StorageModification::Write { ref value }) => {
let key_val = KeyVal {
let key_val = borsh::to_vec(&KeyVal {
key,
val: value.clone(),
}
.serialize_to_vec()
})
.map_err(TxRuntimeError::EncodingError)?;
let len: i64 = key_val
.len()
Expand All @@ -757,11 +757,10 @@ where
continue;
}
Some(write_log::StorageModification::Temp { ref value }) => {
let key_val = KeyVal {
let key_val = borsh::to_vec(&KeyVal {
key,
val: value.clone(),
}
.serialize_to_vec()
})
.map_err(TxRuntimeError::EncodingError)?;
let len: i64 = key_val
.len()
Expand All @@ -772,8 +771,7 @@ where
return Ok(len);
}
None => {
let key_val = KeyVal { key, val }
.serialize_to_vec()
let key_val = borsh::to_vec(&KeyVal { key, val })
.map_err(TxRuntimeError::EncodingError)?;
let len: i64 = key_val
.len()
Expand Down Expand Up @@ -1001,8 +999,7 @@ where
let write_log = unsafe { env.ctx.write_log.get() };
for event in write_log.get_ibc_events() {
if event.event_type == event_type {
let value = event
.serialize_to_vec()
let value = borsh::to_vec(event)
.map_err(TxRuntimeError::EncodingError)?;
let len: i64 = value
.len()
Expand Down Expand Up @@ -1349,8 +1346,7 @@ where
if let Some(iter) = iterators.get_mut(iter_id) {
let gas_meter = unsafe { env.ctx.gas_meter.get() };
if let Some((key, val)) = vp_host_fns::iter_next(gas_meter, iter)? {
let key_val = KeyVal { key, val }
.serialize_to_vec()
let key_val = borsh::to_vec(&KeyVal { key, val })
.map_err(vp_host_fns::RuntimeError::EncodingError)?;
let len: i64 = key_val
.len()
Expand Down Expand Up @@ -1461,8 +1457,7 @@ where
.map_err(|e| TxRuntimeError::InvalidVpCodeHash(e.to_string()))?;
let (addr, gas) = write_log.init_account(&storage.address_gen, code_hash);
let addr_bytes = addr
.serialize_to_vec()
.map_err(TxRuntimeError::EncodingError)?;
.serialize_to_vec();
tx_charge_gas(env, gas)?;
let gas = env
.memory
Expand Down Expand Up @@ -1626,8 +1621,7 @@ where
Ok(match header {
Some(h) => {
let value = h
.serialize_to_vec()
.map_err(TxRuntimeError::EncodingError)?;
.serialize_to_vec();
let len: i64 = value
.len()
.try_into()
Expand Down Expand Up @@ -1703,8 +1697,7 @@ where
Ok(match header {
Some(h) => {
let value = h
.serialize_to_vec()
.map_err(vp_host_fns::RuntimeError::EncodingError)?;
.serialize_to_vec();
let len: i64 = value
.len()
.try_into()
Expand Down
13 changes: 6 additions & 7 deletions shared/src/vm/wasm/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::ptr::NonNull;
use std::str::Utf8Error;
use std::sync::Arc;

use borsh::BorshSerialize;
use namada_core::ledger::gas::VM_MEMORY_ACCESS_GAS_PER_BYTE;
use thiserror::Error;
use wasmer::{
Expand All @@ -19,6 +18,7 @@ use wasmer_vm::{
use crate::proto::Tx;
use crate::vm::memory::VmMemory;
use crate::vm::types::VpInput;
use borsh_ext::BorshSerializeExt;

#[allow(missing_docs)]
#[derive(Error, Debug)]
Expand Down Expand Up @@ -87,7 +87,7 @@ pub fn write_tx_inputs(
) -> Result<TxCallInput> {
let tx_data_ptr = 0;
let tx_data_bytes =
tx_data.serialize_to_vec().map_err(Error::EncodingError)?;
tx_data.serialize_to_vec();
let tx_data_len = tx_data_bytes.len() as _;

write_memory_bytes(memory, tx_data_ptr, tx_data_bytes)?;
Expand Down Expand Up @@ -130,21 +130,20 @@ pub fn write_vp_inputs(
}: VpInput,
) -> Result<VpCallInput> {
let addr_ptr = 0;
let addr_bytes = addr.serialize_to_vec().map_err(Error::EncodingError)?;
let addr_bytes = addr.serialize_to_vec();
let addr_len = addr_bytes.len() as _;

let data_bytes = data.serialize_to_vec().map_err(Error::EncodingError)?;
let data_bytes = data.serialize_to_vec();
let data_ptr = addr_ptr + addr_len;
let data_len = data_bytes.len() as _;

let keys_changed_bytes = keys_changed
.serialize_to_vec()
.map_err(Error::EncodingError)?;
.serialize_to_vec();
let keys_changed_ptr = data_ptr + data_len;
let keys_changed_len = keys_changed_bytes.len() as _;

let verifiers_bytes =
verifiers.serialize_to_vec().map_err(Error::EncodingError)?;
verifiers.serialize_to_vec();
let verifiers_ptr = keys_changed_ptr + keys_changed_len;
let verifiers_len = verifiers_bytes.len() as _;

Expand Down
1 change: 1 addition & 0 deletions shared/src/vm/wasm/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::vm::wasm::{memory, Cache, CacheName, VpCache};
use crate::vm::{
validate_untrusted_wasm, WasmCacheAccess, WasmValidationError,
};
use borsh_ext::BorshSerializeExt;

const TX_ENTRYPOINT: &str = "_apply_tx";
const VP_ENTRYPOINT: &str = "_validate_tx";
Expand Down
1 change: 1 addition & 0 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ tracing.workspace = true
namada_apps = {path = "../apps", features = ["testing"]}
assert_cmd.workspace = true
borsh.workspace = true
borsh-ext.workspace = true
color-eyre.workspace = true
data-encoding.workspace = true
# NOTE: enable "print" feature to see output from builds ran by e2e tests
Expand Down
1 change: 1 addition & 0 deletions tests/src/vm_host_env/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ use namada::vm::{wasm, WasmCacheRwAccess};
use namada_core::ledger::gas::TxGasMeter;
use namada_test_utils::TestWasms;
use namada_tx_prelude::BorshSerialize;
use namada_tx_prelude::borsh_ext::BorshSerializeExt;

use crate::tx::*;

Expand Down
1 change: 1 addition & 0 deletions tests/src/vm_host_env/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use namada_vp_prelude::key::common;
use tempfile::TempDir;

use crate::vp::TestVpEnv;
use namada_tx_prelude::borsh_ext::BorshSerializeExt;

/// Tx execution context provides access to host env functions
static mut CTX: Ctx = unsafe { Ctx::new() };
Expand Down
1 change: 1 addition & 0 deletions tx_prelude/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use core::slice;
use std::marker::PhantomData;

pub use borsh::{BorshDeserialize, BorshSerialize};
pub use borsh_ext;
use borsh_ext::BorshSerializeExt;
pub use namada_core::ledger::eth_bridge;
pub use namada_core::ledger::governance::storage as gov_storage;
Expand Down

0 comments on commit c176701

Please sign in to comment.