Skip to content

Commit 2296a33

Browse files
committed
fixes after rebase
1 parent 55aeb4c commit 2296a33

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

blockchain/blockchain.go

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (b *Blockchain) Head() (*core.Block, error) {
146146

147147
snapshot := b.database.NewSnapshot()
148148
defer snapshot.Close()
149-
return core.GetBlockByNumber(snapshot, curHeight)
149+
return b.transactionLayout.BlockByNumber(snapshot, curHeight)
150150
}
151151

152152
func (b *Blockchain) HeadsHeader() (*core.Header, error) {
@@ -172,7 +172,7 @@ func (b *Blockchain) BlockByNumber(number uint64) (*core.Block, error) {
172172
b.listener.OnRead("BlockByNumber")
173173
snapshot := b.database.NewSnapshot()
174174
defer snapshot.Close()
175-
return core.GetBlockByNumber(snapshot, number)
175+
return b.transactionLayout.BlockByNumber(snapshot, number)
176176
}
177177

178178
func (b *Blockchain) BlockHeaderByNumber(number uint64) (*core.Header, error) {
@@ -194,7 +194,7 @@ func (b *Blockchain) BlockByHash(hash *felt.Felt) (*core.Block, error) {
194194

195195
snapshot := b.database.NewSnapshot()
196196
defer snapshot.Close()
197-
return core.GetBlockByNumber(snapshot, blockNum)
197+
return b.transactionLayout.BlockByNumber(snapshot, blockNum)
198198
}
199199

200200
func (b *Blockchain) BlockHeaderByHash(hash *felt.Felt) (*core.Header, error) {
@@ -320,17 +320,6 @@ func (b *Blockchain) Store(
320320
return err
321321
}
322322

323-
for i, tx := range block.Transactions {
324-
if err := core.WriteTxAndReceipt(txn, block.Number, uint64(i), tx,
325-
block.Receipts[i]); err != nil {
326-
return err
327-
}
328-
}
329-
330-
if err := core.WriteStateUpdateByBlockNum(txn, block.Number, stateUpdate); err != nil {
331-
return err
332-
}
333-
334323
err := b.transactionLayout.WriteTransactionsAndReceipts(
335324
txn,
336325
block.Number,
@@ -341,7 +330,7 @@ func (b *Blockchain) Store(
341330
return err
342331
}
343332

344-
if err := core.WriteL1HandlerMsgHashes(txn, block.Transactions); err != nil {
333+
if err := core.WriteStateUpdateByBlockNum(txn, block.Number, stateUpdate); err != nil {
345334
return err
346335
}
347336

@@ -381,7 +370,7 @@ func (b *Blockchain) Store(
381370
// storeCasmHashMetadata stores CASM hash metadata for declared and migrated classes.
382371
// See [core.ClassCasmHashMetadata]
383372
func storeCasmHashMetadata(
384-
txn db.KeyValueWriter,
373+
txn db.SnapshotBatch,
385374
blockNumber uint64,
386375
protocolVersion string,
387376
stateUpdate *core.StateUpdate,
@@ -404,7 +393,7 @@ func storeCasmHashMetadata(
404393
// storeCasmHashMetadataV2 stores metadata for classes declared with casm hash v2 or
405394
// migrated from v1. casm hash v2 is after protocol version >= 0.14.1.
406395
func storeCasmHashMetadataV2(
407-
txn db.KeyValueWriter,
396+
txn db.SnapshotBatch,
408397
blockNumber uint64,
409398
stateUpdate *core.StateUpdate,
410399
) error {
@@ -450,7 +439,7 @@ func storeCasmHashMetadataV2(
450439
// storeDeclaredV1Classes stores metadata for classes declared with V1 hash (protocol < 0.14.1).
451440
// It computes the V2 hash from the class definition.
452441
func storeCasmHashMetadataV1(
453-
txn db.KeyValueWriter,
442+
txn db.SnapshotBatch,
454443
blockNumber uint64,
455444
stateUpdate *core.StateUpdate,
456445
newClasses map[felt.Felt]core.ClassDefinition,
@@ -639,7 +628,7 @@ func (b *Blockchain) RevertHead() error {
639628
}
640629

641630
func (b *Blockchain) GetReverseStateDiff() (core.StateDiff, error) {
642-
var reverseStateDiff *core.StateDiff
631+
var reverseStateDiff core.StateDiff
643632

644633
snapshot := b.database.NewSnapshot()
645634
defer snapshot.Close()
@@ -772,7 +761,7 @@ func (b *Blockchain) Finalise(
772761
) error {
773762
snapshot := b.database.NewSnapshot()
774763
defer snapshot.Close()
775-
batch := b.dartabase.NewBatch()
764+
batch := b.database.NewBatch()
776765
txn := db.NewSnapshotBatch(batch, snapshot)
777766

778767
if err := b.updateStateRoots(txn, block, stateUpdate, newClasses); err != nil {

db/snapshot_batch.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ func (b *snapshotBatch) Reset() {
9595
b.writes = make(map[string][]byte)
9696
b.deletes = make(map[string]struct{})
9797
b.ranges = b.ranges[:0]
98-
b.batch.Reset()
9998
b.size = 0
10099
}
101100

@@ -137,3 +136,7 @@ func inRange(ranges []deleteRange, key []byte) bool {
137136
func (b *snapshotBatch) NewIterator(prefix []byte, withUpperBound bool) (Iterator, error) {
138137
return b.snapshot.NewIterator(prefix, withUpperBound)
139138
}
139+
140+
func (b *snapshotBatch) Close() error {
141+
return b.batch.Close()
142+
}

0 commit comments

Comments
 (0)