Skip to content

Commit

Permalink
Add commit support
Browse files Browse the repository at this point in the history
  • Loading branch information
dimartiro committed Sep 2, 2024
1 parent 381018b commit 4c2bcb2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/mmr/mmr.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func (mmr *MMR) Root() (MMRElement, error) {
return mmr.bagPeaks(peaks), nil
}

func (mmr *MMR) Commit() error {
return mmr.batch.commit()
}

func (mmr *MMR) findElement(position uint64, values []MMRElement) (MMRElement, error) {
if position > mmr.size {
positionOffset := position - mmr.size
Expand Down
17 changes: 17 additions & 0 deletions pkg/mmr/mmr_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,20 @@ func (b *MMRBatch) getElement(pos uint64) (*MMRElement, error) {

return b.storage.getElement(pos)
}

func (b *MMRBatch) commit() error {
for _, node := range b.drain() {
err := b.storage.append(node.pos, node.elements)
if err != nil {
return err
}
}
return nil
}

func (b *MMRBatch) drain() []MMRNode {
nodes := b.nodes
b.nodes = make([]MMRNode, 0)

return nodes
}

0 comments on commit 4c2bcb2

Please sign in to comment.