You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: crates/fiber-lib/src/rpc/README.md
+44-16Lines changed: 44 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -202,7 +202,9 @@ Attempts to open a channel with a peer.
202
202
203
203
##### Params
204
204
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.
206
208
*`funding_amount` - <em>`u128`</em>, The amount of CKB or UDT to fund the channel with.
207
209
*`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.
208
210
*`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.
296
298
297
299
##### Params
298
300
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.
300
303
*`include_closed` - <em>`Option<bool>`</em>, Whether to include closed channels in the list, an optional parameter, default value is false
301
304
*`only_pending` - <em>`Option<bool>`</em>, When set to true, only return channels that are still being opened (non-final states:
*`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.
680
692
*`custom_records` - <em>Option<[PaymentCustomRecords](#type-paymentcustomrecords)></em>, Some custom records for the payment which contains a map of u32 to Vec<u8>
681
693
The key is the record type, and the value is the serialized data
682
694
For example:
@@ -783,9 +795,19 @@ Builds a router with a list of pubkeys and required channels.
783
795
<aid="payment-send_payment_with_router"></a>
784
796
#### Method `send_payment_with_router`
785
797
786
-
Sends a payment to a peer with specified router
798
+
Sends a payment to a peer with specified router.
787
799
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.
789
811
790
812
##### Params
791
813
@@ -865,7 +887,7 @@ Disconnect from a peer.
865
887
866
888
##### Params
867
889
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`).
869
891
870
892
##### Returns
871
893
@@ -1122,7 +1144,7 @@ The channel data structure
1122
1144
*`is_one_way` - <em>`bool`</em>, Is this channel one-way?
1123
1145
Combines with is_acceptor to determine if the channel able to send payment to the counterparty or not.
1124
1146
*`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`).
1126
1148
*`funding_udt_type_script` - <em>`Option<Script>`</em>, The UDT type script of the channel
1127
1149
*`state` - <em>[ChannelState](#type-channelstate)</em>, The state of the channel
1128
1150
*`local_balance` - <em>`u128`</em>, The local balance of the channel
@@ -1155,8 +1177,8 @@ The Channel information.
1155
1177
#### Fields
1156
1178
1157
1179
*`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).
1160
1182
*`created_timestamp` - <em>`u64`</em>, The created timestamp of the channel, which is the block header timestamp of the block
1161
1183
that contains the channel funding transaction.
1162
1184
*`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.
1349
1371
*`version` - <em>`String`</em>, The version of the node.
1350
1372
*`addresses` - <em>`Vec<MultiAddr>`</em>, The addresses of the node.
1351
1373
*`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`.
1353
1375
*`timestamp` - <em>`u64`</em>, The latest timestamp set by the owner for the node announcement.
1354
1376
When a Node is online this timestamp will be updated to the latest value.
1355
1377
*`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.
1407
1429
1408
1430
#### Fields
1409
1431
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`.
1412
1435
*`address` - <em>`MultiAddr`</em>, The multi-address associated with the connecting peer.
1413
1436
Note: this is only the address which used for connecting to the peer, not all addresses of the peer.
1414
1437
The `graph_nodes` in Graph rpc module will return all addresses of the peer.
@@ -1426,8 +1449,13 @@ A wrapper for secp256k1 secret key
1426
1449
<aid="#type-pubkey"></a>
1427
1450
### Type `Pubkey`
1428
1451
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
0 commit comments