msggen: keep the generated proto wire format stable
What changed, and why it matters
This commit is a large, intentional change to the gRPC code generator used by Core Lightning. Its purpose is to keep the binary wire format of the project's gRPC API stable across future schema changes, so old clients and new servers can still talk to each other. It does this by recording every released field number and type, then adapting mismatches in generated Rust conversion code instead of changing the wire layout. The patch also deprecates several amount fields in on-chain RPCs and introduces new *_sat replacements. There is no obvious security bug in the diff, but the size and complexity of the generator changes create a real risk that future generated conversions could mishandle values, reject valid requests, or silently reinterpret amounts.
Treat this as a high-risk infrastructure change rather than an active vulnerability. Review the generated conversion code for the sat/msat bridges, ensure the new range checks and mutual-exclusion errors cannot be triggered by benign clients, and run the gRPC compatibility test suite against old proto clients. Monitor for follow-up fixes that correct generator edge cases.
Security signals we found
Large generator change affecting how request/response values are translated between gRPC wire format and internal Rust types
Amount-field deprecation and conversion logic for msat-to-sat fields in on-chain RPCs
New range-check and mutual-exclusion helpers (double_to_u32, msat_to_sat, msat_or_all_to_sat, sat_or_legacy)
Reserved field numbers/names added to prevent future accidental reuse
No explicit security claim or bug fix in commit message
Evidence from the diff
The commit adds a ‘wire compatibility’ layer to msggen. A new .msggen.json section (grpc-wire-contract) stores the released proto label and type for each field number. The generator compares the current JSON schema against that contract and, where possible, emits the released proto declaration while recording a ‘pin’ so the Rust From/TryFrom conversions adapt the value. Supported bridges include: optional label preservation, uint64-vs-uint32 width preservation with range checks, double-vs-integer preservation, string-vs-bytes/pubkey hex encoding, and moving sat-denominated fields to new field numbers while keeping deprecated msat fields at the old numbers. The generator also marks removed field numbers/names as reserved. The commit updates node.proto, convert.rs, and generated Python bindings accordingly. No CVE, advisory, or independent researcher attribution is present in the supplied materials.
Changed components
contrib/msggen code generatorcln-grpc/proto/node.protocln-grpc/src/convert.rscontrib/pyln-grpc-proto generated bindingsgRPC request/response messages for on-chain and channel funding RPCsInspect captured patch +6054 / −1537
### .msggen.json
[binary or diff unavailable]
### cln-grpc/proto/node.proto
@@ -209,6 +209,8 @@ message GetinfoResponse {
repeated GetinfoBinding binding = 15;
optional string warning_bitcoind_sync = 16;
optional string warning_lightningd_sync = 17;
+ reserved 18;
+ reserved "msatoshi_fees_collected";
}
message GetinfoAddress {
@@ -272,9 +274,11 @@ message ListpeersPeers {
bool connected = 2;
repeated ListpeersPeersLog log = 3;
repeated string netaddr = 5;
- bytes features = 6;
+ optional bytes features = 6;
optional string remote_addr = 7;
uint32 num_channels = 8;
+ reserved 4;
+ reserved "channels";
}
message ListpeersPeersLog {
@@ -351,6 +355,8 @@ message SendpayRequest {
optional bytes localinvreqid = 11;
optional bytes payment_metadata = 12;
optional string description = 13;
+ reserved 4, 8;
+ reserved "localofferid", "msatoshi";
}
message SendpayResponse {
@@ -360,7 +366,7 @@ message SendpayResponse {
COMPLETE = 1;
}
uint64 id = 1;
- uint64 groupid = 2;
+ optional uint64 groupid = 2;
bytes payment_hash = 3;
SendpayStatus status = 4;
optional Amount amount_msat = 5;
@@ -387,6 +393,8 @@ message SendpayRoute {
optional bytes node_id_out = 7;
optional Amount amount_out_msat = 8;
optional uint32 cltv_out = 9;
+ reserved 1;
+ reserved "msatoshi";
}
message ListchannelsRequest {
@@ -413,7 +421,7 @@ message ListchannelsChannels {
uint32 fee_per_millionth = 11;
uint32 delay = 12;
Amount htlc_minimum_msat = 13;
- Amount htlc_maximum_msat = 14;
+ optional Amount htlc_maximum_msat = 14;
bytes features = 15;
uint32 direction = 16;
}
@@ -426,10 +434,11 @@ message AddgossipResponse {
}
message AddpsbtoutputRequest {
- AmountSat satoshi = 1;
+ Amount satoshi = 1 [deprecated = true];
optional uint32 locktime = 2;
optional string initialpsbt = 3;
optional string destination = 4;
+ AmountSat satoshi_sat = 5;
}
message AddpsbtoutputResponse {
@@ -583,6 +592,8 @@ message CloseResponse {
CloseType item_type = 1;
repeated bytes txs = 4;
repeated bytes txids = 5;
+ reserved 2, 3;
+ reserved "tx", "txid";
}
message ConnectRequest {
@@ -647,6 +658,8 @@ message CreateinvoiceResponse {
optional string invreq_payer_note = 15;
uint64 created_index = 16;
optional CreateinvoicePaidOutpoint paid_outpoint = 17;
+ reserved 14;
+ reserved "payer_note";
}
message CreateinvoicePaidOutpoint {
@@ -668,13 +681,15 @@ message DatastoreRequest {
optional uint64 generation = 4;
repeated string key = 5;
optional string string = 6;
+ reserved 1;
}
message DatastoreResponse {
- uint64 generation = 2;
- bytes hex = 3;
+ optional uint64 generation = 2;
+ optional bytes hex = 3;
optional string string = 4;
repeated string key = 5;
+ reserved 1;
}
message DatastoreusageRequest {
@@ -710,13 +725,15 @@ message CreateonionHops {
message DeldatastoreRequest {
optional uint64 generation = 2;
repeated string key = 3;
+ reserved 1;
}
message DeldatastoreResponse {
- uint64 generation = 2;
- bytes hex = 3;
+ optional uint64 generation = 2;
+ optional bytes hex = 3;
optional string string = 4;
repeated string key = 5;
+ reserved 1;
}
message DelinvoiceRequest {
@@ -754,6 +771,8 @@ message DelinvoiceResponse {
optional Amount amount_received_msat = 15;
optional uint64 paid_at = 16;
optional bytes payment_preimage = 17;
+ reserved 10;
+ reserved "payer_note";
}
message DevforgetchannelRequest {
@@ -826,6 +845,8 @@ message InvoiceRequest {
repeated string exposeprivatechannels = 8;
optional bool deschashonly = 9;
AmountOrAny amount_msat = 10;
+ reserved 1;
+ reserved "msatoshi";
}
message InvoiceResponse {
@@ -892,6 +913,7 @@ message ListinvoicerequestsInvoicerequests {
message ListdatastoreRequest {
repeated string key = 2;
+ reserved 1;
}
message ListdatastoreResponse {
@@ -948,6 +970,8 @@ message ListinvoicesInvoices {
uint64 created_index = 16;
optional uint64 updated_index = 17;
optional ListinvoicesInvoicesPaidOutpoint paid_outpoint = 18;
+ reserved 10;
+ reserved "payer_note";
}
message ListinvoicesInvoicesPaidOutpoint {
@@ -969,6 +993,8 @@ message SendonionRequest {
optional bytes localinvreqid = 13;
optional string description = 14;
optional Amount total_amount_msat = 15;
+ reserved 8, 10;
+ reserved "localofferid", "msatoshi";
}
message SendonionResponse {
@@ -1067,18 +1093,24 @@ message ListtransactionsTransactions {
uint32 version = 8;
repeated ListtransactionsTransactionsInputs inputs = 9;
repeated ListtransactionsTransactionsOutputs outputs = 10;
+ reserved 5, 6;
+ reserved "channel", "item_type";
}
message ListtransactionsTransactionsInputs {
bytes txid = 1;
uint32 index = 2;
uint32 sequence = 3;
+ reserved 4, 5;
+ reserved "channel", "item_type";
}
message ListtransactionsTransactionsOutputs {
uint32 index = 1;
bytes scriptPubKey = 3;
Amount amount_msat = 6;
+ reserved 2, 4, 5;
+ reserved "channel", "item_type", "msat";
}
message MakesecretRequest {
@@ -1104,6 +1136,8 @@ message PayRequest {
optional Amount amount_msat = 13 [deprecated = true];
optional bytes localinvreqid = 14 [deprecated = true];
optional Amount partial_msat = 15 [deprecated = true];
+ reserved 2, 9;
+ reserved "localofferid", "msatoshi";
}
message PayResponse {
@@ -1114,7 +1148,7 @@ message PayResponse {
FAILED = 2 [deprecated = true];
}
bytes payment_preimage = 1 [deprecated = true];
- bytes destination = 2 [deprecated = true];
+ optional bytes destination = 2 [deprecated = true];
bytes payment_hash = 3 [deprecated = true];
double created_at = 4 [deprecated = true];
uint32 parts = 5 [deprecated = true];
@@ -1244,7 +1278,7 @@ message WaitsendpayResponse {
COMPLETE = 0;
}
uint64 id = 1;
- uint64 groupid = 2;
+ optional uint64 groupid = 2;
bytes payment_hash = 3;
WaitsendpayStatus status = 4;
optional Amount amount_msat = 5;
@@ -1278,10 +1312,11 @@ message NewaddrResponse {
message WithdrawRequest {
string destination = 1;
- AmountSatOrAll satoshi = 2;
+ AmountOrAll satoshi = 2 [deprecated = true];
optional uint32 minconf = 3;
repeated Outpoint utxos = 4;
optional Feerate feerate = 5;
+ AmountSatOrAll satoshi_sat = 6;
}
message WithdrawResponse {
@@ -1301,6 +1336,8 @@ message KeysendRequest {
optional TlvStream extratlvs = 9 [deprecated = true];
Amount amount_msat = 10 [deprecated = true];
optional Amount maxfee = 11 [deprecated = true];
+ reserved 2;
+ reserved "msatoshi";
}
message KeysendResponse {
@@ -1320,7 +1357,7 @@ message KeysendResponse {
}
message FundpsbtRequest {
- AmountSatOrAll satoshi = 1;
+ AmountOrAll satoshi = 1 [deprecated = true];
Feerate feerate = 2;
uint32 startweight = 3;
optional uint32 minconf = 4;
@@ -1330,6 +1367,7 @@ message FundpsbtRequest {
optional bool excess_as_change = 8;
optional bool nonwrapped = 9;
optional bool opening_anchor_channel = 10;
+ AmountSatOrAll satoshi_sat = 11;
}
message FundpsbtResponse {
@@ -1369,7 +1407,7 @@ message SignpsbtResponse {
}
message UtxopsbtRequest {
- AmountSatOrAll satoshi = 1;
+ AmountOrAll satoshi = 1 [deprecated = true];
Feerate feerate = 2;
uint32 startweight = 3;
repeated Outpoint utxos = 4;
@@ -1379,6 +1417,7 @@ message UtxopsbtRequest {
optional bool reservedok = 8;
optional bool excess_as_change = 9;
optional bool opening_anchor_channel = 10;
+ AmountSatOrAll satoshi_sat = 11;
}
message UtxopsbtResponse {
@@ -1412,6 +1451,8 @@ message TxprepareRequest {
optional uint32 minconf = 3;
repeated Outpoint utxos = 4;
repeated OutputDesc outputs = 5;
+ reserved 1;
+ reserved "outptus";
}
message TxprepareResponse {
@@ -1445,7 +1486,7 @@ message ListpeerchannelsChannels {
bool peer_connected = 2;
ChannelState state = 3;
optional bytes scratch_txid = 4;
- ListpeerchannelsChannelsChannelType channel_type = 5;
+ optional ListpeerchannelsChannelsChannelType channel_type = 5;
optional ListpeerchannelsChannelsFeerate feerate = 6;
optional string owner = 7;
optional string short_channel_id = 8;
@@ -1502,6 +1543,8 @@ message ListpeerchannelsChannels {
optional Amount their_max_htlc_value_in_flight_msat = 61;
optional Amount our_max_htlc_value_in_flight_msat = 62;
repeated string features = 63;
+ reserved 21, 30;
+ reserved "max_total_htlc_in_msat";
}
message ListpeerchannelsChannelsAlias {
@@ -1618,7 +1661,7 @@ message ListclosedchannelsClosedchannels {
ChannelSide opener = 5;
optional ChannelSide closer = 6;
bool private = 7;
- ListclosedchannelsClosedchannelsChannelType channel_type = 8;
+ optional ListclosedchannelsClosedchannelsChannelType channel_type = 8;
uint64 total_local_commitments = 9;
uint64 total_remote_commitments = 10;
uint64 total_htlcs_sent = 11;
@@ -1761,6 +1804,8 @@ message DecodeResponse {
optional string proof_note = 97;
optional string proof_signature = 98;
repeated DecodeUnknownPayerProofTlvs unknown_payer_proof_tlvs = 99;
+ reserved 17, 20, 68;
+ reserved "offer_node_id", "warning_missing_offer_node_id";
}
message DecodeExtra {
@@ -1780,6 +1825,8 @@ message DecodeFallbacks {
DecodeFallbacksType item_type = 2;
optional string addr = 3;
bytes hex = 4;
+ reserved 1;
+ reserved "warning_invoice_fallbacks_version_invalid";
}
message DecodeInvoiceFallbacks {
@@ -1822,6 +1869,8 @@ message DecodeInvreqPaths {
optional string first_scid = 4;
repeated DecodeInvreqPathsPath path = 5;
optional bytes first_path_key = 6;
+ reserved 2;
+ reserved "blinding";
}
message DecodeInvreqPathsPath {
@@ -1835,6 +1884,8 @@ message DecodeOfferPaths {
optional uint32 first_scid_dir = 4;
optional string first_scid = 5;
optional bytes first_path_key = 6;
+ reserved 2;
+ reserved "blinding";
}
message DecodeOfferPathsPath {
@@ -1921,7 +1972,7 @@ message DelpayPayments {
uint64 created_at = 9;
optional uint64 updated_index = 10;
optional uint64 completed_at = 11;
- uint64 groupid = 12;
+ optional uint64 groupid = 12;
optional bytes payment_preimage = 13;
optional string label = 14;
optional string bolt11 = 15;
@@ -2004,7 +2055,7 @@ message FeeratesOnchainFeeEstimates {
uint64 unilateral_close_satoshis = 3;
uint64 htlc_timeout_satoshis = 4;
uint64 htlc_success_satoshis = 5;
- uint64 unilateral_close_nonanchor_satoshis = 6;
+ optional uint64 unilateral_close_nonanchor_satoshis = 6;
}
message FeeratesPerkb {
@@ -2018,6 +2069,8 @@ message FeeratesPerkb {
uint32 floor = 10;
optional uint32 unilateral_anchor_close = 11;
optional uint32 splice = 12;
+ reserved 6, 7;
+ reserved "delayed_to_us", "htlc_resolution";
}
message FeeratesPerkbEstimates {
@@ -2037,6 +2090,8 @@ message FeeratesPerkw {
uint32 floor = 10;
optional uint32 unilateral_anchor_close = 11;
optional uint32 splice = 12;
+ reserved 6, 7;
+ reserved "delayed_to_us", "htlc_resolution";
}
message FeeratesPerkwEstimates {
@@ -2130,19 +2185,23 @@ message FundchannelCompleteResponse {
}
message FundchannelRequest {
- AmountSatOrAll amount = 1;
+ AmountOrAll amount = 1 [deprecated = true];
optional Feerate feerate = 2;
optional bool announce = 3;
optional Amount push_msat = 5;
optional string close_to = 6;
- optional AmountSat request_amt = 7;
+ optional Amount request_amt = 7 [deprecated = true];
optional string compact_lease = 8;
bytes id = 9;
optional uint32 minconf = 10;
repeated Outpoint utxos = 11;
optional uint32 mindepth = 12;
- optional AmountSat reserve = 13;
+ optional Amount reserve = 13 [deprecated = true];
repeated uint32 channel_type = 14;
+ AmountSatOrAll amount_sat = 15;
+ optional AmountSat request_amt_sat = 16;
+ optional AmountSat reserve_sat = 17;
+ reserved 4;
}
message FundchannelResponse {
@@ -2162,20 +2221,22 @@ message FundchannelChannelType {
message FundchannelStartRequest {
bytes id = 1;
- AmountSat amount = 2;
+ Amount amount = 2 [deprecated = true];
optional Feerate feerate = 3;
optional bool announce = 4;
optional string close_to = 5;
optional Amount push_msat = 6;
optional uint32 mindepth = 7;
- optional AmountSat reserve = 8;
+ optional Amount reserve = 8 [deprecated = true];
repeated uint32 channel_type = 9;
+ AmountSat amount_sat = 10;
+ optional AmountSat reserve_sat = 11;
}
message FundchannelStartResponse {
string funding_address = 1;
bytes scriptpubkey = 2;
- FundchannelStartChannelType channel_type = 3;
+ optional FundchannelStartChannelType channel_type = 3;
optional bytes close_to = 4;
string warning_usage = 5;
optional uint32 mindepth = 6;
@@ -2287,6 +2348,8 @@ message GetrouteRequest {
repeated string exclude = 7 [deprecated = true];
optional uint32 maxhops = 8 [deprecated = true];
Amount amount_msat = 9 [deprecated = true];
+ reserved 2;
+ reserved "msatoshi";
}
message GetrouteResponse {
@@ -2304,6 +2367,8 @@ message GetrouteRoute {
Amount amount_msat = 4 [deprecated = true];
uint32 delay = 5 [deprecated = true];
GetrouteRouteStyle style = 6 [deprecated = true];
+ reserved 7;
+ reserved "msatoshi";
}
message ListaddressesRequest {
@@ -2395,6 +2460,8 @@ message ListforwardsForwards {
optional uint32 failcode = 15;
optional string failreason = 16;
optional ListforwardsForwardsFailureReason failure_reason = 17;
+ reserved 6;
+ reserved "payment_hash";
}
message ListoffersRequest {
@@ -2456,7 +2523,7 @@ message ListpaysPays {
optional string bolt11 = 6;
optional string bolt12 = 7;
optional Amount amount_msat = 8;
- Amount amount_sent_msat = 9;
+ optional Amount amount_sent_msat = 9;
optional bytes erroronion = 10;
optional string description = 11;
optional uint64 completed_at = 12;
@@ -2517,14 +2584,17 @@ message MultifundchannelResponse {
message MultifundchannelDestinations {
string id = 1;
- AmountSatOrAll amount = 2;
+ AmountOrAll amount = 2 [deprecated = true];
optional bool announce = 3;
optional Amount push_msat = 4;
optional string close_to = 5;
- optional AmountSat request_amt = 6;
+ optional Amount request_amt = 6 [deprecated = true];
optional string compact_lease = 7;
optional uint32 mindepth = 8;
- optional AmountSat reserve = 9;
+ optional Amount reserve = 9 [deprecated = true];
+ AmountSatOrAll amount_sat = 10;
+ optional AmountSat request_amt_sat = 11;
+ optional AmountSat reserve_sat = 12;
}
message MultifundchannelChannelIds {
@@ -2585,6 +2655,8 @@ message OfferRequest {
optional bool proportional_amount = 13;
optional bool optional_recurrence = 14;
repeated bytes fronting_nodes = 15;
+ reserved 12;
+ reserved "recurrence_start_any_period";
}
message OfferResponse {
@@ -2612,7 +2684,8 @@ message OpenchannelBumpRequest {
bytes channel_id = 1;
string initialpsbt = 2;
optional Feerate funding_feerate = 3;
- AmountSat amount = 4;
+ Amount amount = 4 [deprecated = true];
+ AmountSat amount_sat = 5;
}
message OpenchannelBumpResponse {
@@ -2621,7 +2694,7 @@ message OpenchannelBumpResponse {
string psbt = 3;
bool commitments_secured = 4;
uint64 funding_serial = 5;
- bool requires_confirmed_inputs = 6;
+ optional bool requires_confirmed_inputs = 6;
}
message OpenchannelBumpChannelType {
@@ -2636,10 +2709,12 @@ message OpenchannelInitRequest {
optional Feerate funding_feerate = 4;
optional bool announce = 5;
optional string close_to = 6;
- optional AmountSat request_amt = 7;
+ optional Amount request_amt = 7 [deprecated = true];
optional bytes compact_lease = 8;
repeated uint32 channel_type = 9;
- AmountSat amount = 10;
+ Amount amount = 10 [deprecated = true];
+ optional AmountSat request_amt_sat = 11;
+ AmountSat amount_sat = 12;
}
message OpenchannelInitResponse {
@@ -2648,7 +2723,7 @@ message OpenchannelInitResponse {
OpenchannelInitChannelType channel_type = 3;
bool commitments_secured = 4;
uint64 funding_serial = 5;
- bool requires_confirmed_inputs = 6;
+ optional bool requires_confirmed_inputs = 6;
}
message OpenchannelInitChannelType {
@@ -2708,6 +2783,8 @@ message PluginResponse {
PluginSubcommand command = 1;
repeated PluginPlugins plugins = 2;
optional string result = 3;
+ reserved 4;
+ reserved "subcommand";
}
message PluginPlugins {
@@ -2736,11 +2813,11 @@ message RenepaystatusPaystatus {
bytes payment_hash = 3 [deprecated = true];
double created_at = 4 [deprecated = true];
uint32 groupid = 5 [deprecated = true];
- uint32 parts = 6 [deprecated = true];
+ optional uint32 parts = 6 [deprecated = true];
Amount amount_msat = 7 [deprecated = true];
optional Amount amount_sent_msat = 8 [deprecated = true];
RenepaystatusPaystatusStatus status = 9 [deprecated = true];
- bytes destination = 10 [deprecated = true];
+ optional bytes destination = 10 [deprecated = true];
repeated string notes = 11 [deprecated = true];
}
@@ -2770,10 +2847,10 @@ message RenepayResponse {
Amount amount_msat = 5 [deprecated = true];
Amount amount_sent_msat = 6 [deprecated = true];
RenepayStatus status = 7 [deprecated = true];
- bytes destination = 8 [deprecated = true];
+ optional bytes destination = 8 [deprecated = true];
optional string bolt11 = 9 [deprecated = true];
optional string bolt12 = 10 [deprecated = true];
- uint64 groupid = 11 [deprecated = true];
+ optional uint64 groupid = 11 [deprecated = true];
}
message ReserveinputsRequest {
@@ -2932,7 +3009,7 @@ message SpliceSignedRequest {
message SpliceSignedResponse {
bytes tx = 1;
bytes txid = 2;
- uint32 outnum = 3;
+ optional uint32 outnum = 3;
string psbt = 4;
}
@@ -2953,9 +3030,9 @@ message SpliceinRequest {
}
message SpliceinResponse {
- string psbt = 1;
+ optional string psbt = 1;
optional string tx = 2;
- string txid = 3;
+ optional string txid = 3;
}
message SpliceoutRequest {
@@ -2966,9 +3043,9 @@ message SpliceoutRequest {
}
message SpliceoutResponse {
- string psbt = 1;
+ optional string psbt = 1;
optional string tx = 2;
- string txid = 3;
+ optional string txid = 3;
}
message DevspliceRequest {
@@ -3069,6 +3146,8 @@ message WaitResponse {
optional WaitChainmoves chainmoves = 10;
optional WaitChannelmoves channelmoves = 11;
optional WaitNetworkevents networkevents = 12;
+ reserved 5;
+ reserved "details";
}
message WaitChainmoves {
@@ -3158,7 +3237,9 @@ message ListconfigsRequest {
}
message ListconfigsResponse {
- ListconfigsConfigs configs = 1;
+ optional ListconfigsConfigs configs = 1;
+ reserved 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72;
+ reserved "accept_htlc_tlv_types", "addr", "alias", "allow_deprecated_apis", "always_use_proxy", "announce_addr", "announce_addr_discovered", "announce_addr_discovered_port", "announce_addr_dns", "autoconnect_seeker_peers", "autolisten", "bind_addr", "bookkeeper_db", "bookkeeper_dir", "cltv_delta", "cltv_final", "commit_fee", "commit_feerate_offset", "commit_time", "conf", "daemon", "database_upgrade", "dev_allowdustreserve", "developer", "disable_dns", "disable_plugin", "encrypted_hsm", "experimental_dual_fund", "experimental_offers", "experimental_onion_messages", "experimental_peer_storage", "experimental_quiesce", "experimental_shutdown_wrong_funding", "experimental_splicing", "experimental_upgrade_protocol", "fee_base", "fee_per_satoshi", "fetchinvoice_noconnect", "force_feerates", "funding_confirms", "htlc_maximum_msat", "htlc_minimum_msat", "ignore_fee_limits", "important_plugins", "invoices_onchain_fallback", "large_channels", "lightning_dir", "log_file", "log_level", "log_prefix", "log_timestamps", "max_concurrent_htlcs", "max_dust_htlc_exposure_msat", "max_locktime_blocks", "min_capacity_sat", "min_emergency_msat", "network", "offline", "pid_file", "plugins", "proxy", "require_confirmed_inputs", "rescan", "rgb", "rpc_file", "rpc_file_mode", "subdaemon", "tor_service_password", "wallet", "watchtime_blocks";
}
message ListconfigsConfigs {
@@ -3241,6 +3322,8 @@ message ListconfigsConfigs {
optional ListconfigsConfigsMinemergencymsat min_emergency_msat = 82;
optional ListconfigsConfigsPaymentfrontingnode payment_fronting_node = 83;
optional ListconfigsConfigsRecover recover = 84;
+ reserved 23, 24, 65, 72, 73;
+ reserved "accept_htlc_tlv_types", "add_source", "disable_source", "experimental_offers", "experimental_onion_messages";
}
message ListconfigsConfigsAccepthtlctlvtype {
@@ -3674,11 +3757,13 @@ message HelpResponse {
SIMPLE = 0;
}
repeated HelpHelp help = 1;
- HelpFormathint format_hint = 2;
+ optional HelpFormathint format_hint = 2;
}
message HelpHelp {
string command = 1;
+ reserved 2, 3, 4;
+ reserved "category", "description", "verbose";
}
message PreapprovekeysendRequest {
@@ -3724,7 +3809,7 @@ message BkprchannelsapyChannelsApy {
Amount our_start_balance_msat = 8;
Amount channel_start_balance_msat = 9;
Amount fees_out_msat = 10;
- Amount fees_in_msat = 11;
+ optional Amount fees_in_msat = 11;
string utilization_out = 12;
optional string utilization_out_initial = 13;
string utilization_in = 14;
@@ -3934,7 +4019,7 @@ message BkpreditdescriptionbyoutpointUpdated {
}
message BkprreportRequest {
- string format = 1;
+ optional string format = 1;
repeated string headers = 2;
optional string escape = 3;
optional uint32 start_time = 4;
@@ -4025,6 +4110,8 @@ message AskreneunreservePath {
Amount amount_msat = 3;
string short_channel_id_dir = 4;
optional string layer = 5;
+ reserved 1, 2;
+ reserved "direction", "short_channel_id";
}
message AskrenelistlayersRequest {
@@ -4070,13 +4157,17 @@ message AskrenelistlayersLayersConstraints {
optional Amount minimum_msat = 4;
string short_channel_id_dir = 5;
optional uint64 timestamp = 6;
+ reserved 1, 2;
+ reserved "direction", "short_channel_id";
}
message AskrenelistlayersLayersCreatedChannels {
bytes source = 1;
bytes destination = 2;
string short_channel_id = 3;
Amount capacity_msat = 4;
+ reserved 5, 6, 7, 8, 9;
+ reserved "delay", "fee_base_msat", "fee_proportional_millionths", "htlc_maximum_msat", "htlc_minimum_msat";
}
message AskrenelistlayersLayersImpressions {
@@ -4184,6 +4275,8 @@ message AskrenereservePath {
Amount amount_msat = 3;
string short_channel_id_dir = 4;
optional string layer = 5;
+ reserved 1, 2;
+ reserved "direction", "short_channel_id";
}
message AskreneageRequest {
@@ -4206,6 +4299,8 @@ message GetroutesRequest {
optional uint32 maxdelay = 8;
optional uint32 maxparts = 9;
optional uint32 maxhops = 10;
+ reserved 6;
+ reserved "finalcltv";
}
message GetroutesResponse {
@@ -4231,6 +4326,8 @@ message GetroutesRoutesPath {
optional bytes node_id_out = 10;
optional uint32 cltv_in = 11;
optional uint32 cltv_out = 12;
+ reserved 1, 2;
+ reserved "direction", "short_channel_id";
}
message AskrenedisablenodeRequest {
@@ -4252,11 +4349,15 @@ message AskreneinformchannelRequest {
string short_channel_id_dir = 6;
Amount amount_msat = 7;
AskreneinformchannelInform inform = 8;
+ reserved 2, 3, 4, 5;
+ reserved "direction", "maximum_msat", "minimum_msat", "short_channel_id";
}
message AskreneinformchannelResponse {
repeated AskreneinformchannelConstraints constraints = 2;
repeated AskreneinformchannelImpressions impressions = 3;
+ reserved 1;
+ reserved "constraint";
}
message AskreneinformchannelConstraints {
@@ -4280,6 +4381,8 @@ message AskrenecreatechannelRequest {
bytes destination = 3;
string short_channel_id = 4;
Amount capacity_msat = 5;
+ reserved 6, 7, 8, 9, 10;
+ reserved "base_fee", "delay", "htlc_max", "htlc_min", "proportional_fee";
}
message AskrenecreatechannelResponse {
@@ -4504,6 +4607,7 @@ message ListchainmovesChainmoves {
optional uint32 output_count = 14;
uint32 blockheight = 15;
repeated string extra_tags = 16;
+ reserved 7;
}
message ListnetworkeventsRequest {
@@ -4801,6 +4905,8 @@ message CoinMovementNotification {
optional Amount output_msat = 24;
optional uint32 output_count = 25;
optional uint32 blockheight = 26;
+ reserved 10, 20, 22, 23;
+ reserved "tags", "txid", "utxo_txid", "vout";
}
message StreamCustomMsgRequest {
### cln-grpc/src/convert.rs
@@ -97,7 +97,7 @@ impl From<responses::ListpeersPeers> for pb::ListpeersPeers {
fn from(c: responses::ListpeersPeers) -> Self {
Self {
connected: c.connected, // Rule #2 for type boolean
- features: hex::decode(&c.features).unwrap(), // Rule #2 for type hex
+ features: Some(hex::decode(&c.features).unwrap()), // Rule #2 for type hex
id: c.id.serialize().to_vec(), // Rule #2 for type pubkey
// Field: ListPeers.peers[].log[]
log: c.log.map(|arr| arr.into_iter().map(|i| i.into()).collect()).unwrap_or(vec![]), // Rule #3
@@ -178,7 +178,7 @@ impl From<responses::SendpayResponse> for pb::SendpayResponse {
created_at: c.created_at, // Rule #2 for type u64
created_index: c.created_index, // Rule #2 for type u64
destination: c.destination.map(|v| v.serialize().to_vec()), // Rule #2 for type pubkey?
- groupid: c.groupid, // Rule #2 for type u64
+ groupid: Some(c.groupid), // Rule #2 for type u64
id: c.id, // Rule #2 for type u64
label: c.label, // Rule #2 for type string?
message: c.message, // Rule #2 for type string?
@@ -524,8 +524,8 @@ impl From<responses::CreateinvoiceResponse> for pb::CreateinvoiceResponse {
impl From<responses::DatastoreResponse> for pb::DatastoreResponse {
fn from(c: responses::DatastoreResponse) -> Self {
Self {
- generation: c.generation, // Rule #2 for type u64
- hex: hex::decode(&c.hex).unwrap(), // Rule #2 for type hex
+ generation: Some(c.generation), // Rule #2 for type u64
+ hex: Some(hex::decode(&c.hex).unwrap()), // Rule #2 for type hex
// Field: Datastore.key
key: c.key.into_iter().map(|i| i.into()).collect(), // Rule #3 for type string
string: c.string, // Rule #2 for type string?
@@ -567,8 +567,8 @@ impl From<responses::CreateonionResponse> for pb::CreateonionResponse {
impl From<responses::DeldatastoreResponse> for pb::DeldatastoreResponse {
fn from(c: responses::DeldatastoreResponse) -> Self {
Self {
- generation: c.generation, // Rule #2 for type u64
- hex: hex::decode(&c.hex).unwrap(), // Rule #2 for type hex
+ generation: Some(c.generation), // Rule #2 for type u64
+ hex: Some(hex::decode(&c.hex).unwrap()), // Rule #2 for type hex
// Field: DelDatastore.key
key: c.key.into_iter().map(|i| i.into()).collect(), // Rule #3 for type string
string: c.string, // Rule #2 for type string?
@@ -930,7 +930,7 @@ impl From<responses::PayResponse> for pb::PayResponse {
#[allow(deprecated)]
created_at: c.created_at, // Rule #2 for type number
#[allow(deprecated)]
- destination: c.destination.serialize().to_vec(), // Rule #2 for type pubkey
+ destination: Some(c.destination.serialize().to_vec()), // Rule #2 for type pubkey
#[allow(deprecated)]
parts: c.parts, // Rule #2 for type u32
#[allow(deprecated)]
@@ -1073,7 +1073,7 @@ impl From<responses::WaitsendpayResponse> for pb::WaitsendpayResponse {
created_at: c.created_at, // Rule #2 for type u64
created_index: c.created_index, // Rule #2 for type u64
destination: c.destination.map(|v| v.serialize().to_vec()), // Rule #2 for type pubkey?
- groupid: c.groupid, // Rule #2 for type u64
+ groupid: Some(c.groupid), // Rule #2 for type u64
id: c.id, // Rule #2 for type u64
label: c.label, // Rule #2 for type string?
partid: c.partid, // Rule #2 for type u64?
@@ -1858,7 +1858,7 @@ impl From<responses::DelpayPayments> for pb::DelpayPayments {
created_index: c.created_index, // Rule #2 for type u64
destination: c.destination.map(|v| v.serialize().to_vec()), // Rule #2 for type pubkey?
erroronion: c.erroronion.map(|v| hex::decode(v).unwrap()), // Rule #2 for type hex?
- groupid: c.groupid, // Rule #2 for type u64
+ groupid: Some(c.groupid), // Rule #2 for type u64
id: c.id, // Rule #2 for type u64
label: c.label, // Rule #2 for type string?
partid: c.partid, // Rule #2 for type u64?
@@ -1936,7 +1936,7 @@ impl From<responses::FeeratesOnchainFeeEstimates> for pb::FeeratesOnchainFeeEsti
htlc_timeout_satoshis: c.htlc_timeout_satoshis, // Rule #2 for type u64
mutual_close_satoshis: c.mutual_close_satoshis, // Rule #2 for type u64
opening_channel_satoshis: c.opening_channel_satoshis, // Rule #2 for type u64
- unilateral_close_nonanchor_satoshis: c.unilateral_close_nonanchor_satoshis, // Rule #2 for type u64
+ unilateral_close_nonanchor_satoshis: Some(c.unilateral_close_nonanchor_satoshis), // Rule #2 for type u64
unilateral_close_satoshis: c.unilateral_close_satoshis, // Rule #2 for type u64
}
}
@@ -2498,7 +2498,7 @@ impl From<responses::OpenchannelBumpResponse> for pb::OpenchannelBumpResponse {
commitments_secured: c.commitments_secured, // Rule #2 for type boolean
funding_serial: c.funding_serial, // Rule #2 for type u64
psbt: c.psbt, // Rule #2 for type string
- requires_confirmed_inputs: c.requires_confirmed_inputs, // Rule #2 for type boolean
+ requires_confirmed_inputs: Some(c.requires_confirmed_inputs), // Rule #2 for type boolean
}
}
}
@@ -2524,7 +2524,7 @@ impl From<responses::OpenchannelInitResponse> for pb::OpenchannelInitResponse {
commitments_secured: c.commitments_secured, // Rule #2 for type boolean
funding_serial: c.funding_serial, // Rule #2 for type u64
psbt: c.psbt, // Rule #2 for type string
- requires_confirmed_inputs: c.requires_confirmed_inputs, // Rule #2 for type boolean
+ requires_confirmed_inputs: Some(c.requires_confirmed_inputs), // Rule #2 for type boolean
}
}
}
@@ -2612,13 +2612,13 @@ impl From<responses::RenepaystatusPaystatus> for pb::RenepaystatusPaystatus {
#[allow(deprecated)]
created_at: c.created_at, // Rule #2 for type number
#[allow(deprecated)]
- destination: c.destination.serialize().to_vec(), // Rule #2 for type pubkey
+ destination: Some(c.destination.serialize().to_vec()), // Rule #2 for type pubkey
#[allow(deprecated)]
groupid: c.groupid, // Rule #2 for type u32
// Field: RenePayStatus.paystatus[].notes[]
notes: c.notes.map(|arr| arr.into_iter().map(|i| i.into()).collect()).unwrap_or(vec![]), // Rule #3
#[allow(deprecated)]
- parts: c.parts, // Rule #2 for type u32
+ parts: Some(c.parts), // Rule #2 for type u32
#[allow(deprecated)]
payment_hash: <Sha256 as AsRef<[u8]>>::as_ref(&c.payment_hash).to_vec(), // Rule #2 for type hash
#[allow(deprecated)]
@@ -2653,9 +2653,9 @@ impl From<responses::RenepayResponse> for pb::RenepayResponse {
#[allow(deprecated)]
created_at: c.created_at, // Rule #2 for type number
#[allow(deprecated)]
- destination: c.destination.serialize().to_vec(), // Rule #2 for type pubkey
+ destination: Some(c.destination.serialize().to_vec()), // Rule #2 for type pubkey
#[allow(deprecated)]
- groupid: c.groupid, // Rule #2 for type u64
+ groupid: Some(c.groupid), // Rule #2 for type u64
#[allow(deprecated)]
parts: c.parts, // Rule #2 for type u32
#[allow(deprecated)]
@@ -2820,7 +2820,7 @@ impl From<responses::SpliceInitResponse> for pb::SpliceInitResponse {
impl From<responses::SpliceSignedResponse> for pb::SpliceSignedResponse {
fn from(c: responses::SpliceSignedResponse) -> Self {
Self {
- outnum: c.outnum, // Rule #2 for type u32
+ outnum: Some(c.outnum), // Rule #2 for type u32
psbt: c.psbt, // Rule #2 for type string
tx: hex::decode(&c.tx).unwrap(), // Rule #2 for type hex
txid: hex::decode(&c.txid).unwrap(), // Rule #2 for type txid
@@ -2843,9 +2843,9 @@ impl From<responses::SpliceUpdateResponse> for pb::SpliceUpdateResponse {
impl From<responses::SpliceinResponse> for pb::SpliceinResponse {
fn from(c: responses::SpliceinResponse) -> Self {
Self {
- psbt: c.psbt, // Rule #2 for type string
+ psbt: Some(c.psbt), // Rule #2 for type string
tx: c.tx, // Rule #2 for type string?
- txid: c.txid, // Rule #2 for type string
+ txid: Some(c.txid), // Rule #2 for type string
}
}
}
@@ -2854,9 +2854,9 @@ impl From<responses::SpliceinResponse> for pb::SpliceinResponse {
impl From<responses::SpliceoutResponse> for pb::SpliceoutResponse {
fn from(c: responses::SpliceoutResponse) -> Self {
Self {
- psbt: c.psbt, // Rule #2 for type string
+ psbt: Some(c.psbt), // Rule #2 for type string
tx: c.tx, // Rule #2 for type string?
- txid: c.txid, // Rule #2 for type string
+ txid: Some(c.txid), // Rule #2 for type string
}
}
}
@@ -3976,7 +3976,7 @@ impl From<responses::HelpHelp> for pb::HelpHelp {
impl From<responses::HelpResponse> for pb::HelpResponse {
fn from(c: responses::HelpResponse) -> Self {
Self {
- format_hint: c.format_hint as i32,
+ format_hint: Some(c.format_hint as i32),
// Field: Help.help[]
help: c.help.into_iter().map(|i| i.into()).collect(), // Rule #3 for type HelpHelp
}
@@ -5535,14 +5535,15 @@ impl From<requests::AddgossipRequest> for pb::AddgossipRequest {
}
}
-#[allow(unused_variables)]
+#[allow(unused_variables,deprecated)]
impl From<requests::AddpsbtoutputRequest> for pb::AddpsbtoutputRequest {
fn from(c: requests::AddpsbtoutputRequest) -> Self {
Self {
destination: c.destination, // Rule #2 for type string?
initialpsbt: c.initialpsbt, // Rule #2 for type string?
locktime: c.locktime, // Rule #2 for type u32?
- satoshi: Some(c.satoshi.into()), // Rule #2 for type sat
+ satoshi_sat: Some(c.satoshi.into()),
+ satoshi: None,
}
}
}
@@ -5966,14 +5967,15 @@ impl From<requests::NewaddrRequest> for pb::NewaddrRequest {
}
}
-#[allow(unused_variables)]
+#[allow(unused_variables,deprecated)]
impl From<requests::WithdrawRequest> for pb::WithdrawRequest {
fn from(c: requests::WithdrawRequest) -> Self {
Self {
destination: c.destination, // Rule #2 for type string
feerate: c.feerate.map(|o|o.into()), // Rule #2 for type feerate?
minconf: c.minconf.map(|v| v.into()), // Rule #2 for type u16?
- satoshi: Some(c.satoshi.into()), // Rule #2 for type sat_or_all
+ satoshi_sat: Some(c.satoshi.into()),
+ satoshi: None,
// Field: Withdraw.utxos[]
utxos: c.utxos.map(|arr| arr.into_iter().map(|i| i.into()).collect()).unwrap_or(vec![]), // Rule #3
}
@@ -6008,7 +6010,7 @@ impl From<requests::KeysendRequest> for pb::KeysendRequest {
}
}
-#[allow(unused_variables)]
+#[allow(unused_variables,deprecated)]
impl From<requests::FundpsbtRequest> for pb::FundpsbtRequest {
fn from(c: requests::FundpsbtRequest) -> Self {
Self {
@@ -6020,7 +6022,8 @@ impl From<requests::FundpsbtRequest> for pb::FundpsbtRequest {
nonwrapped: c.nonwrapped, // Rule #2 for type boolean?
opening_anchor_channel: c.opening_anchor_channel, // Rule #2 for type boolean?
reserve: c.reserve, // Rule #2 for type u32?
- satoshi: Some(c.satoshi.into()), // Rule #2 for type sat_or_all
+ satoshi_sat: Some(c.satoshi.into()),
+ satoshi: None,
startweight: c.startweight, // Rule #2 for type u32
}
}
@@ -6047,7 +6050,7 @@ impl From<requests::SignpsbtRequest> for pb::SignpsbtRequest {
}
}
-#[allow(unused_variables)]
+#[allow(unused_variables,deprecated)]
impl From<requests::UtxopsbtRequest> for pb::UtxopsbtRequest {
fn from(c: requests::UtxopsbtRequest) -> Self {
Self {
@@ -6058,7 +6061,8 @@ impl From<requests::UtxopsbtRequest> for pb::UtxopsbtRequest {
opening_anchor_channel: c.opening_anchor_channel, // Rule #2 for type boolean?
reserve: c.reserve, // Rule #2 for type u32?
reservedok: c.reservedok, // Rule #2 for type boolean?
- satoshi: Some(c.satoshi.into()), // Rule #2 for type sat_or_all
+ satoshi_sat: Some(c.satoshi.into()),
+ satoshi: None,
startweight: c.startweight, // Rule #2 for type u32
// Field: UtxoPsbt.utxos[]
utxos: c.utxos.into_iter().map(|i| i.into()).collect(), // Rule #3 for type outpoint
@@ -6248,11 +6252,12 @@ impl From<requests::FundchannelCompleteRequest> for pb::FundchannelCompleteReque
}
}
-#[allow(unused_variables)]
+#[allow(unused_variables,deprecated)]
impl From<requests::FundchannelRequest> for pb::FundchannelRequest {
fn from(c: requests::FundchannelRequest) -> Self {
Self {
- amount: Some(c.amount.into()), // Rule #2 for type sat_or_all
+ amount_sat: Some(c.amount.into()),
+ amount: None,
announce: c.announce, // Rule #2 for type boolean?
// Field: FundChannel.channel_type[]
channel_type: c.channel_type.map(|arr| arr.into_iter().map(|i| i.into()).collect()).unwrap_or(vec![]), // Rule #3
@@ -6263,19 +6268,22 @@ impl From<requests::FundchannelRequest> for pb::FundchannelRequest {
minconf: c.minconf, // Rule #2 for type u32?
mindepth: c.mindepth, // Rule #2 for type u32?
push_msat: c.push_msat.map(|f| f.into()), // Rule #2 for type msat?
- request_amt: c.request_amt.map(|f| f.into()), // Rule #2 for type sat?
- reserve: c.reserve.map(|f| f.into()), // Rule #2 for type sat?
+ request_amt_sat: c.request_amt.map(|f| f.into()),
+ request_amt: None,
+ reserve_sat: c.reserve.map(|f| f.into()),
+ reserve: None,
// Field: FundChannel.utxos[]
utxos: c.utxos.map(|arr| arr.into_iter().map(|i| i.into()).collect()).unwrap_or(vec![]), // Rule #3
}
}
}
-#[allow(unused_variables)]
+#[allow(unused_variables,deprecated)]
impl From<requests::FundchannelStartRequest> for pb::FundchannelStartRequest {
fn from(c: requests::FundchannelStartRequest) -> Self {
Self {
- amount: Some(c.amount.into()), // Rule #2 for type sat
+ amount_sat: Some(c.amount.into()),
+ amount: None,
announce: c.announce, // Rule #2 for type boolean?
// Field: FundChannel_Start.channel_type[]
channel_type: c.channel_type.map(|arr| arr.into_iter().map(|i| i.into()).collect()).unwrap_or(vec![]), // Rule #3
@@ -6284,7 +6292,8 @@ impl From<requests::FundchannelStartRequest> for pb::FundchannelStartRequest {
id: c.id.serialize().to_vec(), // Rule #2 for type pubkey
mindepth: c.mindepth, // Rule #2 for type u32?
push_msat: c.push_msat.map(|f| f.into()), // Rule #2 for type msat?
- reserve: c.reserve.map(|f| f.into()), // Rule #2 for type sat?
+ reserve_sat: c.reserve.map(|f| f.into()),
+ reserve: None,
}
}
}
@@ -6407,19 +6416,22 @@ impl From<requests::ListhtlcsRequest> for pb::ListhtlcsRequest {
}
}
-#[allow(unused_variables)]
+#[allow(unused_variables,deprecated)]
impl From<requests::MultifundchannelDestinations> for pb::MultifundchannelDestinations {
fn from(c: requests::MultifundchannelDestinations) -> Self {
Self {
- amount: Some(c.amount.into()), // Rule #2 for type sat_or_all
+ amount_sat: Some(c.amount.into()),
+ amount: None,
announce: c.announce, // Rule #2 for type boolean?
close_to: c.close_to, // Rule #2 for type string?
compact_lease: c.compact_lease, // Rule #2 for type string?
id: c.id, // Rule #2 for type string
mindepth: c.mindepth, // Rule #2 for type u32?
push_msat: c.push_msat.map(|f| f.into()), // Rule #2 for type msat?
- request_amt: c.request_amt.map(|f| f.into()), // Rule #2 for type sat?
- reserve: c.reserve.map(|f| f.into()), // Rule #2 for type sat?
+ request_amt_sat: c.request_amt.map(|f| f.into()),
+ request_amt: None,
+ reserve_sat: c.reserve.map(|f| f.into()),
+ reserve: None,
}
}
}
@@ -6486,23 +6498,25 @@ impl From<requests::OpenchannelAbortRequest> for pb::OpenchannelAbortRequest {
}
}
-#[allow(unused_variables)]
+#[allow(unused_variables,deprecated)]
impl From<requests::OpenchannelBumpRequest> for pb::OpenchannelBumpRequest {
fn from(c: requests::OpenchannelBumpRequest) -> Self {
Self {
- amount: Some(c.amount.into()), // Rule #2 for type sat
+ amount_sat: Some(c.amount.into()),
+ amount: None,
channel_id: <Sha256 as AsRef<[u8]>>::as_ref(&c.channel_id).to_vec(), // Rule #2 for type hash
funding_feerate: c.funding_feerate.map(|o|o.into()), // Rule #2 for type feerate?
initialpsbt: c.initialpsbt, // Rule #2 for type string
}
}
}
-#[allow(unused_variables)]
+#[allow(unused_variables,deprecated)]
impl From<requests::OpenchannelInitRequest> for pb::OpenchannelInitRequest {
fn from(c: requests::OpenchannelInitRequest) -> Self {
Self {
- amount: Some(c.amount.into()), // Rule #2 for type sat
+ amount_sat: Some(c.amount.into()),
+ amount: None,
announce: c.announce, // Rule #2 for type boolean?
// Field: OpenChannel_Init.channel_type[]
channel_type: c.channel_type.map(|arr| arr.into_iter().map(|i| i.into()).collect()).unwrap_or(vec![]), // Rule #3
@@ -6512,7 +6526,8 @@ impl From<requests::OpenchannelInitRequest> for pb::OpenchannelInitRequest {
funding_feerate: c.funding_feerate.map(|o|o.into()), // Rule #2 for type feerate?
id: c.id.serialize().to_vec(), // Rule #2 for type pubkey
initialpsbt: c.initialpsbt, // Rule #2 for type string
- request_amt: c.request_amt.map(|f| f.into()), // Rule #2 for type sat?
+ request_amt_sat: c.request_amt.map(|f| f.into()),
+ request_amt: None,
}
}
}
@@ -6936,7 +6951,7 @@ impl From<requests::BkprreportRequest> for pb::BkprreportRequest {
Self {
end_time: c.end_time, // Rule #2 for type u32?
escape: c.escape, // Rule #2 for type string?
- format: c.format, // Rule #2 for type string
+ format: Some(c.format), // Rule #2 for type string
// Field: Bkpr-Report.headers[]
headers: c.headers.map(|arr| arr.into_iter().map(|i| i.into()).collect()).unwrap_or(vec![]), // Rule #3
start_time: c.start_time, // Rule #2 for type u32?
@@ -7595,6 +7610,46 @@ fn missing_field(field: &str) -> tonic::Status {
tonic::Status::invalid_argument(format!("Missing required field `{}`", field))
}
+fn double_to_u32(field: &str, v: f64) -> Result<u32, tonic::Status> {
+ if v.fract() != 0.0 || !(0.0..=u32::MAX as f64).contains(&v) {
+ return Err(invalid_argument(field, format!("{} is not a u32", v)));
+ }
+ Ok(v as u32)
+}
+
+fn msat_to_sat(field: &str, a: pb::Amount) -> Result<cln_rpc::primitives::AmountSat, tonic::Status> {
+ cln_rpc::primitives::AmountSat::from_msat(a.msat)
+ .map_err(|e| invalid_argument(field, e))
+}
+
+fn msat_or_all_to_sat(field: &str, a: pb::AmountOrAll) -> Result<cln_rpc::primitives::AmountSatOrAll, tonic::Status> {
+ use cln_rpc::primitives::{AmountSat, AmountSatOrAll};
+ Ok(match a.value {
+ Some(pb::amount_or_all::Value::Amount(a)) => AmountSatOrAll::AmountSat(
+ AmountSat::from_msat(a.msat).map_err(|e| invalid_argument(field, e))?,
+ ),
+ Some(pb::amount_or_all::Value::All(_)) => AmountSatOrAll::All,
+ None => return Err(invalid_argument(field, "AmountOrAll is empty")),
+ })
+}
+
+fn sat_or_legacy<N, L, T>(
+ field: &str,
+ new: Option<N>,
+ legacy: Option<L>,
+ conv_new: impl FnOnce(N) -> Result<T, tonic::Status>,
+ conv_legacy: impl FnOnce(L) -> Result<T, tonic::Status>,
+) -> Result<Option<T>, tonic::Status> {
+ match (new, legacy) {
+ (Some(_), Some(_)) => Err(tonic::Status::invalid_argument(format!(
+ "Fields `{field}_sat` and deprecated `{field}` are mutually exclusive"
+ ))),
+ (Some(n), None) => conv_new(n).map(Some),
+ (None, Some(l)) => conv_legacy(l).map(Some),
+ (None, None) => Ok(None),
+ }
+}
+
#[allow(unused_variables)]
impl TryFrom<pb::GetinfoRequest> for requests::GetinfoRequest {
type Error = tonic::Status;
@@ -7684,15 +7739,15 @@ impl TryFrom<pb::AddgossipRequest> for requests::AddgossipRequest {
}
}
-#[allow(unused_variables)]
+#[allow(unused_variables,deprecated)]
impl TryFrom<pb::AddpsbtoutputRequest> for requests::AddpsbtoutputRequest {
type Error = tonic::Status;
fn try_from(c: pb::AddpsbtoutputRequest) -> Result<Self, Self::Error> {
Ok(Self {
destination: c.destination, // Rule #1 for type string?
initialpsbt: c.initialpsbt, // Rule #1 for type string?
locktime: c.locktime, // Rule #1 for type u32?
- satoshi: c.satoshi.ok_or_else(|| missing_field("satoshi"))?.into(), // Rule #1 for type sat
+ satoshi: sat_or_legacy("satoshi", c.satoshi_sat, c.satoshi, |a| Ok(a.into()), |a| msat_to_sat("satoshi", a))?.ok_or_else(|| missing_field("satoshi"))?,
})
}
}
@@ -8128,15 +8183,15 @@ impl TryFrom<pb::NewaddrRequest> for requests::NewaddrRequest {
}
}
-#[allow(unused_variables)]
+#[allow(unused_variables,deprecated)]
impl TryFrom<pb::WithdrawRequest> for requests::WithdrawRequest {
type Error = tonic::Status;
fn try_from(c: pb::WithdrawRequest) -> Result<Self, Self::Error> {
Ok(Self {
destination: c.destination, // Rule #1 for type string
feerate: c.feerate.map(|a| a.try_into().map_err(|e| invalid_argument("feerate", e))).transpose()?, // Rule #1 for type feerate?
minconf: c.minconf.map(|v| u16::try_from(v).map_err(|e| invalid_argument("minconf", e))).transpose()?, // Rule #1 for type u16?
- satoshi: c.satoshi.ok_or_else(|| missing_field("satoshi"))?.try_into().map_err(|e| invalid_argument("satoshi", e))?, // Rule #1 for type sat_or_all
+ satoshi: sat_or_legacy("satoshi", c.satoshi_sat, c.satoshi, |a| a.try_into().map_err(|e| invalid_argument("satoshi_sat", e)), |a| msat_or_all_to_sat("satoshi", a))?.ok_or_else(|| missing_field("satoshi"))?,
utxos: Some(c.utxos.into_iter().map(|s| s.try_into().map_err(|e| invalid_argument("utxos", e))).collect::<Result<Vec<_>, tonic::Status>>()?), // Rule #4
})
}
@@ -8161,7 +8216,7 @@ impl TryFrom<pb::KeysendRequest> for requests::KeysendRequest {
}
}
-#[allow(unused_variables)]
+#[allow(unused_variables,deprecated)]
impl TryFrom<pb::FundpsbtRequest> for requests::FundpsbtRequest {
type Error = tonic::Status;
fn try_from(c: pb::FundpsbtRequest) -> Result<Self, Self::Error> {
@@ -8174,7 +8229,7 @@ impl TryFrom<pb::FundpsbtRequest> for requests::FundpsbtRequest {
nonwrapped: c.nonwrapped, // Rule #1 for type boolean?
opening_anchor_channel: c.opening_anchor_channel, // Rule #1 for type boolean?
reserve: c.reserve, // Rule #1 for type u32?
- satoshi: c.satoshi.ok_or_else(|| missing_field("satoshi"))?.try_into().map_err(|e| invalid_argument("satoshi", e))?, // Rule #1 for type sat_or_all
+ satoshi: sat_or_legacy("satoshi", c.satoshi_sat, c.satoshi, |a| a.try_into().map_err(|e| invalid_argument("satoshi_sat", e)), |a| msat_or_all_to_sat("satoshi", a))?.ok_or_else(|| missing_field("satoshi"))?,
startweight: c.startweight, // Rule #1 for type u32
})
}
@@ -8202,7 +8257,7 @@ impl TryFrom<pb::SignpsbtRequest> for requests::SignpsbtRequest {
}
}
-#[allow(unused_variables)]
+#[allow(unused_variables,deprecated)]
impl TryFrom<pb::UtxopsbtRequest> for requests::UtxopsbtRequest {
type Error = tonic::Status;
fn try_from(c: pb::UtxopsbtRequest) -> Result<Self, Self::Error> {
@@ -8214,7 +8269,7 @@ impl TryFrom<pb::UtxopsbtRequest> for requests::UtxopsbtRequest {
opening_anchor_channel: c.opening_anchor_channel, // Rule #1 for type boolean?
reserve: c.reserve, // Rule #1 for type u32?
reservedok: c.reservedok, // Rule #1 for type boolean?
- satoshi: c.satoshi.ok_or_else(|| missing_field("satoshi"))?.try_into().map_err(|e| invalid_argument("satoshi", e))?, // Rule #1 for type sat_or_all
+ satoshi: sat_or_legacy("satoshi", c.satoshi_sat, c.satoshi, |a| a.try_into().map_err(|e| invalid_argument("satoshi_sat", e)), |a| msat_or_all_to_sat("satoshi", a))?.ok_or_else(|| missing_field("satoshi"))?,
startweight: c.startweight, // Rule #1 for type u32
utxos: c.utxos.into_iter().map(|s| s.try_into().map_err(|e| invalid_argument("utxos", e))).collect::<Result<Vec<_>, tonic::Status>>()?, // Rule #4
})
@@ -8418,12 +8473,12 @@ impl TryFrom<pb::FundchannelCompleteRequest> for requests::FundchannelCompleteRe
}
}
-#[allow(unused_variables)]
+#[allow(unused_variables,deprecated)]
impl TryFrom<pb::FundchannelRequest> for requests::FundchannelRequest {
type Error = tonic::Status;
fn try_from(c: pb::FundchannelRequest) -> Result<Self, Self::Error> {
Ok(Self {
- amount: c.amount.ok_or_else(|| missing_field("amount"))?.try_into().map_err(|e| invalid_argument("amount", e))?, // Rule #1 for type sat_or_all
+ amount: sat_or_legacy("amount", c.amount_sat, c.amount, |a| a.try_into().map_err(|e| invalid_argument("amount_sat", e)), |a| msat_or_all_to_sat("amount", a))?.ok_or_else(|| missing_field("amount"))?,
announce: c.announce, // Rule #1 for type boolean?
channel_type: Some(c.channel_type.into_iter().map(|s| s).collect()), // Rule #4
close_to: c.close_to, // Rule #1 for type string?
@@ -8433,27 +8488,27 @@ impl TryFrom<pb::FundchannelRequest> for requests::FundchannelRequest {
minconf: c.minconf, // Rule #1 for type u32?
mindepth: c.mindepth, // Rule #1 for type u32?
push_msat: c.push_msat.map(|a| a.into()), // Rule #1 for type msat?
- request_amt: c.request_amt.map(|a| a.into()), // Rule #1 for type sat?
- reserve: c.reserve.map(|a| a.into()), // Rule #1 for type sat?
+ request_amt: sat_or_legacy("request_amt", c.request_amt_sat, c.request_amt, |a| Ok(a.into()), |a| msat_to_sat("request_amt", a))?,
+ reserve: sat_or_legacy("reserve", c.reserve_sat, c.reserve, |a| Ok(a.into()), |a| msat_to_sat("reserve", a))?,
utxos: Some(c.utxos.into_iter().map(|s| s.try_into().map_err(|e| invalid_argument("utxos", e))).collect::<Result<Vec<_>, tonic::Status>>()?), // Rule #4
})
}
}
-#[allow(unused_variables)]
+#[allow(unused_variables,deprecated)]
impl TryFrom<pb::FundchannelStartRequest> for requests::FundchannelStartRequest {
type Error = tonic::Status;
fn try_from(c: pb::FundchannelStartRequest) -> Result<Self, Self::Error> {
Ok(Self {
- amount: c.amount.ok_or_else(|| missing_field("amount"))?.into(), // Rule #1 for type sat
+ amount: sat_or_legacy("amount", c.amount_sat, c.amount, |a| Ok(a.into()), |a| msat_to_sat("amount", a))?.ok_or_else(|| missing_field("amount"))?,
announce: c.announce, // Rule #1 for type boolean?
channel_type: Some(c.channel_type.into_iter().map(|s| s).collect()), // Rule #4
close_to: c.close_to, // Rule #1 for type string?
feerate: c.feerate.map(|a| a.try_into().map_err(|e| invalid_argument("feerate", e))).transpose()?, // Rule #1 for type feerate?
id: PublicKey::from_slice(&c.id).map_err(|e| invalid_argument("id", e))?, // Rule #1 for type pubkey
mindepth: c.mindepth, // Rule #1 for type u32?
push_msat: c.push_msat.map(|a| a.into()), // Rule #1 for type msat?
- reserve: c.reserve.map(|a| a.into()), // Rule #1 for type sat?
+ reserve: sat_or_legacy("reserve", c.reserve_sat, c.reserve, |a| Ok(a.into()), |a| msat_to_sat("reserve", a))?,
})
}
}
@@ -8576,20 +8631,20 @@ impl TryFrom<pb::ListhtlcsRequest> for requests::ListhtlcsRequest {
}
}
-#[allow(unused_variables)]
+#[allow(unused_variables,deprecated)]
impl TryFrom<pb::MultifundchannelDestinations> for requests::MultifundchannelDestinations {
type Error = tonic::Status;
fn try_from(c: pb::MultifundchannelDestinations) -> Result<Self, Self::Error> {
Ok(Self {
- amount: c.amount.ok_or_else(|| missing_field("amount"))?.try_into().map_err(|e| invalid_argument("amount", e))?, // Rule #1 for type sat_or_all
+ amount: sat_or_legacy("amount", c.amount_sat, c.amount, |a| a.try_into().map_err(|e| invalid_argument("amount_sat", e)), |a| msat_or_all_to_sat("amount", a))?.ok_or_else(|| missing_field("amount"))?,
announce: c.announce, // Rule #1 for type boolean?
close_to: c.close_to, // Rule #1 for type string?
compact_lease: c.compact_lease, // Rule #1 for type string?
id: c.id, // Rule #1 for type string
mindepth: c.mindepth, // Rule #1 for type u32?
push_msat: c.push_msat.map(|a| a.into()), // Rule #1 for type msat?
- request_amt: c.request_amt.map(|a| a.into()), // Rule #1 for type sat?
- reserve: c.reserve.map(|a| a.into()), // Rule #1 for type sat?
+ request_amt: sat_or_legacy("request_amt", c.request_amt_sat, c.request_amt, |a| Ok(a.into()), |a| msat_to_sat("request_amt", a))?,
+ reserve: sat_or_legacy("reserve", c.reserve_sat, c.reserve, |a| Ok(a.into()), |a| msat_to_sat("reserve", a))?,
})
}
}
@@ -8655,25 +8710,25 @@ impl TryFrom<pb::OpenchannelAbortRequest> for requests::OpenchannelAbortRequest
}
}
-#[allow(unused_variables)]
+#[allow(unused_variables,deprecated)]
impl TryFrom<pb::OpenchannelBumpRequest> for requests::OpenchannelBumpRequest {
type Error = tonic::Status;
fn try_from(c: pb::OpenchannelBumpRequest) -> Result<Self, Self::Error> {
Ok(Self {
- amount: c.amount.ok_or_else(|| missing_field("amount"))?.into(), // Rule #1 for type sat
+ amount: sat_or_legacy("amount", c.amount_sat, c.amount, |a| Ok(a.into()), |a| msat_to_sat("amount", a))?.ok_or_else(|| missing_field("amount"))?,
channel_id: Sha256::from_slice(&c.channel_id).map_err(|e| invalid_argument("channel_id", e))?, // Rule #1 for type hash
funding_feerate: c.funding_feerate.map(|a| a.try_into().map_err(|e| invalid_argument("funding_feerate", e))).transpose()?, // Rule #1 for type feerate?
initialpsbt: c.initialpsbt, // Rule #1 for type string
})
}
}
-#[allow(unused_variables)]
+#[allow(unused_variables,deprecated)]
impl TryFrom<pb::OpenchannelInitRequest> for requests::OpenchannelInitRequest {
type Error = tonic::Status;
fn try_from(c: pb::OpenchannelInitRequest) -> Result<Self, Self::Error> {
Ok(Self {
- amount: c.amount.ok_or_else(|| missing_field("amount"))?.into(), // Rule #1 for type sat
+ amount: sat_or_legacy("amount", c.amount_sat, c.amount, |a| Ok(a.into()), |a| msat_to_sat("amount", a))?.ok_or_else(|| missing_field("amount"))?,
announce: c.announce, // Rule #1 for type boolean?
channel_type: Some(c.channel_type.into_iter().map(|s| s).collect()), // Rule #4
close_to: c.close_to, // Rule #1 for type string?
@@ -8682,7 +8737,7 @@ impl TryFrom<pb::OpenchannelInitRequest> for requests::OpenchannelInitRequest {
funding_feerate: c.funding_feerate.map(|a| a.try_into().map_err(|e| invalid_argument("funding_feerate", e))).transpose()?, // Rule #1 for type feerate?
id: PublicKey::from_slice(&c.id).map_err(|e| invalid_argument("id", e))?, // Rule #1 for type pubkey
initialpsbt: c.initialpsbt, // Rule #1 for type string
- request_amt: c.request_amt.map(|a| a.into()), // Rule #1 for type sat?
+ request_amt: sat_or_legacy("request_amt", c.request_amt_sat, c.request_amt, |a| Ok(a.into()), |a| msat_to_sat("request_amt", a))?,
})
}
}
@@ -9134,7 +9189,7 @@ impl TryFrom<pb::BkprreportRequest> for requests::BkprreportRequest {
Ok(Self {
end_time: c.end_time, // Rule #1 for type u32?
escape: c.escape, // Rule #1 for type string?
- format: c.format, // Rule #1 for type string
+ format: (c.format.ok_or_else(|| missing_field("format"))?), // Rule #1 for type string
headers: Some(c.headers.into_iter().map(|s| s.into()).collect()), // Rule #4
start_time: c.start_time, // Rule #1 for type u32?
})
### contrib/msggen/msggen/__main__.py
@@ -1,9 +1,11 @@
import json
import os
import argparse
+import subprocess
import sys
from pathlib import Path
from msggen.gen.grpc import GrpcGenerator, GrpcConverterGenerator, GrpcUnconverterGenerator, GrpcServerGenerator
+from msggen.gen.grpc.wire import WireState, released_contract
from msggen.gen.grpc2py import Grpc2PyGenerator
from msggen.gen.rpc import RustGenerator, NotificationGenerator, HookGenerator
from msggen.gen.generator import GeneratorChain
@@ -26,14 +28,15 @@
def add_handler_gen_grpc(generator_chain: GeneratorChain, meta):
"""Load all mapped RPC methods, wrap them in a Service, and split them into messages.
"""
+ state = WireState()
fname = Path("cln-grpc") / "proto" / "node.proto"
dest = open(fname, "w")
- generator_chain.add_generator(GrpcGenerator(dest, meta))
+ generator_chain.add_generator(GrpcGenerator(dest, meta, state))
fname = Path("cln-grpc") / "src" / "convert.rs"
dest = open(fname, "w")
- generator_chain.add_generator(GrpcConverterGenerator(dest))
- generator_chain.add_generator(GrpcUnconverterGenerator(dest))
+ generator_chain.add_generator(GrpcConverterGenerator(dest, state))
+ generator_chain.add_generator(GrpcUnconverterGenerator(dest, state))
fname = Path("cln-grpc") / "src" / "server.rs"
dest = open(fname, "w")
@@ -72,6 +75,29 @@ def write_msggen_meta(meta):
os.rename(f'.msggen.json.tmp.{pid}', '.msggen.json')
+def record_wire_contract(revision: str):
+ """Replace `grpc-wire-contract` with the labels released at `revision`.
+
+ Reads `cln-grpc/proto/node.proto` and `primitives.proto` from git, so
+ the contract records what was shipped, not what the schema now says.
+ """
+ def show(path):
+ res = subprocess.run(
+ ["git", "show", f"{revision}:{path}"], capture_output=True, text=True
+ )
+ if res.returncode != 0:
+ raise SystemExit(f"{revision}:{path} not found: {res.stderr.strip()}")
+ return res.stdout
+
+ contract = released_contract(
+ [show("cln-grpc/proto/node.proto"), show("cln-grpc/proto/primitives.proto")]
+ )
+ meta = load_msggen_meta()
+ meta["grpc-wire-contract"] = contract
+ write_msggen_meta(meta)
+ print(f"Recorded {sum(len(f) for f in contract.values())} fields from {revision}")
+
+
def run():
meta = load_msggen_meta()
service = load_jsonrpc_service(
@@ -109,6 +135,11 @@ def main():
subcmds.add_parser("generate", help="generate all files")
subcmds.add_parser("missing-grpc", help="print all rpc commands missing from grpc")
+ record = subcmds.add_parser(
+ "record-wire-contract",
+ help="replace grpc-wire-contract with the labels released at a git revision",
+ )
+ record.add_argument("revision", help="git tag or revision, e.g. v26.06")
args = parser.parse_args()
if args.silent:
@@ -125,6 +156,8 @@ def main():
print(f"Combining schemas from {src.resolve()} into {dest.resolve()}")
schema = combine_schemas(src, dest)
print(f"Created {dest} from {len(schema)} files")
+ elif args.command == 'record-wire-contract':
+ record_wire_contract(args.revision)
elif args.command == 'missing-grpc':
missing, stale = check_missing()
print("Missing RPC commands in grpc:")
### contrib/msggen/msggen/gen/grpc/convert.py
@@ -1,6 +1,7 @@
# A grpc model
from msggen.model import ArrayField, CompositeField, EnumField, PrimitiveField, Service
from msggen.gen.grpc.util import notification_typename_overrides
+from msggen.gen.grpc.wire import WireState
from msggen.gen import IGenerator
from typing import TextIO
from textwrap import indent, dedent
@@ -9,8 +10,9 @@
class GrpcConverterGenerator(IGenerator):
- def __init__(self, dest: TextIO):
+ def __init__(self, dest: TextIO, state: WireState):
self.dest = dest
+ self.state = state
self.logger = logging.getLogger("msggen.grpc.GrpcConversionGenerator")
def generate_array(self, prefix, field: ArrayField, override):
@@ -41,7 +43,12 @@ def generate_composite(self, prefix, field: CompositeField, override=None):
# warning we mark the construction here to allow deprecated
# fields being access.
- has_deprecated = any([f.deprecated for f in field.fields])
+ has_deprecated = any(
+ [
+ f.deprecated or f"{pbname}.{f.path}" in self.state.legacy
+ for f in field.fields
+ ]
+ )
deprecated = ",deprecated" if has_deprecated else ""
# And now we can convert the current field:
@@ -60,6 +67,7 @@ def generate_composite(self, prefix, field: CompositeField, override=None):
name = f.normalized()
name = re.sub(r"(?<!^)(?=[A-Z])", "_", name).lower()
+ key = f"{pbname}.{f.path}"
if isinstance(f, ArrayField):
typ = f.itemtype.typename
# The inner conversion applied to each element in the
@@ -87,9 +95,27 @@ def generate_composite(self, prefix, field: CompositeField, override=None):
)
elif isinstance(f, EnumField):
if not f.optional:
- self.write(f"{name}: c.{name} as i32,\n", numindent=3)
+ rhs = f"c.{name} as i32"
else:
- self.write(f"{name}: c.{name}.map(|v| v as i32),\n", numindent=3)
+ rhs = f"c.{name}.map(|v| v as i32)"
+ rhs = self.pin_to_proto(key, rhs)
+ self.write(f"{name}: {rhs},\n", numindent=3)
+
+ elif isinstance(f, PrimitiveField) and key in self.state.legacy:
+ if prefix != "requests":
+ raise ValueError(
+ f"{f.path}: renumbered fields are only supported in requests"
+ )
+ legacy = self.state.legacy[key]
+ typ = f.typename + ("?" if f.optional else "")
+ rhs = {
+ "sat": f"Some(c.{name}.into())",
+ "sat?": f"c.{name}.map(|f| f.into())",
+ "sat_or_all": f"Some(c.{name}.into())",
+ "sat_or_all?": f"c.{name}.map(|o| o.into())",
+ }[typ]
+ self.write(f"{legacy['new_name']}: {rhs},\n", numindent=3)
+ self.write(f"{name}: None,\n", numindent=3)
elif isinstance(f, PrimitiveField):
typ = f.typename + ("?" if f.optional else "")
@@ -144,6 +170,8 @@ def generate_composite(self, prefix, field: CompositeField, override=None):
f"c.{name}", # default to just assignment
)
+ rhs = self.pin_to_proto(key, rhs)
+
if f.deprecated:
self.write(f"#[allow(deprecated)]\n", numindent=3)
self.write(f"{name}: {rhs}, // Rule #2 for type {typ}\n", numindent=3)
@@ -164,6 +192,29 @@ def generate_composite(self, prefix, field: CompositeField, override=None):
"""
)
+ def pin_to_proto(self, key: str, rhs: str) -> str:
+ """Adapt an expression of the schema-implied proto type to the
+ released proto type of the field."""
+ pin = self.state.pinned.get(key)
+ if pin is None:
+ return rhs
+ proto, schema = pin["proto"], pin["schema"]
+ optional = schema["label"] == "optional"
+
+ if proto["type"] != schema["type"]:
+ conv = {
+ ("uint64", "uint32"): "u64::from",
+ ("double", "uint32"): "f64::from",
+ ("string", "bytes"): "hex::encode",
+ }[(proto["type"], schema["type"])]
+ rhs = f"{rhs}.map({conv})" if optional else f"{conv}({rhs})"
+
+ if proto["label"] == "optional" and not optional:
+ rhs = f"Some({rhs})"
+ elif proto["label"] == "plain" and optional:
+ rhs = f"{rhs}.unwrap_or_default()"
+ return rhs
+
def to_camel_case(self, snake_str):
components = snake_str.split("_")
# We capitalize the first letter of each component except the first one
### contrib/msggen/msggen/gen/grpc/proto.py
@@ -2,16 +2,19 @@
from typing import TextIO, List, Dict, Any
from textwrap import dedent
import logging
+import re
from msggen.gen import IGenerator
from msggen.gen.grpc.util import (
typemap,
method_name_overrides,
notification_typename_overrides,
)
+from msggen.gen.grpc import wire
from msggen.model import (
ArrayField,
Field,
+ FieldName,
CompositeField,
EnumField,
EnumVariant,
@@ -27,18 +30,20 @@
class GrpcGenerator(IGenerator):
"""A generator that generates protobuf files."""
- def __init__(self, dest: TextIO, meta: Dict[str, Any]):
+ def __init__(self, dest: TextIO, meta: Dict[str, Any], state: wire.WireState):
self.dest = dest
self.logger = logging.getLogger("msggen.grpc.GrpcGenerator")
self.meta = meta
+ self.state = state
+ wire.ensure_meta(meta)
def write(self, text: str, cleanup: bool = True) -> None:
if cleanup:
self.dest.write(dedent(text))
else:
self.dest.write(text)
- def field2number(self, message_name: TypeName, field):
+ def field2number(self, message_name: TypeName, field, taken=()):
m = self.meta["grpc-field-map"]
message_name = (
@@ -59,7 +64,7 @@ def field2number(self, message_name: TypeName, field):
# Now let's find the highest number we have in the parent
# context
parent = ".".join(field.path.split(".")[:-1])
- maxnum = 0
+ maxnum = max(taken, default=0)
for k, v in m.items():
parent2 = ".".join(k.split(".")[:-1])
if parent2 == parent:
@@ -232,36 +237,138 @@ def generate_message(self, message: CompositeField, typename_override=None):
if isinstance(f, EnumField) and not f.override():
self.generate_enum(f, indent=1, typename_override=typename_override)
+ pbname = str(typename_override(message.typename))
+ contract = self.meta["grpc-wire-contract"].setdefault(pbname, {})
+ emitted = []
+
for i, f in self.enumerate_fields(message.typename, message.fields):
if f.omit():
continue
- opt = "optional " if f.optional and not (isinstance(f, PrimitiveField) and f.typename == "string_map") else ""
- depri = " [deprecated = true]" if f.deprecated else ""
+ label, typename = self.field_decl(f, typename_override)
+ name = f.normalized()
+ key = f"{pbname}.{f.path}"
+ current = {"label": label, "type": self.wire_type(f, typename)}
+ schema_type = getattr(f, "typename", None)
+
+ if str(i) not in contract:
+ contract[str(i)] = wire.pack(current)
+ resolved = wire.resolve(
+ f.path, schema_type, wire.unpack(contract[str(i)]), current
+ )
- if isinstance(f, ArrayField):
- typename = f.override(
- typemap.get(f.itemtype.typename, f.itemtype.typename)
+ if resolved.get("renumber"):
+ # Keep serving the released msat field under its old
+ # number, and move the sat value to a new one.
+ legacy = self.meta["grpc-legacy-fields"].setdefault(
+ f.path, {"number": i, **wire.unpack(contract[str(i)])}
+ )
+ self.state.legacy[key] = {"new_name": f"{name}_sat", **legacy}
+ emitted.append(
+ (legacy["number"], legacy["label"], legacy["type"], name, True)
+ )
+ name = f"{name}_sat"
+ i = self.field2number(
+ message.typename,
+ wire.RenumberedField(f.path),
+ taken=[int(n) for n in contract],
+ )
+ if str(i) not in contract:
+ contract[str(i)] = wire.pack(current)
+ resolved = wire.resolve(
+ f.path, schema_type, wire.unpack(contract[str(i)]), current
)
- self.write(f"\trepeated {typename} {f.normalized()} = {i}{depri};\n", False)
- elif isinstance(f, PrimitiveField):
- typename = f.override(typemap.get(f.typename, f.typename))
- typename = typename_override(typename)
- self.write(f"\t{opt}{typename} {f.normalized()} = {i}{depri};\n", False)
- elif isinstance(f, EnumField):
- typename = f.override(f.typename)
- typename = typename_override(typename)
- self.write(f"\t{opt}{typename} {f.normalized()} = {i}{depri};\n", False)
- elif isinstance(f, CompositeField):
- typename = f.override(f.typename)
- typename = typename_override(typename)
- self.write(f"\t{opt}{typename} {f.normalized()} = {i}{depri};\n", False)
+ if resolved.get("renumber"):
+ raise wire.WireCompatError(f"{f.path}: renumbered twice")
+
+ contract[str(i)] = wire.pack(
+ {
+ "label": resolved["label"],
+ "type": wire.unpack(contract[str(i)])["type"],
+ }
+ )
+
+ if resolved["type"] != current["type"]:
+ self.state.pinned[key] = {"proto": resolved, "schema": current}
+ typename = resolved["type"]
+ elif resolved["label"] != current["label"] and wire.is_scalar(current):
+ # Message fields are `Option<T>` in prost regardless of
+ # the label, so only scalars need converting.
+ self.state.pinned[key] = {"proto": resolved, "schema": current}
+
+ emitted.append((i, resolved["label"], typename, name, bool(f.deprecated)))
+
+ used = {e[0] for e in emitted}
+ known = {int(n) for n in contract}
+ known |= set(
+ self.meta["grpc-field-map"].get(message.typename.name, {}).values()
+ )
+ reserved = sorted(known - used)
+ names = {
+ num: path.split(".")[-1].replace("[]", "")
+ for path, num in self.meta["grpc-field-map"]
+ .get(message.typename.name, {})
+ .items()
+ }
+ emitted_names = {e[3] for e in emitted}
+ reserved_names = sorted(
+ {
+ FieldName(names[n]).normalized()
+ for n in reserved
+ if n in names and re.fullmatch(r"[A-Za-z_][A-Za-z0-9_-]*", names[n])
+ }
+ - emitted_names
+ )
+
+ for i, label, typename, name, deprecated in sorted(emitted):
+ depri = " [deprecated = true]" if deprecated else ""
+ self.write(
+ f"\t{self.decl_label(label)}{typename} {name} = {i}{depri};\n", False
+ )
+
+ if reserved:
+ nums = ", ".join(str(n) for n in reserved)
+ self.write(f"\treserved {nums};\n", False)
+ if reserved_names:
+ quoted = ", ".join(f'"{n}"' for n in reserved_names)
+ self.write(f"\treserved {quoted};\n", False)
self.write(
"""}
"""
)
+ @staticmethod
+ def decl_label(label: str) -> str:
+ return "" if label == "plain" else f"{label} "
+
+ def field_decl(self, f: Field, typename_override):
+ """Return the (label, typename) the schema implies for a field."""
+ if isinstance(f, ArrayField):
+ typename = f.override(typemap.get(f.itemtype.typename, f.itemtype.typename))
+ return "repeated", typename
+
+ if isinstance(f, PrimitiveField):
+ typename = typename_override(
+ f.override(typemap.get(f.typename, f.typename))
+ )
+ if f.typename == "string_map":
+ return "plain", typename
+ else:
+ typename = typename_override(f.override(f.typename))
+ return ("optional" if f.optional else "plain"), str(typename)
+
+ @staticmethod
+ def wire_type(f: Field, typename: str) -> str:
+ """Generated types are only identified by kind, since their
+ names derive from the (stable) field path."""
+ item = f.itemtype if isinstance(f, ArrayField) else f
+ if isinstance(item, CompositeField):
+ return "message"
+ if isinstance(item, EnumField):
+ return "enum"
+ return typename
+
def generate(self, service: Service) -> None:
"""Generate the GRPC protobuf file and write to `dest`"""
self.write(f"""syntax = "proto3";\npackage cln;\n""")
### contrib/msggen/msggen/gen/grpc/unconvert.py
@@ -1,4 +1,6 @@
# A grpc model
+import re
+
from msggen.model import ArrayField, CompositeField, EnumField, PrimitiveField, Service
from msggen.gen.grpc.convert import GrpcConverterGenerator
@@ -24,6 +26,46 @@ def write_helpers(self) -> None:
tonic::Status::invalid_argument(format!("Missing required field `{}`", field))
}
+ fn double_to_u32(field: &str, v: f64) -> Result<u32, tonic::Status> {
+ if v.fract() != 0.0 || !(0.0..=u32::MAX as f64).contains(&v) {
+ return Err(invalid_argument(field, format!("{} is not a u32", v)));
+ }
+ Ok(v as u32)
+ }
+
+ fn msat_to_sat(field: &str, a: pb::Amount) -> Result<cln_rpc::primitives::AmountSat, tonic::Status> {
+ cln_rpc::primitives::AmountSat::from_msat(a.msat)
+ .map_err(|e| invalid_argument(field, e))
+ }
+
+ fn msat_or_all_to_sat(field: &str, a: pb::AmountOrAll) -> Result<cln_rpc::primitives::AmountSatOrAll, tonic::Status> {
+ use cln_rpc::primitives::{AmountSat, AmountSatOrAll};
+ Ok(match a.value {
+ Some(pb::amount_or_all::Value::Amount(a)) => AmountSatOrAll::AmountSat(
+ AmountSat::from_msat(a.msat).map_err(|e| invalid_argument(field, e))?,
+ ),
+ Some(pb::amount_or_all::Value::All(_)) => AmountSatOrAll::All,
+ None => return Err(invalid_argument(field, "AmountOrAll is empty")),
+ })
+ }
+
+ fn sat_or_legacy<N, L, T>(
+ field: &str,
+ new: Option<N>,
+ legacy: Option<L>,
+ conv_new: impl FnOnce(N) -> Result<T, tonic::Status>,
+ conv_legacy: impl FnOnce(L) -> Result<T, tonic::Status>,
+ ) -> Result<Option<T>, tonic::Status> {
+ match (new, legacy) {
+ (Some(_), Some(_)) => Err(tonic::Status::invalid_argument(format!(
+ "Fields `{field}_sat` and deprecated `{field}` are mutually exclusive"
+ ))),
+ (Some(n), None) => conv_new(n).map(Some),
+ (None, Some(l)) => conv_legacy(l).map(Some),
+ (None, None) => Ok(None),
+ }
+ }
+
"""
)
@@ -82,6 +124,63 @@ def array_element(self, name: str, itemtype) -> tuple:
),
}.get(typ, ("s.into()", False))
+ def with_pinned(self, f, key: str, name: str, rhs: str) -> str:
+ """Bridge a field whose proto label/type is pinned to the released
+ one by substituting `c.{name}` in `rhs` (which is written against
+ the schema-implied proto type) with a converted value."""
+ pin = self.state.pinned.get(key)
+ if pin is None:
+ return rhs
+ proto, schema = pin["proto"], pin["schema"]
+ v = f"c.{name}"
+
+ # Released as plain, so 0/""/false is all an old client can send
+ # to mean "not set".
+ if proto["label"] == "plain" and schema["label"] == "optional":
+ if proto["type"] == "bool":
+ v = f"Some({v}).filter(|v| *v)"
+ elif proto["type"] in ("string", "bytes"):
+ v = f"Some({v}).filter(|v| !v.is_empty())"
+ else:
+ v = f"Some({v}).filter(|v| *v != Default::default())"
+ elif proto["label"] == "optional" and schema["label"] == "plain":
+ v = f'{v}.ok_or_else(|| missing_field("{name}"))?'
+
+ optional = schema["label"] == "optional"
+ if proto["type"] != schema["type"]:
+ conv = {
+ (
+ "uint64",
+ "uint32",
+ ): f'|v| u32::try_from(v).map_err(|e| invalid_argument("{name}", e))',
+ ("double", "uint32"): f'|v| double_to_u32("{name}", v)',
+ (
+ "string",
+ "bytes",
+ ): f'|v| hex::decode(v).map_err(|e| invalid_argument("{name}", e))',
+ }[(proto["type"], schema["type"])]
+ if optional:
+ v = f"{v}.map({conv}).transpose()?"
+ else:
+ v = f"({conv})({v})?"
+
+ return re.sub(rf"\bc\.{name}\b", lambda _: f"({v})", rhs)
+
+ def legacy_rhs(self, key: str, f, name: str) -> str:
+ legacy = self.state.legacy[key]
+ new = f"c.{legacy['new_name']}"
+ old = f"c.{name}"
+ if f.typename == "sat":
+ conv_new = "|a| Ok(a.into())"
+ conv_old = f'|a| msat_to_sat("{name}", a)'
+ else:
+ conv_new = f'|a| a.try_into().map_err(|e| invalid_argument("{legacy["new_name"]}", e))'
+ conv_old = f'|a| msat_or_all_to_sat("{name}", a)'
+ rhs = f'sat_or_legacy("{name}", {new}, {old}, {conv_new}, {conv_old})?'
+ if not f.optional:
+ rhs += f'.ok_or_else(|| missing_field("{name}"))?'
+ return rhs
+
def generate_composite(self, prefix, field: CompositeField, override=None) -> None:
# First pass: generate any sub-fields before we generate the
# top-level field itself.
@@ -97,10 +196,14 @@ def generate_composite(self, prefix, field: CompositeField, override=None) -> No
elif isinstance(f, CompositeField):
self.generate_composite(prefix, f, override)
- has_deprecated = any([f.deprecated for f in field.fields])
- deprecated = ",deprecated" if has_deprecated else ""
-
pbname = self.to_camel_case(str(field.typename))
+ has_deprecated = any(
+ [
+ f.deprecated or f"{pbname}.{f.path}" in self.state.legacy
+ for f in field.fields
+ ]
+ )
+ deprecated = ",deprecated" if has_deprecated else ""
# And now we can convert the current field:
self.write(
f"""\
@@ -114,6 +217,7 @@ def generate_composite(self, prefix, field: CompositeField, override=None) -> No
for f in field.fields:
name = f.normalized()
+ key = f"{pbname}.{f.path}"
if f.omit():
continue
@@ -155,15 +259,15 @@ def generate_composite(self, prefix, field: CompositeField, override=None) -> No
if f.path == "ListPeers.peers[].channels[].htlcs[].state":
continue
if not f.optional:
- self.write(
- f'{name}: c.{name}.try_into().map_err(|e| invalid_argument("{name}", e))?,\n',
- numindent=3,
- )
+ rhs = f'c.{name}.try_into().map_err(|e| invalid_argument("{name}", e))?'
else:
- self.write(
- f'{name}: c.{name}.map(|v| v.try_into().map_err(|e| invalid_argument("{name}", e))).transpose()?,\n',
- numindent=3,
- )
+ rhs = f'c.{name}.map(|v| v.try_into().map_err(|e| invalid_argument("{name}", e))).transpose()?'
+ self.write(
+ f"{name}: {self.with_pinned(f, key, name, rhs)},\n", numindent=3
+ )
+
+ elif isinstance(f, PrimitiveField) and key in self.state.legacy:
+ self.write(f"{name}: {self.legacy_rhs(key, f, name)},\n", numindent=3)
elif isinstance(f, PrimitiveField):
typ = f.typename + ("?" if f.optional else "")
@@ -222,6 +326,7 @@ def generate_composite(self, prefix, field: CompositeField, override=None) -> No
typ,
f"c.{name}", # default to just assignment
)
+ rhs = self.with_pinned(f, key, name, rhs)
self.write(f"{name}: {rhs}, // Rule #1 for type {typ}\n", numindent=3)
elif isinstance(f, CompositeField):
### contrib/msggen/msggen/gen/grpc/wire.py
@@ -0,0 +1,190 @@
+"""Keep the generated protobuf wire format stable across schema changes.
+
+Every field number msggen emits is recorded in `.msggen.json` under
+`grpc-wire-contract` together with its label and type. When the JSON
+schema later implies a different label or type for that number, we keep
+emitting the recorded one if the difference can be bridged in the Rust
+conversion code, and refuse to generate otherwise.
+"""
+
+import re
+from typing import Any, Dict, Optional
+
+SCALARS = {
+ "double",
+ "float",
+ "int32",
+ "int64",
+ "uint32",
+ "uint64",
+ "sint32",
+ "sint64",
+ "fixed32",
+ "fixed64",
+ "sfixed32",
+ "sfixed64",
+ "bool",
+ "string",
+ "bytes",
+}
+
+UNSIGNED_WIDTH = {"uint32": 32, "uint64": 64}
+
+# Sat-denominated types that replaced msat-denominated ones. The value
+# moves to a new field number and the old number stays as a deprecated
+# msat field.
+SAT_LEGACY = {"AmountSat": "Amount", "AmountSatOrAll": "AmountOrAll"}
+
+
+class WireCompatError(Exception):
+ pass
+
+
+class RenumberedField:
+ """Key for the new field number of a renumbered field."""
+
+ def __init__(self, path: str):
+ self.path = f"{path}#sat"
+
+
+class WireState:
+ """Results of the proto generation that the Rust converters need.
+
+ `pinned` maps field paths whose proto label or type differs from
+ the schema to `{"proto": desc, "schema": desc}`. `legacy` maps
+ renumbered field paths to their deprecated msat field.
+ """
+
+ def __init__(self):
+ self.pinned: Dict[str, Dict[str, Dict[str, str]]] = {}
+ self.legacy: Dict[str, Dict[str, Any]] = {}
+
+
+def ensure_meta(meta: Dict[str, Any]) -> None:
+ meta.setdefault("grpc-wire-contract", {})
+ meta.setdefault("grpc-legacy-fields", {})
+
+
+def parse_proto(text: str, enums=()) -> Dict[str, Dict[int, Dict[str, str]]]:
+ """Extract `{message: {number: {label, type}}}` from a node.proto.
+
+ Types of generated messages are recorded as "message" and enum
+ types as "enum", matching what `GrpcGenerator.wire_desc` produces.
+ """
+ messages: Dict[str, Dict[int, Dict[str, str]]] = {}
+ enum_names = set(enums)
+ stack = []
+ for line in text.splitlines():
+ s = line.strip()
+ m = re.match(r"(message|enum|service) (\w+) \{", s)
+ if m:
+ stack.append(m.groups())
+ if m.group(1) == "message":
+ messages.setdefault(m.group(2), {})
+ elif m.group(1) == "enum":
+ enum_names.add(m.group(2))
+ continue
+ if s == "}" and stack:
+ stack.pop()
+ continue
+ if not stack or stack[-1][0] != "message":
+ continue
+ m = re.match(r"(optional |repeated )?(map<[\w, ]+>|[\w.]+) (\w+) = (\d+)", s)
+ if m:
+ label = (m.group(1) or "plain").strip()
+ messages[stack[-1][1]][int(m.group(4))] = {
+ "label": label,
+ "type": m.group(2),
+ }
+
+ for fields in messages.values():
+ for desc in fields.values():
+ if desc["type"] in messages:
+ desc["type"] = "message"
+ elif desc["type"] in enum_names:
+ desc["type"] = "enum"
+ return messages
+
+
+def released_contract(texts) -> Dict[str, Dict[str, str]]:
+ """Build `grpc-wire-contract` from the released `.proto` sources.
+
+ `texts` is the list of proto files of one release. Labels and types
+ are taken as released, and enum and message types are recorded by
+ kind, so the result compares directly with the recorded contract.
+ """
+ enums, messages = set(), set()
+ for text in texts:
+ enums.update(re.findall(r"^\s*enum (\w+) \{", text, re.M))
+ messages.update(re.findall(r"^\s*message (\w+) \{", text, re.M))
+
+ contract: Dict[str, Dict[str, str]] = {}
+ for text in texts:
+ for msg, fields in parse_proto(text, enums=enums).items():
+ if msg not in messages:
+ continue
+ contract.setdefault(msg, {}).update(
+ {str(n): pack(desc) for n, desc in fields.items()}
+ )
+ return contract
+
+
+def is_scalar(desc: Dict[str, str]) -> bool:
+ return desc["type"] in SCALARS or desc["type"] == "enum"
+
+
+def pack(desc: Dict[str, str]) -> str:
+ return f"{desc['label']} {desc['type']}"
+
+
+def unpack(value: str) -> Dict[str, str]:
+ label, typename = value.split(" ", 1)
+ return {"label": label, "type": typename}
+
+
+def resolve(
+ path: str,
+ schema_type: Optional[str],
+ recorded: Dict[str, str],
+ current: Dict[str, str],
+) -> Dict[str, Any]:
+ """Decide what to emit for a field number.
+
+ Returns the descriptor to emit, plus `renumber: True` if the value
+ has to move to a new field number.
+ """
+ if (recorded["label"] == "repeated") != (current["label"] == "repeated"):
+ raise WireCompatError(
+ f"{path}: cannot change between repeated and non-repeated "
+ f"({recorded['label']} {recorded['type']} -> "
+ f"{current['label']} {current['type']})"
+ )
+
+ # Adding `optional` is wire compatible. Dropping it would turn
+ # 0/""/false into "absent", so once released it stays.
+ if "optional" in (recorded["label"], current["label"]):
+ label = "optional"
+ else:
+ label = recorded["label"]
+
+ rt, ct = recorded["type"], current["type"]
+ if rt == ct:
+ return {"label": label, "type": ct}
+
+ if current["label"] != "repeated":
+ if rt in UNSIGNED_WIDTH and ct in UNSIGNED_WIDTH:
+ if UNSIGNED_WIDTH[rt] > UNSIGNED_WIDTH[ct]:
+ return {"label": label, "type": rt}
+ if rt == "double" and ct == "uint32":
+ return {"label": label, "type": rt}
+ if rt == "string" and ct == "bytes" and schema_type == "pubkey":
+ return {"label": label, "type": rt}
+ if SAT_LEGACY.get(ct) == rt:
+ return {"label": current["label"], "type": ct, "renumber": True}
+
+ raise WireCompatError(
+ f"{path}: the schema now maps to `{current['label']} {ct}` but "
+ f"the field number was released as `{recorded['label']} {rt}`. "
+ f"This is not wire compatible: teach msggen.gen.grpc.wire how to "
+ f"bridge it, or give the field a new name."
+ )
### contrib/pyln-grpc-proto/pyln/grpc/node_pb2.py
[binary or diff unavailable]Why this scored 34/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.