Skip to content

Commit 124c015

Browse files
authored
Merge branch 'main' into fix-ledger-api-doc
2 parents fe1c757 + 992e404 commit 124c015

File tree

8 files changed

+86
-6
lines changed

8 files changed

+86
-6
lines changed

Cargo.lock

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

SECURITY.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Security
2+
3+
## Reporting a Vulnerability
4+
5+
Please report (suspected) security vulnerabilities to [email protected]. You will receive a
6+
response from us within 48 hours. If the issue is confirmed, we will release a patch as soon
7+
as possible.
8+
9+
Please provide a clear and concise description of the vulnerability, including:
10+
11+
* the affected version(s),
12+
* steps that can be followed to exercise the vulnerability,
13+
* any workarounds or mitigations.
14+
15+
If you have developed any code or utilities that can help demonstrate the suspected
16+
vulnerability, please mention them in your email but ***DO NOT*** attempt to include them as
17+
attachments as this may cause your Email to be blocked by spam filters.

src/jormungandr/jormungandr-lib/src/interfaces/fragment_log.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
use std::net::IpAddr;
2+
13
use crate::{crypto::hash::Hash, interfaces::BlockDate, time::SystemTime};
24
use chain_impl_mockchain::key;
5+
36
use serde::{Deserialize, Serialize};
47

58
/// identify the source of a fragment
@@ -10,9 +13,7 @@ pub enum FragmentOrigin {
1013
/// origins of the fragment and eventually blacklisting
1114
/// the senders from sending us more fragment (in case
1215
/// they are invalids or so)
13-
///
14-
/// TODO: add the network identifier/IP Address
15-
Network,
16+
Network { addr: IpAddr },
1617
/// This marks the fragment is coming from the REST interface
1718
/// (a client wallet or another service).
1819
Rest,

src/jormungandr/jormungandr/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ prometheus = { version = "0.13", optional = true }
6969
jsonrpsee-http-server = { version = "0.11.0" }
7070
jsonrpsee-core = { version = "0.11.0" }
7171
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls"] }
72+
local-ip-address = "0.4.9"
7273

7374
[dev-dependencies]
7475
tokio = { version = "^1.15", features = ["full"] }

src/jormungandr/jormungandr/src/fragment/logs.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::fragment::FragmentId;
1+
use crate::{fragment::FragmentId, network::retrieve_local_ip};
22
use jormungandr_lib::{
33
crypto::hash::Hash,
44
interfaces::{BlockDate, FragmentLog, FragmentOrigin, FragmentStatus},
@@ -76,7 +76,12 @@ impl Logs {
7676
// Also, in this scenario we accept any provided FragmentStatus, since we do not
7777
// actually know what the previous status was, and thus cannot execute the correct
7878
// state transition.
79-
let mut entry = FragmentLog::new(fragment_id.into_hash(), FragmentOrigin::Network);
79+
let mut entry = FragmentLog::new(
80+
fragment_id.into_hash(),
81+
FragmentOrigin::Network {
82+
addr: retrieve_local_ip(),
83+
},
84+
);
8085
entry.modify(status);
8186
self.entries.put(fragment_id, (entry, Some(ledger_date)));
8287
}

src/jormungandr/jormungandr/src/network/bootstrap.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{
88
use chain_core::property::ReadError;
99
use chain_network::{data as net_data, error::Error as NetworkError};
1010
use futures::prelude::*;
11+
1112
use std::fmt::Debug;
1213
use tokio_util::sync::CancellationToken;
1314

src/jormungandr/jormungandr/src/network/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ mod subscription;
1515

1616
use self::convert::Encode;
1717
use futures::{future, prelude::*};
18+
use local_ip_address::local_ip;
19+
use std::{
20+
fmt::Debug,
21+
net::{IpAddr, Ipv4Addr},
22+
};
1823
use thiserror::Error;
1924
use tokio_util::sync::CancellationToken;
2025

@@ -781,3 +786,17 @@ pub enum FetchBlockError {
781786
#[error("could not download block hash {block}")]
782787
CouldNotDownloadBlock { block: HeaderHash },
783788
}
789+
790+
/// Infallible util function to obtain local IP addr
791+
pub fn retrieve_local_ip() -> IpAddr {
792+
match local_ip() {
793+
Ok(ip) => ip,
794+
Err(err) => {
795+
tracing::error!(
796+
reason = %err,
797+
"unable to lookup local addr"
798+
);
799+
std::net::IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))
800+
}
801+
}
802+
}

src/jormungandr/jormungandr/src/network/subscription.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::{buffer_sizes, convert::Decode, GlobalStateR};
22
use crate::{
33
blockcfg::Fragment,
44
intercom::{self, BlockMsg, TopologyMsg, TransactionMsg},
5+
network::retrieve_local_ip,
56
settings::start::network::Configuration,
67
topology::{Gossip, NodeId},
78
utils::async_msg::{self, MessageBox},
@@ -19,6 +20,7 @@ use std::{
1920
pin::Pin,
2021
task::{Context, Poll},
2122
};
23+
2224
use tracing_futures::Instrument;
2325

2426
fn filter_gossip_node(node: &Gossip, config: &Configuration) -> bool {
@@ -372,10 +374,21 @@ impl FragmentProcessor {
372374
&mut self.buffered_fragments,
373375
Vec::with_capacity(buffer_sizes::inbound::FRAGMENTS),
374376
);
377+
378+
let addr = match self.global_state.config.address() {
379+
Some(addr) => FragmentOrigin::Network { addr: addr.ip() },
380+
None => {
381+
tracing::info!("node addr not present in config, reverting to local lookup");
382+
FragmentOrigin::Network {
383+
addr: retrieve_local_ip(),
384+
}
385+
}
386+
};
387+
375388
let (reply_handle, _reply_future) = intercom::unary_reply();
376389
self.mbox
377390
.start_send(TransactionMsg::SendTransactions {
378-
origin: FragmentOrigin::Network,
391+
origin: addr,
379392
fragments,
380393
fail_fast: false,
381394
reply_handle,

0 commit comments

Comments
 (0)