From 1ef8fb7ef8b9f52d8167dd35e00776cab8cfb222 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Mon, 12 Sep 2022 17:43:54 -0300 Subject: [PATCH] rename `block_processed` to `block_added` --- doc/PLUGINS.md | 4 ++-- lightningd/chaintopology.c | 2 +- lightningd/notification.c | 16 ++++++++-------- lightningd/notification.h | 4 ++-- .../{block_processed.py => block_added.py} | 4 ++-- tests/test_plugin.py | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) rename tests/plugins/{block_processed.py => block_added.py} (74%) diff --git a/doc/PLUGINS.md b/doc/PLUGINS.md index 1d481420e..563e34fe0 100644 --- a/doc/PLUGINS.md +++ b/doc/PLUGINS.md @@ -873,14 +873,14 @@ current accounts (`account_id` matches the `account_id` emitted from } ``` -### `block_processed` +### `block_added` Emitted after each block is received from bitcoind, either during the initial sync or throughout the node's life as new blocks appear. ```json { - "block_processed": { + "block": { "hash": "000000000000000000034bdb3c01652a0aa8f63d32f949313d55af2509f9d245", "height": 753304 } diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index 6ad5aa8a0..b5d6d71e6 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -823,7 +823,7 @@ static void get_new_block(struct bitcoind *bitcoind, add_tip(topo, new_block(topo, blk, topo->tip->height + 1)); /* tell plugins a new block was processed */ - notify_block_processed(topo->ld, topo->tip); + notify_block_added(topo->ld, topo->tip); } /* Try for next one. */ diff --git a/lightningd/notification.c b/lightningd/notification.c index 4e9e1d575..2935094f2 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -582,8 +582,8 @@ void notify_balance_snapshot(struct lightningd *ld, plugins_notify(ld->plugins, take(n)); } -static void block_processed_notification_serialize(struct json_stream *stream, - struct block *block) +static void block_added_notification_serialize(struct json_stream *stream, + struct block *block) { json_object_start(stream, "block"); json_add_string(stream, "hash", @@ -592,17 +592,17 @@ static void block_processed_notification_serialize(struct json_stream *stream, json_object_end(stream); } -REGISTER_NOTIFICATION(block_processed, - block_processed_notification_serialize); +REGISTER_NOTIFICATION(block_added, + block_added_notification_serialize); -void notify_block_processed(struct lightningd *ld, - const struct block *block) +void notify_block_added(struct lightningd *ld, + const struct block *block) { void (*serialize)(struct json_stream *, - const struct block *block) = block_processed_notification_gen.serialize; + const struct block *block) = block_added_notification_gen.serialize; struct jsonrpc_notification *n = - jsonrpc_notification_start(NULL, "block_processed"); + jsonrpc_notification_start(NULL, "block_added"); serialize(n->stream, block); jsonrpc_notification_end(n); plugins_notify(ld->plugins, take(n)); diff --git a/lightningd/notification.h b/lightningd/notification.h index ca8c6a084..7b1c624b0 100644 --- a/lightningd/notification.h +++ b/lightningd/notification.h @@ -87,8 +87,8 @@ void notify_coin_mvt(struct lightningd *ld, void notify_balance_snapshot(struct lightningd *ld, const struct balance_snapshot *snap); -void notify_block_processed(struct lightningd *ld, - const struct block *block); +void notify_block_added(struct lightningd *ld, + const struct block *block); void notify_openchannel_peer_sigs(struct lightningd *ld, const struct channel_id *cid, diff --git a/tests/plugins/block_processed.py b/tests/plugins/block_added.py similarity index 74% rename from tests/plugins/block_processed.py rename to tests/plugins/block_added.py index f80e2bd7c..a85b288e6 100755 --- a/tests/plugins/block_processed.py +++ b/tests/plugins/block_added.py @@ -8,8 +8,8 @@ plugin = Plugin() blocks_catched = [] -@plugin.subscribe("block_processed") -def notify_block_processed(plugin, block, **kwargs): +@plugin.subscribe("block_added") +def notify_block_added(plugin, block, **kwargs): global blocks_catched blocks_catched.append(block["height"]) diff --git a/tests/test_plugin.py b/tests/test_plugin.py index f52453910..75dd78e12 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -2925,11 +2925,11 @@ def test_commando_badrune(node_factory): pass -def test_block_processed_notifications(node_factory, bitcoind): +def test_block_added_notifications(node_factory, bitcoind): """Test if a plugin gets notifications when a new block is found""" base = bitcoind.rpc.getblockchaininfo()["blocks"] plugin = [ - os.path.join(os.getcwd(), "tests/plugins/block_processed.py"), + os.path.join(os.getcwd(), "tests/plugins/block_added.py"), ] l1 = node_factory.get_node(options={"plugin": plugin}) ret = l1.rpc.call("blockscatched")