Skip to content

Commit

Permalink
- fixes after reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau committed Apr 14, 2022
1 parent 99cd142 commit 603ea55
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 57 deletions.
17 changes: 11 additions & 6 deletions common/disabled/processStatusHandler.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
package disabled

// ProcessStatusHandler is the disabled implementation for the status handler that keeps track what the node is doing:
// processStatusHandler is the disabled implementation for the status handler that keeps track what the node is doing:
// processing blocks or idle
type ProcessStatusHandler struct {
type processStatusHandler struct {
}

// NewProcessStatusHandler creates a new instance of type processStatusHandler
func NewProcessStatusHandler() *processStatusHandler {
return &processStatusHandler{}
}

// SetBusy does nothing
func (psh *ProcessStatusHandler) SetBusy(_ string) {}
func (psh *processStatusHandler) SetBusy(_ string) {}

// SetIdle does nothing
func (psh *ProcessStatusHandler) SetIdle() {}
func (psh *processStatusHandler) SetIdle() {}

// IsIdle returns true
func (psh *ProcessStatusHandler) IsIdle() bool {
func (psh *processStatusHandler) IsIdle() bool {
return true
}

// IsInterfaceNil returns true if there is no value under the interface
func (psh *ProcessStatusHandler) IsInterfaceNil() bool {
func (psh *processStatusHandler) IsInterfaceNil() bool {
return psh == nil
}
26 changes: 26 additions & 0 deletions common/disabled/processStatusHandler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package disabled

import (
"fmt"
"testing"

"github.com/ElrondNetwork/elrond-go-core/core/check"
"github.com/stretchr/testify/assert"
)

func TestProcessStatusHandler_MethodsShouldNotPanic(t *testing.T) {
t.Parallel()

defer func() {
r := recover()
if r != nil {
assert.Fail(t, fmt.Sprintf("should have not panicked: %v", r))
}
}()

psh := NewProcessStatusHandler()
assert.False(t, check.IfNil(psh))
psh.SetBusy("")
psh.SetIdle()
assert.True(t, psh.IsIdle())
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (brcf *baseResolversContainerFactory) newImportDBTrieStorage(
MaxTrieLevelInMem: brcf.generalConfig.StateTriesConfig.MaxStateTrieLevelInMemory,
DisableOldTrieStorageEpoch: brcf.disableOldTrieStorageEpoch,
EpochStartNotifier: brcf.epochNotifier,
IdleProvider: &disabled.ProcessStatusHandler{},
IdleProvider: disabled.NewProcessStatusHandler(),
}
return trieFactoryInstance.Create(args)
}
2 changes: 1 addition & 1 deletion genesis/process/memoryComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func createAccountAdapter(
AccountFactory: accountFactory,
StoragePruningManager: disabled.NewDisabledStoragePruningManager(),
ProcessingMode: common.Normal,
ProcessStatusHandler: &commonDisabled.ProcessStatusHandler{},
ProcessStatusHandler: commonDisabled.NewProcessStatusHandler(),
}

adb, err := state.NewAccountsDB(args)
Expand Down
85 changes: 38 additions & 47 deletions state/accountsDB_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func generateAccountDBFromTrie(trie common.Trie) *state.AccountsDB {
args := createMockAccountsDBArgs()
args.Trie = trie

accnt, _ := state.NewAccountsDB(args)
return accnt
accounts, _ := state.NewAccountsDB(args)
return accounts
}

func generateAccount() *stateMock.AccountWrapMock {
Expand Down Expand Up @@ -1593,15 +1593,12 @@ func TestAccountsDB_MainTrieAutomaticallyMarksCodeUpdatesForEviction(t *testing.
tr, _ := trie.NewTrie(storageManager, marshaller, hasher, maxTrieLevelInMemory)
spm, _ := storagePruningManager.NewStoragePruningManager(ewl, 5)

argsAccountsDB := state.ArgsAccountsDB{
Trie: tr,
Hasher: hasher,
Marshaller: marshaller,
AccountFactory: factory.NewAccountCreator(),
StoragePruningManager: spm,
ProcessingMode: common.Normal,
ProcessStatusHandler: &testscommon.ProcessStatusHandlerStub{},
}
argsAccountsDB := createMockAccountsDBArgs()
argsAccountsDB.Trie = tr
argsAccountsDB.Hasher = hasher
argsAccountsDB.Marshaller = marshaller
argsAccountsDB.AccountFactory = factory.NewAccountCreator()
argsAccountsDB.StoragePruningManager = spm

adb, _ := state.NewAccountsDB(argsAccountsDB)

Expand Down Expand Up @@ -1683,15 +1680,13 @@ func TestAccountsDB_RemoveAccountMarksObsoleteHashesForEviction(t *testing.T) {
tr, _ := trie.NewTrie(storageManager, marshaller, hasher, maxTrieLevelInMemory)
spm, _ := storagePruningManager.NewStoragePruningManager(ewl, 5)

argsAccountsDB := state.ArgsAccountsDB{
Trie: tr,
Hasher: hasher,
Marshaller: marshaller,
AccountFactory: factory.NewAccountCreator(),
StoragePruningManager: spm,
ProcessingMode: common.Normal,
ProcessStatusHandler: &testscommon.ProcessStatusHandlerStub{},
}
argsAccountsDB := createMockAccountsDBArgs()
argsAccountsDB.Trie = tr
argsAccountsDB.Hasher = hasher
argsAccountsDB.Marshaller = marshaller
argsAccountsDB.AccountFactory = factory.NewAccountCreator()
argsAccountsDB.StoragePruningManager = spm

adb, _ := state.NewAccountsDB(argsAccountsDB)

addr := make([]byte, 32)
Expand Down Expand Up @@ -2115,15 +2110,13 @@ func TestAccountsDB_GetCode(t *testing.T) {
storageManager, _ := trie.NewTrieStorageManager(args)
tr, _ := trie.NewTrie(storageManager, marshaller, hasher, maxTrieLevelInMemory)
spm := disabled.NewDisabledStoragePruningManager()
argsAccountsDB := state.ArgsAccountsDB{
Trie: tr,
Hasher: hasher,
Marshaller: marshaller,
AccountFactory: factory.NewAccountCreator(),
StoragePruningManager: spm,
ProcessingMode: common.Normal,
ProcessStatusHandler: &testscommon.ProcessStatusHandlerStub{},
}
argsAccountsDB := createMockAccountsDBArgs()
argsAccountsDB.Trie = tr
argsAccountsDB.Hasher = hasher
argsAccountsDB.Marshaller = marshaller
argsAccountsDB.AccountFactory = factory.NewAccountCreator()
argsAccountsDB.StoragePruningManager = spm

adb, _ := state.NewAccountsDB(argsAccountsDB)

address := make([]byte, 32)
Expand Down Expand Up @@ -2232,15 +2225,14 @@ func TestAccountsDB_Close(t *testing.T) {
hasher := &hashingMocks.HasherMock{}
ewl, _ := evictionWaitingList.NewEvictionWaitingList(100, testscommon.NewMemDbMock(), marshaller)
spm, _ := storagePruningManager.NewStoragePruningManager(ewl, 10)
argsAccountsDB := state.ArgsAccountsDB{
Trie: tr,
Hasher: hasher,
Marshaller: marshaller,
AccountFactory: factory.NewAccountCreator(),
StoragePruningManager: spm,
ProcessingMode: common.Normal,
ProcessStatusHandler: &testscommon.ProcessStatusHandlerStub{},
}

argsAccountsDB := createMockAccountsDBArgs()
argsAccountsDB.Trie = tr
argsAccountsDB.Hasher = hasher
argsAccountsDB.Marshaller = marshaller
argsAccountsDB.AccountFactory = factory.NewAccountCreator()
argsAccountsDB.StoragePruningManager = spm

adb, _ := state.NewAccountsDB(argsAccountsDB)

err := adb.Close()
Expand Down Expand Up @@ -2356,15 +2348,14 @@ func BenchmarkAccountsDb_GetCodeEntry(b *testing.B) {
storageManager, _ := trie.NewTrieStorageManager(args)
tr, _ := trie.NewTrie(storageManager, marshaller, hasher, maxTrieLevelInMemory)
spm := disabled.NewDisabledStoragePruningManager()
argsAccountsDB := state.ArgsAccountsDB{
Trie: tr,
Hasher: hasher,
Marshaller: marshaller,
AccountFactory: factory.NewAccountCreator(),
StoragePruningManager: spm,
ProcessingMode: common.Normal,
ProcessStatusHandler: &testscommon.ProcessStatusHandlerStub{},
}

argsAccountsDB := createMockAccountsDBArgs()
argsAccountsDB.Trie = tr
argsAccountsDB.Hasher = hasher
argsAccountsDB.Marshaller = marshaller
argsAccountsDB.AccountFactory = factory.NewAccountCreator()
argsAccountsDB.StoragePruningManager = spm

adb, _ := state.NewAccountsDB(argsAccountsDB)

address := make([]byte, 32)
Expand Down
4 changes: 2 additions & 2 deletions update/genesis/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func (si *stateImport) getAccountsDB(accType Type, shardID uint32) (state.Accoun
AccountFactory: accountFactory,
StoragePruningManager: disabled.NewDisabledStoragePruningManager(),
ProcessingMode: common.Normal,
ProcessStatusHandler: &commonDisabled.ProcessStatusHandler{},
ProcessStatusHandler: commonDisabled.NewProcessStatusHandler(),
}
accountsDB, errCreate := state.NewAccountsDB(argsAccountDB)
if errCreate != nil {
Expand All @@ -424,7 +424,7 @@ func (si *stateImport) getAccountsDB(accType Type, shardID uint32) (state.Accoun
AccountFactory: accountFactory,
StoragePruningManager: disabled.NewDisabledStoragePruningManager(),
ProcessingMode: common.Normal,
ProcessStatusHandler: &commonDisabled.ProcessStatusHandler{},
ProcessStatusHandler: commonDisabled.NewProcessStatusHandler(),
}
accountsDB, err = state.NewAccountsDB(argsAccountDB)
si.accountDBsMap[shardID] = accountsDB
Expand Down

0 comments on commit 603ea55

Please sign in to comment.