From fc437f9315c5af99bfd369480690c236d242696c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20Mo=CC=88ser?= Date: Mon, 23 Mar 2020 12:40:40 -0400 Subject: [PATCH] fix: inconsistent txFirstSpend Fixes a rare situation where, due to the parallel processing of transactions, it can happen that an input script is serialized as a wrapped script in a later transaction before it is serialized as a normal input script in a previous transaction. This is a simpler fix than moving the input processing of wrapped scripts to the last stage of the processing pipeline. Reparsing the chain is recommended. --- tools/parser/address_writer.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/parser/address_writer.hpp b/tools/parser/address_writer.hpp index c1f68094..88599b14 100644 --- a/tools/parser/address_writer.hpp +++ b/tools/parser/address_writer.hpp @@ -122,14 +122,19 @@ class AddressWriter { /** Default value of ScriptDataBase.txFirstSpent is (std::numeric_limits::max()) */ bool isFirstSpend = data->txFirstSpent == std::numeric_limits::max(); + /** Can occur when a wrapped input is serialized before the top-level input */ + bool isNewerFirstSpend = txNum < data->txFirstSpent; + /** Default value of ScriptDataBase.txFirstSeen is the txNum of the transaction that contained the script */ bool isNewerFirstSeen = outputTxNum < data->txFirstSeen; if (isNewerFirstSeen) { data->txFirstSeen = outputTxNum; } - if (isFirstSpend) { + if (isNewerFirstSpend) { data->txFirstSpent = txNum; + } + if (isFirstSpend) { serializeInputImp(input, file); } }