mirror of
https://github.com/aljazceru/cyphernode.git
synced 2026-01-18 20:14:23 +01:00
Better manage_missed_conf algo
This commit is contained in:
@@ -33,7 +33,7 @@ manage_not_imported() {
|
||||
}
|
||||
|
||||
manage_missed_conf() {
|
||||
# Maybe we missed confirmations, because we were down or no network or
|
||||
# Maybe we missed 0-conf or 1-conf watched txs, because we were down or no network or
|
||||
# whatever, so we look at what might be missed and do confirmations.
|
||||
|
||||
# The strategy here: get the list of watched addresses, see if they received something on the Bitcoin node,
|
||||
@@ -42,7 +42,7 @@ manage_missed_conf() {
|
||||
trace "[Entering manage_missed_conf()]"
|
||||
|
||||
local watches=$(sql "SELECT DISTINCT address FROM watching w LEFT JOIN watching_tx ON w.id = watching_id LEFT JOIN tx t ON t.id = tx_id WHERE watching AND imported AND (tx_id IS NULL OR t.confirmations=0) ORDER BY address")
|
||||
# trace "[manage_missed_conf] watches=${watches}"
|
||||
trace "[manage_missed_conf] watches=${watches}"
|
||||
if [ ${#watches} -eq 0 ]; then
|
||||
trace "[manage_missed_conf] Nothing missed!"
|
||||
return 0
|
||||
@@ -55,7 +55,7 @@ manage_missed_conf() {
|
||||
data='{"method":"listreceivedbyaddress","params":[0,false,true]}'
|
||||
received=$(send_to_watcher_node "${data}")
|
||||
received_addresses=$(echo "${received}" | jq -r ".result[].address" | sort)
|
||||
# trace "[manage_missed_conf] received_addresses=${received_addresses}"
|
||||
trace "[manage_missed_conf] received_addresses=${received_addresses}"
|
||||
|
||||
# Let's extract addresses that are in the watches list as well as in the received_addresses list
|
||||
echo "${watches}" > watches-$$
|
||||
@@ -66,6 +66,7 @@ manage_missed_conf() {
|
||||
|
||||
local received
|
||||
local received_address
|
||||
local confirmations
|
||||
local watching
|
||||
local latesttxid
|
||||
local tx
|
||||
@@ -76,47 +77,52 @@ manage_missed_conf() {
|
||||
local row
|
||||
local address
|
||||
local inserted_ts
|
||||
local calledback0conf
|
||||
local txid
|
||||
local txids
|
||||
local IFS=$'\n'
|
||||
for address in ${received_watches}
|
||||
do
|
||||
watching=$(sql "SELECT address, inserted_ts FROM watching WHERE address='${address}'")
|
||||
watching=$(sql "SELECT address, inserted_ts, calledback0conf FROM watching WHERE address='${address}'")
|
||||
trace "[manage_missed_conf] watching=${watching}"
|
||||
if [ ${#watching} -eq 0 ]; then
|
||||
trace "[manage_missed_conf] Nothing missed!"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Let's get confirmed received txs for the address
|
||||
# address=$(echo "${watches}" | cut -d '|' -f1)
|
||||
inserted_ts=$(date -d "$(echo "${watching}" | cut -d '|' -f2)" -D '%Y-%m-%d %H:%M:%S' +"%s")
|
||||
trace "[manage_missed_conf] inserted_ts=${inserted_ts}"
|
||||
calledback0conf=$(echo "${watching}" | cut -d '|' -f3)
|
||||
trace "[manage_missed_conf] calledback0conf=${calledback0conf}"
|
||||
|
||||
received_address=$(echo "${received}" | jq -Mc ".result | map(select(.address==\"${address}\" and .confirmations>0))[0]")
|
||||
received_address=$(echo "${received}" | jq -Mc ".result | map(select(.address==\"${address}\"))[0]")
|
||||
trace "[manage_missed_conf] received_address=${received_address}"
|
||||
if [ "${received_address}" = "null" ]; then
|
||||
# Not confirmed while we were away...
|
||||
trace "[manage_missed_conf] Nothing missed here"
|
||||
confirmations=$(echo "${received_address}" | jq -r ".confirmations")
|
||||
trace "[manage_missed_conf] confirmations=${confirmations}"
|
||||
|
||||
if [ "${confirmations}" -eq "0" ] && [ "${calledback0conf}" = "t" ]; then
|
||||
# 0-conf and calledback0conf is true, so let's skip this one
|
||||
trace "[manage_missed_conf] Nothing missed!"
|
||||
else
|
||||
# We got something confirmed
|
||||
# Let's find out if it was confirmed after being watched
|
||||
trace "[manage_missed_conf] We got something confirmed"
|
||||
# 0-conf and calledback0conf false, let's call confirmation
|
||||
# or
|
||||
# 1-conf and calledback1conf false, let's call confirmation
|
||||
trace "[manage_missed_conf] We got something to check..."
|
||||
|
||||
latesttxid=$(echo "${received_address}" | jq -r ".txids | last")
|
||||
trace "[manage_missed_conf] latesttxid=${latesttxid}"
|
||||
data='{"method":"gettransaction","params":["'${latesttxid}'"]}'
|
||||
tx=$(send_to_watcher_node ${data})
|
||||
blocktime=$(echo "${tx}" | jq '.result.blocktime')
|
||||
txtime=$(echo "${tx}" | jq '.result.time')
|
||||
confirmations=$(echo "${tx}" | jq '.result.confirmations')
|
||||
|
||||
trace "[manage_missed_conf] blocktime=${blocktime}"
|
||||
trace "[manage_missed_conf] txtime=${txtime}"
|
||||
trace "[manage_missed_conf] inserted_ts=${inserted_ts}"
|
||||
trace "[manage_missed_conf] confirmations=${confirmations}"
|
||||
|
||||
if [ "${txtime}" -gt "${inserted_ts}" ] && [ "${confirmations}" -gt "0" ]; then
|
||||
# Mined after watch, we missed it!
|
||||
if [ "${txtime}" -ge "${inserted_ts}" ]; then
|
||||
# Broadcast after watch, we missed it!
|
||||
trace "[manage_missed_conf] Mined after watch, we missed it!"
|
||||
confirmation "${latesttxid}" "true"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user