Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ type SerializedNode struct {

// BatchSerialize is an optimized serialization API when multiple VerkleNodes serializations are required, and all are
// available in memory.
func (n *InternalNode) BatchSerialize() ([]SerializedNode, error) {
func (n *InternalNode) BatchSerialize() []SerializedNode {
// Commit to the node to update all the nodes commitments.
n.Commit()

Expand Down Expand Up @@ -1690,10 +1690,7 @@ func (n *InternalNode) BatchSerialize() ([]SerializedNode, error) {
for i := range nodes {
switch n := nodes[i].(type) {
case *InternalNode:
serialized, err := n.serializeInternalWithUncompressedCommitment(serializedPointsIdxs, serializedPoints)
if err != nil {
return nil, err
}
serialized := n.serializeInternalWithUncompressedCommitment(serializedPointsIdxs, serializedPoints)
sn := SerializedNode{
Node: n,
Path: paths[i],
Expand All @@ -1717,7 +1714,7 @@ func (n *InternalNode) BatchSerialize() ([]SerializedNode, error) {
}
}

return ret, nil
return ret
}

func (n *InternalNode) collectNonHashedNodes(list []VerkleNode, paths [][]byte, path []byte) ([]VerkleNode, [][]byte) {
Expand All @@ -1739,7 +1736,7 @@ func (n *InternalNode) collectNonHashedNodes(list []VerkleNode, paths [][]byte,
}

// unpack one compressed commitment from the list of batch-compressed commitments
func (n *InternalNode) serializeInternalWithUncompressedCommitment(pointsIdx map[VerkleNode]int, serializedPoints [][banderwagon.UncompressedSize]byte) ([]byte, error) {
func (n *InternalNode) serializeInternalWithUncompressedCommitment(pointsIdx map[VerkleNode]int, serializedPoints [][banderwagon.UncompressedSize]byte) []byte {
serialized := make([]byte, nodeTypeSize+bitlistSize+banderwagon.UncompressedSize)
bitlist := serialized[internalBitlistOffset:internalCommitmentOffset]
for i, c := range n.children {
Expand All @@ -1748,13 +1745,10 @@ func (n *InternalNode) serializeInternalWithUncompressedCommitment(pointsIdx map
}
}
serialized[nodeTypeOffset] = internalRLPType
pointidx, ok := pointsIdx[n]
if !ok {
return nil, fmt.Errorf("child node not found in cache")
}
pointidx := pointsIdx[n]
copy(serialized[internalCommitmentOffset:], serializedPoints[pointidx][:])

return serialized, nil
return serialized
}

func (n *LeafNode) serializeLeafWithUncompressedCommitments(cBytes, c1Bytes, c2Bytes [banderwagon.UncompressedSize]byte) []byte {
Expand Down
13 changes: 3 additions & 10 deletions tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1419,9 +1419,7 @@ func TestBatchMigratedKeyValues(t *testing.T) {
}
}
unbatchedRoot := tree.Commit().Bytes()
if _, err := tree.(*InternalNode).BatchSerialize(); err != nil {
t.Fatalf("failed to serialize unbatched tree: %v", err)
}
tree.(*InternalNode).BatchSerialize()
unbatchedDuration += time.Since(now)

// ***Insert the key pairs with optimized strategy & methods***
Expand Down Expand Up @@ -1465,9 +1463,7 @@ func TestBatchMigratedKeyValues(t *testing.T) {
t.Fatalf("failed to insert key: %v", err)
}
batchedRoot := tree.Commit().Bytes()
if _, err := tree.(*InternalNode).BatchSerialize(); err != nil {
t.Fatalf("failed to serialize batched tree: %v", err)
}
tree.(*InternalNode).BatchSerialize()
batchedDuration += time.Since(now)

if unbatchedRoot != batchedRoot {
Expand Down Expand Up @@ -1551,10 +1547,7 @@ func BenchmarkBatchLeavesInsert(b *testing.B) {
if err := tree.(*InternalNode).InsertMigratedLeaves(newLeaves, nil); err != nil {
b.Fatalf("failed to insert key: %v", err)
}

if _, err := tree.(*InternalNode).BatchSerialize(); err != nil {
b.Fatalf("failed to serialize batched tree: %v", err)
}
tree.(*InternalNode).BatchSerialize()
}
}

Expand Down