lightningdevkit
Version:
Lightning Development Kit
171 lines (170 loc) • 8.82 kB
text/typescript
import { Network } from '../enums/Network.mjs';
import { Option_u32Z } from '../structs/Option_u32Z.mjs';
import { UnsignedChannelAnnouncement } from '../structs/UnsignedChannelAnnouncement.mjs';
import { Logger } from '../structs/Logger.mjs';
import { NetworkUpdate } from '../structs/NetworkUpdate.mjs';
import { Option_UtxoLookupZ } from '../structs/Option_UtxoLookupZ.mjs';
import { Result_NoneLightningErrorZ } from '../structs/Result_NoneLightningErrorZ.mjs';
import { ChannelAnnouncement } from '../structs/ChannelAnnouncement.mjs';
import { ChannelUpdate } from '../structs/ChannelUpdate.mjs';
import { NodeAnnouncement } from '../structs/NodeAnnouncement.mjs';
import { Result_NetworkGraphDecodeErrorZ } from '../structs/Result_NetworkGraphDecodeErrorZ.mjs';
import { UnsignedChannelUpdate } from '../structs/UnsignedChannelUpdate.mjs';
import { UnsignedNodeAnnouncement } from '../structs/UnsignedNodeAnnouncement.mjs';
import { ChannelFeatures } from '../structs/ChannelFeatures.mjs';
import { ReadOnlyNetworkGraph } from '../structs/ReadOnlyNetworkGraph.mjs';
import { CommonBase } from './CommonBase.mjs';
/**
* Represents the network as nodes and channels between them
*/
export declare class NetworkGraph extends CommonBase {
/**
* Handles any network updates originating from [`Event`]s.
*
* [`Event`]: crate::events::Event
*/
handle_network_update(network_update: NetworkUpdate): void;
/**
* Gets the chain hash for this network graph.
*/
get_chain_hash(): Uint8Array;
/**
* Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
*/
write(): Uint8Array;
/**
* Read a NetworkGraph from a byte array, created by NetworkGraph_write
*/
static constructor_read(ser: Uint8Array, arg: Logger): Result_NetworkGraphDecodeErrorZ;
/**
* Get the string representation of a NetworkGraph object
*/
to_str(): string;
/**
* Creates a new, empty, network graph.
*/
static constructor_new(network: Network, logger: Logger): NetworkGraph;
/**
* Returns a read-only view of the network graph.
*/
read_only(): ReadOnlyNetworkGraph;
/**
* The unix timestamp provided by the most recent rapid gossip sync.
* It will be set by the rapid sync process after every sync completion.
*/
get_last_rapid_gossip_sync_timestamp(): Option_u32Z;
/**
* Update the unix timestamp provided by the most recent rapid gossip sync.
* This should be done automatically by the rapid sync process after every sync completion.
*/
set_last_rapid_gossip_sync_timestamp(last_rapid_gossip_sync_timestamp: number): void;
/**
* For an already known node (from channel announcements), update its stored properties from a
* given node announcement.
*
* You probably don't want to call this directly, instead relying on a P2PGossipSync's
* RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
* routing messages from a source using a protocol other than the lightning P2P protocol.
*/
update_node_from_announcement(msg: NodeAnnouncement): Result_NoneLightningErrorZ;
/**
* For an already known node (from channel announcements), update its stored properties from a
* given node announcement without verifying the associated signatures. Because we aren't
* given the associated signatures here we cannot relay the node announcement to any of our
* peers.
*/
update_node_from_unsigned_announcement(msg: UnsignedNodeAnnouncement): Result_NoneLightningErrorZ;
/**
* Store or update channel info from a channel announcement.
*
* You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s
* [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept
* routing messages from a source using a protocol other than the lightning P2P protocol.
*
* If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify
* the corresponding UTXO exists on chain and is correctly-formatted.
*/
update_channel_from_announcement(msg: ChannelAnnouncement, utxo_lookup: Option_UtxoLookupZ): Result_NoneLightningErrorZ;
/**
* Store or update channel info from a channel announcement.
*
* You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s
* [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept
* routing messages from a source using a protocol other than the lightning P2P protocol.
*
* This will skip verification of if the channel is actually on-chain.
*/
update_channel_from_announcement_no_lookup(msg: ChannelAnnouncement): Result_NoneLightningErrorZ;
/**
* Store or update channel info from a channel announcement without verifying the associated
* signatures. Because we aren't given the associated signatures here we cannot relay the
* channel announcement to any of our peers.
*
* If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify
* the corresponding UTXO exists on chain and is correctly-formatted.
*/
update_channel_from_unsigned_announcement(msg: UnsignedChannelAnnouncement, utxo_lookup: Option_UtxoLookupZ): Result_NoneLightningErrorZ;
/**
* Update channel from partial announcement data received via rapid gossip sync
*
* `timestamp: u64`: Timestamp emulating the backdated original announcement receipt (by the
* rapid gossip sync server)
*
* All other parameters as used in [`msgs::UnsignedChannelAnnouncement`] fields.
*/
add_channel_from_partial_announcement(short_channel_id: bigint, timestamp: bigint, features: ChannelFeatures, node_id_1: Uint8Array, node_id_2: Uint8Array): Result_NoneLightningErrorZ;
/**
* Marks a channel in the graph as failed permanently.
*
* The channel and any node for which this was their last channel are removed from the graph.
*/
channel_failed_permanent(short_channel_id: bigint): void;
/**
* Marks a node in the graph as permanently failed, effectively removing it and its channels
* from local storage.
*/
node_failed_permanent(node_id: Uint8Array): void;
/**
* Removes information about channels that we haven't heard any updates about in some time.
* This can be used regularly to prune the network graph of channels that likely no longer
* exist.
*
* While there is no formal requirement that nodes regularly re-broadcast their channel
* updates every two weeks, the non-normative section of BOLT 7 currently suggests that
* pruning occur for updates which are at least two weeks old, which we implement here.
*
* This method will also cause us to stop tracking removed nodes and channels if they have been
* in the map for a while so that these can be resynced from gossip in the future.
*/
remove_stale_channels_and_tracking_with_time(current_time_unix: bigint): void;
/**
* For an already known (from announcement) channel, update info about one of the directions
* of the channel.
*
* You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s
* [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept
* routing messages from a source using a protocol other than the lightning P2P protocol.
*
* If not built with `std`, any updates with a timestamp more than two weeks in the past or
* materially in the future will be rejected.
*/
update_channel(msg: ChannelUpdate): Result_NoneLightningErrorZ;
/**
* For an already known (from announcement) channel, update info about one of the directions
* of the channel without verifying the associated signatures. Because we aren't given the
* associated signatures here we cannot relay the channel update to any of our peers.
*
* If not built with `std`, any updates with a timestamp more than two weeks in the past or
* materially in the future will be rejected.
*/
update_channel_unsigned(msg: UnsignedChannelUpdate): Result_NoneLightningErrorZ;
/**
* For an already known (from announcement) channel, verify the given [`ChannelUpdate`].
*
* This checks whether the update currently is applicable by [`Self::update_channel`].
*
* If not built with `std`, any updates with a timestamp more than two weeks in the past or
* materially in the future will be rejected.
*/
verify_channel_update(msg: ChannelUpdate): Result_NoneLightningErrorZ;
}