Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/state/snapshot/difflayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,11 @@ func (dl *diffLayer) StorageList(accountHash common.Hash) ([]common.Hash, bool)
dl.memory += uint64(len(dl.storageList)*common.HashLength + common.HashLength)
return storageList, destructed
}

// markStale sets the stale flag as true.
func (dl *diffLayer) markStale() {
dl.lock.Lock()
defer dl.lock.Unlock()

dl.stale.Store(true)
}
23 changes: 23 additions & 0 deletions core/state/snapshot/disklayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ func (dl *diskLayer) Stale() bool {
return dl.stale
}

// markStale sets the stale flag as true.
func (dl *diskLayer) markStale() {
dl.lock.Lock()
defer dl.lock.Unlock()

dl.stale = true
}

// Account directly retrieves the account associated with a particular hash in
// the snapshot slim data format.
func (dl *diskLayer) Account(hash common.Hash) (*types.SlimAccount, error) {
Expand Down Expand Up @@ -176,3 +184,18 @@ func (dl *diskLayer) Storage(accountHash, storageHash common.Hash) ([]byte, erro
func (dl *diskLayer) Update(blockHash common.Hash, destructs map[common.Hash]struct{}, accounts map[common.Hash][]byte, storage map[common.Hash]map[common.Hash][]byte) *diffLayer {
return newDiffLayer(dl, blockHash, destructs, accounts, storage)
}

// stopGeneration aborts the state snapshot generation if it is currently running.
func (dl *diskLayer) stopGeneration() {
dl.lock.RLock()
generating := dl.genMarker != nil
dl.lock.RUnlock()
if !generating {
return
}
if dl.genAbort != nil {
abort := make(chan *generatorStats)
dl.genAbort <- abort
<-abort
}
}
41 changes: 12 additions & 29 deletions core/state/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,15 @@ func (t *Tree) Disable() {
for _, layer := range t.layers {
switch layer := layer.(type) {
case *diskLayer:
// If the base layer is generating, abort it
if layer.genAbort != nil {
abort := make(chan *generatorStats)
layer.genAbort <- abort
<-abort
}
// Layer should be inactive now, mark it as stale
layer.lock.Lock()
layer.stale = true
layer.lock.Unlock()
// TODO this function will hang if it's called twice. Will
// fix it in the following PRs.
layer.stopGeneration()
layer.markStale()
layer.Release()

case *diffLayer:
// If the layer is a simple diff, simply mark as stale
layer.lock.Lock()
layer.stale.Store(true)
layer.lock.Unlock()
layer.markStale()

default:
panic(fmt.Sprintf("unknown layer type: %T", layer))
Expand Down Expand Up @@ -760,25 +753,15 @@ func (t *Tree) Rebuild(root common.Hash) {
for _, layer := range t.layers {
switch layer := layer.(type) {
case *diskLayer:
// If the base layer is generating, abort it and save
if layer.genAbort != nil {
abort := make(chan *generatorStats)
layer.genAbort <- abort

if stats := <-abort; stats != nil {
wiper = stats.wiping
}
}
// Layer should be inactive now, mark it as stale
layer.lock.Lock()
layer.stale = true
layer.lock.Unlock()
// TODO this function will hang if it's called twice. Will
// fix it in the following PRs.
layer.stopGeneration()
layer.markStale()
layer.Release()

case *diffLayer:
// If the layer is a simple diff, simply mark as stale
layer.lock.Lock()
layer.stale.Store(true)
layer.lock.Unlock()
layer.markStale()

default:
panic(fmt.Sprintf("unknown layer type: %T", layer))
Expand Down
2 changes: 1 addition & 1 deletion nightly.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GOFLAGS=-modcacherw make
echo "running cortex..."
#./test.sh > nightly.log 2>&1 &
rm -rf /tmp/.cortex_test
./build/bin/cortex --datadir=/tmp/.cortex_test/ --port=0 --storage.mode=lazy --storage.dht --v5disc > nightly.log 2>&1 &
./build/bin/cortex --datadir=/tmp/.cortex_test/ --port=0 --storage.mode=lazy --storage.dht --v5disc --snapshot > nightly.log 2>&1 &

CORTEX_PID=$!

Expand Down