Skip to content

Commit

Permalink
Merge pull request #3577 from anoma/tomas/relax-bounds
Browse files Browse the repository at this point in the history
relax bounds
  • Loading branch information
mergify[bot] authored Aug 2, 2024
2 parents d8abc13 + 1ff2f61 commit fdf8471
Show file tree
Hide file tree
Showing 107 changed files with 2,874 additions and 1,882 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/3497-di-pos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Replaced cross-system dependencies in namada_proof_of_stake crate with
dependency-injection. ([\#3497](https://github.com/anoma/namada/pull/3497))
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/3509-di-ibc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Replaced cross-system dependencies in namada_ibc crate with dependency-
injection. ([\#3509](https://github.com/anoma/namada/pull/3509))
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/3577-relax-bounds.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Removed unnecessary trait bound from declarations.
([\#3577](https://github.com/anoma/namada/pull/3577))
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.

38 changes: 25 additions & 13 deletions crates/benches/native_vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use namada_apps_lib::validation::{
IbcVpContext, MaspVp, MultitokenVp, ParametersVp, PgfVp, PosVp,
};
use namada_apps_lib::wallet::defaults;
use namada_apps_lib::{governance, proof_of_stake, storage, token};
use namada_apps_lib::{governance, parameters, proof_of_stake, storage, token};
use namada_node::bench_utils::{
generate_foreign_key_tx, BenchShell, BenchShieldedCtx,
ALBERT_PAYMENT_ADDRESS, ALBERT_SPENDING_KEY, BERTHA_PAYMENT_ADDRESS,
Expand Down Expand Up @@ -110,9 +110,11 @@ fn governance(c: &mut Criterion) {
"minimal_proposal" => {
let content_section =
Section::ExtraData(Code::new(vec![], None));
let params =
proof_of_stake::storage::read_pos_params(&shell.state)
.unwrap();
let params = proof_of_stake::storage::read_pos_params::<
_,
governance::Store<_>,
>(&shell.state)
.unwrap();
let voting_start_epoch =
Epoch(2 + params.pipeline_len + params.unbonding_len);
// Must start after current epoch
Expand Down Expand Up @@ -163,9 +165,11 @@ fn governance(c: &mut Criterion) {
None,
));

let params =
proof_of_stake::storage::read_pos_params(&shell.state)
.unwrap();
let params = proof_of_stake::storage::read_pos_params::<
_,
governance::Store<_>,
>(&shell.state)
.unwrap();
let voting_start_epoch =
Epoch(2 + params.pipeline_len + params.unbonding_len);
// Must start after current epoch
Expand Down Expand Up @@ -1670,16 +1674,20 @@ fn ibc_vp_validate_action(c: &mut Criterion) {

let exec_ctx = IbcVpContext::new(ibc.ctx.pre());
let ctx = Rc::new(RefCell::new(exec_ctx));
let mut actions = IbcActions::new(ctx.clone(), verifiers.clone());
let mut actions =
IbcActions::<_, parameters::Store<_>, token::Store<()>>::new(
ctx.clone(),
verifiers.clone(),
);
actions.set_validation_params(ibc.validation_params().unwrap());

let module = TransferModule::new(ctx.clone(), verifiers);
actions.add_transfer_module(module);
let module = NftTransferModule::new(ctx);
let module = NftTransferModule::<_, token::Store<()>>::new(ctx);
actions.add_transfer_module(module);

group.bench_function(bench_name, |b| {
b.iter(|| actions.validate(&tx_data).unwrap())
b.iter(|| actions.validate::<Transfer>(&tx_data).unwrap())
});
}

Expand Down Expand Up @@ -1727,16 +1735,20 @@ fn ibc_vp_execute_action(c: &mut Criterion) {
let exec_ctx = IbcVpContext::new(ibc.ctx.pre());
let ctx = Rc::new(RefCell::new(exec_ctx));

let mut actions = IbcActions::new(ctx.clone(), verifiers.clone());
let mut actions =
IbcActions::<_, parameters::Store<_>, token::Store<()>>::new(
ctx.clone(),
verifiers.clone(),
);
actions.set_validation_params(ibc.validation_params().unwrap());

let module = TransferModule::new(ctx.clone(), verifiers);
actions.add_transfer_module(module);
let module = NftTransferModule::new(ctx);
let module = NftTransferModule::<_, token::Store<()>>::new(ctx);
actions.add_transfer_module(module);

group.bench_function(bench_name, |b| {
b.iter(|| actions.execute(&tx_data).unwrap())
b.iter(|| actions.execute::<token::Transfer>(&tx_data).unwrap())
});
}

Expand Down
92 changes: 92 additions & 0 deletions crates/core/src/ibc.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//! IBC-related data types

use std::collections::BTreeMap;
use std::fmt::Display;
use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use data_encoding::{DecodePartial, HEXLOWER, HEXLOWER_PERMISSIVE};
use ibc::core::host::types::identifiers::{ChannelId, PortId};
pub use ibc::*;
use namada_macros::BorshDeserializer;
#[cfg(feature = "migrations")]
Expand All @@ -13,6 +15,7 @@ use serde::{Deserialize, Serialize};

use super::address::HASH_LEN;
use crate::hash::Hash;
use crate::token;

/// IBC token hash derived from a denomination.
#[derive(
Expand Down Expand Up @@ -70,3 +73,92 @@ impl FromStr for IbcTxDataRefs {
serde_json::from_str(s)
}
}

/// The target of a PGF payment
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
Ord,
Eq,
PartialOrd,
BorshDeserializer,
Hash,
)]
pub struct PGFIbcTarget {
/// The target address on the target chain
pub target: String,
/// The amount of token to fund the target address
pub amount: token::Amount,
/// Port ID to fund
pub port_id: PortId,
/// Channel ID to fund
pub channel_id: ChannelId,
}

impl BorshSerialize for PGFIbcTarget {
fn serialize<W: std::io::Write>(
&self,
writer: &mut W,
) -> std::io::Result<()> {
BorshSerialize::serialize(&self.target, writer)?;
BorshSerialize::serialize(&self.amount, writer)?;
BorshSerialize::serialize(&self.port_id.to_string(), writer)?;
BorshSerialize::serialize(&self.channel_id.to_string(), writer)
}
}

impl borsh::BorshDeserialize for PGFIbcTarget {
fn deserialize_reader<R: std::io::Read>(
reader: &mut R,
) -> std::io::Result<Self> {
use std::io::{Error, ErrorKind};
let target: String = BorshDeserialize::deserialize_reader(reader)?;
let amount: token::Amount =
BorshDeserialize::deserialize_reader(reader)?;
let port_id: String = BorshDeserialize::deserialize_reader(reader)?;
let port_id: PortId = port_id.parse().map_err(|err| {
Error::new(
ErrorKind::InvalidData,
format!("Error decoding port ID: {}", err),
)
})?;
let channel_id: String = BorshDeserialize::deserialize_reader(reader)?;
let channel_id: ChannelId = channel_id.parse().map_err(|err| {
Error::new(
ErrorKind::InvalidData,
format!("Error decoding channel ID: {}", err),
)
})?;
Ok(Self {
target,
amount,
port_id,
channel_id,
})
}
}

impl borsh::BorshSchema for PGFIbcTarget {
fn add_definitions_recursively(
definitions: &mut BTreeMap<
borsh::schema::Declaration,
borsh::schema::Definition,
>,
) {
let fields = borsh::schema::Fields::NamedFields(vec![
("target".into(), String::declaration()),
("amount".into(), token::Amount::declaration()),
("port_id".into(), String::declaration()),
("channel_id".into(), String::declaration()),
]);
let definition = borsh::schema::Definition::Struct { fields };
definitions.insert(Self::declaration(), definition);
}

fn declaration() -> borsh::schema::Declaration {
std::any::type_name::<Self>().into()
}
}
4 changes: 3 additions & 1 deletion crates/ethereum_bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ testing = [
"namada_account",
"namada_core/testing",
"namada_state/testing",
"namada_governance",
]
migrations = [
"namada_migrations",
Expand All @@ -29,6 +30,7 @@ migrations = [
namada_account = {path = "../account", optional = true}
namada_core = {path = "../core", default-features = false, features = ["ethers-derive"]}
namada_events = { path = "../events", default-features = false }
namada_governance = {path = "../governance", optional = true}
namada_macros = {path = "../macros"}
namada_migrations = {path = "../migrations", optional = true}
namada_parameters = {path = "../parameters"}
Expand All @@ -53,10 +55,10 @@ thiserror.workspace = true
tracing = "0.1.30"

[dev-dependencies]
# Added "testing" feature.
namada_account = {path = "../account"}
namada_core = {path = "../core", default-features = false, features = ["ethers-derive", "testing"]}
namada_gas = {path = "../gas"}
namada_governance = {path = "../governance"}
namada_proof_of_stake = {path = "../proof_of_stake", default-features = false, features = ["testing"]}
namada_state = { path = "../state", features = ["testing"] }
namada_token = {path = "../token", features = ["testing"]}
Expand Down
Loading

0 comments on commit fdf8471

Please sign in to comment.