Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contrib/api/generate-python-docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@

def generate_docs(output_dir: Path, repo_root: Path):
"""Generate documentation for all packages."""
print(f"Generating Python documentation for all workspace packages...")
print("Generating Python documentation for all workspace packages...")
print(f"Output directory: {output_dir}")

# Clean and create output directory
Expand Down
26 changes: 13 additions & 13 deletions contrib/msggen/msggen/gen/grpc/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ def generate_composite(self, prefix, field: CompositeField, override=None):
# The inner conversion applied to each element in the
# array. The current item is called `i`
mapping = {
"hex": f"hex::decode(i).unwrap()",
"secret": f"i.to_vec()",
"hash": f"<Sha256 as AsRef<[u8]>>::as_ref(&i).to_vec()",
"short_channel_id": f"i.to_string()",
"short_channel_id_dir": f"i.to_string()",
"pubkey": f"i.serialize().to_vec()",
"txid": f"hex::decode(i).unwrap()",
}.get(typ, f"i.into()")
"hex": "hex::decode(i).unwrap()",
"secret": "i.to_vec()",
"hash": "<Sha256 as AsRef<[u8]>>::as_ref(&i).to_vec()",
"short_channel_id": "i.to_string()",
"short_channel_id_dir": "i.to_string()",
"pubkey": "i.serialize().to_vec()",
"txid": "hex::decode(i).unwrap()",
}.get(typ, "i.into()")

self.write(f"// Field: {f.path}\n", numindent=3)
if not f.optional:
Expand Down Expand Up @@ -138,7 +138,7 @@ def generate_composite(self, prefix, field: CompositeField, override=None):
)

if f.deprecated:
self.write(f"#[allow(deprecated)]\n", numindent=3)
self.write("#[allow(deprecated)]\n", numindent=3)
self.write(f"{name}: {rhs}, // Rule #2 for type {typ}\n", numindent=3)

elif isinstance(f, CompositeField):
Expand All @@ -149,10 +149,10 @@ def generate_composite(self, prefix, field: CompositeField, override=None):
rhs = f"c.{name}.map(|v| v.into())"
self.write(f"{name}: {rhs},\n", numindent=3)
self.write(
f"""\
}}
}}
}}
"""\
}
}
}

"""
)
Expand Down
4 changes: 2 additions & 2 deletions contrib/msggen/msggen/gen/grpc/proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def generate_service(self, service: Service) -> None:
)

self.write(
f"""}}
"""}
"""
)

Expand Down Expand Up @@ -228,7 +228,7 @@ def generate_message(self, message: CompositeField, typename_override=None):

def generate(self, service: Service) -> None:
"""Generate the GRPC protobuf file and write to `dest`"""
self.write(f"""syntax = "proto3";\npackage cln;\n""")
self.write("""syntax = "proto3";\npackage cln;\n""")
self.write(
"""
// This file was automatically derived from the JSON-RPC schemas in
Expand Down
5 changes: 3 additions & 2 deletions contrib/msggen/msggen/gen/grpc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def write(self, text: str, numindent: Optional[int] = None):

def generate(self, service: Service) -> None:
self.write(
f"""\
"""\
use crate::pb::node_server::Node;
use crate::pb;
use cln_rpc::{{Request, Response, ClnRpc}};
Expand Down Expand Up @@ -113,7 +113,8 @@ def generate(self, service: Service) -> None:
#[tonic::async_trait]
impl Node for Server
{{
""",
"""
.replace("{{", "{").replace("}}", "}"),
numindent=0,
)

Expand Down
28 changes: 14 additions & 14 deletions contrib/msggen/msggen/gen/grpc/unconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ def generate_composite(self, prefix, field: CompositeField, override=None) -> No
if isinstance(f, ArrayField):
typ = f.itemtype.typename
mapping = {
"hex": f"hex::encode(s)",
"u32": f"s",
"secret": f"s.try_into().unwrap()",
"hash": f"Sha256::from_slice(&s).unwrap()",
"short_channel_id": f"cln_rpc::primitives::ShortChannelId::from_str(&s).unwrap()",
"short_channel_id_dir": f"cln_rpc::primitives::ShortChannelIdDir::from_str(&s).unwrap()",
"pubkey": f"PublicKey::from_slice(&s).unwrap()",
"txid": f"hex::encode(s)",
}.get(typ, f"s.into()")
"hex": "hex::encode(s)",
"u32": "s",
"secret": "s.try_into().unwrap()",
"hash": "Sha256::from_slice(&s).unwrap()",
"short_channel_id": "cln_rpc::primitives::ShortChannelId::from_str(&s).unwrap()",
"short_channel_id_dir": "cln_rpc::primitives::ShortChannelIdDir::from_str(&s).unwrap()",
"pubkey": "PublicKey::from_slice(&s).unwrap()",
"txid": "hex::encode(s)",
}.get(typ, "s.into()")

# TODO fix properly
if typ in ["ListtransactionsTransactionsType"]:
continue
if name == "state_changes":
self.write(f" state_changes: None,")
self.write(" state_changes: None,")
continue

if not f.optional:
Expand Down Expand Up @@ -147,10 +147,10 @@ def generate_composite(self, prefix, field: CompositeField, override=None) -> No
self.write(f"{name}: {rhs},\n", numindent=3)

self.write(
f"""\
}}
}}
}}
"""\
}
}
}

"""
)
2 changes: 1 addition & 1 deletion contrib/msggen/msggen/gen/grpc2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def {converter_name}(m):
cleanup=False,
)

self.write(f" }})\n", cleanup=False)
self.write(" }})\n", cleanup=False)

# Add ourselves to the converters so if we were generated as a
# dependency for a composite they can find us again. We have
Expand Down
25 changes: 13 additions & 12 deletions contrib/msggen/msggen/gen/rpc/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ def gen_enum(e, meta, override):
norm = v.normalized()
decl += f' {typename}::{norm} => "{norm}",\n'
decl += dedent(
f"""\
}}.to_string()
}}
}}
"""\
}.to_string()
}
}

"""
)
Expand All @@ -196,7 +196,7 @@ def gen_enum(e, meta, override):
defi += rename_if_necessary(str(e.name), e.name.normalized())
defi += f" pub {e.name.normalized()}: {typename},\n"
else:
defi = f' #[serde(skip_serializing_if = "Option::is_none")]\n'
defi = ' #[serde(skip_serializing_if = "Option::is_none")]\n'
defi += f" pub {e.name.normalized()}: Option<{typename}>,\n"

return defi, decl
Expand All @@ -223,7 +223,7 @@ def rename_if_necessary(original, name):
if str(original) != str(name):
return f" #[serde(rename = \"{original}\")]\n"
else:
return f""
return ""


def gen_array(a, meta, override=None):
Expand Down Expand Up @@ -390,14 +390,15 @@ def generate_response_trait_impl(self, method: Method):
def generate_enums(self, service: Service):
"""The Request and Response enums serve as parsing primitives."""
self.write(
f"""\
"""\
use serde::{{Deserialize, Serialize}};

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(tag = "method", content = "params")]
#[serde(rename_all = "lowercase")]
pub enum Request {{
"""
.replace("{{", "{").replace("}}", "}"),
)

for method in service.methods:
Expand All @@ -410,13 +411,13 @@ def generate_enums(self, service: Service):
)

