Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ability to Run as Full Simulator #2

Open
wants to merge 7 commits into
base: bitcoin-dev-project-fresheyes-staging-main-165
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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