Skip to content

feat: allow setting custom preimage in spontaneous-send#233

Open
f3r10 wants to merge 1 commit into
lightningdevkit:mainfrom
f3r10:feat/custom_preimage_in_spontaneous_send
Open

feat: allow setting custom preimage in spontaneous-send#233
f3r10 wants to merge 1 commit into
lightningdevkit:mainfrom
f3r10:feat/custom_preimage_in_spontaneous_send

Conversation

@f3r10

@f3r10 f3r10 commented Jun 15, 2026

Copy link
Copy Markdown

address #226

Summary

  • Adds an optional preimage field to SpontaneousSendRequest, allowing callers to supply a custom 32-byte hex preimage instead of having the node generate one randomly
  • Dispatches to the appropriate ldk-node method (send_with_preimage or send_with_preimage_and_custom_tlvs) based on whether preimage and/or custom TLVs are present
  • Exposes the flag in the CLI (--preimage) and MCP schema
  • Adds an e2e test verifying the receiver observes a payment hash equal to
    SHA256 of the provided preimage

@ldk-reviews-bot

ldk-reviews-bot commented Jun 15, 2026

Copy link
Copy Markdown

👋 Thanks for assigning @benthecarman as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@benthecarman benthecarman linked an issue Jun 15, 2026 that may be closed by this pull request
Comment thread e2e-tests/tests/e2e.rs
bolt11_invoice_description, Bolt11InvoiceDescription,
};

use ldk_server_grpc::types::payment_kind;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we have a new line between the imports and const

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@f3r10 Looks like you missed this in your latest push.

Comment thread ldk-server-cli/src/main.rs Outdated
help = "Custom TLV record to attach, format: <type_num>:<hex_value>. Repeatable. type_num must be >= 65536."
)]
custom_tlvs: Vec<(u64, Vec<u8>)>,
#[arg(long)]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add help text

@f3r10 f3r10 force-pushed the feat/custom_preimage_in_spontaneous_send branch from 1eba0c8 to 590ea22 Compare July 6, 2026 14:55
@f3r10 f3r10 requested a review from benthecarman July 6, 2026 14:56

@Anyitechs Anyitechs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

The CI is currently failing because the proto files are now out of date and needs to be updated.

})
.transpose()?;

let custom_tlvs: Vec<_> = request.custom_tlvs.iter().map(proto_to_node_custom_tlv).collect();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong opinion here, especially as I believe there's really no runtime cost in iterating and mapping over an empty vector. But since we're creating the vector and immediately checking if it's empty in the match statement below.

I'm wondering if we could do something like this instead?

let custom_tlvs: Option<Vec<CustomTlvRecord>> = if request.custom_tlvs.is_empty() {
  None
} else {
  Some(request.custom_tlvs.iter().map(proto_to_node_custom_tlv).collect())
};

let payment_id = match (preimage, custom_tlvs) {
		(None, None) => context.node.spontaneous_payment().send(
			request.amount_msat,
			node_id,
			route_parameters,
		)?,
		(None, Some(custom_tlvs)) => context.node.spontaneous_payment().send_with_custom_tlvs(
			request.amount_msat,
			node_id,
			route_parameters,
			custom_tlvs,
		)?,
		(Some(preimage), None) => context.node.spontaneous_payment().send_with_preimage(
			request.amount_msat,
			node_id,
			preimage,
			route_parameters,
		)?,
		(Some(preimage), Some(custom_tlvs)) => context
			.node
			.spontaneous_payment()
			.send_with_preimage_and_custom_tlvs(
				request.amount_msat, 
                 node_id, 
                 custom_tlvs, 
                 preimage, 
                 route_parameters,
			)?,
};

Comment thread e2e-tests/tests/e2e.rs
bolt11_invoice_description, Bolt11InvoiceDescription,
};

use ldk_server_grpc::types::payment_kind;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@f3r10 Looks like you missed this in your latest push.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow setting custom preimage in spontaneous-send

4 participants