Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bkpr: add two custom notifications that we listen for #7258

Merged

Conversation

chrisguida
Copy link
Contributor

This PR adds two new event types that bookkeeper listens for in order to track on-chain movements in external wallets.

This API is currently implemented by the plugin Smaug, which depends on this PR being merged before a release can be cut.

tests/plugins/bookkeeper_custom_coins.py Outdated Show resolved Hide resolved
tests/plugins/bookkeeper_custom_coins.py Show resolved Hide resolved
tests/plugins/bookkeeper_custom_coins.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

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

Looked inside the CI failure and I think I found the problem

plugins/bkpr/bookkeeper.c Show resolved Hide resolved
Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

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

Concept ACK

I left a comment


See the doc/PLUGINS.md#coin_movement section on the message that CLN emits for us to process.

// FIXME: add more detailed documenation for how bookkeeper works.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// FIXME: add more detailed documenation for how bookkeeper works.
// FIXME: add more detailed documenation for how bookkeeper works.

This can be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it should stay until there's more detailed documentation, currently the README only describes how the 2 new event types work. But up to @niftynei really

plugins/bkpr/bookkeeper.c Show resolved Hide resolved
@@ -1935,11 +1935,12 @@ char *maybe_update_onchain_fees(const tal_t *ctx, struct db *db,
}

void maybe_closeout_external_deposits(struct db *db,
struct chain_event *ev)
struct bitcoin_txid *txid,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
struct bitcoin_txid *txid,
const struct bitcoin_txid *txid,

usually we use const here

