Branch

📖 Definition:

The Branch Node in MPT is a unique node type designed to represent potential multiple paths at a given point in the trie. Unlike Leaf and Extension nodes, a Branch Node can point to multiple children, making it instrumental in diverging paths based on key differences.

📌 Key Characteristics:

  1. Path Divergence: Where paths within the trie differ, a Branch Node stands as the point of divergence, directing to different child nodes based on key segments

  2. Multiple Children: A Branch Node features 16 slots, each corresponding to a nibble value from 0-F. This allows it to potentially reference 16 distinct child nodes, based on key segments

  3. Optional Value Storage: While primarily serving as a path diverger, a Branch Node can also store a value directly if a key corresponds to its position in the trie

🛠️ Structure:

The Branch Node's Go representation is as follows:

type BranchNode struct {
	Children   [BranchChildrenSize]Node
	Value      []byte
	childCount int
	Dirty      bool
}
  • Children: An array structured to accommodate up to 16 child nodes, each slot catering to a unique nibble from 0-F

  • Value: Contains any direct data value associated with the current node's position in the trie

  • childCount: An integer tracker that records the number of children currently linked by the Branch Node

  • Dirty: A boolean flag signifying whether the node has seen modifications since its last commit

Last updated