1

This question is centered around the implementation of how transactions from a reorganized block return to the mempool.

In my understanding, once a block becomes organized out of the best chain all its transactions (that aren't in blocks of the best chain) need to return to the mempool.

Do we start from genesis block until we reach the last block of the active chain checking every transaction along the way, or is it there a more efficient algorithm that's based on some constraint/property that allows the algorithm to start from a more recent block?

Proto code for starting from the genesis block:

Blockchain blockchain = ...
function Dictionary<Key, Tx> deleteOrphanTx (Dictionary<Key, Tx> orphanTx) {
    foreach (Block currBlock : blockchain.getBlocks())
        foreach (Tx tx : currBlock.getTx())
            Key txKey = tx.getKey();
            if(orphanTx.contains(txKey)
                orphanTx.remove(txKey);
    return orphanTx;
}

2 Answers 2

1

Proto code for returning transactions from orphan block:

foreach ( tx: orphanBlock )
  if ( tx.isValidAfterReorg ( ) )
    mempool.insert ( tx );
4
  • What does "isValidAfterReorg" does? Does it check the entirety of the chain like my proto code does? Commented Apr 10, 2018 at 11:02
  • it checks that transaction is valid in reorganized chain. it does not matter where transaction came from - either from network or from orphan block - if it is valid we can add it to the mempool
    – amaclin
    Commented Apr 10, 2018 at 11:03
  • What if another block already has said Tx? Even if it's valid, it's duplicated. Since orphan blocks occur from forks/concurrency, it's highly probable that block A already has many of the Tx that block B has (block A and B create a fork in this case) Commented Apr 10, 2018 at 11:08
  • if the mainchain already contains the transaction the tx will be invalid-for-mainchain because its inputs are not connected to utxo set
    – amaclin
    Commented Apr 10, 2018 at 15:40
0

Since there weren't other entries and the only answer didn't provide a clear answer to my question, I'm going to sum up what I found to be the solution to my question.

There are no properties or constraints that allow the algorithm to start from a more recent block. In order to check if a transaction from an orphan block needs to go back to the mem pool, one needs to start from the genesis block and check every block along the way to guarantee that the transaction doesn't already belong to a validated block. If at the end no blockchain no block contains said transaction, we need to add it back to the mem pool.

If in the meantime someone participates with more relevant information I'll happily delete this answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.