Most of the full nodes are operating on normal CPUs which is now basically ineffective for mining. The mining process is handled by specific mining pools. So for full nodes that basically sees the same blockchain (there might be inconsistencies at the tip if two blocks are mined at the same time), they have the same UTXO set. This is because the UTXO set is built based on the transactions that are included in the blocks. Whenever a block is received by a full node, they delete the UTXOs which were consumed by the inputs in the transactions and add the UTXOs that were created in the output. For a mining node it is similar. If they mined the last block at the same time as the other miner, then the first miner would be building the next block using a different UTXO set than the other miner. However, after one or two blocks when the network converges (they cannot indefinitely generate blocks simultaneously) the network would have the same UTXO set.
For mempool the story is different. Bitcoin transactions are relayed on the network on a best effort basis. So it might be the case that some nodes do not see some transactions until they are finally included in the blocks. So, yes there are inconsistencies in the mempool.
how can a node resume mining after the new block is introduced?
As mentioned above, if two blocks are mined at the same time then some miners would be working on a different version versus others. The accepted principle is to build on the block that was received first. However, this is not always the case. So when a mining node who is still calculating the header hashes notice that a new block is mined, they realize that they have lost the 'race' for that particular block height and try to mine on the block that was most recently received.
I have two questions still not resolved: First, If two branched blockchains get merged, how do
UTXO setare fixed? Is it just replaced by the mainstream blockchain's one(by the result of replacing the lost blockchain by the winning longest blockchain), or re-computed from not overlapped block to the most recent block(according to the updated new blocks ahead)? I guess the latter is not an practical way. – cadenzah – 2019-05-17T01:55:57.477Second, almost same question on
mempool. As two branched blockchains have some of blocks different, themempoolthey each have must not be identical before they are merged. How does this inconsistency be resolved? When a new block is generated, each node choosestxs from itsmempool(decide to use transactions occured until certain point of time, and the rest will be included when another next block is generated). – cadenzah – 2019-05-17T02:03:29.660(Continuing from the previous comment) So right before the unidentical blockchains get merged, the elements of
mempoolcould be different each other(while onetxmay be included in blockchain A, the one may not be in blockchain B). In this situation, how does the node resolve themempooldifference issue? – cadenzah – 2019-05-17T02:05:41.477And thank you very much for the detailed answer and explanation! – cadenzah – 2019-05-17T02:12:24.893
First UTXO set is built by the full node by it self. It is not broadcasted over the network. So when one node receives a block, it removes the input of the transactions from the UTXO set and adds the outputs. In case there is a branched chain and subsequent re-org, the node undoes the changes for transactions that are not included in the other block, but was present in the first block also adding the new transactions – Ugam Kamat – 2019-05-17T05:44:09.807
Second As I mentioned in the answer, mempool is not always consistent across nodes even if they are seeing the same view of the blockchain. Again, as I mentioned in my answer, mining nodes generate blocks. Full nodes verify that the blocks generated confine with the consensus protocol. When a block is received by a full node, it would remove transactions from its mempool that were included in the block. There is no one way of including transactions. If miners decide they can just mine the blocks without including any transactions (just the coinbase transaction) – Ugam Kamat – 2019-05-17T05:48:39.067
@cadenzah In case of a chain re-org, when the node receives the other branch of the chain which should be the main chain, it would remove transactions from the mempool that are included in the current chain and add transactions from previous block back to the mempool if it was not included in the re-orged chain – Ugam Kamat – 2019-05-17T05:50:06.130
So in terms of
mempoolandUTXO set, it is totally un-do and adoptrestructuring procedure, not the kind of replacing. That clears my understanding. Thank you for your kind and detailed explanation! – cadenzah – 2019-05-17T06:56:55.270