Skip to content

Commit 545d0b7

Browse files
committed
Carry an optional fee claim in register_node
Adds an optional fee_claim string to RegisterNodeRequest so a node can present a signed grant when it registers. The field is hex of the SignedFeeClaim bytes from the previous commit. Nothing reads it yet; the service-side verify and persist land later. serde(default, skip_serializing_if = "Option::is_none") keeps the wire backward compatible both ways. An old client that sends {} still decodes to fee_claim: None through the existing params.unwrap_or(json!({})) path, and a node with no claim emits {} rather than an explicit null, so the request bytes match today exactly when no claim is set. The client constructs the request with fee_claim: None; only a node that has been granted a claim populates it, which is wired up in a later change.
1 parent b8aaab5 commit 545d0b7

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

lightning-liquidity/src/lsps4/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ where
109109
}
110110
}
111111

112-
let request = LSPS4Request::RegisterNode(RegisterNodeRequest {});
112+
let request = LSPS4Request::RegisterNode(RegisterNodeRequest { fee_claim: None });
113113
let msg = LSPS4Message::Request(request_id.clone(), request).into();
114114
let mut message_queue_notifier = self.pending_messages.notifier();
115115
message_queue_notifier.enqueue(&counterparty_node_id, msg);

lightning-liquidity/src/lsps4/msgs.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ pub(crate) const LSPS4_REGISTER_NODE_METHOD_NAME: &str = "lsps4.register_node";
2222

2323
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
2424
/// A request made to an LSP to register a node.
25-
pub struct RegisterNodeRequest {}
25+
pub struct RegisterNodeRequest {
26+
/// An optional signed claim, lowercase-hex encoded, granting this node a
27+
/// non-standard fee policy. Absent or unverifiable claims leave the node on
28+
/// the standard policy.
29+
#[serde(default, skip_serializing_if = "Option::is_none")]
30+
pub fee_claim: Option<String>,
31+
}
2632

2733
/// A newtype that holds a `short_channel_id` in human readable format of BBBxTTTx000.
2834
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
@@ -96,3 +102,32 @@ impl From<LSPS4Message> for LSPSMessage {
96102
LSPSMessage::LSPS4(message)
97103
}
98104
}
105+
106+
#[cfg(test)]
107+
mod tests {
108+
use super::*;
109+
use crate::alloc::string::ToString;
110+
111+
#[test]
112+
fn register_node_request_with_claim_round_trips() {
113+
let request = RegisterNodeRequest { fee_claim: Some("deadbeef".to_string()) };
114+
let json_str = r#"{"fee_claim":"deadbeef"}"#;
115+
116+
assert_eq!(json_str, serde_json::json!(request).to_string());
117+
assert_eq!(request, serde_json::from_str(json_str).unwrap());
118+
}
119+
120+
#[test]
121+
fn register_node_request_without_claim_omits_field() {
122+
let request = RegisterNodeRequest { fee_claim: None };
123+
124+
assert_eq!("{}", serde_json::json!(request).to_string());
125+
}
126+
127+
#[test]
128+
fn legacy_empty_object_decodes_to_no_claim() {
129+
let request: RegisterNodeRequest = serde_json::from_str("{}").unwrap();
130+
131+
assert_eq!(request, RegisterNodeRequest { fee_claim: None });
132+
}
133+
}

0 commit comments

Comments
 (0)