Skip to content

Commit

Permalink
do not recreate visitor for every tree
Browse files Browse the repository at this point in the history
  • Loading branch information
walldiss committed Apr 13, 2024
1 parent d87a0b3 commit daa9ec2
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions share/eds/retriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,17 @@ func (r *Retriever) newSession(ctx context.Context, dah *da.DataAvailabilityHead
r.bServ,
ipld.MaxSizeBatchOption(size),
)

treeFn := func(_ rsmt2d.Axis, index uint) rsmt2d.Tree {
proofsVisitor := ipld.ProofsAdderFromCtx(ctx).VisitFn()
visitor := func(hash []byte, children ...[]byte) {
// use proofs adder if provided, to cache collected proofs while recomputing the eds
var opts []nmt.Option

proofsAdder := ipld.ProofsAdderFromCtx(ctx)
visitor := func(hash []byte, children ...[]byte) {
if proofsAdder != nil {
proofsAdder.VisitFn()(hash, children...)
}
adder.Visit(hash, children...)
if proofsVisitor != nil {
proofsVisitor(hash, children...)
}
opts = append(opts, nmt.NodeVisitor(visitor))
adder.Visit(hash, children...)
}

tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(size)/2, index, opts...)
treeFn := func(_ rsmt2d.Axis, index uint) rsmt2d.Tree {
tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(size)/2, index, nmt.NodeVisitor(visitor))
return &tree
}

Expand Down

0 comments on commit daa9ec2

Please sign in to comment.