Skip to content

Commit c8e7d44

Browse files
authored
[Refactor] Hide fragment ids calculation under the insert_and_propagate_all function (#4081)
* Hide fragment ids calculation under the insert_and_propagate_all function * change id() to hash() * fix clippy * fix evm build
1 parent 2dd35d7 commit c8e7d44

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

Diff for: jormungandr/src/fragment/pool.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,18 @@ impl Pool {
154154
pub async fn insert_and_propagate_all(
155155
&mut self,
156156
origin: FragmentOrigin,
157-
fragments: Vec<(Fragment, FragmentId)>,
157+
fragments: Vec<Fragment>,
158158
fail_fast: bool,
159159
) -> Result<FragmentsProcessingSummary, Error> {
160160
tracing::debug!(origin = ?origin, "received {} fragments", fragments.len());
161161

162162
let mut filtered_fragments = Vec::new();
163163
let mut rejected = Vec::new();
164164

165-
let mut fragments = fragments.into_iter();
165+
let mut fragments = fragments.into_iter().map(|el| {
166+
let id = el.hash();
167+
(el, id)
168+
});
166169

167170
let tip = self.tip.get_ref().await;
168171
let ledger = tip.ledger();

Diff for: jormungandr/src/fragment/process.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::{
88
task::TokioServiceInfo,
99
},
1010
};
11-
use chain_core::property::Fragment;
1211
use futures::{future, TryFutureExt};
1312
use std::{
1413
collections::HashMap,
@@ -138,10 +137,7 @@ impl Process {
138137
async {
139138
let stats_counter = stats_counter.clone();
140139
let summary = pool
141-
.insert_and_propagate_all(origin, fragments.into_iter().map(|el| {
142-
let id = el.id();
143-
(el, id)
144-
}).collect(), fail_fast)
140+
.insert_and_propagate_all(origin, fragments, fail_fast)
145141
.await?;
146142

147143
stats_counter.add_tx_recv_cnt(summary.accepted.len());

Diff for: jormungandr/src/rest/v0/mod.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@ pub fn filter(
1010
let with_context = warp::any().map(move || context.clone());
1111
let root = warp::path!("v0" / ..);
1212

13+
#[cfg(feature = "evm")]
14+
let address_mapping = {
15+
let root = warp::path!("address_mapping" / ..);
16+
17+
let get_jor_address = warp::path!("jormungandr_address" / String)
18+
.and(warp::get())
19+
.and(with_context.clone())
20+
.and_then(handlers::get_jor_address)
21+
.boxed();
22+
23+
let get_evm_address = warp::path!("evm_address" / String)
24+
.and(warp::get())
25+
.and(with_context.clone())
26+
.and_then(handlers::get_evm_address)
27+
.boxed();
28+
29+
root.and(get_jor_address.or(get_evm_address)).boxed()
30+
};
31+
1332
let shutdown = warp::path!("shutdown")
1433
.and(warp::get().or(warp::post()))
1534
.and(with_context.clone())
@@ -221,31 +240,12 @@ pub fn filter(
221240

222241
let vote_plans = warp::path!("plans")
223242
.and(warp::get())
224-
.and(with_context.clone())
243+
.and(with_context)
225244
.and_then(handlers::get_active_vote_plans)
226245
.boxed();
227246
root.and(committees.or(vote_plans)).boxed()
228247
};
229248

230-
#[cfg(feature = "evm")]
231-
let address_mapping = {
232-
let root = warp::path!("address_mapping" / ..);
233-
234-
let get_jor_address = warp::path!("jormungandr_address" / String)
235-
.and(warp::get())
236-
.and(with_context.clone())
237-
.and_then(handlers::get_jor_address)
238-
.boxed();
239-
240-
let get_evm_address = warp::path!("evm_address" / String)
241-
.and(warp::get())
242-
.and(with_context)
243-
.and_then(handlers::get_evm_address)
244-
.boxed();
245-
246-
root.and(get_jor_address.or(get_evm_address)).boxed()
247-
};
248-
249249
let routes = shutdown
250250
.or(account)
251251
.or(block)

0 commit comments

Comments
 (0)