From dd9d39b57d59a25755ab51b8e0cda32535c3d3a5 Mon Sep 17 00:00:00 2001 From: Jerzy Kozera Date: Mon, 15 Apr 2013 00:20:56 +0200 Subject: [PATCH] Order transactions from the same block correctly Currently transactions are stored in reversed order if they belong to the same block, which can result in holes in history when pruning. For example, consider a transaction chain A->B->C->D, where A,B,C belong to the same block, and D to the next block. It's stored in the history as C,B,A,D. So when C is pruned first, we have B,A,D in history, which results in incorrect balance calculations, because both A and D are considered to come from pruned outputs. Storing transactions in A,B,C,D order, and then pruning A first, correctly results in only B being considered as coming from pruned output. --- backends/bitcoind/blockchain_processor.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/backends/bitcoind/blockchain_processor.py b/backends/bitcoind/blockchain_processor.py index 9a14ded..c5ed9c5 100644 --- a/backends/bitcoind/blockchain_processor.py +++ b/backends/bitcoind/blockchain_processor.py @@ -340,7 +340,7 @@ class BlockchainProcessor(Processor): for i in range(l-1, -1, -1): item = serialized_hist[80*i:80*(i+1)] item_height = int(rev_hex(item[36:39].encode('hex')), 16) - if item_height < tx_height: + if item_height <= tx_height: serialized_hist = serialized_hist[0:80*(i+1)] + s + serialized_hist[80*(i+1):] break else: -- 1.7.1