Skip to content

Commit 405b836

Browse files
authored
Merge of #3577
2 parents d8abc13 + 1ff2f61 commit 405b836

File tree

107 files changed

+2874
-1882
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+2874
-1882
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Replaced cross-system dependencies in namada_proof_of_stake crate with
2+
dependency-injection. ([\#3497](https://github.com/anoma/namada/pull/3497))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Replaced cross-system dependencies in namada_ibc crate with dependency-
2+
injection. ([\#3509](https://github.com/anoma/namada/pull/3509))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Removed unnecessary trait bound from declarations.
2+
([\#3577](https://github.com/anoma/namada/pull/3577))

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/benches/native_vps.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use namada_apps_lib::validation::{
5151
IbcVpContext, MaspVp, MultitokenVp, ParametersVp, PgfVp, PosVp,
5252
};
5353
use namada_apps_lib::wallet::defaults;
54-
use namada_apps_lib::{governance, proof_of_stake, storage, token};
54+
use namada_apps_lib::{governance, parameters, proof_of_stake, storage, token};
5555
use namada_node::bench_utils::{
5656
generate_foreign_key_tx, BenchShell, BenchShieldedCtx,
5757
ALBERT_PAYMENT_ADDRESS, ALBERT_SPENDING_KEY, BERTHA_PAYMENT_ADDRESS,
@@ -110,9 +110,11 @@ fn governance(c: &mut Criterion) {
110110
"minimal_proposal" => {
111111
let content_section =
112112
Section::ExtraData(Code::new(vec![], None));
113-
let params =
114-
proof_of_stake::storage::read_pos_params(&shell.state)
115-
.unwrap();
113+
let params = proof_of_stake::storage::read_pos_params::<
114+
_,
115+
governance::Store<_>,
116+
>(&shell.state)
117+
.unwrap();
116118
let voting_start_epoch =
117119
Epoch(2 + params.pipeline_len + params.unbonding_len);
118120
// Must start after current epoch
@@ -163,9 +165,11 @@ fn governance(c: &mut Criterion) {
163165
None,
164166
));
165167

166-
let params =
167-
proof_of_stake::storage::read_pos_params(&shell.state)
168-
.unwrap();
168+
let params = proof_of_stake::storage::read_pos_params::<
169+
_,
170+
governance::Store<_>,
171+
>(&shell.state)
172+
.unwrap();
169173
let voting_start_epoch =
170174
Epoch(2 + params.pipeline_len + params.unbonding_len);
171175
// Must start after current epoch
@@ -1670,16 +1674,20 @@ fn ibc_vp_validate_action(c: &mut Criterion) {
16701674

16711675
let exec_ctx = IbcVpContext::new(ibc.ctx.pre());
16721676
let ctx = Rc::new(RefCell::new(exec_ctx));
1673-
let mut actions = IbcActions::new(ctx.clone(), verifiers.clone());
1677+
let mut actions =
1678+
IbcActions::<_, parameters::Store<_>, token::Store<()>>::new(
1679+
ctx.clone(),
1680+
verifiers.clone(),
1681+
);
16741682
actions.set_validation_params(ibc.validation_params().unwrap());
16751683

16761684
let module = TransferModule::new(ctx.clone(), verifiers);
16771685
actions.add_transfer_module(module);
1678-
let module = NftTransferModule::new(ctx);
1686+
let module = NftTransferModule::<_, token::Store<()>>::new(ctx);
16791687
actions.add_transfer_module(module);
16801688

16811689
group.bench_function(bench_name, |b| {
1682-
b.iter(|| actions.validate(&tx_data).unwrap())
1690+
b.iter(|| actions.validate::<Transfer>(&tx_data).unwrap())
16831691
});
16841692
}
16851693

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

1730-
let mut actions = IbcActions::new(ctx.clone(), verifiers.clone());
1738+
let mut actions =
1739+
IbcActions::<_, parameters::Store<_>, token::Store<()>>::new(
1740+
ctx.clone(),
1741+
verifiers.clone(),
1742+
);
17311743
actions.set_validation_params(ibc.validation_params().unwrap());
17321744

17331745
let module = TransferModule::new(ctx.clone(), verifiers);
17341746
actions.add_transfer_module(module);
1735-
let module = NftTransferModule::new(ctx);
1747+
let module = NftTransferModule::<_, token::Store<()>>::new(ctx);
17361748
actions.add_transfer_module(module);
17371749

17381750
group.bench_function(bench_name, |b| {
1739-
b.iter(|| actions.execute(&tx_data).unwrap())
1751+
b.iter(|| actions.execute::<token::Transfer>(&tx_data).unwrap())
17401752
});
17411753
}
17421754

crates/core/src/ibc.rs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
//! IBC-related data types
22
3+
use std::collections::BTreeMap;
34
use std::fmt::Display;
45
use std::str::FromStr;
56

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

1416
use super::address::HASH_LEN;
1517
use crate::hash::Hash;
18+
use crate::token;
1619

1720
/// IBC token hash derived from a denomination.
1821
#[derive(
@@ -70,3 +73,92 @@ impl FromStr for IbcTxDataRefs {
7073
serde_json::from_str(s)
7174
}
7275
}
76+
77+
/// The target of a PGF payment
78+
#[derive(
79+
Debug,
80+
Clone,
81+
PartialEq,
82+
Serialize,
83+
Deserialize,
84+
Ord,
85+
Eq,
86+
PartialOrd,
87+
BorshDeserializer,
88+
Hash,
89+
)]
90+
pub struct PGFIbcTarget {
91+
/// The target address on the target chain
92+
pub target: String,
93+
/// The amount of token to fund the target address
94+
pub amount: token::Amount,
95+
/// Port ID to fund
96+
pub port_id: PortId,
97+
/// Channel ID to fund
98+
pub channel_id: ChannelId,
99+
}
100+
101+
impl BorshSerialize for PGFIbcTarget {
102+
fn serialize<W: std::io::Write>(
103+
&self,
104+
writer: &mut W,
105+
) -> std::io::Result<()> {
106+
BorshSerialize::serialize(&self.target, writer)?;
107+
BorshSerialize::serialize(&self.amount, writer)?;
108+
BorshSerialize::serialize(&self.port_id.to_string(), writer)?;
109+
BorshSerialize::serialize(&self.channel_id.to_string(), writer)
110+
}
111+
}
112+
113+
impl borsh::BorshDeserialize for PGFIbcTarget {
114+
fn deserialize_reader<R: std::io::Read>(
115+
reader: &mut R,
116+
) -> std::io::Result<Self> {
117+
use std::io::{Error, ErrorKind};
118+
let target: String = BorshDeserialize::deserialize_reader(reader)?;
119+
let amount: token::Amount =
120+
BorshDeserialize::deserialize_reader(reader)?;
121+
let port_id: String = BorshDeserialize::deserialize_reader(reader)?;
122+
let port_id: PortId = port_id.parse().map_err(|err| {
123+
Error::new(
124+
ErrorKind::InvalidData,
125+
format!("Error decoding port ID: {}", err),
126+
)
127+
})?;
128+
let channel_id: String = BorshDeserialize::deserialize_reader(reader)?;
129+
let channel_id: ChannelId = channel_id.parse().map_err(|err| {
130+
Error::new(
131+
ErrorKind::InvalidData,
132+
format!("Error decoding channel ID: {}", err),
133+
)
134+
})?;
135+
Ok(Self {
136+
target,
137+
amount,
138+
port_id,
139+
channel_id,
140+
})
141+
}
142+
}
143+
144+
impl borsh::BorshSchema for PGFIbcTarget {
145+
fn add_definitions_recursively(
146+
definitions: &mut BTreeMap<
147+
borsh::schema::Declaration,
148+
borsh::schema::Definition,
149+
>,
150+
) {
151+
let fields = borsh::schema::Fields::NamedFields(vec![
152+
("target".into(), String::declaration()),
153+
("amount".into(), token::Amount::declaration()),
154+
("port_id".into(), String::declaration()),
155+
("channel_id".into(), String::declaration()),
156+
]);
157+
let definition = borsh::schema::Definition::Struct { fields };
158+
definitions.insert(Self::declaration(), definition);
159+
}
160+
161+
fn declaration() -> borsh::schema::Declaration {
162+
std::any::type_name::<Self>().into()
163+
}
164+
}

crates/ethereum_bridge/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ testing = [
1919
"namada_account",
2020
"namada_core/testing",
2121
"namada_state/testing",
22+
"namada_governance",
2223
]
2324
migrations = [
2425
"namada_migrations",
@@ -29,6 +30,7 @@ migrations = [
2930
namada_account = {path = "../account", optional = true}
3031
namada_core = {path = "../core", default-features = false, features = ["ethers-derive"]}
3132
namada_events = { path = "../events", default-features = false }
33+
namada_governance = {path = "../governance", optional = true}
3234
namada_macros = {path = "../macros"}
3335
namada_migrations = {path = "../migrations", optional = true}
3436
namada_parameters = {path = "../parameters"}
@@ -53,10 +55,10 @@ thiserror.workspace = true
5355
tracing = "0.1.30"
5456

5557
[dev-dependencies]
56-
# Added "testing" feature.
5758
namada_account = {path = "../account"}
5859
namada_core = {path = "../core", default-features = false, features = ["ethers-derive", "testing"]}
5960
namada_gas = {path = "../gas"}
61+
namada_governance = {path = "../governance"}
6062
namada_proof_of_stake = {path = "../proof_of_stake", default-features = false, features = ["testing"]}
6163
namada_state = { path = "../state", features = ["testing"] }
6264
namada_token = {path = "../token", features = ["testing"]}

0 commit comments

Comments
 (0)