From ed1c1d079d6216e1160a7dd13215e0a953a729dd Mon Sep 17 00:00:00 2001 From: weiihann Date: Fri, 25 Oct 2024 14:32:19 +0800 Subject: [PATCH] more fixes --- blockchain/blockchain.go | 9 ++- blockchain/snap_server_interface.go | 114 ++++++++++++++-------------- 2 files changed, 62 insertions(+), 61 deletions(-) diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index b1f312636a..19fc26c6c4 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -387,10 +387,11 @@ func (b *Blockchain) Store(block *core.Block, blockCommitments *core.BlockCommit return err } - err = b.seedSnapshot() - if err != nil { - return err - } + // TODO: the following is only used for snap sync, uncomment when we need it again + // err = b.seedSnapshot() + // if err != nil { + // return err + // } return nil } diff --git a/blockchain/snap_server_interface.go b/blockchain/snap_server_interface.go index 2717bdae09..ce530af9a9 100644 --- a/blockchain/snap_server_interface.go +++ b/blockchain/snap_server_interface.go @@ -3,7 +3,6 @@ package blockchain import ( "context" "errors" - "fmt" "github.com/NethermindEth/juno/core" "github.com/NethermindEth/juno/core/felt" @@ -14,6 +13,7 @@ import ( const MaxSnapshots = 128 +//nolint:unused type snapshotRecord struct { stateRoot *felt.Felt contractsRoot *felt.Felt @@ -102,62 +102,62 @@ func (b *Blockchain) GetDClasses(felts []*felt.Felt) ([]*core.DeclaredClass, err return classes, nil } -func (b *Blockchain) seedSnapshot() error { - headheader, err := b.HeadsHeader() - if err != nil { - return err - } - - stateR, srCloser, err := b.HeadState() - if err != nil { - return err - } - - defer func() { _ = srCloser() }() - - state := stateR.(*core.State) - contractsRoot, classRoot, err := state.StateAndClassRoot() - if err != nil { - return err - } - - stateRoot, err := state.Root() - if err != nil { - return err - } - - txn, closer, err := b.database.PersistedView() - if err != nil { - return err - } - - dbsnap := snapshotRecord{ - stateRoot: stateRoot, - contractsRoot: contractsRoot, - classRoot: classRoot, - blockHash: headheader.Hash, - txn: txn, - closer: closer, - } - - fmt.Printf("Snapshot %d %s %s\n", headheader.Number, headheader.GlobalStateRoot, stateRoot) - - // TODO: Reorgs - b.snapshots = append(b.snapshots, &dbsnap) - if len(b.snapshots) > MaxSnapshots { - toremove := b.snapshots[0] - err = toremove.closer() - if err != nil { - return err - } - - // TODO: I think internally, it keep the old array. - // maybe the append copy it to a new array, who knows... - b.snapshots = b.snapshots[1:] - } - - return nil -} +// func (b *Blockchain) seedSnapshot() error { +// headheader, err := b.HeadsHeader() +// if err != nil { +// return err +// } + +// stateR, srCloser, err := b.HeadState() +// if err != nil { +// return err +// } + +// defer func() { _ = srCloser() }() + +// state := stateR.(*core.State) +// contractsRoot, classRoot, err := state.StateAndClassRoot() +// if err != nil { +// return err +// } + +// stateRoot, err := state.Root() +// if err != nil { +// return err +// } + +// txn, closer, err := b.database.PersistedView() +// if err != nil { +// return err +// } + +// dbsnap := snapshotRecord{ +// stateRoot: stateRoot, +// contractsRoot: contractsRoot, +// classRoot: classRoot, +// blockHash: headheader.Hash, +// txn: txn, +// closer: closer, +// } + +// fmt.Printf("Snapshot %d %s %s\n", headheader.Number, headheader.GlobalStateRoot, stateRoot) + +// // TODO: Reorgs +// b.snapshots = append(b.snapshots, &dbsnap) +// if len(b.snapshots) > MaxSnapshots { +// toremove := b.snapshots[0] +// err = toremove.closer() +// if err != nil { +// return err +// } + +// // TODO: I think internally, it keep the old array. +// // maybe the append copy it to a new array, who knows... +// b.snapshots = b.snapshots[1:] +// } + +// return nil +// } func (b *Blockchain) Close() { for _, snapshot := range b.snapshots {