Skip to content

Commit

Permalink
remove empty storage diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Aug 29, 2024
1 parent 247cc55 commit 40936a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 0 additions & 1 deletion blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,6 @@ func MakeStateDiffForEmptyBlock(bc Reader, blockNumber uint64) (*core.StateDiff,
stateDiff.StorageDiffs[*blockHashStorageContract] = map[felt.Felt]*felt.Felt{
*new(felt.Felt).SetUint64(header.Number): header.Hash,
}
fmt.Printf("\nSET blockNumber %d %s %s\n", blockNumber, blockHashStorageContract.String(), header.Hash)
return stateDiff, nil
}

Expand Down
14 changes: 11 additions & 3 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,11 @@ func (b *Builder) Run(ctx context.Context) error {
// ind := new(felt.Felt).SetUint64(b.pendingBlock.Block.Number - 10)
// // b.log.Infow("FINALISE 0x1 %s %s", ind.String(), qwe[*ind].String())
// // b.log.Debugw("Finalising new block")
err := b.compressStateDiff(b.pendingBlock.StateUpdate.StateDiff)
err := b.cleanStorageDiff(b.pendingBlock.StateUpdate.StateDiff)
if err != nil {
return err
}
b.log.Debugw("Finalising new block")
err = b.Finalise(signFunc)
if err != nil {
return err
Expand All @@ -204,7 +205,8 @@ func (b *Builder) Run(ctx context.Context) error {
}
}

func (b *Builder) compressStateDiff(sd *core.StateDiff) error {
func (b *Builder) cleanStorageDiff(sd *core.StateDiff) error {
b.log.Infof("removing unneeded values in the storage diffs")
state, closer, err := b.bc.HeadState()
if err != nil {
return err
Expand All @@ -222,6 +224,11 @@ func (b *Builder) compressStateDiff(sd *core.StateDiff) error {
}
}
}
for addr := range sd.StorageDiffs {
if len(sd.StorageDiffs[addr]) == 0 {
delete(sd.StorageDiffs, addr)
}
}
return nil
}

Expand Down Expand Up @@ -520,7 +527,8 @@ func (b *Builder) runTxn(txn *mempool.BroadcastedTransaction) error {
refTrace := vm2core.AdaptStateDiff(b.blockTraces[b.pendingBlock.Block.TransactionCount].TraceRoot.StateDiff)
diffString, diffsNotEqual := seqTrace.Diff(refTrace, "sequencer", "sepolia")
if diffsNotEqual {
b.log.Fatalf("Generated transaction trace does not match that from Sepolia %s, \n %s", txn.Transaction.Hash().String(), diffString)
// Can't be fatal since FGW may remove values later (eg if the storage update element doesn't alter state)
b.log.Debugw("Generated transaction trace does not match that from Sepolia %s, \n %s", txn.Transaction.Hash().String(), diffString)
}
// fmt.Println("========\n\n")
// seqTrace.Print()
Expand Down

0 comments on commit 40936a5

Please sign in to comment.