Skip to content

Commit

Permalink
[Refactor] Hide fragment ids calculation under the insert_and_propaga…
Browse files Browse the repository at this point in the history
…te_all function (#4081)

* Hide fragment ids calculation under the insert_and_propagate_all function

* change id() to hash()

* fix clippy

* fix evm build
  • Loading branch information
Mr-Leshiy authored Sep 29, 2022
1 parent 2dd35d7 commit c8e7d44
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
7 changes: 5 additions & 2 deletions jormungandr/src/fragment/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,18 @@ impl Pool {
pub async fn insert_and_propagate_all(
&mut self,
origin: FragmentOrigin,
fragments: Vec<(Fragment, FragmentId)>,
fragments: Vec<Fragment>,
fail_fast: bool,
) -> Result<FragmentsProcessingSummary, Error> {
tracing::debug!(origin = ?origin, "received {} fragments", fragments.len());

let mut filtered_fragments = Vec::new();
let mut rejected = Vec::new();

let mut fragments = fragments.into_iter();
let mut fragments = fragments.into_iter().map(|el| {
let id = el.hash();
(el, id)
});

let tip = self.tip.get_ref().await;
let ledger = tip.ledger();
Expand Down
6 changes: 1 addition & 5 deletions jormungandr/src/fragment/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::{
task::TokioServiceInfo,
},
};
use chain_core::property::Fragment;
use futures::{future, TryFutureExt};
use std::{
collections::HashMap,
Expand Down Expand Up @@ -138,10 +137,7 @@ impl Process {
async {
let stats_counter = stats_counter.clone();
let summary = pool
.insert_and_propagate_all(origin, fragments.into_iter().map(|el| {
let id = el.id();
(el, id)
}).collect(), fail_fast)
.insert_and_propagate_all(origin, fragments, fail_fast)
.await?;

stats_counter.add_tx_recv_cnt(summary.accepted.len());
Expand Down
40 changes: 20 additions & 20 deletions jormungandr/src/rest/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ pub fn filter(
let with_context = warp::any().map(move || context.clone());
let root = warp::path!("v0" / ..);

#[cfg(feature = "evm")]
let address_mapping = {
let root = warp::path!("address_mapping" / ..);

let get_jor_address = warp::path!("jormungandr_address" / String)
.and(warp::get())
.and(with_context.clone())
.and_then(handlers::get_jor_address)
.boxed();

let get_evm_address = warp::path!("evm_address" / String)
.and(warp::get())
.and(with_context.clone())
.and_then(handlers::get_evm_address)
.boxed();

root.and(get_jor_address.or(get_evm_address)).boxed()
};

let shutdown = warp::path!("shutdown")
.and(warp::get().or(warp::post()))
.and(with_context.clone())
Expand Down Expand Up @@ -221,31 +240,12 @@ pub fn filter(

let vote_plans = warp::path!("plans")
.and(warp::get())
.and(with_context.clone())
.and(with_context)
.and_then(handlers::get_active_vote_plans)
.boxed();
root.and(committees.or(vote_plans)).boxed()
};

#[cfg(feature = "evm")]
let address_mapping = {
let root = warp::path!("address_mapping" / ..);

let get_jor_address = warp::path!("jormungandr_address" / String)
.and(warp::get())
.and(with_context.clone())
.and_then(handlers::get_jor_address)
.boxed();

let get_evm_address = warp::path!("evm_address" / String)
.and(warp::get())
.and(with_context)
.and_then(handlers::get_evm_address)
.boxed();

root.and(get_jor_address.or(get_evm_address)).boxed()
};

let routes = shutdown
.or(account)
.or(block)
Expand Down

0 comments on commit c8e7d44

Please sign in to comment.