Skip to content

Commit

Permalink
pass config by parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
iFrostizz committed Apr 26, 2024
1 parent 058d7e7 commit 4aec589
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
11 changes: 2 additions & 9 deletions merkle/merkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import (
"github.com/ava-labs/avalanchego/database/memdb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/trace"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/x/merkledb"
"github.com/ava-labs/hypersdk/utils"
)

// Generate merkle root for a set of items
func GenerateMerkleRoot(ctx context.Context, tracer trace.Tracer, merkleItems [][]byte, consumeBytes bool) (ids.ID, merkledb.MerkleDB, error) {
func GenerateMerkleRoot(ctx context.Context, config merkledb.Config, tracer trace.Tracer, merkleItems [][]byte, consumeBytes bool) (ids.ID, merkledb.MerkleDB, error) {
batchOps := make([]database.BatchOp, 0, len(merkleItems))

for _, item := range merkleItems {
Expand All @@ -24,13 +23,7 @@ func GenerateMerkleRoot(ctx context.Context, tracer trace.Tracer, merkleItems []
})
}

db, err := merkledb.New(ctx, memdb.New(), merkledb.Config{
BranchFactor: merkledb.BranchFactor16,
HistoryLength: 100,
IntermediateNodeCacheSize: units.MiB,
ValueNodeCacheSize: units.MiB,
Tracer: tracer,
})
db, err := merkledb.New(ctx, memdb.New(), config)
if err != nil {
return ids.Empty, nil, err
}
Expand Down
13 changes: 11 additions & 2 deletions merkle/merkle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package merkle
import (
"testing"

"crypto/rand"
"context"
"crypto/rand"
"strconv"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/trace"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/x/merkledb"
)

Expand All @@ -34,10 +35,18 @@ func BenchmarkMerkleTxRoot(b *testing.B) {
var db merkledb.MerkleDB
var err error

defaultConfig := merkledb.Config{
BranchFactor: merkledb.BranchFactor16,
HistoryLength: 100,
IntermediateNodeCacheSize: units.MiB,
ValueNodeCacheSize: units.MiB,
Tracer: tracer,
}

b.Run(strconv.Itoa(size), func(b *testing.B) {
for n := 0; n < b.N; n++ {
for i := 0; i < size; i++ {
root, db, err = GenerateMerkleRoot(ctx, tracer, merkleItems, false)
root, db, err = GenerateMerkleRoot(ctx, defaultConfig, tracer, merkleItems, false)
}
}
})
Expand Down

0 comments on commit 4aec589

Please sign in to comment.