Skip to content

Commit

Permalink
Count decendants when decoding branch
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Mar 1, 2022
1 parent 689751f commit f33420d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions internal/trie/node/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ func decodeBranch(reader io.Reader, header byte) (branch *Branch, err error) {
if (childrenBitmap[i/8]>>(i%8))&1 != 1 {
continue
}
branch.AddDescendants(1)

var hash []byte
err := sd.Decode(&hash)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions internal/trie/node/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ func Test_decodeBranch(t *testing.T) {
HashDigest: []byte{1, 2, 3, 4, 5},
},
},
Dirty: true,
Dirty: true,
Descendants: 1,
},
},
"value decoding error for node type 3": {
Expand Down Expand Up @@ -211,7 +212,8 @@ func Test_decodeBranch(t *testing.T) {
HashDigest: []byte{1, 2, 3, 4, 5},
},
},
Dirty: true,
Dirty: true,
Descendants: 1,
},
},
}
Expand Down
3 changes: 2 additions & 1 deletion internal/trie/node/encode_decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ func Test_Branch_Encode_Decode(t *testing.T) {
HashDigest: []byte{0x41, 0x9, 0x4, 0xa},
},
},
Dirty: true,
Dirty: true,
Descendants: 1,
},
},
}
Expand Down

0 comments on commit f33420d

Please sign in to comment.