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

wallet: Add new format string placeholders for walletnotify #21141

Merged
merged 1 commit into from Mar 15, 2021

Conversation

maayank
Copy link
Contributor

@maayank maayank commented Feb 10, 2021

This patch includes two new format placeholders for walletnotify:
%b - the hash of the block containting the transaction (zeroed if a mempool transaction)
%h - the height of the block containing the transaction (zero if a mempool transaction)

I've included test suite changes to check and validate the above functional requirements as well as doc/help description changes.

Motivation
The walletnotify option is used to be notified of new transactions relevant to the wallet of the node.
A common usage pattern is to perform afterwards additional RPC calls to determine:

  1. If this is a mempool transaction or not (i.e. are there any confirmations?)
  2. What block was it included in?
  3. Did this transaction was seen before and is now seen again because of a fork?

All of these questions can be answered with the current features, but the resulting RPC calls may be expensive in a heavily used node. As this information is readily available when calling the walletnotify callback, it makes sense to save expensive round trips by optionally sending this information at that point in time. I can definitely say we would like to use it in Fireblocks, my employer.

Please let me know of any questions and suggestions.

@maayank maayank changed the title Add new format string placeholders for walletnotify wallet: Add new format string placeholders for walletnotify Feb 10, 2021
Copy link
Member

@promag promag left a comment

Choose a reason for hiding this comment

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

This seems fine, but keep in mind that -walletnotify scripts are called async, so you don't really know if you are processing in the right order. Not so sure if it's a good approach to avoid RPC calls.

@maayank
Copy link
Contributor Author

maayank commented Feb 10, 2021

Thank you for the comment @promag . It's an important comment especially for future readers intending to use it for fork detection.

(not related) I've changed the code to use ToString instead of std::to_string to avoid locale linter errors.

What do you say on changing the start of the description "Execute command when a wallet transaction changes" to "Asynchronously execute command when a wallet transaction changes"? It's true also before this commit. Would help to highlight potential tradeoffs for future users.

@laanwj
Copy link
Member

laanwj commented Feb 10, 2021

Concept ACK, I don't think adding this information to notifications can hurt and it's only very little more code.

@maayank maayank force-pushed the walletnotify-blockhash branch 3 times, most recently from 4a04028 to 3d0ee35 Compare February 10, 2021 21:21
@maayank
Copy link
Contributor Author

maayank commented Feb 11, 2021

I've noticed in the CI checks some linter errors as well as that on some systems the notification test case failed due to the concatenation of wallet, txid, block height and block hash being too long of a filename. I've changed the test case so it now checks not only the filename (for wallet and txid) but contents (for block height and block hash). Now the request passes all the CI tests and is ready to merge.

@meshcollider
Copy link
Contributor

Concept ACK

Copy link
Member

@laanwj laanwj left a comment

Choose a reason for hiding this comment

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

Code review ACK 3d0ee35

src/wallet/init.cpp Outdated Show resolved Hide resolved
src/wallet/init.cpp Outdated Show resolved Hide resolved
@maayank
Copy link
Contributor Author

maayank commented Mar 11, 2021

Thank you for your comments @luke-jr , made the changes you suggested. FYI @laanwj @promag

@laanwj
Copy link
Member

laanwj commented Mar 15, 2021

Agree with @luke-jr 's suggestions, ACK after squashing commits.

@maayank maayank force-pushed the walletnotify-blockhash branch 2 times, most recently from 9ad59c9 to 4d6b785 Compare March 15, 2021 16:11
@laanwj
Copy link
Member

laanwj commented Mar 15, 2021

ACK 06e1fb0

@laanwj laanwj merged commit b650c91 into bitcoin:master Mar 15, 2021
Copy link
Contributor

@jonatack jonatack 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, looks like a helpful nice addition.

@@ -944,6 +944,14 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const CWalletTx::Confirmatio
if (!strCmd.empty())
{
boost::replace_all(strCmd, "%s", hash.GetHex());
if (confirm.status == CWalletTx::Status::CONFIRMED)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

-        if (confirm.status == CWalletTx::Status::CONFIRMED)
-        {
+        if (confirm.status == CWalletTx::Status::CONFIRMED) {

Copy link
Member

Choose a reason for hiding this comment

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

Oops, noticed this too late, sorry

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Mar 16, 2021
…alletnotify

06e1fb0 Add new format string placeholders for walletnotify to include relevant block information for transactions (Maayan Keshet)

Pull request description:

  This patch includes two new format placeholders for walletnotify:
  %b - the hash of the block containting the transaction (zeroed if a mempool transaction)
  %h - the height of the block containing the transaction (zero if a mempool transaction)

  I've included test suite changes to check and validate the above functional requirements as well as doc/help description changes.

  **Motivation**
  The walletnotify option is used to be notified of new transactions relevant to the wallet of the node.
  A common usage pattern is to perform afterwards additional RPC calls to determine:
  1. If this is a mempool transaction or not (i.e. are there any confirmations?)
  2. What block was it included in?
  3. Did this transaction was seen before and is now seen again because of a fork?

  All of these questions can be answered with the current features, but the resulting RPC calls may be expensive in a heavily used node. As this information is readily available when calling the walletnotify callback, it makes sense to save expensive round trips by optionally sending this information at that point in time. I can definitely say we would like to use it in Fireblocks, my employer.

  Please let me know of any questions and suggestions.

ACKs for top commit:
  laanwj:
    ACK 06e1fb0

Tree-SHA512: d2744e2a7a883f9c3a9fd32237110e048c4b6b11fea8221c33d10b74157f65bbc4351211f441e8c1a4af5d5d38e2ba6b1943a7673dc18860c0553d7b41e00775
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Jun 27, 2021
…nt block information for transactions

Github-Pull: bitcoin#21141
Rebased-From: 06e1fb0
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants