Skip to content

Commit b23fd51

Browse files
update dataspace model
1 parent fbf3681 commit b23fd51

File tree

22 files changed

+1168
-3787
lines changed

22 files changed

+1168
-3787
lines changed

crates/iroha_core/src/block.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5620,7 +5620,7 @@ pub(crate) mod valid {
56205620
}
56215621
}
56225622
}
5623-
let routing_decisions: Vec<_> = if workers > 1 {
5623+
let routing_results: Vec<_> = if workers > 1 {
56245624
if let Some(pool) = pool.as_ref() {
56255625
pool.install(|| {
56265626
txs.par_iter()
@@ -5665,6 +5665,20 @@ pub(crate) mod valid {
56655665
})
56665666
.collect()
56675667
};
5668+
let mut routing_decisions = Vec::with_capacity(routing_results.len());
5669+
let mut routing_errors = Vec::with_capacity(routing_results.len());
5670+
for routing in routing_results {
5671+
match routing {
5672+
Ok(decision) => {
5673+
routing_decisions.push(decision);
5674+
routing_errors.push(None);
5675+
}
5676+
Err(err) => {
5677+
routing_decisions.push(crate::queue::RoutingDecision::default());
5678+
routing_errors.push(Some(err));
5679+
}
5680+
}
5681+
}
56685682
let mut signature_overrides: Vec<
56695683
Option<Result<(), crate::tx::SignatureVerificationFail>>,
56705684
> = vec![None; txs.len()];
@@ -6156,6 +6170,13 @@ pub(crate) mod valid {
61566170
let t_stateless_start = Instant::now();
61576171
let mut stateless_rejections: Vec<Option<TransactionRejectionReason>> = {
61586172
let validate_tx = |(idx, tx): (usize, &&SignedTransaction)| {
6173+
if let Some(err) = routing_errors[idx].as_ref() {
6174+
return Some(TransactionRejectionReason::Validation(
6175+
iroha_data_model::ValidationFail::NotPermitted(format!(
6176+
"transaction routing could not be resolved: {err}"
6177+
)),
6178+
));
6179+
}
61596180
if !skip_stateless_checks && tx.creation_time() >= block_creation_time {
61606181
return Some(TransactionRejectionReason::Validation(
61616182
iroha_data_model::ValidationFail::NotPermitted(format!(

crates/iroha_core/src/gossiper.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,30 @@ impl TransactionGossiper {
13891389
) {
13901390
Ok(tx) => {
13911391
let advertised_route = RoutingDecision::new(route.lane_id, route.dataspace_id);
1392-
let local_route = self.queue.route_for_gossip_with_state(&tx, state);
1392+
let local_route = match self.queue.route_for_gossip_with_state(&tx, state) {
1393+
Ok(route) => route,
1394+
Err(err) => {
1395+
iroha_logger::warn!(
1396+
%tx_hash,
1397+
reason = %err,
1398+
reason_label = err.as_label(),
1399+
"dropping transaction gossip entry due to unresolved local route"
1400+
);
1401+
self.record_drop_metric(
1402+
plane,
1403+
route.dataspace_id,
1404+
&[route.lane_id],
1405+
"route_unresolved",
1406+
false,
1407+
None,
1408+
&[],
1409+
self.target_cap_for_plane(plane),
1410+
1,
1411+
0,
1412+
);
1413+
continue;
1414+
}
1415+
};
13931416
if local_route != advertised_route {
13941417
iroha_logger::warn!(
13951418
%tx_hash,
@@ -1648,7 +1671,30 @@ impl TransactionGossiper {
16481671
) {
16491672
Ok(tx) => {
16501673
let advertised_route = RoutingDecision::new(route.lane_id, route.dataspace_id);
1651-
let local_route = self.queue.route_for_gossip_with_state(&tx, state);
1674+
let local_route = match self.queue.route_for_gossip_with_state(&tx, state) {
1675+
Ok(route) => route,
1676+
Err(err) => {
1677+
iroha_logger::warn!(
1678+
%tx_hash,
1679+
reason = %err,
1680+
reason_label = err.as_label(),
1681+
"dropping transaction gossip entry due to unresolved local route"
1682+
);
1683+
self.record_drop_metric(
1684+
plane,
1685+
route.dataspace_id,
1686+
&[route.lane_id],
1687+
"route_unresolved",
1688+
false,
1689+
None,
1690+
&[],
1691+
self.target_cap_for_plane(plane),
1692+
1,
1693+
0,
1694+
);
1695+
continue;
1696+
}
1697+
};
16521698
if local_route != advertised_route {
16531699
iroha_logger::warn!(
16541700
%tx_hash,

crates/iroha_core/src/kura.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6295,7 +6295,7 @@ mod tests {
62956295
domain::{Domain, DomainId},
62966296
isi::{Log, Upgrade},
62976297
merge::MergeQuorumCertificate,
6298-
nexus::{LaneCatalog, LaneConfig as ModelLaneConfig, LaneId},
6298+
nexus::{DataSpaceId, LaneCatalog, LaneConfig as ModelLaneConfig, LaneId},
62996299
peer::PeerId,
63006300
prelude::{Executor, IvmBytecode},
63016301
transaction::TransactionBuilder,
@@ -6796,13 +6796,21 @@ mod tests {
67966796
let epoch_plus_three = epoch_u8
67976797
.checked_add(3)
67986798
.expect("test epoch offset 3 must fit in a u8");
6799-
let lane_tips = vec![HashOf::from_untyped_unchecked(Hash::new([epoch_u8]))];
6800-
let merge_hint_roots = vec![Hash::new([epoch_plus_one])];
6799+
let lane_snapshots = vec![iroha_data_model::merge::MergeLaneSnapshot {
6800+
lane_id: LaneId::SINGLE,
6801+
dataspace_id: DataSpaceId::GLOBAL,
6802+
lane_block_height: epoch,
6803+
tip_hash: HashOf::from_untyped_unchecked(Hash::new([epoch_u8])),
6804+
merge_hint_root: Hash::new([epoch_plus_one]),
6805+
}];
6806+
let merge_hint_roots: Vec<Hash> = lane_snapshots
6807+
.iter()
6808+
.map(|snapshot| snapshot.merge_hint_root)
6809+
.collect();
68016810
let global_state_root = reduce_merge_hint_roots(&merge_hint_roots);
68026811
MergeLedgerEntry {
68036812
epoch_id: epoch,
6804-
lane_tips,
6805-
merge_hint_roots,
6813+
lane_snapshots,
68066814
global_state_root,
68076815
merge_qc: MergeQuorumCertificate::new(
68086816
epoch,

crates/iroha_core/src/merge.rs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use iroha_crypto::{Hash, HashOf};
44
use iroha_data_model::{
55
ChainId,
66
block::BlockHeader,
7-
merge::{MergeLedgerEntry, MergeQuorumCertificate},
7+
merge::{MergeLaneSnapshot, MergeLedgerEntry, MergeQuorumCertificate},
88
};
99
use iroha_zkp_halo2::poseidon;
1010
use norito::codec::Encode;
@@ -21,22 +21,37 @@ pub struct MergeLedgerCandidate {
2121
pub epoch_id: u64,
2222
/// Merge committee view derived from lane tips.
2323
pub view: u64,
24-
/// Canonical tips for each execution lane.
25-
pub lane_tips: Vec<HashOf<BlockHeader>>,
26-
/// Merge-hint Poseidon roots aligned with the lane tips.
27-
pub merge_hint_roots: Vec<Hash>,
24+
/// Canonical per-lane snapshots for this merge entry.
25+
pub lane_snapshots: Vec<MergeLaneSnapshot>,
2826
/// Deterministic reduction of `merge_hint_roots` across all lanes.
2927
pub global_state_root: Hash,
3028
}
3129

3230
impl MergeLedgerCandidate {
31+
/// Canonical lane tips derived from [`Self::lane_snapshots`].
32+
#[must_use]
33+
pub fn lane_tips(&self) -> Vec<HashOf<BlockHeader>> {
34+
self.lane_snapshots
35+
.iter()
36+
.map(|snapshot| snapshot.tip_hash)
37+
.collect()
38+
}
39+
40+
/// Canonical merge-hint roots derived from [`Self::lane_snapshots`].
41+
#[must_use]
42+
pub fn merge_hint_roots(&self) -> Vec<Hash> {
43+
self.lane_snapshots
44+
.iter()
45+
.map(|snapshot| snapshot.merge_hint_root)
46+
.collect()
47+
}
48+
3349
/// Convert this candidate into a full merge-ledger entry with the supplied QC.
3450
#[must_use]
3551
pub fn into_entry(self, merge_qc: MergeQuorumCertificate) -> MergeLedgerEntry {
3652
MergeLedgerEntry {
3753
epoch_id: self.epoch_id,
38-
lane_tips: self.lane_tips,
39-
merge_hint_roots: self.merge_hint_roots,
54+
lane_snapshots: self.lane_snapshots,
4055
global_state_root: self.global_state_root,
4156
merge_qc,
4257
}
@@ -48,8 +63,7 @@ impl From<&MergeLedgerEntry> for MergeLedgerCandidate {
4863
Self {
4964
epoch_id: entry.epoch_id,
5065
view: entry.merge_qc.view,
51-
lane_tips: entry.lane_tips.clone(),
52-
merge_hint_roots: entry.merge_hint_roots.clone(),
66+
lane_snapshots: entry.lane_snapshots.clone(),
5367
global_state_root: entry.global_state_root,
5468
}
5569
}
@@ -59,8 +73,7 @@ impl From<&MergeLedgerEntry> for MergeLedgerCandidate {
5973
struct MergeLedgerSignPayload {
6074
view: u64,
6175
epoch_id: u64,
62-
lane_tips: Vec<HashOf<BlockHeader>>,
63-
merge_hint_roots: Vec<Hash>,
76+
lane_snapshots: Vec<MergeLaneSnapshot>,
6477
global_state_root: Hash,
6578
}
6679

@@ -70,8 +83,7 @@ pub fn merge_qc_message_digest(chain_id: &ChainId, candidate: &MergeLedgerCandid
7083
let payload = MergeLedgerSignPayload {
7184
view: candidate.view,
7285
epoch_id: candidate.epoch_id,
73-
lane_tips: candidate.lane_tips.clone(),
74-
merge_hint_roots: candidate.merge_hint_roots.clone(),
86+
lane_snapshots: candidate.lane_snapshots.clone(),
7587
global_state_root: candidate.global_state_root,
7688
};
7789
let payload_bytes = payload.encode();
@@ -151,8 +163,13 @@ mod tests {
151163
let candidate = MergeLedgerCandidate {
152164
epoch_id: 7,
153165
view: 3,
154-
lane_tips: vec![HashOf::from_untyped_unchecked(Hash::new(b"lane-0"))],
155-
merge_hint_roots: vec![Hash::new(b"hint-0")],
166+
lane_snapshots: vec![MergeLaneSnapshot {
167+
lane_id: iroha_data_model::nexus::LaneId::new(1),
168+
dataspace_id: iroha_data_model::nexus::DataSpaceId::new(7),
169+
lane_block_height: 9,
170+
tip_hash: HashOf::from_untyped_unchecked(Hash::new(b"lane-0")),
171+
merge_hint_root: Hash::new(b"hint-0"),
172+
}],
156173
global_state_root: Hash::new(b"global"),
157174
};
158175
let chain_id: ChainId = "nexus-merge".parse().expect("chain id parses");

0 commit comments

Comments
 (0)