@@ -208,7 +208,9 @@ void add_payment_hash_desc(struct db *db,
*
* This method updates the blockheight on these events to the
* height an input was spent into */
void maybe_closeout_external_deposits(struct db *db, struct chain_event *ev);
void maybe_closeout_external_deposits(struct db *db,
struct bitcoin_txid *txid,
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here

Copy link
Collaborator

Choose a reason for hiding this comment

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

ack.

@endothermicdev endothermicdev added this to the v24.05 milestone Apr 29, 2024
Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

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

Minor change, I think the first commit is overzealous, and I'd like the fixup folded so we don't have an intermediary commit using type_to_strings which doesn't compile.

const struct account *acct,
struct chain_event *e)
{
struct db_stmt *stmt;

/* We're responsible for de-duping chain events! */
if (find_chain_event(e, db, acct,
if (find_chain_event(ctx, db, acct,
Copy link
Contributor

Choose a reason for hiding this comment

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

This should actually be tmpctx!

Copy link
Contributor

Choose a reason for hiding this comment

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

And ctx arg is unnecessary...

Copy link
Collaborator

Choose a reason for hiding this comment

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

wow yeah, lots of gymnastics on this one. fixing..

@@ -2040,7 +2041,7 @@ bool log_chain_event(struct db *db,
db_exec_prepared_v2(stmt);
e->db_id = db_last_insert_id_v2(stmt);
e->acct_db_id = acct->db_id;
e->acct_name = tal_strdup(e, acct->name);
e->acct_name = tal_strdup(ctx, acct->name);
Copy link
Contributor

Choose a reason for hiding this comment

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

This change looks wrong?

Copy link
Collaborator

Choose a reason for hiding this comment

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

ack.

@@ -2415,7 +2415,7 @@ bool plugin_single_notify(struct plugin *p,
const struct jsonrpc_notification *n TAKES)
{
bool interested;
if (plugin_subscriptions_contains(p, n->method)) {
if (p->plugin_state == INIT_COMPLETE && plugin_subscriptions_contains(p, n->method)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🧡

@rustyrussell rustyrussell modified the milestones: v24.05, v24.08 Jun 9, 2024
It might be nice to let the bookkeeper keep track of external accounts
as well as the internal onchain wallet? To this end, we add some new
custom notifications, which the bookkeeper will ingest and add to its
ledger.

Suggested-By: @chrisguida

Changelog-Added: PLUGINS: `bookkeeper` now listens for two custom events: `utxo_deposit` and `utxo_spend`. This allows for 3rd party plugins to send onchain coin events to the `bookkeeper`.  See the new plugins/bkpr/README.md for details on how these work!
Copy link
Collaborator

@niftynei niftynei left a comment

Choose a reason for hiding this comment

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

Comments have been addressed and fixed up as requested!

tests/plugins/bookkeeper_custom_coins.py Show resolved Hide resolved
@@ -1724,10 +1724,10 @@ static struct command_result *json_utxo_deposit(struct command *cmd, const char

plugin_log(cmd->plugin, LOG_DBG, "%s (%s|%s) %s -%s %"PRIu64" %d %s",
move_tag, ev.tag, ev.acct_name,
type_to_string(tmpctx, struct amount_msat, &ev.credit),
type_to_string(tmpctx, struct amount_msat, &ev.debit),
fmt_amount_msat(tmpctx, ev.credit),
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as prior, this should be squashed into the original commit that makes these changes.

const struct account *acct,
struct chain_event *e)
{
struct db_stmt *stmt;

/* We're responsible for de-duping chain events! */
if (find_chain_event(e, db, acct,
if (find_chain_event(ctx, db, acct,
Copy link
Collaborator

Choose a reason for hiding this comment

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

wow yeah, lots of gymnastics on this one. fixing..

@@ -2040,7 +2041,7 @@ bool log_chain_event(struct db *db,
db_exec_prepared_v2(stmt);
e->db_id = db_last_insert_id_v2(stmt);
e->acct_db_id = acct->db_id;
e->acct_name = tal_strdup(e, acct->name);
e->acct_name = tal_strdup(ctx, acct->name);
Copy link
Collaborator

Choose a reason for hiding this comment

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

ack.

@@ -208,7 +208,9 @@ void add_payment_hash_desc(struct db *db,
*
* This method updates the blockheight on these events to the
* height an input was spent into */
void maybe_closeout_external_deposits(struct db *db, struct chain_event *ev);
void maybe_closeout_external_deposits(struct db *db,
struct bitcoin_txid *txid,
Copy link
Collaborator

Choose a reason for hiding this comment

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

ack.

@chrisguida
Copy link
Contributor Author

Thanks for the fixups @niftynei!

@rustyrussell I think this one should be ready to go now :)

@rustyrussell rustyrussell merged commit 0e99f2e into ElementsProject:master Aug 9, 2024
39 checks passed
chrisguida added a commit to chrisguida/smaug that referenced this pull request Sep 26, 2024
ElementsProject/lightning#7258 finally merged,
so we need to switch to the new more consistent tag names and
use the elementsproject fork instead of niftynei

There are also some changes required for the new startup_regtest script.
chrisguida added a commit to chrisguida/smaug that referenced this pull request Sep 26, 2024
ElementsProject/lightning#7258 finally merged,
so we need to switch to the new more consistent tag names and
use the elementsproject fork instead of niftynei

There are also some changes required for the new startup_regtest script.
chrisguida added a commit to chrisguida/smaug that referenced this pull request Sep 26, 2024
ElementsProject/lightning#7258 finally merged,
so we need to switch to the new more consistent tag names and
use the elementsproject fork instead of niftynei

There are also some changes required for the new startup_regtest script.
chrisguida added a commit to chrisguida/smaug that referenced this pull request Sep 26, 2024
ElementsProject/lightning#7258 finally merged,
so we need to switch to the new more consistent tag names and
use the elementsproject fork instead of niftynei

There are also some changes required for the new startup_regtest script.
chrisguida added a commit to chrisguida/smaug that referenced this pull request Sep 26, 2024
ElementsProject/lightning#7258 finally merged,
so we need to switch to the new more consistent tag names and
use the elementsproject fork instead of niftynei

There are also some changes required for the new startup_regtest script.
chrisguida added a commit to chrisguida/smaug that referenced this pull request Sep 27, 2024
ElementsProject/lightning#7258 finally merged,
so we need to switch to the new more consistent tag names and
use the elementsproject fork instead of niftynei

There are also some changes required for the new startup_regtest script.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants