The general meaning of "next state root hash" has changed to be simpler:
The next state root hash of a Block is meant as the state root hash resulting from an execution of the Blockregardless of its protocol version number.
The next state root hash of a pre-Sloth Block is its state root hash, i.e. Block.StateRootHash.
The next state root hash of a post-Sloth Block is the state root hash after its evaluation.
On top of this, the next state root hash of any Block is considered ephemeral until it can be derived from the BlockChain itself:
Note that any Block that is either pre-Sloth or that is included in BlockChain that is not the Tip can be fetched from the BlockChain.
This is notion is dependent upon the general assumption that the BlockChain itself is always valid.
The next state root hash of the Tipmay be missing only if the Tip is a post-Sloth Block and it is still under evaluation.
I have (temporarily) moved a possible lock inside GetNextStateRootHash() to a more appropriate place, i.e. ConsensusContext. This doesn't actually resolve the (issue)[#3833], but should be handled separately.
Internally, the next state root hash of the BlockChain (i.e., BlockChain.GetNextStateRootHash()) is kept up to date by managing it through BlockChain(), Fork(), and Swap().
@OnedgeLee
I've made the suggested changes except for the indexing issue in ConsensusContext.NewHeight() method, which will be handled in a separate PR.
The general meaning of "next state root hash" has changed to be simpler:
Block
is meant as the state root hash resulting from an execution of theBlock
regardless of its protocol version number.Block
is its state root hash, i.e.Block.StateRootHash
.Block
is the state root hash after its evaluation.On top of this, the next state root hash of any
Block
is considered ephemeral until it can be derived from theBlockChain
itself:Block
that is either pre-Sloth or that is included inBlockChain
that is not theTip
can be fetched from theBlockChain
.BlockChain
itself is always valid.Tip
may be missing only if theTip
is a post-SlothBlock
and it is still under evaluation.I have (temporarily) moved a possible lock inside
GetNextStateRootHash()
to a more appropriate place, i.e.ConsensusContext
. This doesn't actually resolve the (issue)[#3833], but should be handled separately.Internally, the next state root hash of the
BlockChain
(i.e.,BlockChain.GetNextStateRootHash()
) is kept up to date by managing it throughBlockChain()
,Fork()
, andSwap()
.