How to return Tx to mem pool from orphan block

0

This question is centered around the implementation of how transactions on an orphan block return to the mem pool.

In my understanding, once a block becomes orphan all it's transactions (that aren't on other non-orphan blocks) need to return to the mem pool.

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;
}

The Apprentice

Posted 2018-04-10T10:52:18.920

Reputation: 1

Answers

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.

The Apprentice

Posted 2018-04-10T10:52:18.920

Reputation: 1

1

Proto code for returning transactions from orphan block:

foreach ( tx: orphanBlock )
  if ( tx.isValidAfterReorg ( ) )
    mempool.insert ( tx );

amaclin

Posted 2018-04-10T10:52:18.920

Reputation: 5 763

What does "isValidAfterReorg" does? Does it check the entirety of the chain like my proto code does?The Apprentice 2018-04-10T11:02:00.993

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 mempoolamaclin 2018-04-10T11:03:48.673

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)The Apprentice 2018-04-10T11:08:25.063

if the mainchain already contains the transaction the tx will be invalid-for-mainchain because its inputs are not connected to utxo setamaclin 2018-04-10T15:40:55.040