Every block has a selected parent (selected by GHOSTDAG algo).
virtual is a virtual block pointing at all current tips of the local node.
Like any other block, virtual has a selected parent (aka the selected tip).
Starting from this tip, one can walk down the path of "selected parent" links, this is the "selected chain".
Note that by def the selected chain can change (since virtual point-of-view changes), it's called a reorg. In a wide DAG small reorgs are frequent, however security of GHOSTDAG implies that the chain is robust — meaning it stabilizes very fast up to a small suffix.
The selected chain is what determines the order of events in the DAG, and blocks in it (aka chain blocks) have a special role in the sense that we (recursively) accept their point of view.
The mergeset of a chain block
C is defined to be the set of blocks in the past of
C (i.e. reachable from
C) but not in the past of the selected parent of
C. Note that the mergeset includes the selected parent itself (which is the preceding chain block)
C is the merging block of block
B in his mergeset.
C is the accepting block for valid transactions coming from
The GHOSTDAG order of a mergeset: sorts the mergeset in increasing order by blue work and tiebreaks by hash (lexicographically).
From the context of a chain block
B in the mergeset has 2 classifications:
B blue ? meaning
B is well-connected and contributes to security;
B in the DAA window of
C (roughly speaking, blocks out of the DAA window are blocks which at least 45 minutes passed between their mining and publication times -- that is, they are highly disconnected).
P.S. If a block is blue it is also surely in the DAA window (code does not assume that, but it's true). The selected parent is by def both blue and in the DAA window.
Every blue block
B is rewarded by
C in the following way:
C calculates the coinbase subsidy based on the emission schedule and the current DAA score.
C sums up the fees from all accepted transactions which were included by
C rewards itself for every block
R in the mergeset which is red (non-blue) if it is in the DAA window of
C iterates the mergeset in GHOSTDAG order as defined above: for each blue block it appends an output entry to its coinbase tx with the calculated reward. If there are red + DAA blocks, it appends another output paying himself their reward.
C is not a chain block, then regardless of the fact that it performs all the same activities, its coinbase and self-reward transactions are not considered valid after the DAG structure is stabilized and thus discarded by each node.
So if you have a mined block hash
B, and you want to calculate the exact reward associated with it:
C which merged
B is in
C.MergesetReds -> no reward.
B is in
C.MergesetBlues -> find the position
C.MergesetBlues. The i'th output in the coinbase tx of
C is the one paying the reward to
B itself is a chain block and has merged red blocks which are also in the DAA window, then the coinbase of
B itself should have a last entry paying the miner of
B (one can validate this by checking that the coinbase has
|B.MergsetBlues| + 1 entries).