Skip to content

Commit

Permalink
rebase & blk marshal/unmarshal & merkleroot to ids.ID
Browse files Browse the repository at this point in the history
  • Loading branch information
bianyuanop authored and iFrostizz committed Apr 26, 2024
1 parent e551960 commit 7442836
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions merkle/merkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (

"github.com/ava-labs/avalanchego/database"
"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) ([]byte, merkledb.MerkleDB, error) {
func GenerateMerkleRoot(ctx context.Context, 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 @@ -26,27 +27,26 @@ func GenerateMerkleRoot(ctx context.Context, tracer trace.Tracer, merkleItems []
db, err := merkledb.New(ctx, memdb.New(), merkledb.Config{
BranchFactor: merkledb.BranchFactor16,
HistoryLength: 100,
EvictionBatchSize: units.MiB,
IntermediateNodeCacheSize: units.MiB,
ValueNodeCacheSize: units.MiB,
Tracer: tracer,
})
if err != nil {
return nil, nil, err
return ids.Empty, nil, err
}

view, err := db.NewView(ctx, merkledb.ViewChanges{BatchOps: batchOps, ConsumeBytes: consumeBytes})
if err != nil {
return nil, nil, err
return ids.Empty, nil, err
}
if err := view.CommitToDB(ctx); err != nil {
return nil, nil, err
return ids.Empty, nil, err
}

root, err := db.GetMerkleRoot(ctx)
if err != nil {
return nil, nil, err
return ids.Empty, nil, err
}

return root[:], db, nil
return root, db, nil
}

0 comments on commit 7442836

Please sign in to comment.