-
Notifications
You must be signed in to change notification settings - Fork 68
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
Features/async walletnotify #266
Features/async walletnotify #266
Conversation
I added coreutils in Dockerfile to use the most recent version of base64. The date command changed breaking this. -D Option is not an option anymore: Line replaced by (in manage_missed_conf.sh): |
Core will filter out transactions based on the wallet and will only send trx concerning the "watching" wallets. Core sends the trx details to the broker since it had to do a "gettransaction" to identify the wallet. The proxy will not have to do this anymore |
I had to build a new core image called "async-blocknotify". It brings a script that gets called by In setup.sh, you can see BITCOIN_VERSION="async-blocknotify" |
I don't understand why you had to build a new Bitcoin Core image? The templates' |
Ah it's probably to include the mosquitto package to be able to publish the message... |
tx=$(bitcoin-cli -rpcwallet=$wallet gettransaction $txid true) | ||
|
||
if [ -n "$tx" ]; then | ||
echo "[walletnotify-$pid] Found [$txid] in wallet [$wallet]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Insert something like tx=$(echo $tx | jq -Mc)
here to remove unnecessary json formatting
if [ -n "$tx" ]; then | ||
echo "[walletnotify-$pid] Found [$txid] in wallet [$wallet]" | ||
echo "[walletnotify-$pid] mosquitto_pub -h broker -t confirmation -m \"$tx\" " | ||
mosquitto_pub -h broker -t confirmation -m $(echo $tx | base64 -w 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename the topic bitcoin_watching_walletnotify
to make it clear that it's triggered by Bitcoin Core's walletnotify on a watching wallet. Especially since in confirmation(), we publish something on tx_confirmation
topic after making sure the related address is still being watched by CN.
#!/bin/sh | ||
|
||
walletnotify(){ | ||
local pid=$(cut -d' ' -f4 < /proc/self/stat) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use $$
to get the PID
dist/setup.sh
Outdated
@@ -885,7 +891,7 @@ PROXYCRON_VERSION="v0.9.0-dev" | |||
OTSCLIENT_VERSION="v0.9.0-dev" | |||
PYCOIN_VERSION="v0.9.0-dev" | |||
CYPHERAPPS_VERSION="dev" | |||
BITCOIN_VERSION="v22.0" | |||
BITCOIN_VERSION="async-blocknotify" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I'll publish v22.0-mosquitto
to Docker's hub, we can use it until I publish v23 that will include mosquitto by default, and will be used for CN v0.9.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default walletnotify.sh
in the image will be a no-op
|
||
while true # Keep an infinite loop to reconnect when connection lost/broker unavailable | ||
do | ||
mosquitto_sub -h broker -t confirmation | while read -r message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
topic name here as well
confirmation() { | ||
( | ||
flock -x 201 | ||
|
||
trace "Entering confirmation()..." | ||
|
||
local returncode | ||
local txid=${1} | ||
local tx_details=$(echo ${1} | base64 -d) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, we got tx_details
needed to have wallet-specific information about the tx and we got tx_raw_details
needed to get some other information not found in gettransaction
but found in getrawtransaction
.
Here, we are receiving tx_details
(result of gettransaction
) but a few lines below we are calling getrawtransaction
to get the rest of the details (into tx_raw_details
).
I would like that we call getrawtransaction
on the Bitcoin Core container's side in the walletnotify script and include the result in the published message. So we would have something like {"gettransaction":{...},"getrawtransaction":{...}}
in the base64 message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...instead of calling get_rawtransaction from the proxy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhh wait a minute. We can use gettransaction txid true true
on the node to get everything we need, including the rawtransaction info (in the decoded
field)! Let's use it in walletnotify.sh and publish the result as message!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIce, I did not see the third argument on chainquery.com, it's not up to date (second time !!). I'll add this !!
tx_blockhash="$(echo "${tx_details}" | jq -r '.result.blockhash')" | ||
tx_blockheight=$(get_block_info ${tx_blockhash} | jq '.result.height') | ||
tx_blockhash="$(echo "${tx_details}" | jq -r '.blockhash')" | ||
tx_blockheight=$(get_block_info ${tx_blockhash} | jq '.height') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We calling the Bitcoin Core container here to get block height... Do you think it's a good idea to do this stuff in the walletnotify.sh script in the Bitcoin container and include it in the message? Instead of calling it here from the proxy...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey we have the blockheight and blockhash fields in gettransaction's result! It's not even needed anymore to call getblockinfo...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
trace "[confirmation] tx_blockhash=${tx_blockhash}" | ||
if [ "${tx_blockhash}" = "null" ]; then | ||
trace "[confirmation] probably being called by executecallbacks without any confirmations since the last time we checked" | ||
else | ||
local tx_blockheight=$(get_block_info "${tx_blockhash}" | jq '.result.height') | ||
local tx_blocktime=$(echo "${tx_details}" | jq '.result.blocktime') | ||
local tx_blockheight=$(get_block_info "${tx_blockhash}" | jq '.height') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, we would already have this info in the published message...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get the info from the gettransaction result!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done - no more calls to core
@@ -111,7 +111,8 @@ manage_missed_conf() { | |||
|
|||
latesttxid=$(echo "${received_address}" | jq -r ".txids | last") | |||
trace "[manage_missed_conf] latesttxid=${latesttxid}" | |||
data='{"method":"gettransaction","params":["'${latesttxid}'"]}' | |||
data="{\"method\":\"gettransaction\",\"params\":[\"${latesttxid}\",true]}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, watching01.dat and xpubwatching01.dat are not created as watch-only wallets, so the "true" arg wasn't needed... But I think it's a good idea to add it, just in case. After all, this is a watching wallet...
@@ -126,7 +127,7 @@ manage_missed_conf() { | |||
trace "[manage_missed_conf] Broadcast or mined after watch, we missed it!" | |||
# We skip the callbacks because do_callbacks is called right after in | |||
# requesthandler.executecallbacks (where we're from) | |||
confirmation "${latesttxid}" "true" | |||
confirmation $(echo "${tx}" | jq .result | base64 -w 0) "true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use jq -Mc
to remove formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
First commit usng MQTT to send events from core to Proxy. Event are filtrer t send watching wallets tx only.
Next: remove code in confirmation and use data received in sub message