self.write(
f"""\
}}
"""\
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(tag = "method", content = "result")]
#[serde(rename_all = "lowercase")]
pub enum Response {{
pub enum Response {
"""
)

Expand All @@ -430,8 +431,8 @@ def generate_enums(self, service: Service):
)

self.write(
f"""\
}}
"""\
}

"""
)
Expand Down
2 changes: 1 addition & 1 deletion contrib/pyln-grpc-proto/pyln/grpc/node_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
if _version_not_supported:
raise RuntimeError(
f'The grpc package installed is at version {GRPC_VERSION},'
+ f' but the generated code in node_pb2_grpc.py depends on'
+ ' but the generated code in node_pb2_grpc.py depends on'
+ f' grpcio>={GRPC_GENERATED_VERSION}.'
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
Expand Down
16 changes: 8 additions & 8 deletions tests/autogenerate-rpc-examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def update_examples_in_schema_files():
with open(TEMP_EXAMPLES_FILE, 'w+', encoding='utf-8') as file:
json.dump({'new_values_list': NEW_VALUES_LIST, 'replace_response_values': REPLACE_RESPONSE_VALUES[4:], 'examples_json': EXAMPLES_JSON, 'updated_examples_json': updated_examples}, file, indent=2, ensure_ascii=False)

logger.info(f'Updated All Examples in Schema Files!')
logger.info('Updated All Examples in Schema Files!')
return None


Expand Down Expand Up @@ -1138,12 +1138,12 @@ def generate_wait_examples(l1, l2, bitcoind, executor):
if curr_blockheight < 130:
bitcoind.generate_block(130 - curr_blockheight)
sync_blockheight(bitcoind, [l2])
update_example(node=l2, method='waitblockheight', params={'blockheight': 126}, description=[f'This will return immediately since the current blockheight exceeds the requested waitblockheight.'])
update_example(node=l2, method='waitblockheight', params={'blockheight': 126}, description=['This will return immediately since the current blockheight exceeds the requested waitblockheight.'])
wbh = executor.submit(l2.rpc.waitblockheight, curr_blockheight + 1, 600)
bitcoind.generate_block(1)
sync_blockheight(bitcoind, [l2])
wbhres = wbh.result(5)
update_example(node=l2, method='waitblockheight', params={'blockheight': curr_blockheight + 1, 'timeout': 600}, response=wbhres, description=[f'This will return after the next block is mined because requested waitblockheight is one block higher than the current blockheight.'])
update_example(node=l2, method='waitblockheight', params={'blockheight': curr_blockheight + 1, 'timeout': 600}, response=wbhres, description=['This will return after the next block is mined because requested waitblockheight is one block higher than the current blockheight.'])
REPLACE_RESPONSE_VALUES.extend([
{'data_keys': ['payment_hash'], 'original_value': wspc_res['details']['payment_hash'], 'new_value': NEW_VALUES_LIST['payment_hash_wspc_1']},
{'data_keys': ['paid_at'], 'original_value': waires['paid_at'], 'new_value': NEW_VALUES_LIST['time_at_850']},
Expand Down Expand Up @@ -1257,7 +1257,7 @@ def generate_utils_examples(l1, l2, l3, l4, l5, l6, c23_2, c34_2, inv_l11, inv_l

# SQL
update_example(node=l1, method='sql', params={'query': 'SELECT id FROM peers'}, description=['A simple peers selection query:'])
update_example(node=l1, method='sql', params=[f"SELECT label, description, status FROM invoices WHERE label='label inv_l12'"], description=["A statement containing `=` needs `-o` in shell:"])
update_example(node=l1, method='sql', params=["SELECT label, description, status FROM invoices WHERE label='label inv_l12'"], description=["A statement containing `=` needs `-o` in shell:"])
sql_res3 = l1.rpc.sql(f"SELECT nodeid FROM nodes WHERE nodeid != x'{l3.info['id']}'")
update_example(node=l1, method='sql', params=[f"SELECT nodeid FROM nodes WHERE nodeid != x'{NEW_VALUES_LIST['l3_id']}'"], description=['If you want to get specific nodeid values from the nodes table:'], response=sql_res3)
sql_res4 = l1.rpc.sql(f"SELECT nodeid FROM nodes WHERE nodeid IN (x'{l1.info['id']}', x'{l3.info['id']}')")
Expand Down Expand Up @@ -1524,7 +1524,7 @@ def generate_channels_examples(node_factory, bitcoind, l1, l3, l4, l5):
utxo = f"{outputs[0]['txid']}:{outputs[0]['output']}"
c41res = update_example(node=l4, method='fundchannel',
params={'id': l1.info['id'], 'amount': 'all', 'feerate': 'normal', 'push_msat': 100000, 'utxos': [utxo]},
description=[f'This example shows how to to open new channel with peer 1 from one whole utxo (you can use **listfunds** command to get txid and vout):'])
description=['This example shows how to to open new channel with peer 1 from one whole utxo (you can use **listfunds** command to get txid and vout):'])
# Close newly funded channels to bring the setup back to initial state
l3.rpc.close(c35res['channel_id'])
l4.rpc.close(c41res['channel_id'])
Expand Down Expand Up @@ -1593,7 +1593,7 @@ def generate_channels_examples(node_factory, bitcoind, l1, l3, l4, l5):
]
example_destinations_2 = [
{
'id': f'fakenodeid' + ('03' * 28) + '@127.0.0.1:19736',
'id': 'fakenodeid' + ('03' * 28) + '@127.0.0.1:19736',
'amount': 50000
},
{
Expand Down Expand Up @@ -1696,7 +1696,7 @@ def generate_autoclean_delete_examples(l1, l2, l3, l4, l5, c12, c23):
try:
logger.info('Auto-clean and Delete Start...')
l2.rpc.close(l5.info['id'])
dfc_res1 = update_example(node=l2, method='dev-forget-channel', params={'id': l5.info['id']}, description=[f'Forget a channel by peer pubkey when only one channel exists with the peer:'])
dfc_res1 = update_example(node=l2, method='dev-forget-channel', params={'id': l5.info['id']}, description=['Forget a channel by peer pubkey when only one channel exists with the peer:'])

# Create invoices for delpay and delinvoice examples
inv_l35 = l3.rpc.invoice('50000sat', 'lbl_l35', 'l35 description')
Expand Down Expand Up @@ -1741,7 +1741,7 @@ def generate_autoclean_delete_examples(l1, l2, l3, l4, l5, c12, c23):
update_example(node=l2, method='delforward', params={'in_channel': c12, 'in_htlc_id': local_failed_forwards[0]['in_htlc_id'], 'status': 'local_failed'})
if len(failed_forwards) > 0 and 'in_htlc_id' in failed_forwards[0]:
update_example(node=l2, method='delforward', params={'in_channel': c12, 'in_htlc_id': failed_forwards[0]['in_htlc_id'], 'status': 'failed'})
dfc_res2 = update_example(node=l2, method='dev-forget-channel', params={'id': l3.info['id'], 'short_channel_id': c23, 'force': True}, description=[f'Forget a channel by short channel id when peer has multiple channels:'])
dfc_res2 = update_example(node=l2, method='dev-forget-channel', params={'id': l3.info['id'], 'short_channel_id': c23, 'force': True}, description=['Forget a channel by short channel id when peer has multiple channels:'])

# Autoclean
update_example(node=l2, method='autoclean-once', params=['failedpays', 1])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_closing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4076,7 +4076,7 @@ def test_peer_anchor_push(node_factory, bitcoind, executor, chainparams):
assert len(bitcoind.rpc.getrawmempool()) == 2

# Feerate tops out at +1, so this is the same. This time we mine it!
l2.daemon.wait_for_log(fr"Worth fee [0-9]*sat for remote commit tx to get 100000000msat at block 125 \(\+1\) at feerate 15000perkw")
l2.daemon.wait_for_log(r"Worth fee [0-9]*sat for remote commit tx to get 100000000msat at block 125 \(\+1\) at feerate 15000perkw")
l2.daemon.wait_for_log("sendrawtx exit 0")

bitcoind.generate_block(1, needfeerate=15000)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4743,7 +4743,7 @@ def test_networkevents(node_factory, executor):
'peer_id': l2.info['id'],
'type': 'connect_fail',
'connect_attempted': True,
'reason': f'All addresses failed: 127.0.0.1:1: Connection establishment: Connection refused. '}]
'reason': 'All addresses failed: 127.0.0.1:1: Connection establishment: Connection refused. '}]

