fiber-types 0.9.0-rc2

Core domain types for the Fiber Network
Documentation
import blockchain;
import fiber;

array SchnorrSignature [byte; 64];
array SchnorrXOnlyPubkey [byte; 32];

// A cursor for the broadcast message. Consists of the following data
// timestamp (8 bytes in big-endian), union id (1 byte), message id (36 bytes)
// where message ID is defined as
// ChannelAnnouncement (union ID 0): channel_outpoint, 36 bytes
// ChannelUpdate (union ID 1): channel_outpoint, 36 bytes
// NodeAnnouncement (union ID 2): node_id 33 bytes padding 3 zero bytes
// All broadcast messages are sorted by Cursor in dictionary order,
// so whenever we pass a `after_cursor` parameter below, we want data that
// come after the `after_cursor` in dictionary order, which basically means that we
// need data after certain timestamp.
array Cursor [byte; 45];

// BroadcastMessageQuery is a query sent to another peer to query
// ChannelAnnouncement/ChannelUpdate/NodeAnnouncement messages related a channel outpoint.
// The `flags` is used to specify an array of bitfields. Bits have the following meaning:
// 0 	Sender wants ChannelAnnouncement
// 1 	Sender wants ChannelUpdate for node 1
// 2 	Sender wants ChannelUpdate for node 2
// 3 	Sender wants NodeAnnouncement for node 1
// 4 	Sender wants NodeAnnouncement for node 2
// The bit field order of these messages is the same to the union id order of cursors.
struct BroadcastMessageQuery {
    channel_outpoint: OutPoint,
    flags: byte,
}

vector BroadcastMessageQueries <BroadcastMessageQuery>;

// A NodeAnnouncement is a broadcast message to the network for the node information.
// An update to the node information can be broadcasted with a NodeAnnouncement with larger timestamp.
table NodeAnnouncement {
    // Signature to this message.
    signature: EcdsaSignature,
    features: Bytes,
    // Timestamp to the node announcement update, later update should have larger timestamp.
    timestamp: Uint64,
    node_id: Pubkey,
    version: Bytes,
    // Must be a valid utf-8 string of length maximal length 32 bytes.
    node_name: Byte32,
    // All the reachable addresses.
    address: BytesVec,
    // Chain hash
    chain_hash: Byte32,
    // Minimal auto accept ckb amount
    auto_accept_min_ckb_funding_amount: Uint64,
    // UDT configs
    udt_cfg_infos: UdtCfgInfos,
}

// A ChannelAnnouncement is an announcement of a channel to the network.
// This message must be immutable for any specific channel.
table ChannelAnnouncement {
    node1_signature: EcdsaSignature,
    node2_signature: EcdsaSignature,
    // Signature signed by the funding transaction output public key.
    ckb_signature: SchnorrSignature,
    // Tentatively using 64 bits for features. May change the type later while developing.
    // https://github.com/lightningdevkit/rust-lightning/blob/8c1b3d1263f6b9247c0c819039ef2027dc4d4588/lightning/src/ln/msgs.rs#L1200-L1200
    // rust-lightning uses a Vec<u8> here.
    features: Uint64,
    chain_hash: Byte32,
    channel_outpoint: OutPoint,
    node1_id: Pubkey,
    node2_id: Pubkey,
    // The aggregated public key of the funding transaction output.
    ckb_key: SchnorrXOnlyPubkey,
    capacity: Uint128,
    udt_type_script: ScriptOpt,
}

// All the broadcast messages.
union BroadcastMessage {
    NodeAnnouncement,
    ChannelAnnouncement,
    ChannelUpdate,
}

vector BroadcastMessages <BroadcastMessage>;

vector MissingQueryIndexes <Uint16>;

// BroadcastMessagesFilter is used to instruct peer to broadcast messages to the sender.
// The sender must only send messages after the cursor specified in `after_cursor`.
// The sender should also send current broadcast message which are after the cursor immediately.
struct BroadcastMessagesFilter {
    chain_hash: Byte32,
    after_cursor: Cursor,
}

// GetBroadcastMessages is used to batch get broadcast messages from another peer.
// This is used in the initial sync process of a node. The node should repeatedly send GetBroadcastMessages
// to peers (with `after_cursor` replaced with the cursor of the latest data) until an empty result is returned.
// The difference between GetBroadcastMessages and QueryBroadcastMessages is that QueryBroadcastMessages
// will make some specific queries to some specific channels/nodes, while GetBroadcastMessages only gets
// messages after a cursor.
struct GetBroadcastMessages {
    id: Uint64,
    chain_hash: Byte32,
    after_cursor: Cursor,
    count: Uint16,
}

// To query some specific messages (e.g. a NodeAnnouncement) from peers.
// The difference between GetBroadcastMessages and QueryBroadcastMessages is that QueryBroadcastMessages
// will make some specific queries to some specific channels/nodes, while GetBroadcastMessages only gets
// messages after a cursor.
table QueryBroadcastMessages {
    id: Uint64,
    chain_hash: Byte32,
    queries: BroadcastMessageQueries,
}

// BroadcastMessagesFilterResult is the message to BroadcastMessagesFilter requests.
table BroadcastMessagesFilterResult {
    messages: BroadcastMessages,
}

// GetBroadcastMessagesResult is the response to GetBroadcastMessages requests.
// The id here corresponds to the id passed by the peer. This is used to track the progress of certain request.
table GetBroadcastMessagesResult {
    id: Uint64,
    messages: BroadcastMessages,
}

// QueryBroadcastMessagesResult is the response to QueryBroadcastMessages requests.
// The id here corresponds to the id passed by the peer. This is used to track the progress of certain request.
// The missing_queries here is used to indicate that the results corresponding to some queries can not be found
// by the remote peer. The request initiator should try another remote node for the missing data.
table QueryBroadcastMessagesResult {
    id: Uint64,
    messages: BroadcastMessages,
    missing_queries: MissingQueryIndexes,
}

union GossipMessage {
    BroadcastMessagesFilter,
    BroadcastMessagesFilterResult,
    GetBroadcastMessages,
    GetBroadcastMessagesResult,
    QueryBroadcastMessages,
    QueryBroadcastMessagesResult,
}