Skip to content

Commit

Permalink
Merge pull request #165 from carlaKC/sim-node
Browse files Browse the repository at this point in the history
Add Ability to Run as Full Simulator
  • Loading branch information
carlaKC authored Mar 13, 2024
2 parents 736a5a9 + f155904 commit b66a84a
Show file tree
Hide file tree
Showing 4 changed files with 1,091 additions and 49 deletions.
67 changes: 19 additions & 48 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sim-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ expanduser = "1.2.2"
serde = { version="1.0.183", features=["derive"] }
serde_json = "1.0.104"
bitcoin = { version = "0.30.1", features=["serde"] }
lightning = { version = "0.0.116" }
lightning = { version = "0.0.121" }
tonic_lnd = { package="fedimint-tonic-lnd", version="0.1.2", features=["lightningrpc", "routerrpc"]}
tonic = { version = "0.8", features = ["tls", "transport"] }
async-trait = "0.1.73"
Expand Down
34 changes: 34 additions & 0 deletions sim-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mod defined_activity;
pub mod lnd;
mod random_activity;
mod serializers;
pub mod sim_node;
#[cfg(test)]
mod test_utils;

Expand Down Expand Up @@ -84,6 +85,37 @@ impl std::fmt::Display for NodeId {
}
}

/// Represents a short channel ID, expressed as a struct so that we can implement display for the trait.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)]
pub struct ShortChannelID(u64);

/// Utility function to easily convert from u64 to `ShortChannelID`
impl From<u64> for ShortChannelID {
fn from(value: u64) -> Self {
ShortChannelID(value)
}
}

/// Utility function to easily convert `ShortChannelID` into u64
impl From<ShortChannelID> for u64 {
fn from(scid: ShortChannelID) -> Self {
scid.0
}
}

/// See https://github.com/lightning/bolts/blob/60de4a09727c20dea330f9ee8313034de6e50594/07-routing-gossip.md#definition-of-short_channel_id.
impl std::fmt::Display for ShortChannelID {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}:{}:{}",
(self.0 >> 40) as u32,
((self.0 >> 16) & 0xFFFFFF) as u32,
(self.0 & 0xFFFF) as u16,
)
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct SimParams {
pub nodes: Vec<NodeConnection>,
Expand Down Expand Up @@ -133,6 +165,8 @@ pub enum SimulationError {
FileError,
#[error("{0}")]
RandomActivityError(RandomActivityError),
#[error("Simulated Network Error: {0}")]
SimulatedNetworkError(String),
}

#[derive(Debug, Error)]
Expand Down
Loading

0 comments on commit b66a84a

Please sign in to comment.