Struct NodeState

Source
pub struct NodeState {
    pub invoices: Map<PaymentHash, PaymentState>,
    pub issued_invoices: Map<PaymentHash, PaymentState>,
    pub payments: Map<PaymentHash, RoutedPayment>,
    pub excess_amount: u64,
    pub log_prefix: String,
    pub velocity_control: VelocityControl,
    pub fee_velocity_control: VelocityControl,
    pub last_summary: String,
    pub dbid_high_water_mark: u64,
}
Expand description

Enforcement state for a node

Fields§

§invoices: Map<PaymentHash, PaymentState>

Added invoices for outgoing payments indexed by their payment hash

§issued_invoices: Map<PaymentHash, PaymentState>

Issued invoices for incoming payments indexed by their payment hash

§payments: Map<PaymentHash, RoutedPayment>

Payment states. There is one entry for each invoice. Entries also exist for HTLCs we route.

§excess_amount: u64

Accumulator of excess payment amount in satoshi, for tracking certain payment corner cases. If this falls below zero, the attempted commit is failed.

§log_prefix: String

Prefix for emitted logs lines

§velocity_control: VelocityControl

Per node velocity control

§fee_velocity_control: VelocityControl

Per node fee velocity control

§last_summary: String

Last summary string

§dbid_high_water_mark: u64

dbid high water mark

Implementations§

Source§

impl NodeState

Source

pub fn new( velocity_control: VelocityControl, fee_velocity_control: VelocityControl, ) -> Self

Create a state

Source

pub fn restore( invoices_v: Vec<(Vec<u8>, PaymentState)>, issued_invoices_v: Vec<(Vec<u8>, PaymentState)>, preimages: Vec<[u8; 32]>, excess_amount: u64, velocity_control: VelocityControl, fee_velocity_control: VelocityControl, dbid_high_water_mark: u64, ) -> Self

Restore a state from persistence

Source

pub fn summary(&mut self) -> (String, bool)

Return a summary for debugging and whether it changed since last call

Source

pub fn validate_payments( &self, channel_id: &ChannelId, incoming_payment_summary: &Map<PaymentHash, u64>, outgoing_payment_summary: &Map<PaymentHash, u64>, balance_delta: &BalanceDelta, validator: Arc<dyn Validator>, ) -> Result<(), ValidationError>

Validate outgoing in-flight payment amounts as a result of a new commitment tx.

The following policies are checked:

  • no overpayment for any invoice.
  • Sends without invoices (e.g. keysend) are only allowed if policy.require_invoices is false.

The amounts are in satoshi.

Source

pub fn apply_payments( &mut self, channel_id: &ChannelId, incoming_payment_summary: &Map<PaymentHash, u64>, outgoing_payment_summary: &Map<PaymentHash, u64>, balance_delta: &BalanceDelta, validator: Arc<dyn Validator>, )

Apply outgoing in-flight payment amounts as a result of a new commitment tx. Must call NodeState::validate_payments first.

Source

pub fn htlc_fulfilled( &mut self, channel_id: &ChannelId, preimage: PaymentPreimage, validator: Arc<dyn Validator>, ) -> bool

Fulfills an HTLC. Performs bookkeeping on any invoice or routed payment with this payment hash.

Trait Implementations§

Source§

impl Debug for NodeState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PreimageMap for NodeState

Source§

fn has_preimage(&self, hash: &PaymentHash) -> bool

Whether a preimage is known for the payment hash

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more