chromaway/ngcccbase

Color Mempool Transactions

Closed this issue · 1 comments

From killerstorm:

A new class: MempoolColorData
Method update():

  1. fetches mempool contents from bitcoind
  2. makes sure that the last block is scanned using ColorDataBuilder (*)
  3. make sure that transactions are dependency-sorted (probably bitcoind gives them to us this way, but I'm not sure)
  4. run scan_tx on each transaction in the list.
  5. is of transactions is remembered.

ThickColorData first tries to classify transactions. Three cases are possible:

  1. It is in blockchain: call ColorDataBuilder
  2. it is in mempool. Is it in MempoolColorData?
    2.1. If yes, use ColorDataStore, just like in the first cast
    2.2. If no, then update MempoolColorData, go to 1.

*: It bothers me that these calls are not atomic, I think we can do it this way (pseudo-code):

while 1:
the_last_block_1 = bitcoind.get_last_block_hash()
mempool = bitcoin.get_mempool()
the_last_block_2 = bitcoind.get_last_block_hash()
if the_last_block_1 == the_last_block_2:
cdb.ensure_scanned_upto(the_last_block_1)
break

Basically, we need to make sure that the last block haven't changed while we were getting mempool contents. If we get same block hash, then it haven't changed, and so we can proceed.
If it did change in process, just try again.

Current approach:

Change publish_tx in wallet_controller to insert utxo's into the utxodb.
Change ThickColorData to scan the mempool if blockchain doesn't exist.