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;
}
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 mempool – amaclin – 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
txwill be invalid-for-mainchain because its inputs are not connected to utxo set – amaclin – 2018-04-10T15:40:55.040