Skip to content

Commit 6120a71

Browse files
committed
docs: improve RPC docs for node identifiers and channel rebalancing
Clarify the distinction between Pubkey (secp256k1 hex) and PeerId (base58 hash) across all RPC doc comments and regenerate README.md. Add detailed documentation for channel rebalancing via send_payment and send_payment_with_router. Add a glossary section explaining node identifier types and a standalone channel-rebalancing guide.
1 parent 34c95d0 commit 6120a71

File tree

10 files changed

+231
-34
lines changed

10 files changed

+231
-34
lines changed

crates/fiber-lib/src/fiber/network.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,11 @@ pub struct NodeInfoResponse {
260260
#[serde_as]
261261
#[derive(Clone, Serialize, Deserialize, Debug)]
262262
pub struct PeerInfo {
263-
/// The identity public key of the peer.
263+
/// The identity public key of the peer (also known as `node_id`).
264264
pub pubkey: Pubkey,
265265

266-
/// The peer ID of the peer
266+
/// The peer ID of the peer (base58 string, derived by hashing the `pubkey` above).
267+
/// This is used for P2P transport connections, e.g. when calling `open_channel` or `disconnect_peer`.
267268
#[serde_as(as = "DisplayFromStr")]
268269
pub peer_id: PeerId,
269270

crates/fiber-lib/src/fiber/types.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,13 @@ impl Privkey {
323323
}
324324
}
325325

326-
/// The public key for a Node
327-
/// It stores the serialized form ([u8; 33]) directly for fast comparison and hashing
326+
/// A compressed secp256k1 public key (33 bytes), used as the primary identity of a node.
327+
/// In the RPC interface this value is also referred to as `node_id`.
328+
/// It is serialized as a 66-character hex string (e.g. `"02aaaa..."`) in JSON.
329+
///
330+
/// Note: `Pubkey` is different from `PeerId`. A `PeerId` is derived by hashing the
331+
/// public key and is used only for P2P transport connections. You can obtain both
332+
/// values from the `list_peers` or `node_info` RPC.
328333
#[serde_as]
329334
#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Serialize, Deserialize)]
330335
pub struct Pubkey(#[serde_as(as = "IfIsHumanReadable<SliceHexNoPrefix, [_; 33]>")] pub [u8; 33]);

crates/fiber-lib/src/rpc/README.md

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ Attempts to open a channel with a peer.
202202

203203
##### Params
204204

205-
* `peer_id` - <em>`PeerId`</em>, The peer ID to open a channel with, the peer must be connected through the [connect_peer](#peer-connect_peer) rpc first.
205+
* `peer_id` - <em>`PeerId`</em>, The peer ID to open a channel with (base58 string, derived from the peer's `Pubkey`).
206+
The peer must be connected through the [connect_peer](#peer-connect_peer) rpc first.
207+
You can obtain a peer's `peer_id` from the `list_peers` RPC.
206208
* `funding_amount` - <em>`u128`</em>, The amount of CKB or UDT to fund the channel with.
207209
* `public` - <em>`Option<bool>`</em>, Whether this is a public channel (will be broadcasted to network, and can be used to forward TLCs), an optional parameter, default value is true.
208210
* `one_way` - <em>`Option<bool>`</em>, Whether this is a one-way channel (will not be broadcasted to network, and can only be used to send payment one way), an optional parameter, default value is false.
@@ -296,7 +298,8 @@ Lists all channels.
296298

297299
##### Params
298300

299-
* `peer_id` - <em>`Option<PeerId>`</em>, The peer ID to list channels for, an optional parameter, if not provided, all channels will be listed
301+
* `peer_id` - <em>`Option<PeerId>`</em>, The peer ID to list channels for (base58 string, derived from the peer's `Pubkey`).
302+
An optional parameter, if not provided, all channels will be listed.
300303
* `include_closed` - <em>`Option<bool>`</em>, Whether to include closed channels in the list, an optional parameter, default value is false
301304
* `only_pending` - <em>`Option<bool>`</em>, When set to true, only return channels that are still being opened (non-final states:
302305
negotiating, collaborating on funding tx, signing, awaiting tx signatures, awaiting channel
@@ -513,7 +516,9 @@ Get the node information.
513516

514517
* `version` - <em>`String`</em>, The version of the node software.
515518
* `commit_hash` - <em>`String`</em>, The commit hash of the node software.
516-
* `node_id` - <em>[Pubkey](#type-pubkey)</em>, The identity public key of the node.
519+
* `node_id` - <em>[Pubkey](#type-pubkey)</em>, The identity public key of this node (secp256k1 compressed, hex string).
520+
This is the same value referred to as `pubkey` in `list_peers` responses.
521+
Note: this is different from `peer_id`, which is a base58 hash derived from this key.
517522
* `features` - <em>`Vec<String>`</em>, The features supported by the node.
518523
* `node_name` - <em>`Option<String>`</em>, The optional name of the node.
519524
* `addresses` - <em>`Vec<MultiAddr>`</em>, A list of multi-addresses associated with the node.
@@ -653,7 +658,9 @@ Sends a payment to a peer.
653658

654659
##### Params
655660

656-
* `target_pubkey` - <em>Option<[Pubkey](#type-pubkey)></em>, the identifier of the payment target
661+
* `target_pubkey` - <em>Option<[Pubkey](#type-pubkey)></em>, The public key (`Pubkey`) of the payment target node, serialized as a hex string.
662+
You can obtain a node's pubkey via the `node_info` or `graph_nodes` RPC.
663+
Note: this is the `Pubkey` (secp256k1 public key), not the `PeerId`.
657664
* `amount` - <em>`Option<u128>`</em>, the amount of the payment, the unit is Shannons for non UDT payment
658665
If not set and there is a invoice, the amount will be set to the invoice amount
659666
* `payment_hash` - <em>Option<[Hash256](#type-hash256)></em>, the hash to use within the payment's HTLC.
@@ -676,7 +683,12 @@ Sends a payment to a peer.
676683
payer to `t1`, and the inner trampoline onion will encode `t1 -> t2 -> ... -> final`.
677684
* `keysend` - <em>`Option<bool>`</em>, keysend payment
678685
* `udt_type_script` - <em>`Option<Script>`</em>, udt type script for the payment
679-
* `allow_self_payment` - <em>`Option<bool>`</em>, allow self payment, default is false
686+
* `allow_self_payment` - <em>`Option<bool>`</em>, Allow paying yourself through a circular route, default is false.
687+
This is useful for **channel rebalancing**: the payment flows out of one channel and
688+
back through another, shifting liquidity between your channels without changing your
689+
total balance (only routing fees are deducted).
690+
Set `target_pubkey` to your own node pubkey and `keysend` to `true` to perform a rebalance.
691+
Note: `allow_self_payment` is not compatible with trampoline routing.
680692
* `custom_records` - <em>Option<[PaymentCustomRecords](#type-paymentcustomrecords)></em>, Some custom records for the payment which contains a map of u32 to Vec<u8>
681693
The key is the record type, and the value is the serialized data
682694
For example:
@@ -783,9 +795,19 @@ Builds a router with a list of pubkeys and required channels.
783795
<a id="payment-send_payment_with_router"></a>
784796
#### Method `send_payment_with_router`
785797

786-
Sends a payment to a peer with specified router
798+
Sends a payment to a peer with specified router.
787799
This method differs from SendPayment in that it allows users to specify a full route manually.
788-
This can be used for things like rebalancing.
800+
801+
A typical use case is **channel rebalancing**: you can construct a circular route
802+
(your node -> intermediate nodes -> your node) to shift liquidity between your channels.
803+
804+
To rebalance, follow these steps:
805+
806+
1. Call `build_router` with `hops_info` defining the circular route you want,
807+
e.g. your_node -> peer_A -> peer_B -> your_node.
808+
2. Call `send_payment_with_router` with the returned `router_hops` and `keysend: true`.
809+
810+
Only routing fees are deducted; your total balance across channels remains the same.
789811

790812
##### Params
791813

@@ -865,7 +887,7 @@ Disconnect from a peer.
865887

866888
##### Params
867889

868-
* `peer_id` - <em>`PeerId`</em>, The peer ID of the peer to disconnect.
890+
* `peer_id` - <em>`PeerId`</em>, The peer ID of the peer to disconnect (base58 string, derived from the peer's `Pubkey`).
869891

870892
##### Returns
871893

@@ -1122,7 +1144,7 @@ The channel data structure
11221144
* `is_one_way` - <em>`bool`</em>, Is this channel one-way?
11231145
Combines with is_acceptor to determine if the channel able to send payment to the counterparty or not.
11241146
* `channel_outpoint` - <em>`Option<OutPoint>`</em>, The outpoint of the channel
1125-
* `peer_id` - <em>`PeerId`</em>, The peer ID of the channel
1147+
* `peer_id` - <em>`PeerId`</em>, The peer ID of the channel counterparty (base58 string, derived from the peer's `Pubkey`).
11261148
* `funding_udt_type_script` - <em>`Option<Script>`</em>, The UDT type script of the channel
11271149
* `state` - <em>[ChannelState](#type-channelstate)</em>, The state of the channel
11281150
* `local_balance` - <em>`u128`</em>, The local balance of the channel
@@ -1155,8 +1177,8 @@ The Channel information.
11551177
#### Fields
11561178

11571179
* `channel_outpoint` - <em>`OutPoint`</em>, The outpoint of the channel.
1158-
* `node1` - <em>[Pubkey](#type-pubkey)</em>, The identity public key of the first node.
1159-
* `node2` - <em>[Pubkey](#type-pubkey)</em>, The identity public key of the second node.
1180+
* `node1` - <em>[Pubkey](#type-pubkey)</em>, The identity public key of the first node (secp256k1 compressed, hex string).
1181+
* `node2` - <em>[Pubkey](#type-pubkey)</em>, The identity public key of the second node (secp256k1 compressed, hex string).
11601182
* `created_timestamp` - <em>`u64`</em>, The created timestamp of the channel, which is the block header timestamp of the block
11611183
that contains the channel funding transaction.
11621184
* `update_info_of_node1` - <em>Option<[ChannelUpdateInfo](#type-channelupdateinfo)></em>, The update info from node1 to node2, e.g. timestamp, fee_rate, tlc_expiry_delta, tlc_minimum_value
@@ -1349,7 +1371,7 @@ The Node information.
13491371
* `version` - <em>`String`</em>, The version of the node.
13501372
* `addresses` - <em>`Vec<MultiAddr>`</em>, The addresses of the node.
13511373
* `features` - <em>`Vec<String>`</em>, The node features supported by the node.
1352-
* `node_id` - <em>[Pubkey](#type-pubkey)</em>, The identity public key of the node.
1374+
* `node_id` - <em>[Pubkey](#type-pubkey)</em>, The identity public key of the node (secp256k1 compressed, hex string), same as `pubkey` in `list_peers`.
13531375
* `timestamp` - <em>`u64`</em>, The latest timestamp set by the owner for the node announcement.
13541376
When a Node is online this timestamp will be updated to the latest value.
13551377
* `chain_hash` - <em>[Hash256](#type-hash256)</em>, The chain hash of the node.
@@ -1407,8 +1429,9 @@ The information about a peer connected to the node.
14071429

14081430
#### Fields
14091431

1410-
* `pubkey` - <em>[Pubkey](#type-pubkey)</em>, The identity public key of the peer.
1411-
* `peer_id` - <em>`PeerId`</em>, The peer ID of the peer
1432+
* `pubkey` - <em>[Pubkey](#type-pubkey)</em>, The identity public key of the peer (also known as `node_id`).
1433+
* `peer_id` - <em>`PeerId`</em>, The peer ID of the peer (base58 string, derived by hashing the `pubkey` above).
1434+
This is used for P2P transport connections, e.g. when calling `open_channel` or `disconnect_peer`.
14121435
* `address` - <em>`MultiAddr`</em>, The multi-address associated with the connecting peer.
14131436
Note: this is only the address which used for connecting to the peer, not all addresses of the peer.
14141437
The `graph_nodes` in Graph rpc module will return all addresses of the peer.
@@ -1426,8 +1449,13 @@ A wrapper for secp256k1 secret key
14261449
<a id="#type-pubkey"></a>
14271450
### Type `Pubkey`
14281451

1429-
The public key for a Node
1430-
It stores the serialized form ([u8; 33]) directly for fast comparison and hashing
1452+
A compressed secp256k1 public key (33 bytes), used as the primary identity of a node.
1453+
In the RPC interface this value is also referred to as `node_id`.
1454+
It is serialized as a 66-character hex string (e.g. `"02aaaa..."`) in JSON.
1455+
1456+
Note: `Pubkey` is different from `PeerId`. A `PeerId` is derived by hashing the
1457+
public key and is used only for P2P transport connections. You can obtain both
1458+
values from the `list_peers` or `node_info` RPC.
14311459

14321460

14331461

crates/fiber-lib/src/rpc/channel.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ use tentacle::secio::PeerId;
3434
#[serde_as]
3535
#[derive(Serialize, Deserialize, Debug)]
3636
pub struct OpenChannelParams {
37-
/// The peer ID to open a channel with, the peer must be connected through the [connect_peer](#peer-connect_peer) rpc first.
37+
/// The peer ID to open a channel with (base58 string, derived from the peer's `Pubkey`).
38+
/// The peer must be connected through the [connect_peer](#peer-connect_peer) rpc first.
39+
/// You can obtain a peer's `peer_id` from the `list_peers` RPC.
3840
#[serde_as(as = "DisplayFromStr")]
3941
pub peer_id: PeerId,
4042

@@ -162,7 +164,8 @@ pub struct AcceptChannelResult {
162164
#[serde_as]
163165
#[derive(Serialize, Deserialize)]
164166
pub struct ListChannelsParams {
165-
/// The peer ID to list channels for, an optional parameter, if not provided, all channels will be listed
167+
/// The peer ID to list channels for (base58 string, derived from the peer's `Pubkey`).
168+
/// An optional parameter, if not provided, all channels will be listed.
166169
#[serde_as(as = "Option<DisplayFromStr>")]
167170
pub peer_id: Option<PeerId>,
168171
/// Whether to include closed channels in the list, an optional parameter, default value is false
@@ -269,7 +272,7 @@ pub struct Channel {
269272
#[serde_as(as = "Option<EntityHex>")]
270273
/// The outpoint of the channel
271274
pub channel_outpoint: Option<OutPoint>,
272-
/// The peer ID of the channel
275+
/// The peer ID of the channel counterparty (base58 string, derived from the peer's `Pubkey`).
273276
#[serde_as(as = "DisplayFromStr")]
274277
pub peer_id: PeerId,
275278
/// The UDT type script of the channel

crates/fiber-lib/src/rpc/graph.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub struct NodeInfo {
145145
pub addresses: Vec<MultiAddr>,
146146
/// The node features supported by the node.
147147
pub features: Vec<String>,
148-
/// The identity public key of the node.
148+
/// The identity public key of the node (secp256k1 compressed, hex string), same as `pubkey` in `list_peers`.
149149
pub node_id: Pubkey,
150150
#[serde_as(as = "U64Hex")]
151151
/// The latest timestamp set by the owner for the node announcement.
@@ -201,9 +201,9 @@ pub struct ChannelInfo {
201201
/// The outpoint of the channel.
202202
#[serde_as(as = "EntityHex")]
203203
pub channel_outpoint: OutPoint,
204-
/// The identity public key of the first node.
204+
/// The identity public key of the first node (secp256k1 compressed, hex string).
205205
pub node1: Pubkey,
206-
/// The identity public key of the second node.
206+
/// The identity public key of the second node (secp256k1 compressed, hex string).
207207
pub node2: Pubkey,
208208
/// The created timestamp of the channel, which is the block header timestamp of the block
209209
/// that contains the channel funding transaction.

crates/fiber-lib/src/rpc/info.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ pub struct NodeInfoResult {
2727
/// The commit hash of the node software.
2828
pub commit_hash: String,
2929

30-
/// The identity public key of the node.
30+
/// The identity public key of this node (secp256k1 compressed, hex string).
31+
/// This is the same value referred to as `pubkey` in `list_peers` responses.
32+
/// Note: this is different from `peer_id`, which is a base58 hash derived from this key.
3133
pub node_id: Pubkey,
3234

3335
/// The features supported by the node.

crates/fiber-lib/src/rpc/payment.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ impl From<PaymentCustomRecords> for crate::fiber::PaymentCustomRecords {
9797
#[serde_as]
9898
#[derive(Clone, Debug, Serialize, Deserialize)]
9999
pub struct SendPaymentCommandParams {
100-
/// the identifier of the payment target
100+
/// The public key (`Pubkey`) of the payment target node, serialized as a hex string.
101+
/// You can obtain a node's pubkey via the `node_info` or `graph_nodes` RPC.
102+
/// Note: this is the `Pubkey` (secp256k1 public key), not the `PeerId`.
101103
pub target_pubkey: Option<Pubkey>,
102104

103105
/// the amount of the payment, the unit is Shannons for non UDT payment
@@ -153,7 +155,12 @@ pub struct SendPaymentCommandParams {
153155
/// udt type script for the payment
154156
pub udt_type_script: Option<Script>,
155157

156-
/// allow self payment, default is false
158+
/// Allow paying yourself through a circular route, default is false.
159+
/// This is useful for **channel rebalancing**: the payment flows out of one channel and
160+
/// back through another, shifting liquidity between your channels without changing your
161+
/// total balance (only routing fees are deducted).
162+
/// Set `target_pubkey` to your own node pubkey and `keysend` to `true` to perform a rebalance.
163+
/// Note: `allow_self_payment` is not compatible with trampoline routing.
157164
pub allow_self_payment: Option<bool>,
158165

159166
/// Some custom records for the payment which contains a map of u32 to Vec<u8>
@@ -316,9 +323,19 @@ trait PaymentRpc {
316323
params: BuildRouterParams,
317324
) -> Result<BuildPaymentRouterResult, ErrorObjectOwned>;
318325

319-
/// Sends a payment to a peer with specified router
326+
/// Sends a payment to a peer with specified router.
320327
/// This method differs from SendPayment in that it allows users to specify a full route manually.
321-
/// This can be used for things like rebalancing.
328+
///
329+
/// A typical use case is **channel rebalancing**: you can construct a circular route
330+
/// (your node -> intermediate nodes -> your node) to shift liquidity between your channels.
331+
///
332+
/// To rebalance, follow these steps:
333+
///
334+
/// 1. Call `build_router` with `hops_info` defining the circular route you want,
335+
/// e.g. your_node -> peer_A -> peer_B -> your_node.
336+
/// 2. Call `send_payment_with_router` with the returned `router_hops` and `keysend: true`.
337+
///
338+
/// Only routing fees are deducted; your total balance across channels remains the same.
322339
#[method(name = "send_payment_with_router")]
323340
async fn send_payment_with_router(
324341
&self,
@@ -366,9 +383,9 @@ where
366383
self.build_router(params).await
367384
}
368385

369-
/// Sends a payment to a peer with specified router
386+
/// Sends a payment to a peer with specified router.
370387
/// This method differs from SendPayment in that it allows users to specify a full route manually.
371-
/// This can be used for things like rebalancing.
388+
/// This can be used for things like channel rebalancing.
372389
async fn send_payment_with_router(
373390
&self,
374391
params: SendPaymentWithRouterParams,

crates/fiber-lib/src/rpc/peer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct ConnectPeerParams {
2323
#[serde_as]
2424
#[derive(Serialize, Deserialize, Debug)]
2525
pub struct DisconnectPeerParams {
26-
/// The peer ID of the peer to disconnect.
26+
/// The peer ID of the peer to disconnect (base58 string, derived from the peer's `Pubkey`).
2727
#[serde_as(as = "DisplayFromStr")]
2828
pub peer_id: PeerId,
2929
}

0 commit comments

Comments
 (0)