Skip to content

Commit

Permalink
fix: inconsistent txFirstSpend
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
maltemoeser committed Mar 30, 2020
1 parent 68b6d36 commit fc437f9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tools/parser/address_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,19 @@ class AddressWriter {
/** Default value of ScriptDataBase.txFirstSpent is (std::numeric_limits<uint32_t>::max()) */
bool isFirstSpend = data->txFirstSpent == std::numeric_limits<uint32_t>::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);
}
}
Expand Down

0 comments on commit fc437f9

Please sign in to comment.