gcash/bchwallet

Handle CTOR blocks

Closed this issue · 1 comments

Not 100% sure but I think CTOR may prevent the wallet from learning of relevant transactions. I've taken a brief look at the code and it looks like the fix may be as easy as modifying this function in chain/block_filterer.go to sort the block in topological order before checking each tx for relevancy.

func (bf *BlockFilterer) FilterBlock(block *wire.MsgBlock) bool {
	var hasRelevantTxns bool
	for _, tx := range block.Transactions {
		if bf.FilterTx(tx) {
			bf.RelevantTxns = append(bf.RelevantTxns, tx)
			hasRelevantTxns = true
		}
	}

	return hasRelevantTxns
}

If this is indeed all that is needed it looks like the topological sort may not be that resource intensive as it appears this function is only call if the block matches the CF filter. Which means we'd expect it to be a relatively small number of blocks that match and thus require sorting.

Is there a less intensive way of handling CTOR than doing a full sort of the block?

Honestly, I don't think the sort is that bad now, but when blocks are really large, this could start to become an issue. If we do a sort, then we need to leave a TODO that we will revisit this and figure out a better solution.