Skip to content

Commit b18f692

Browse files
quakeCopilot
andcommitted
unify RPC public key field names
Rename node_id/public_key RPC output fields to pubkey, sync tests and fiber-js types, regenerate RPC docs, and simplify glossary wording. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 134b0fb commit b18f692

File tree

9 files changed

+30
-51
lines changed

9 files changed

+30
-51
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ async fn test_rpc_graph() {
299299
eprintln!("Graph nodes: {:#?}", graph_nodes);
300300

301301
assert!(!graph_nodes.nodes.is_empty());
302-
assert!(graph_nodes.nodes.iter().any(|n| n.node_id == node_1.pubkey));
302+
assert!(graph_nodes.nodes.iter().any(|n| n.pubkey == node_1.pubkey));
303303
assert!(graph_nodes
304304
.nodes
305305
.iter()
@@ -469,10 +469,10 @@ async fn test_rpc_node_info() {
469469
assert_eq!(node_info.default_funding_lock_script, Default::default());
470470
}
471471

472-
/// Test that node_id in node_info RPC and payee_public_key in invoice RPC
472+
/// Test that pubkey in node_info RPC and payee_public_key in invoice RPC
473473
/// have the same JSON format (both without "0x" prefix).
474474
#[tokio::test]
475-
async fn test_rpc_node_id_and_payee_public_key_same_format() {
475+
async fn test_rpc_pubkey_and_payee_public_key_same_format() {
476476
let (nodes, _channels) = create_n_nodes_network_with_params(
477477
&[(
478478
(0, 1),
@@ -491,9 +491,9 @@ async fn test_rpc_node_id_and_payee_public_key_same_format() {
491491

492492
// Get node_info raw response
493493
let node_info_raw = node_0.send_rpc_request_raw("node_info", ()).await.unwrap();
494-
let node_id = node_info_raw["node_id"]
494+
let pubkey = node_info_raw["pubkey"]
495495
.as_str()
496-
.expect("node_id should be a string");
496+
.expect("pubkey should be a string");
497497

498498
// Create an invoice and get raw response
499499
let new_invoice_params = NewInvoiceParams {
@@ -527,18 +527,18 @@ async fn test_rpc_node_id_and_payee_public_key_same_format() {
527527

528528
// Both should have the same format (without "0x" prefix)
529529
assert_eq!(
530-
node_id, payee_public_key,
531-
"node_id and payee_public_key should have the same format.\n\
532-
node_id: {}\n\
530+
pubkey, payee_public_key,
531+
"pubkey and payee_public_key should have the same format.\n\
532+
pubkey: {}\n\
533533
payee_public_key: {}",
534-
node_id, payee_public_key
534+
pubkey, payee_public_key
535535
);
536536

537537
// Verify neither has "0x" prefix
538538
assert!(
539-
!node_id.starts_with("0x"),
540-
"node_id should not have 0x prefix, got: {}",
541-
node_id
539+
!pubkey.starts_with("0x"),
540+
"pubkey should not have 0x prefix, got: {}",
541+
pubkey
542542
);
543543
assert!(
544544
!payee_public_key.starts_with("0x"),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl Privkey {
324324
}
325325

326326
/// 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`.
327+
/// In the RPC interface this value is exposed as fields such as `pubkey`.
328328
/// It is serialized as a 66-character hex string (e.g. `"02aaaa..."`) in JSON.
329329
///
330330
/// Note: `Pubkey` is different from `PeerId`. A `PeerId` is derived by hashing the

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ Get the node information.
515515

516516
* `version` - <em>`String`</em>, The version of the node software.
517517
* `commit_hash` - <em>`String`</em>, The commit hash of the node software.
518-
* `node_id` - <em>[Pubkey](#type-pubkey)</em>, The identity public key of this node (secp256k1 compressed, hex string).
518+
* `pubkey` - <em>[Pubkey](#type-pubkey)</em>, The identity public key of this node (secp256k1 compressed, hex string).
519519
This is the same value referred to as `pubkey` in `list_peers` responses.
520520
Note: this is different from `peer_id`, which is a base58 hash derived from this key.
521521
* `features` - <em>`Vec<String>`</em>, The features supported by the node.
@@ -1370,7 +1370,7 @@ The Node information.
13701370
* `version` - <em>`String`</em>, The version of the node.
13711371
* `addresses` - <em>`Vec<MultiAddr>`</em>, The addresses of the node.
13721372
* `features` - <em>`Vec<String>`</em>, The node features supported by the node.
1373-
* `node_id` - <em>[Pubkey](#type-pubkey)</em>, The identity public key of the node (secp256k1 compressed, hex string), same as `pubkey` in `list_peers`.
1373+
* `pubkey` - <em>[Pubkey](#type-pubkey)</em>, The identity public key of the node (secp256k1 compressed, hex string), same as `pubkey` in `list_peers`.
13741374
* `timestamp` - <em>`u64`</em>, The latest timestamp set by the owner for the node announcement.
13751375
When a Node is online this timestamp will be updated to the latest value.
13761376
* `chain_hash` - <em>[Hash256](#type-hash256)</em>, The chain hash of the node.
@@ -1428,7 +1428,7 @@ The information about a peer connected to the node.
14281428

14291429
#### Fields
14301430

1431-
* `pubkey` - <em>[Pubkey](#type-pubkey)</em>, The identity public key of the peer (also known as `node_id`).
1431+
* `pubkey` - <em>[Pubkey](#type-pubkey)</em>, The identity public key of the peer.
14321432
* `address` - <em>`MultiAddr`</em>, The multi-address associated with the connecting peer.
14331433
Note: this is only the address which used for connecting to the peer, not all addresses of the peer.
14341434
The `graph_nodes` in Graph rpc module will return all addresses of the peer.
@@ -1447,7 +1447,7 @@ A wrapper for secp256k1 secret key
14471447
### Type `Pubkey`
14481448

14491449
A compressed secp256k1 public key (33 bytes), used as the primary identity of a node.
1450-
In the RPC interface this value is also referred to as `node_id`.
1450+
In the RPC interface this value is exposed as fields such as `pubkey`.
14511451
It is serialized as a 66-character hex string (e.g. `"02aaaa..."`) in JSON.
14521452

14531453
Note: `Pubkey` is different from `PeerId`. A `PeerId` is derived by hashing the

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub struct NodeInfo {
146146
/// The node features supported by the node.
147147
pub features: Vec<String>,
148148
/// The identity public key of the node (secp256k1 compressed, hex string), same as `pubkey` in `list_peers`.
149-
pub node_id: Pubkey,
149+
pub pubkey: Pubkey,
150150
#[serde_as(as = "U64Hex")]
151151
/// The latest timestamp set by the owner for the node announcement.
152152
/// When a Node is online this timestamp will be updated to the latest value.
@@ -166,7 +166,7 @@ impl From<super::super::fiber::graph::NodeInfo> for NodeInfo {
166166
node_name: value.node_name.to_string(),
167167
version: value.version,
168168
addresses: value.addresses,
169-
node_id: value.node_id,
169+
pubkey: value.node_id,
170170
timestamp: value.timestamp,
171171
features: value.features.enabled_features_names(),
172172
chain_hash: get_chain_hash(),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct NodeInfoResult {
3030
/// The identity public key of this node (secp256k1 compressed, hex string).
3131
/// This is the same value referred to as `pubkey` in `list_peers` responses.
3232
/// Note: this is different from `peer_id`, which is a base58 hash derived from this key.
33-
pub node_id: Pubkey,
33+
pub pubkey: Pubkey,
3434

3535
/// The features supported by the node.
3636
pub features: Vec<String>,
@@ -137,7 +137,7 @@ impl InfoRpcServerImpl {
137137
version,
138138
commit_hash,
139139
features: response.features.enabled_features_names(),
140-
node_id: response.node_id,
140+
pubkey: response.node_id,
141141
node_name: response.node_name.map(|name| name.to_string()),
142142
addresses: response.addresses,
143143
chain_hash: response.chain_hash,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct DisconnectPeerParams {
3131
/// The information about a peer connected to the node.
3232
#[derive(Debug, Clone, Serialize, Deserialize)]
3333
pub struct PeerInfo {
34-
/// The identity public key of the peer (also known as `node_id`).
34+
/// The identity public key of the peer.
3535
pub pubkey: Pubkey,
3636

3737
/// The multi-address associated with the connecting peer.

docs/glossary.md

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,12 @@ The "Asset Handling Fee." Intermediate nodes lock up their own liquidity to forw
4444
## Watchtower
4545
Your "Asset Bodyguard." Since channel asset states are stored off-chain, a dishonest partner might try to broadcast an "old agreement" to steal funds while you are offline. A Watchtower monitors the CKB chain 24/7 and automatically intercepts any cheating attempts, punishing the attacker.
4646

47-
## Node Identifiers: Pubkey, Node ID, and Peer ID
47+
## Node Identifiers: Pubkey and Peer ID
4848

49-
A Fiber node has two forms of identity. They look different, serve different purposes, and are **not interchangeable** in RPC calls.
49+
Fiber uses two identity forms:
5050

51-
### Pubkey (aka Node ID)
51+
- **Pubkey**: a 33-byte compressed secp256k1 public key (66-char hex), e.g. `"02ab1234..."`.
52+
- **Peer ID**: a base58 transport identifier derived from the pubkey.
5253

53-
A 33-byte compressed secp256k1 public key, displayed as a 66-character hex string (e.g. `"02ab1234..."`). This is the cryptographic identity of a node. In the RPC interface it appears under several field names depending on context:
54-
55-
| RPC Field | Used In |
56-
|-----------|---------|
57-
| `node_id` | `node_info`, `graph_nodes` |
58-
| `pubkey` | `list_peers`, `graph_nodes`, `hop_hints` |
59-
| `target_pubkey` | `send_payment` |
60-
| `node1` / `node2` | `graph_channels` |
61-
62-
All of the above are the same type (`Pubkey`) and can be used wherever a `Pubkey` is expected.
63-
64-
### Peer ID
65-
66-
A base58-encoded string (e.g. `"QmYJnK7..."`), derived by **hashing** the node's `Pubkey`. This is used by the P2P transport layer to identify network connections. The derivation is one-way: you cannot recover a `Pubkey` from a `Peer ID`.
67-
68-
| RPC Field | Used In |
69-
|-----------|---------|
70-
| `peer_id` | `open_channel`, `list_channels`, `disconnect_peer`, `list_peers` |
71-
72-
### Which One to Use?
73-
74-
- **Payment-related RPCs** (`send_payment`, `build_router`, etc.) expect a **`Pubkey`** (hex).
75-
- **Connection/channel management RPCs** (`open_channel`, `disconnect_peer`, etc.) expect a **`Peer ID`** (base58).
76-
- The `list_peers` RPC returns **both** `pubkey` and `peer_id` for each connected peer, making it easy to look up either value.
54+
For RPC usage, treat **`pubkey` as the standard node identity**.
55+
`Peer ID` is mainly an internal/P2P transport identifier and is generally not what you pass around in normal RPC workflows.

fiber-js/src/types/graph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type UdtCfgInfos = UdtArgInfo[];
3939
interface NodeInfo {
4040
node_name: string;
4141
addresses: string[];
42-
node_id: HexString;
42+
pubkey: HexString;
4343
timestamp: HexString;
4444
chain_hash: HexString;
4545
auto_accept_min_ckb_funding_amount: HexString;

fiber-js/src/types/info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { UdtCfgInfos } from "./graph";
55
interface NodeInfoResult {
66
version: string;
77
commit_hash: string;
8-
node_id: string;
8+
pubkey: string;
99
node_name?: string;
1010
addresses: string[];
1111
chain_hash: HexString;

0 commit comments

Comments
 (0)