# Connect failed because unreachable
with pytest.raises(RpcError, match="Connection establishment: Connection timed out."):
Expand All @@ -4756,7 +4756,7 @@ def test_networkevents(node_factory, executor):
'peer_id': l2.info['id'],
'type': 'connect_fail',
'connect_attempted': True,
'reason': f'All addresses failed: 1.1.1.1:8081: Connection establishment: Connection timed out. '}]
'reason': 'All addresses failed: 1.1.1.1:8081: Connection establishment: Connection timed out. '}]

# Connect failed because it doesn't advertize any addresses.
with pytest.raises(RpcError, match="Unable to connect, no address known for peer"):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2986,9 +2986,9 @@ def test_custommsg_triggers_notification(node_factory):

# TODO: Check if the peer_id and payload matches
peer_id = l2.info["id"]
l1.daemon.wait_for_log(f"Received a custommsg with data")
l1.daemon.wait_for_log("Received a custommsg with data")
l1.daemon.wait_for_log(f"peer_id={peer_id}")
l1.daemon.wait_for_log(f"payload=77770012")
l1.daemon.wait_for_log("payload=77770012")


def test_makesecret(node_factory):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_opening.py
Original file line number Diff line number Diff line change
Expand Up @@ -2921,7 +2921,7 @@ def test_zeroconf_withhold(node_factory, bitcoind, stay_withheld, mutual_close):
funds = l1.rpc.listfunds()
for utxo in funds['outputs']:
assert utxo['status'] == 'confirmed', \
f"UTXO still reserved after withheld close"
"UTXO still reserved after withheld close"
else:
if mutual_close:
wait_for(lambda: only_one(l1.rpc.listpeerchannels()['channels'])['state'] == 'CLOSINGD_COMPLETE')
Expand Down
Loading
Loading