@@ -9,12 +9,15 @@ import (
9
9
"fmt"
10
10
"time"
11
11
12
+ "github.com/ava-labs/avalanchego/database"
13
+ "github.com/ava-labs/avalanchego/database/memdb"
12
14
"github.com/ava-labs/avalanchego/ids"
13
15
"github.com/ava-labs/avalanchego/snow/choices"
14
16
"github.com/ava-labs/avalanchego/snow/consensus/snowman"
15
17
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
16
18
"github.com/ava-labs/avalanchego/snow/validators"
17
19
"github.com/ava-labs/avalanchego/utils/set"
20
+ "github.com/ava-labs/avalanchego/utils/units"
18
21
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
19
22
"github.com/ava-labs/avalanchego/x/merkledb"
20
23
"go.opentelemetry.io/otel/attribute"
@@ -40,7 +43,8 @@ type StatefulBlock struct {
40
43
Tmstmp int64 `json:"timestamp"`
41
44
Hght uint64 `json:"height"`
42
45
43
- Txs []* Transaction `json:"txs"`
46
+ Txs []* Transaction `json:"txs"`
47
+ TxsRoot []byte `json:"txsRoot"`
44
48
45
49
// StateRoot is the root of the post-execution state
46
50
// of [Prnt].
@@ -290,6 +294,46 @@ func (b *StatelessBlock) initializeBuilt(
290
294
b .containsWarp = true
291
295
}
292
296
}
297
+
298
+ // transaction hash generation
299
+ db , err := merkledb .New (ctx , memdb .New (), merkledb.Config {
300
+ BranchFactor : merkledb .BranchFactor16 ,
301
+ HistoryLength : 100 ,
302
+ EvictionBatchSize : units .MiB ,
303
+ IntermediateNodeCacheSize : units .MiB ,
304
+ ValueNodeCacheSize : units .MiB ,
305
+ Tracer : b .vm .Tracer (),
306
+ })
307
+ if err != nil {
308
+ return err
309
+ }
310
+ // collect keys, values from transactions/results
311
+ var ops []database.BatchOp
312
+ for _ , tx := range b .Txs {
313
+ key := utils .ToID (tx .Bytes ())
314
+ ops = append (ops , database.BatchOp {
315
+ Key : key [:],
316
+ Value : tx .Bytes (),
317
+ })
318
+ }
319
+ for _ , result := range b .results {
320
+ key := utils .ToID (result .Output )
321
+ ops = append (ops , database.BatchOp {
322
+ Key : key [:],
323
+ Value : result .Output ,
324
+ })
325
+ }
326
+ view , err = db .NewView (ctx , merkledb.ViewChanges {BatchOps : ops })
327
+ if err != nil {
328
+ return err
329
+ }
330
+ view .CommitToDB (ctx )
331
+ txsRoot , err := db .GetMerkleRoot (ctx )
332
+ if err != nil {
333
+ return err
334
+ }
335
+ b .TxsRoot = txsRoot [:]
336
+
293
337
return nil
294
338
}
295
339
0 commit comments