Skip to content

Commit

Permalink
Merge branch 'master' into integrate-core-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianMarian committed Feb 10, 2022
2 parents d4a9428 + 65043df commit c5cdfec
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 145 deletions.
2 changes: 1 addition & 1 deletion cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
VersionsByEpochs = [
{ StartEpoch = 0, Version = "*" },
# The value of StartEpoch parameter for version 2 should be the same with the ScheduledMiniBlocksEnableEpoch flag from enableEpoch.toml file
{ StartEpoch = 2, Version = "2" },
{ StartEpoch = 1000000, Version = "2" },
]
[Versions.Cache]
Name = "VersionsCache"
Expand Down
2 changes: 1 addition & 1 deletion cmd/node/config/enableEpochs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
ESDTRegisterAndSetAllRolesEnableEpoch = 3

# ScheduledMiniBlocksEnableEpoch represents the epoch when scheduled mini blocks would be created if needed
ScheduledMiniBlocksEnableEpoch = 2
ScheduledMiniBlocksEnableEpoch = 1000000

# CorrectJailedNotUnstakedEpoch represents the epoch when the jailed validators will also be unstaked if the queue is empty
CorrectJailedNotUnstakedEmptyQueueEpoch = 2
Expand Down
1 change: 0 additions & 1 deletion factory/apiResolverFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ func CreateApiResolver(args *ApiResolverArgs) (facade.ApiResolver, error) {
ShardID: args.BootstrapComponents.ShardCoordinator().SelfId(),
Accounts: accountsWrapper,
PublicKeyConverter: args.CoreComponents.AddressPubKeyConverter(),
BlockChain: args.DataComponents.Blockchain(),
QueryService: scQueryService,
}
totalStakedValueHandler, err := trieIteratorsFactory.CreateTotalStakedValueHandler(argsProcessors)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/ElrondNetwork/elrond-go-core v1.1.12-0.20220208154045-40b0ce29d709
github.com/ElrondNetwork/elrond-go-crypto v1.0.1
github.com/ElrondNetwork/elrond-go-logger v1.0.5
github.com/ElrondNetwork/elrond-vm-common v1.2.10
github.com/ElrondNetwork/elrond-vm-common v1.2.11
github.com/ElrondNetwork/notifier-go v1.0.3
github.com/beevik/ntp v0.3.0
github.com/btcsuite/btcd v0.22.0-beta
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/ElrondNetwork/elrond-go-logger v1.0.5 h1:tB/HBvV9IVeCaSrGakX+GLGu7K5U
github.com/ElrondNetwork/elrond-go-logger v1.0.5/go.mod h1:cBfgx0ST/CJx8jrxJSC5aiSrvkGzcnF7sK06RD8mFxQ=
github.com/ElrondNetwork/elrond-vm-common v1.1.0/go.mod h1:w3i6f8uiuRkE68Ie/gebRcLgTuHqvruJSYrFyZWuLrE=
github.com/ElrondNetwork/elrond-vm-common v1.2.9/go.mod h1:B/Y8WiqHyDd7xsjNYsaYbVMp1jQgQ+z4jTJkFvj/EWI=
github.com/ElrondNetwork/elrond-vm-common v1.2.10 h1:r4bGIFrql6gMmRivlAIq9fA1ehX0IXnVOmUzBk4++es=
github.com/ElrondNetwork/elrond-vm-common v1.2.10/go.mod h1:B/Y8WiqHyDd7xsjNYsaYbVMp1jQgQ+z4jTJkFvj/EWI=
github.com/ElrondNetwork/elrond-vm-common v1.2.11 h1:eAr+lo10STPGByMAKdta9wsZUkQK43nY9Vmv8nvQZh4=
github.com/ElrondNetwork/elrond-vm-common v1.2.11/go.mod h1:B/Y8WiqHyDd7xsjNYsaYbVMp1jQgQ+z4jTJkFvj/EWI=
github.com/ElrondNetwork/notifier-go v1.0.3 h1:LhecyXqKuc/Q4NtIOlb9rw4hfMSj6usmxvYQWvb7Pn4=
github.com/ElrondNetwork/notifier-go v1.0.3/go.mod h1:GOv7j2o90e/GVmmBddWwyfJZ/JW4V4pvyXIpukd6FfY=
github.com/ElrondNetwork/protobuf v1.3.2 h1:qoCSYiO+8GtXBEZWEjw0WPcZfM3g7QuuJrwpN+y6Mvg=
Expand Down
1 change: 0 additions & 1 deletion integrationTests/testProcessorNodeWithTestWebServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ func createFacadeComponents(tpn *TestProcessorNode) (nodeFacade.ApiResolver, nod
ShardID: tpn.ShardCoordinator.SelfId(),
Accounts: accountsWrapper,
QueryService: tpn.SCQueryService,
BlockChain: tpn.BlockChain,
PublicKeyConverter: TestAddressPubkeyConverter,
}
totalStakedValueHandler, err := factory.CreateTotalStakedValueHandler(args)
Expand Down
12 changes: 0 additions & 12 deletions node/trieIterators/commonStakingProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"math/big"

"github.com/ElrondNetwork/elrond-go-core/data"
"github.com/ElrondNetwork/elrond-go/epochStart"
"github.com/ElrondNetwork/elrond-go/process"
"github.com/ElrondNetwork/elrond-go/state"
Expand All @@ -19,7 +18,6 @@ type stakingValidatorInfo struct {

type commonStakingProcessor struct {
queryService process.SCQueryService
blockChain data.ChainHandler
accounts *AccountsWrapper
}

Expand Down Expand Up @@ -53,16 +51,6 @@ func (csp *commonStakingProcessor) getValidatorInfoFromSC(validatorAddress []byt
}

func (csp *commonStakingProcessor) getAccount(scAddress []byte) (state.UserAccountHandler, error) {
rootHash := csp.blockChain.GetCurrentBlockRootHash()
if len(rootHash) == 0 {
return nil, ErrNodeNotInitialized
}

err := csp.accounts.RecreateTrie(rootHash)
if err != nil {
return nil, err
}

accountHandler, err := csp.accounts.GetExistingAccount(scAddress)
if err != nil {
return nil, err
Expand Down
3 changes: 1 addition & 2 deletions node/trieIterators/delegatedListProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func NewDelegatedListProcessor(arg ArgTrieIteratorProcessor) (*delegatedListProc
return &delegatedListProcessor{
commonStakingProcessor: &commonStakingProcessor{
queryService: arg.QueryService,
blockChain: arg.BlockChain,
accounts: arg.Accounts,
},
publicKeyConverter: arg.PublicKeyConverter,
Expand Down Expand Up @@ -88,7 +87,7 @@ func (dlp *delegatedListProcessor) getDelegatorsInfo(delegationSC []byte, delega
for _, delegatorAddress := range delegatorsList {
value, err = dlp.getActiveFund(delegationSC, delegatorAddress)
if err != nil {
//delegatorAddress byte slice might not represent a real delegator address
// delegatorAddress byte slice might not represent a real delegator address
continue
}

Expand Down
1 change: 0 additions & 1 deletion node/trieIterators/directStakedListProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func NewDirectStakedListProcessor(arg ArgTrieIteratorProcessor) (*directStakedLi
return &directStakedListProcessor{
commonStakingProcessor: &commonStakingProcessor{
queryService: arg.QueryService,
blockChain: arg.BlockChain,
accounts: arg.Accounts,
},
publicKeyConverter: arg.PublicKeyConverter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/ElrondNetwork/elrond-go-core/core"
"github.com/ElrondNetwork/elrond-go/node/mock"
"github.com/ElrondNetwork/elrond-go/node/trieIterators"
"github.com/ElrondNetwork/elrond-go/testscommon"
stateMock "github.com/ElrondNetwork/elrond-go/testscommon/state"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -36,7 +35,6 @@ func TestCreateDelegatedListHandlerHandler_DelegatedListProcessor(t *testing.T)
AccountsAdapter: &stateMock.AccountsStub{},
},
PublicKeyConverter: &mock.PubkeyConverterMock{},
BlockChain: &testscommon.ChainHandlerStub{},
QueryService: &mock.SCQueryServiceStub{},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/ElrondNetwork/elrond-go-core/core"
"github.com/ElrondNetwork/elrond-go/node/mock"
"github.com/ElrondNetwork/elrond-go/node/trieIterators"
"github.com/ElrondNetwork/elrond-go/testscommon"
stateMock "github.com/ElrondNetwork/elrond-go/testscommon/state"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -36,7 +35,6 @@ func TestCreateDirectStakedListHandlerHandler_DirectStakedListProcessor(t *testi
AccountsAdapter: &stateMock.AccountsStub{},
},
PublicKeyConverter: &mock.PubkeyConverterMock{},
BlockChain: &testscommon.ChainHandlerStub{},
QueryService: &mock.SCQueryServiceStub{},
}

Expand Down
2 changes: 0 additions & 2 deletions node/trieIterators/factory/stakeValuesHandlerFactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/ElrondNetwork/elrond-go-core/core"
"github.com/ElrondNetwork/elrond-go/node/mock"
"github.com/ElrondNetwork/elrond-go/node/trieIterators"
"github.com/ElrondNetwork/elrond-go/testscommon"
stateMock "github.com/ElrondNetwork/elrond-go/testscommon/state"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -36,7 +35,6 @@ func TestCreateTotalStakedValueHandler_TotalStakedValueProcessor(t *testing.T) {
AccountsAdapter: &stateMock.AccountsStub{},
},
PublicKeyConverter: &mock.PubkeyConverterMock{},
BlockChain: &testscommon.ChainHandlerStub{},
QueryService: &mock.SCQueryServiceStub{},
}

Expand Down
8 changes: 1 addition & 7 deletions node/trieIterators/stakeValuesProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/ElrondNetwork/elrond-go-core/core"
"github.com/ElrondNetwork/elrond-go-core/core/check"
"github.com/ElrondNetwork/elrond-go-core/data"
"github.com/ElrondNetwork/elrond-go-core/data/api"
"github.com/ElrondNetwork/elrond-go/process"
"github.com/ElrondNetwork/elrond-go/state"
Expand All @@ -29,7 +28,6 @@ type stakedValuesProcessor struct {
type ArgTrieIteratorProcessor struct {
ShardID uint32
Accounts *AccountsWrapper
BlockChain data.ChainHandler
QueryService process.SCQueryService
PublicKeyConverter core.PubkeyConverter
}
Expand All @@ -44,7 +42,6 @@ func NewTotalStakedValueProcessor(arg ArgTrieIteratorProcessor) (*stakedValuesPr
return &stakedValuesProcessor{
commonStakingProcessor: &commonStakingProcessor{
queryService: arg.QueryService,
blockChain: arg.BlockChain,
accounts: arg.Accounts,
},
publicKeyConverter: arg.PublicKeyConverter,
Expand All @@ -55,9 +52,6 @@ func checkArguments(arg ArgTrieIteratorProcessor) error {
if arg.Accounts == nil || check.IfNil(arg.Accounts) {
return ErrNilAccountsAdapter
}
if check.IfNil(arg.BlockChain) {
return ErrNilBlockChain
}
if check.IfNil(arg.QueryService) {
return ErrNilQueryService
}
Expand Down Expand Up @@ -98,7 +92,7 @@ func (svp *stakedValuesProcessor) computeBaseStakedAndTopUp() (*big.Int, *big.In
return nil, nil, err
}

//TODO investigate if a call to GetAllLeavesKeysOnChannel (without values) might increase performance
// TODO investigate if a call to GetAllLeavesKeysOnChannel (without values) might increase performance
chLeaves, err := validatorAccount.DataTrie().GetAllLeavesOnChannel(rootHash)
if err != nil {
return nil, nil, err
Expand Down
40 changes: 4 additions & 36 deletions node/trieIterators/stakeValuesProcessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/ElrondNetwork/elrond-go/node/mock"
"github.com/ElrondNetwork/elrond-go/process"
"github.com/ElrondNetwork/elrond-go/state"
"github.com/ElrondNetwork/elrond-go/testscommon"
stateMock "github.com/ElrondNetwork/elrond-go/testscommon/state"
trieMock "github.com/ElrondNetwork/elrond-go/testscommon/trie"
"github.com/ElrondNetwork/elrond-go/vm"
Expand All @@ -30,12 +29,7 @@ func createAccountsWrapper() *AccountsWrapper {

func createMockArgs() ArgTrieIteratorProcessor {
return ArgTrieIteratorProcessor{
Accounts: createAccountsWrapper(),
BlockChain: &testscommon.ChainHandlerStub{
GetCurrentBlockRootHashCalled: func() []byte {
return []byte("root hash")
},
},
Accounts: createAccountsWrapper(),
QueryService: &mock.SCQueryServiceStub{},
PublicKeyConverter: &mock.PubkeyConverterMock{},
}
Expand Down Expand Up @@ -66,16 +60,6 @@ func TestNewTotalStakedValueProcessor(t *testing.T) {
},
exError: nil,
},
{
name: "NilBlockChain",
argsFunc: func() ArgTrieIteratorProcessor {
arg := createMockArgs()
arg.BlockChain = nil

return arg
},
exError: ErrNilBlockChain,
},
{
name: "NilQueryService",
argsFunc: func() ArgTrieIteratorProcessor {
Expand Down Expand Up @@ -136,30 +120,14 @@ func TestTotalStakedValueProcessor_GetTotalStakedValue_CannotGetAccount(t *testi
require.Equal(t, expectedErr, err)
}

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

arg := createMockArgs()
arg.BlockChain = &testscommon.ChainHandlerStub{
GetCurrentBlockRootHashCalled: func() []byte {
return nil
},
}
totalStakedProc, _ := NewTotalStakedValueProcessor(arg)

resTotalStaked, err := totalStakedProc.GetTotalStakedValue()
require.Nil(t, resTotalStaked)
require.Equal(t, ErrNodeNotInitialized, err)
}

func TestTotalStakedValueProcessor_GetTotalStakedValue_CannotRecreateTree(t *testing.T) {
func TestTotalStakedValueProcessor_GetTotalStakedValueAccountsAdapterErrors(t *testing.T) {
t.Parallel()

expectedErr := errors.New("expected error")
arg := createMockArgs()
arg.Accounts.AccountsAdapter = &stateMock.AccountsStub{
RecreateTrieCalled: func(rootHash []byte) error {
return expectedErr
GetExistingAccountCalled: func(addressContainer []byte) (vmcommon.AccountHandler, error) {
return nil, expectedErr
},
}
totalStakedProc, _ := NewTotalStakedValueProcessor(arg)
Expand Down
19 changes: 15 additions & 4 deletions state/accountsDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (
)

const (
leavesChannelSize = 100
leavesChannelSize = 100
lastSnapshotStarted = "lastSnapshot"
)

var numCheckpointsKey = []byte("state checkpoint")
Expand Down Expand Up @@ -143,11 +144,18 @@ func NewAccountsDB(
}

func startSnapshotAfterRestart(adb AccountsAdapter, tsm common.StorageManager) {
rootHash, err := adb.RootHash()
rootHash, err := tsm.Get([]byte(lastSnapshotStarted))
if err != nil {
log.Error("startSnapshotAfterRestart root hash", "error", err)
log.Warn("startSnapshotAfterRestart root hash", "error", err)

err = tsm.Put([]byte(common.ActiveDBKey), []byte(common.ActiveDBVal))
if err != nil {
log.Warn("error while putting active DB value into main storer", "error", err)
}

return
}
log.Debug("snapshot hash after restart", "hash", rootHash)

if tsm.ShouldTakeSnapshot() {
log.Debug("startSnapshotAfterRestart")
Expand Down Expand Up @@ -1079,8 +1087,11 @@ func (adb *AccountsDB) SnapshotState(rootHash []byte) {

adb.lastSnapshot.rootHash = rootHash
adb.lastSnapshot.epoch = epoch
err = trieStorageManager.Put([]byte(lastSnapshotStarted), rootHash)
if err != nil {
log.Warn("could not set lastSnapshotStarted", "err", err, "rootHash", rootHash)
}

log.Trace("accountsDB.SnapshotState", "root hash", rootHash)
trieStorageManager.EnterPruningBufferingMode()

stats := newSnapshotStatistics(1)
Expand Down
Loading

0 comments on commit c5cdfec

Please sign in to comment.