mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
plugins/sql: add listclosedchannels
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-Added: JSON-RPC: `sql` now includes `listclosedchannels`.
This commit is contained in:
@@ -136,6 +136,40 @@ The following tables are currently supported:
|
||||
- `htlc_maximum_msat` (type `msat`, sqltype `INTEGER`)
|
||||
- `features` (type `hex`, sqltype `BLOB`)
|
||||
|
||||
- `closedchannels` (see lightning-listclosedchannels(7))
|
||||
- `peer_id` (type `pubkey`, sqltype `BLOB`)
|
||||
- `channel_id` (type `hash`, sqltype `BLOB`)
|
||||
- `short_channel_id` (type `short_channel_id`, sqltype `TEXT`)
|
||||
- `alias_local` (type `short_channel_id`, sqltype `TEXT`, from JSON object `alias`)
|
||||
- `alias_remote` (type `short_channel_id`, sqltype `TEXT`, from JSON object `alias`)
|
||||
- `opener` (type `string`, sqltype `TEXT`)
|
||||
- `closer` (type `string`, sqltype `TEXT`)
|
||||
- `private` (type `boolean`, sqltype `INTEGER`)
|
||||
- related table `closedchannels_channel_type_bits`, from JSON object `channel_type`
|
||||
- `row` (reference to `closedchannels_channel_type.rowid`, sqltype `INTEGER`)
|
||||
- `arrindex` (index within array, sqltype `INTEGER`)
|
||||
- `bits` (type `u32`, sqltype `INTEGER`)
|
||||
- related table `closedchannels_channel_type_names`, from JSON object `channel_type`
|
||||
- `row` (reference to `closedchannels_channel_type.rowid`, sqltype `INTEGER`)
|
||||
- `arrindex` (index within array, sqltype `INTEGER`)
|
||||
- `names` (type `string`, sqltype `TEXT`)
|
||||
- `total_local_commitments` (type `u64`, sqltype `INTEGER`)
|
||||
- `total_remote_commitments` (type `u64`, sqltype `INTEGER`)
|
||||
- `total_htlcs_sent` (type `u64`, sqltype `INTEGER`)
|
||||
- `funding_txid` (type `txid`, sqltype `BLOB`)
|
||||
- `funding_outnum` (type `u32`, sqltype `INTEGER`)
|
||||
- `leased` (type `boolean`, sqltype `INTEGER`)
|
||||
- `funding_fee_paid_msat` (type `msat`, sqltype `INTEGER`)
|
||||
- `funding_fee_rcvd_msat` (type `msat`, sqltype `INTEGER`)
|
||||
- `funding_pushed_msat` (type `msat`, sqltype `INTEGER`)
|
||||
- `total_msat` (type `msat`, sqltype `INTEGER`)
|
||||
- `final_to_us_msat` (type `msat`, sqltype `INTEGER`)
|
||||
- `min_to_us_msat` (type `msat`, sqltype `INTEGER`)
|
||||
- `max_to_us_msat` (type `msat`, sqltype `INTEGER`)
|
||||
- `last_commitment_txid` (type `hash`, sqltype `BLOB`)
|
||||
- `last_commitment_fee_msat` (type `msat`, sqltype `INTEGER`)
|
||||
- `close_cause` (type `string`, sqltype `TEXT`)
|
||||
|
||||
- `forwards` indexed by `in_channel and in_htlc_id` (see lightning-listforwards(7))
|
||||
- `in_channel` (type `short_channel_id`, sqltype `TEXT`)
|
||||
- `in_htlc_id` (type `u64`, sqltype `INTEGER`)
|
||||
@@ -480,4 +514,4 @@ RESOURCES
|
||||
---------
|
||||
|
||||
Main web site: <https://github.com/ElementsProject/lightning>
|
||||
[comment]: # ( SHA256STAMP:ccc382f01d39253aff5a6c7ccd74400feb2f900f78f492a4c55b0a80e04fe813)
|
||||
[comment]: # ( SHA256STAMP:3eb4e024a1e1a4b40460b48b835354514456558797b8f8ce3c76dcbb9ca79dab)
|
||||
|
||||
@@ -210,7 +210,7 @@ plugins/fetchinvoice: $(PLUGIN_FETCHINVOICE_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_CO
|
||||
plugins/funder: bitcoin/psbt.o common/psbt_open.o $(PLUGIN_FUNDER_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS)
|
||||
|
||||
# This covers all the low-level list RPCs which return simple arrays
|
||||
SQL_LISTRPCS := listchannels listforwards listhtlcs listinvoices listnodes listoffers listpeers listpeerchannels listtransactions listsendpays bkpr-listaccountevents bkpr-listincome
|
||||
SQL_LISTRPCS := listchannels listforwards listhtlcs listinvoices listnodes listoffers listpeers listpeerchannels listclosedchannels listtransactions listsendpays bkpr-listaccountevents bkpr-listincome
|
||||
SQL_LISTRPCS_SCHEMAS := $(foreach l,$(SQL_LISTRPCS),doc/schemas/$l.schema.json)
|
||||
# We squeeze:
|
||||
# descriptions (we don't need)
|
||||
|
||||
@@ -3308,9 +3308,6 @@ def test_sql(node_factory, bitcoind):
|
||||
# Test that we correctly clean up subtables!
|
||||
assert len(l2.rpc.sql("SELECT * from peerchannels_features")['rows']) == len(l2.rpc.sql("SELECT * from peerchannels_features")['rows'])
|
||||
|
||||
# This should create a forward through l2
|
||||
l1.rpc.pay(l3.rpc.invoice(amount_msat=12300, label='inv1', description='description')['bolt11'])
|
||||
|
||||
expected_schemas = {
|
||||
'channels': {
|
||||
'indices': [['short_channel_id']],
|
||||
@@ -3346,6 +3343,69 @@ def test_sql(node_factory, bitcoind):
|
||||
'type': 'msat'},
|
||||
{'name': 'features',
|
||||
'type': 'hex'}]},
|
||||
'closedchannels': {
|
||||
'columns': [{'name': 'peer_id',
|
||||
'type': 'pubkey'},
|
||||
{'name': 'channel_id',
|
||||
'type': 'hash'},
|
||||
{'name': 'short_channel_id',
|
||||
'type': 'short_channel_id'},
|
||||
{'name': 'alias_local',
|
||||
'type': 'short_channel_id'},
|
||||
{'name': 'alias_remote',
|
||||
'type': 'short_channel_id'},
|
||||
{'name': 'opener',
|
||||
'type': 'string'},
|
||||
{'name': 'closer',
|
||||
'type': 'string'},
|
||||
{'name': 'private',
|
||||
'type': 'boolean'},
|
||||
{'name': 'total_local_commitments',
|
||||
'type': 'u64'},
|
||||
{'name': 'total_remote_commitments',
|
||||
'type': 'u64'},
|
||||
{'name': 'total_htlcs_sent',
|
||||
'type': 'u64'},
|
||||
{'name': 'funding_txid',
|
||||
'type': 'txid'},
|
||||
{'name': 'funding_outnum',
|
||||
'type': 'u32'},
|
||||
{'name': 'leased',
|
||||
'type': 'boolean'},
|
||||
{'name': 'funding_fee_paid_msat',
|
||||
'type': 'msat'},
|
||||
{'name': 'funding_fee_rcvd_msat',
|
||||
'type': 'msat'},
|
||||
{'name': 'funding_pushed_msat',
|
||||
'type': 'msat'},
|
||||
{'name': 'total_msat',
|
||||
'type': 'msat'},
|
||||
{'name': 'final_to_us_msat',
|
||||
'type': 'msat'},
|
||||
{'name': 'min_to_us_msat',
|
||||
'type': 'msat'},
|
||||
{'name': 'max_to_us_msat',
|
||||
'type': 'msat'},
|
||||
{'name': 'last_commitment_txid',
|
||||
'type': 'txid'},
|
||||
{'name': 'last_commitment_fee_msat',
|
||||
'type': 'msat'},
|
||||
{'name': 'close_cause',
|
||||
'type': 'string'}]},
|
||||
'closedchannels_channel_type_bits': {
|
||||
'columns': [{'name': 'row',
|
||||
'type': 'u64'},
|
||||
{'name': 'arrindex',
|
||||
'type': 'u64'},
|
||||
{'name': 'bits',
|
||||
'type': 'u64'}]},
|
||||
'closedchannels_channel_type_names': {
|
||||
'columns': [{'name': 'row',
|
||||
'type': 'u64'},
|
||||
{'name': 'arrindex',
|
||||
'type': 'u64'},
|
||||
{'name': 'names',
|
||||
'type': 'string'}]},
|
||||
'nodes': {
|
||||
'indices': [['nodeid']],
|
||||
'columns': [{'name': 'nodeid',
|
||||
@@ -3842,6 +3902,20 @@ def test_sql(node_factory, bitcoind):
|
||||
== sorted(expected_schemas.keys()))
|
||||
assert len(l1.rpc.listsqlschemas()['schemas']) == len(expected_schemas)
|
||||
|
||||
# We need one closed channel (but open a new one)
|
||||
l2.rpc.close(l1.info['id'])
|
||||
bitcoind.generate_block(1, wait_for_mempool=1)
|
||||
scid, _ = l1.fundchannel(l2)
|
||||
# Completely forget old channel
|
||||
bitcoind.generate_block(99)
|
||||
wait_for(lambda: len(l2.rpc.listpeerchannels()['channels']) == 2)
|
||||
|
||||
# Make sure l3 sees new channel
|
||||
wait_for(lambda: len(l3.rpc.listchannels(scid)['channels']) == 2)
|
||||
|
||||
# This should create a forward through l2
|
||||
l1.rpc.pay(l3.rpc.invoice(amount_msat=12300, label='inv1', description='description')['bolt11'])
|
||||
|
||||
# Very rough checks of other list commands (make sure l2 has one of each)
|
||||
l2.rpc.offer(1, 'desc')
|
||||
l2.rpc.invoice(1, 'label', 'desc')
|
||||
|
||||
Reference in New Issue
Block a user