aboutsummaryrefslogtreecommitdiffstats
path: root/trie/node.go
diff options
context:
space:
mode:
Diffstat (limited to 'trie/node.go')
-rw-r--r--trie/node.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/trie/node.go b/trie/node.go
index 02815042c..a06f1b389 100644
--- a/trie/node.go
+++ b/trie/node.go
@@ -47,9 +47,22 @@ type (
valueNode []byte
)
+// nilValueNode is used when collapsing internal trie nodes for hashing, since
+// unset children need to serialize correctly.
+var nilValueNode = valueNode(nil)
+
// EncodeRLP encodes a full node into the consensus RLP format.
func (n *fullNode) EncodeRLP(w io.Writer) error {
- return rlp.Encode(w, n.Children)
+ var nodes [17]node
+
+ for i, child := range n.Children {
+ if child != nil {
+ nodes[i] = child
+ } else {
+ nodes[i] = nilValueNode
+ }
+ }
+ return rlp.Encode(w, nodes)
}
func (n *fullNode) copy() *fullNode { copy := *n; return &copy }