Skip to content

Commit b66a84a

Browse files
authored
Merge pull request #165 from carlaKC/sim-node
Add Ability to Run as Full Simulator
2 parents 736a5a9 + f155904 commit b66a84a

File tree

4 files changed

+1091
-49
lines changed

4 files changed

+1091
-49
lines changed

Cargo.lock

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

sim-lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ expanduser = "1.2.2"
1515
serde = { version="1.0.183", features=["derive"] }
1616
serde_json = "1.0.104"
1717
bitcoin = { version = "0.30.1", features=["serde"] }
18-
lightning = { version = "0.0.116" }
18+
lightning = { version = "0.0.121" }
1919
tonic_lnd = { package="fedimint-tonic-lnd", version="0.1.2", features=["lightningrpc", "routerrpc"]}
2020
tonic = { version = "0.8", features = ["tls", "transport"] }
2121
async-trait = "0.1.73"

sim-lib/src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ mod defined_activity;
2727
pub mod lnd;
2828
mod random_activity;
2929
mod serializers;
30+
pub mod sim_node;
3031
#[cfg(test)]
3132
mod test_utils;
3233

@@ -84,6 +85,37 @@ impl std::fmt::Display for NodeId {
8485
}
8586
}
8687

88+
/// Represents a short channel ID, expressed as a struct so that we can implement display for the trait.
89+
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)]
90+
pub struct ShortChannelID(u64);
91+
92+
/// Utility function to easily convert from u64 to `ShortChannelID`
93+
impl From<u64> for ShortChannelID {
94+
fn from(value: u64) -> Self {
95+
ShortChannelID(value)
96+
}
97+
}
98+
99+
/// Utility function to easily convert `ShortChannelID` into u64
100+
impl From<ShortChannelID> for u64 {
101+
fn from(scid: ShortChannelID) -> Self {
102+
scid.0
103+
}
104+
}
105+
106+
/// See https://github.com/lightning/bolts/blob/60de4a09727c20dea330f9ee8313034de6e50594/07-routing-gossip.md#definition-of-short_channel_id.
107+
impl std::fmt::Display for ShortChannelID {
108+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
109+
write!(
110+
f,
111+
"{}:{}:{}",
112+
(self.0 >> 40) as u32,
113+
((self.0 >> 16) & 0xFFFFFF) as u32,
114+
(self.0 & 0xFFFF) as u16,
115+
)
116+
}
117+
}
118+
87119
#[derive(Debug, Serialize, Deserialize, Clone)]
88120
pub struct SimParams {
89121
pub nodes: Vec<NodeConnection>,
@@ -133,6 +165,8 @@ pub enum SimulationError {
133165
FileError,
134166
#[error("{0}")]
135167
RandomActivityError(RandomActivityError),
168+
#[error("Simulated Network Error: {0}")]
169+
SimulatedNetworkError(String),
136170
}
137171

138172
#[derive(Debug, Error)]

0 commit comments

Comments
 (0)