Skip to content

Set idempotency key in renew_leaf gRPC calls#755

Merged
JssDWt merged 1 commit intobreez:mainfrom
carsonp6:set_idempotency_key_in_renew_leaf
Mar 30, 2026
Merged

Set idempotency key in renew_leaf gRPC calls#755
JssDWt merged 1 commit intobreez:mainfrom
carsonp6:set_idempotency_key_in_renew_leaf

Conversation

@carsonp6
Copy link
Copy Markdown
Contributor

@carsonp6 carsonp6 commented Mar 21, 2026

Summary

  • Adds x-idempotency-key gRPC metadata header to all three renew_leaf call sites (renew_node, renew_refund, renew_zero_timelock)
  • Uses the node's refund transaction txid as the idempotency key, matching the approach in the JS SDK
  • Extracts a reusable set_idempotency_key helper in a new metadata.rs module for use by future RPC endpoints

Motivation

We've been seeing renew_leaf failures when paying Spark invoices:

validating refresh timelock failed: leaf {leaf_id} refund transaction sequence must be less than or equal to 300, got 2000

Root cause: the SDK occasionally calls renew_leaf twice for the same leaf within milliseconds. The first call succeeds but the second fails because the leaf was already renewed. With the idempotency key, the signing operator returns the cached response from the first call instead of processing the duplicate.

Copy link
Copy Markdown
Collaborator

@dangeross dangeross left a comment

Choose a reason for hiding this comment

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

LGTM. Looks like just faucet errors in the tests

Copy link
Copy Markdown
Member

@roeierez roeierez left a comment

Choose a reason for hiding this comment

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

Thanks a lot @carsonp6 !
Looks good, just a minor comment.

Comment thread crates/spark/src/operator/rpc/spark_rpc_client.rs
Copy link
Copy Markdown
Collaborator

@JssDWt JssDWt left a comment

Choose a reason for hiding this comment

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

Looking good. Just a nit.

Comment thread crates/spark/src/operator/rpc/metadata.rs Outdated
@JssDWt JssDWt force-pushed the set_idempotency_key_in_renew_leaf branch from 960a1d4 to 71bf0ae Compare March 26, 2026 12:48
@JssDWt
Copy link
Copy Markdown
Collaborator

JssDWt commented Mar 26, 2026

I took the liberty of taking over this PR.

@JssDWt JssDWt merged commit 731ac5f into breez:main Mar 30, 2026
22 of 24 checks passed
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.

5 participants