pub struct SimulatedChannel { /* private fields */ }
Expand description
Represents a simulated channel, and is responsible for managing addition and removal of HTLCs from the channel and sanity checks. Channel state is tracked unidirectionally for each participant in the channel.
Each node represented in the channel tracks only its outgoing HTLCs, and balance is transferred between the two nodes as they settle or fail. Given some channel: node_1 <––> node_2:
- HTLC sent node_1 -> node_2: added to in-flight outgoing htlcs on node_1.
- HTLC sent node_2 -> node_1: added to in-flight outgoing htlcs on node_2.
Rules for managing balance are as follows:
- When an HTLC is in flight, the channel’s local outgoing liquidity decreases (as it’s locked up).
- When an HTLC fails, the balance is returned to the local node (the one that it was in-flight / outgoing on).
- When an HTLC succeeds, the balance is sent to the remote node (the one that did not track it as in-flight).
With each state transition, the simulated channel checks that the sum of its local balances and in-flight equal the total channel capacity. Failure of this sanity check represents a critical failure in the state machine.
Implementations§
Source§impl SimulatedChannel
impl SimulatedChannel
Sourcepub fn new(
capacity_msat: u64,
short_channel_id: ShortChannelID,
node_1: ChannelPolicy,
node_2: ChannelPolicy,
) -> Self
pub fn new( capacity_msat: u64, short_channel_id: ShortChannelID, node_1: ChannelPolicy, node_2: ChannelPolicy, ) -> Self
Creates a new channel with the capacity and policies provided. The total capacity of the channel is evenly split between the channel participants (this is an arbitrary decision).
Trait Implementations§
Source§impl Clone for SimulatedChannel
impl Clone for SimulatedChannel
Source§fn clone(&self) -> SimulatedChannel
fn clone(&self) -> SimulatedChannel
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for SimulatedChannel
impl RefUnwindSafe for SimulatedChannel
impl Send for SimulatedChannel
impl Sync for SimulatedChannel
impl Unpin for SimulatedChannel
impl UnwindSafe for SimulatedChannel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request