Skip to content

Commit

Permalink
mvstates: fix oom issue when mining is enabled; (#40)
Browse files Browse the repository at this point in the history
Co-authored-by: galaio <[email protected]>
  • Loading branch information
2 people authored and welkin22 committed Oct 22, 2024
1 parent 7d375ff commit 0aa6d95
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2701,7 +2701,7 @@ func (bc *BlockChain) HeaderChainForceSetHead(headNumber uint64) {
}

func (bc *BlockChain) TxDAGEnabledWhenMine() bool {
return bc.enableTxDAG && bc.txDAGReader == nil
return bc.enableTxDAG && bc.txDAGWriteCh == nil
}

func (bc *BlockChain) TxDAGFileOpened() bool {
Expand Down
3 changes: 3 additions & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2388,6 +2388,9 @@ func (s *StateDB) ResetMVStates(txCount int) {
if s.isParallel && s.parallel.isSlotDB {
return
}
if s.mvStates != nil {
s.mvStates.Stop()
}
s.mvStates = types.NewMVStates(txCount).EnableAsyncDepGen()
s.rwSet = nil
}
Expand Down
12 changes: 11 additions & 1 deletion core/types/mvstates.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,21 @@ func (s *MVStates) EnableAsyncDepGen() *MVStates {
return s
}

func (s *MVStates) Stop() error {
s.lock.Lock()
defer s.lock.Unlock()
s.stopAsyncDepGen()
return nil
}

func (s *MVStates) stopAsyncDepGen() {
if s.asyncRunning {
return
}
s.asyncRunning = false
if s.stopChan != nil {
close(s.stopChan)
}
s.asyncRunning = false
}

func (s *MVStates) asyncDepGenLoop() {
Expand Down
2 changes: 2 additions & 0 deletions core/types/mvstates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ func TestMVStates_AsyncDepGen_SimpleResolveTxDAG(t *testing.T) {

dag, err := ms.ResolveTxDAG(10, nil)
require.NoError(t, err)
time.Sleep(100 * time.Millisecond)
require.NoError(t, ms.Stop())
require.Equal(t, mockSimpleDAG(), dag)
t.Log(dag)
}
Expand Down

0 comments on commit 0aa6d95

Please sign in to comment.