Skip to content

Commit

Permalink
[light-node] manually create new db 'version'
Browse files Browse the repository at this point in the history
  • Loading branch information
kroggen committed Jul 8, 2024
1 parent 4d1f1d0 commit 939bfca
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion chain/chainhandle.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,12 @@ func (cp *chainProcessor) connectToChain(block *types.Block) (types.BlockNo, err
dbTx := cp.cdb.store.NewTx()
defer dbTx.Discard()

// if this is a light node
if cp.cdb.store.Type() == "dummydb" {
// create a new "version" on the database
cp.cdb.store.IoCtl("new-version")
}

// skip to add hash/block if wal of block is already written
oldLatest := cp.cdb.connectToChain(dbTx, block, cp.isByBP && cp.HasWAL())
if err := cp.cdb.addTxsOfBlock(&dbTx, block.GetBody().GetTxs(), block.BlockHash()); err != nil {
Expand Down Expand Up @@ -773,12 +779,21 @@ func (e *blockExecutor) execute() error {
return nil
}

// commit state changes and update state root
func (e *blockExecutor) commit() error {

// if this is a light node
if e.sdb.store.Type() == "deldeldb" {
// create a new "version" on the database
e.sdb.store.IoCtl("new-version")
}

// commit changes to the state db
if err := e.BlockState.Commit(); err != nil {
return err
}

//TODO: after implementing BlockRootHash, remove statedb.lastest
// update state root
if err := e.sdb.UpdateRoot(e.BlockState); err != nil {
return err
}
Expand Down

0 comments on commit 939bfca

Please sign in to comment.