Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes staking v4 #3993

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c000cff
FEAT: Move unjailed and new staked nodes to auction
mariusmihaic Apr 15, 2022
751d213
FIX: Check for no error
mariusmihaic Apr 15, 2022
cbe5cb1
FEAT: Refactor code in stakingDataProvider and systemScs
mariusmihaic Apr 18, 2022
79d4fc4
FIX: Pointer bugs + refactor systemSCs.go
mariusmihaic Apr 18, 2022
aa31e14
FEAT: Unit tests for stakingDataProvider.go with staking v4
mariusmihaic Apr 18, 2022
8af8559
FIX: Small fixes
mariusmihaic Apr 18, 2022
1c1987c
FIX: Epoch flag name
mariusmihaic Apr 19, 2022
2ce0098
FIX: Pass staking v4 epoch in nodes coord
mariusmihaic Apr 19, 2022
6cf20ea
Merge branch 'EN-11927-integration-tests-staking-v4' into EN-11957-mo…
mariusmihaic Apr 19, 2022
d8039c4
Merge branch 'EN-11927-integration-tests-staking-v4' into EN-11957-mo…
mariusmihaic Apr 20, 2022
cb549f6
FIX: Delete error condition for maxNumNodes decrease
mariusmihaic Apr 20, 2022
d60e2d0
Merge branch 'EN-11927-integration-tests-staking-v4' into EN-11957-mo…
mariusmihaic Apr 20, 2022
cf4c2f4
FEAT: One more unit test
mariusmihaic Apr 20, 2022
e4cd7f2
FIX: Hot fix for chicken-egg problem in CreateNodesCoordinatorRegistry
mariusmihaic Apr 20, 2022
098bb93
FIX: Bug in storageHandler when saving nodes coord registry
mariusmihaic Apr 27, 2022
7ef95c4
FIX: saveState in indexHashedNodesCoordinator.go
mariusmihaic Apr 28, 2022
d353ece
Merge branch 'EN-11927-integration-tests-staking-v4' into EN-11957-mo…
mariusmihaic Apr 28, 2022
b90f7c3
Merge branch 'EN-11927-integration-tests-staking-v4' into EN-11957-mo…
mariusmihaic Apr 28, 2022
e109d6c
Merge branch 'EN-11927-integration-tests-staking-v4' into EN-11957-mo…
mariusmihaic Apr 29, 2022
1574f53
FIX: Bug in maxNumNodesUpdate in legacySystemSCs.go
mariusmihaic Apr 29, 2022
0ade9ea
FIX: Do some fixes
mariusmihaic Apr 29, 2022
4366a7d
FIX: Add missed file
mariusmihaic Apr 29, 2022
4316271
FIX: Gas schedule
mariusmihaic Apr 29, 2022
8338304
FIX: Flags inconsistency between systemSCs.go and staking.go
mariusmihaic May 2, 2022
7d507b1
FIX: Broken tests
mariusmihaic May 2, 2022
3d4d319
FIX: Broken tests
mariusmihaic May 3, 2022
3557a42
FIX: Review finding
mariusmihaic May 3, 2022
7a3c479
FIX: Linter errors
mariusmihaic May 3, 2022
91ca831
Merge branch 'feat/liquid-staking' into EN-11957-move-unjailed-new-no…
mariusmihaic May 3, 2022
0a13853
FIX: More tests
mariusmihaic May 3, 2022
cee9d7e
FIX: Review findings
mariusmihaic May 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/node/config/gasSchedules/gasScheduleV1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
ValidatorToDelegation = 500000000
GetAllNodeStates = 100000000
FixWaitingListSize = 500000000
LiquidStakingOps = 10000000
LiquidStakingOps = 10000000

[BaseOperationCost]
StorePerByte = 50000
Expand Down
1 change: 1 addition & 0 deletions cmd/node/config/gasSchedules/gasScheduleV4.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
UnstakeTokens = 5000000
UnbondTokens = 5000000
FixWaitingListSize = 500000000
LiquidStakingOps = 10000000

[BaseOperationCost]
StorePerByte = 10000
Expand Down
1 change: 1 addition & 0 deletions cmd/node/config/gasSchedules/gasScheduleV5.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
UnstakeTokens = 5000000
UnbondTokens = 5000000
FixWaitingListSize = 500000000
LiquidStakingOps = 10000000

[BaseOperationCost]
StorePerByte = 10000
Expand Down
1 change: 1 addition & 0 deletions cmd/node/config/gasSchedules/gasScheduleV6.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
UnstakeTokens = 5000000
UnbondTokens = 5000000
FixWaitingListSize = 500000000
LiquidStakingOps = 10000000

[BaseOperationCost]
StorePerByte = 10000
Expand Down
57 changes: 47 additions & 10 deletions epochStart/bootstrap/baseStorageHandler.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,67 @@
package bootstrap

import (
"encoding/json"

"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/block"
"github.com/ElrondNetwork/elrond-go-core/data/typeConverters"
"github.com/ElrondNetwork/elrond-go-core/hashing"
"github.com/ElrondNetwork/elrond-go-core/marshal"
"github.com/ElrondNetwork/elrond-go/common"
"github.com/ElrondNetwork/elrond-go/config"
"github.com/ElrondNetwork/elrond-go/dataRetriever"
"github.com/ElrondNetwork/elrond-go/process/block/bootstrapStorage"
"github.com/ElrondNetwork/elrond-go/sharding"
"github.com/ElrondNetwork/elrond-go/sharding/nodesCoordinator"
"github.com/ElrondNetwork/elrond-go/storage"
)

// StorageHandlerArgs is a struct placeholder for all arguments required to create either a shard or a meta storage handler
type StorageHandlerArgs struct {
GeneralConfig config.Config
PreferencesConfig config.PreferencesConfig
ShardCoordinator sharding.Coordinator
PathManagerHandler storage.PathManagerHandler
Marshaller marshal.Marshalizer
Hasher hashing.Hasher
CurrentEpoch uint32
Uint64Converter typeConverters.Uint64ByteSliceConverter
NodeTypeProvider NodeTypeProviderHandler
NodesCoordinatorRegistryFactory nodesCoordinator.NodesCoordinatorRegistryFactory
}

func checkNilArgs(args StorageHandlerArgs) error {
if check.IfNil(args.ShardCoordinator) {
return core.ErrNilShardCoordinator
}
if check.IfNil(args.PathManagerHandler) {
return dataRetriever.ErrNilPathManager
}
if check.IfNil(args.Marshaller) {
return core.ErrNilMarshalizer
}
if check.IfNil(args.Hasher) {
return core.ErrNilHasher
}
if check.IfNil(args.Uint64Converter) {
return dataRetriever.ErrNilUint64ByteSliceConverter
}
if check.IfNil(args.NodesCoordinatorRegistryFactory) {
return nodesCoordinator.ErrNilNodesCoordinatorRegistryFactory
}
return nil
}

// baseStorageHandler handles the storage functions for saving bootstrap data
type baseStorageHandler struct {
storageService dataRetriever.StorageService
shardCoordinator sharding.Coordinator
marshalizer marshal.Marshalizer
hasher hashing.Hasher
currentEpoch uint32
uint64Converter typeConverters.Uint64ByteSliceConverter
storageService dataRetriever.StorageService
shardCoordinator sharding.Coordinator
marshalizer marshal.Marshalizer
hasher hashing.Hasher
currentEpoch uint32
uint64Converter typeConverters.Uint64ByteSliceConverter
nodesCoordinatorRegistryFactory nodesCoordinator.NodesCoordinatorRegistryFactory
}

func (bsh *baseStorageHandler) groupMiniBlocksByShard(miniBlocks map[string]*block.MiniBlock) ([]bootstrapStorage.PendingMiniBlocksInfo, error) {
Expand All @@ -50,8 +88,7 @@ func (bsh *baseStorageHandler) saveNodesCoordinatorRegistry(
) ([]byte, error) {
key := append([]byte(common.NodesCoordinatorRegistryKeyPrefix), metaBlock.GetPrevRandSeed()...)

// TODO: replace hardcoded json - although it is hardcoded in nodesCoordinator as well.
registryBytes, err := json.Marshal(nodesConfig)
registryBytes, err := bsh.nodesCoordinatorRegistryFactory.GetRegistryData(nodesConfig, metaBlock.GetEpoch())
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion epochStart/bootstrap/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type EpochStartMetaBlockInterceptorProcessor interface {
// StartInEpochNodesCoordinator defines the methods to process and save nodesCoordinator information to storage
type StartInEpochNodesCoordinator interface {
EpochStartPrepare(metaHdr data.HeaderHandler, body data.BodyHandler)
NodesCoordinatorToRegistry() nodesCoordinator.NodesCoordinatorRegistryHandler
NodesCoordinatorToRegistry(epoch uint32) nodesCoordinator.NodesCoordinatorRegistryHandler
ShardIdForEpoch(epoch uint32) (uint32, error)
IsInterfaceNil() bool
}
Expand Down
48 changes: 19 additions & 29 deletions epochStart/bootstrap/metaStorageHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,11 @@ import (
"github.com/ElrondNetwork/elrond-go-core/core"
"github.com/ElrondNetwork/elrond-go-core/data"
"github.com/ElrondNetwork/elrond-go-core/data/block"
"github.com/ElrondNetwork/elrond-go-core/data/typeConverters"
"github.com/ElrondNetwork/elrond-go-core/hashing"
"github.com/ElrondNetwork/elrond-go-core/marshal"
"github.com/ElrondNetwork/elrond-go/common"
"github.com/ElrondNetwork/elrond-go/config"
"github.com/ElrondNetwork/elrond-go/dataRetriever"
"github.com/ElrondNetwork/elrond-go/epochStart"
"github.com/ElrondNetwork/elrond-go/epochStart/bootstrap/disabled"
"github.com/ElrondNetwork/elrond-go/process/block/bootstrapStorage"
"github.com/ElrondNetwork/elrond-go/sharding"
"github.com/ElrondNetwork/elrond-go/storage"
"github.com/ElrondNetwork/elrond-go/storage/factory"
)

Expand All @@ -26,26 +20,21 @@ type metaStorageHandler struct {
}

// NewMetaStorageHandler will return a new instance of metaStorageHandler
func NewMetaStorageHandler(
generalConfig config.Config,
prefsConfig config.PreferencesConfig,
shardCoordinator sharding.Coordinator,
pathManagerHandler storage.PathManagerHandler,
marshalizer marshal.Marshalizer,
hasher hashing.Hasher,
currentEpoch uint32,
uint64Converter typeConverters.Uint64ByteSliceConverter,
nodeTypeProvider NodeTypeProviderHandler,
) (*metaStorageHandler, error) {
func NewMetaStorageHandler(args StorageHandlerArgs) (*metaStorageHandler, error) {
err := checkNilArgs(args)
if err != nil {
return nil, err
}

epochStartNotifier := &disabled.EpochStartNotifier{}
storageFactory, err := factory.NewStorageServiceFactory(
&generalConfig,
&prefsConfig,
shardCoordinator,
pathManagerHandler,
&args.GeneralConfig,
&args.PreferencesConfig,
args.ShardCoordinator,
args.PathManagerHandler,
epochStartNotifier,
nodeTypeProvider,
currentEpoch,
args.NodeTypeProvider,
args.CurrentEpoch,
false,
)
if err != nil {
Expand All @@ -58,12 +47,13 @@ func NewMetaStorageHandler(
}

base := &baseStorageHandler{
storageService: storageService,
shardCoordinator: shardCoordinator,
marshalizer: marshalizer,
hasher: hasher,
currentEpoch: currentEpoch,
uint64Converter: uint64Converter,
storageService: storageService,
shardCoordinator: args.ShardCoordinator,
marshalizer: args.Marshaller,
hasher: args.Hasher,
currentEpoch: args.CurrentEpoch,
uint64Converter: args.Uint64Converter,
nodesCoordinatorRegistryFactory: args.NodesCoordinatorRegistryFactory,
}

return &metaStorageHandler{baseStorageHandler: base}, nil
Expand Down
97 changes: 33 additions & 64 deletions epochStart/bootstrap/metaStorageHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,30 @@ import (
"github.com/ElrondNetwork/elrond-go/testscommon"
"github.com/ElrondNetwork/elrond-go/testscommon/hashingMocks"
"github.com/ElrondNetwork/elrond-go/testscommon/nodeTypeProviderMock"
"github.com/ElrondNetwork/elrond-go/testscommon/shardingMocks"
"github.com/stretchr/testify/assert"
)

func createStorageHandlerArgs() StorageHandlerArgs {
return StorageHandlerArgs{
GeneralConfig: testscommon.GetGeneralConfig(),
PreferencesConfig: config.PreferencesConfig{},
ShardCoordinator: &mock.ShardCoordinatorStub{},
PathManagerHandler: &testscommon.PathManagerStub{},
Marshaller: &mock.MarshalizerMock{},
Hasher: &hashingMocks.HasherMock{},
CurrentEpoch: 0,
Uint64Converter: &mock.Uint64ByteSliceConverterMock{},
NodeTypeProvider: &nodeTypeProviderMock.NodeTypeProviderStub{},
NodesCoordinatorRegistryFactory: &shardingMocks.NodesCoordinatorRegistryFactoryMock{},
}
}

func TestNewMetaStorageHandler_InvalidConfigErr(t *testing.T) {
gCfg := config.Config{}
prefsConfig := config.PreferencesConfig{}
coordinator := &mock.ShardCoordinatorStub{}
pathManager := &testscommon.PathManagerStub{}
marshalizer := &mock.MarshalizerMock{}
hasher := &hashingMocks.HasherMock{}
uit64Cvt := &mock.Uint64ByteSliceConverterMock{}
nodeTypeProvider := &nodeTypeProviderMock.NodeTypeProviderStub{}

mtStrHandler, err := NewMetaStorageHandler(gCfg, prefsConfig, coordinator, pathManager, marshalizer, hasher, 1, uit64Cvt, nodeTypeProvider)
args := createStorageHandlerArgs()
args.GeneralConfig = config.Config{}

mtStrHandler, err := NewMetaStorageHandler(args)
assert.True(t, check.IfNil(mtStrHandler))
assert.NotNil(t, err)
}
Expand All @@ -37,16 +47,8 @@ func TestNewMetaStorageHandler_CreateForMetaErr(t *testing.T) {
_ = os.RemoveAll("./Epoch_0")
}()

gCfg := testscommon.GetGeneralConfig()
prefsConfig := config.PreferencesConfig{}
coordinator := &mock.ShardCoordinatorStub{}
pathManager := &testscommon.PathManagerStub{}
marshalizer := &mock.MarshalizerMock{}
hasher := &hashingMocks.HasherMock{}
uit64Cvt := &mock.Uint64ByteSliceConverterMock{}
nodeTypeProvider := &nodeTypeProviderMock.NodeTypeProviderStub{}

mtStrHandler, err := NewMetaStorageHandler(gCfg, prefsConfig, coordinator, pathManager, marshalizer, hasher, 1, uit64Cvt, nodeTypeProvider)
args := createStorageHandlerArgs()
mtStrHandler, err := NewMetaStorageHandler(args)
assert.False(t, check.IfNil(mtStrHandler))
assert.Nil(t, err)
}
Expand All @@ -56,20 +58,11 @@ func TestMetaStorageHandler_saveLastHeader(t *testing.T) {
_ = os.RemoveAll("./Epoch_0")
}()

gCfg := testscommon.GetGeneralConfig()
prefsConfig := config.PreferencesConfig{}
coordinator := &mock.ShardCoordinatorStub{}
pathManager := &testscommon.PathManagerStub{}
marshalizer := &mock.MarshalizerMock{}
hasher := &hashingMocks.HasherMock{}
uit64Cvt := &mock.Uint64ByteSliceConverterMock{}
nodeTypeProvider := &nodeTypeProviderMock.NodeTypeProviderStub{}

mtStrHandler, _ := NewMetaStorageHandler(gCfg, prefsConfig, coordinator, pathManager, marshalizer, hasher, 1, uit64Cvt, nodeTypeProvider)

args := createStorageHandlerArgs()
mtStrHandler, _ := NewMetaStorageHandler(args)
header := &block.MetaBlock{Nonce: 0}

headerHash, _ := core.CalculateHash(marshalizer, hasher, header)
headerHash, _ := core.CalculateHash(args.Marshaller, args.Hasher, header)
expectedBootInfo := bootstrapStorage.BootstrapHeaderInfo{
ShardId: core.MetachainShardId, Hash: headerHash,
}
Expand All @@ -84,21 +77,13 @@ func TestMetaStorageHandler_saveLastCrossNotarizedHeaders(t *testing.T) {
_ = os.RemoveAll("./Epoch_0")
}()

gCfg := testscommon.GetGeneralConfig()
prefsConfig := config.PreferencesConfig{}
coordinator := &mock.ShardCoordinatorStub{}
pathManager := &testscommon.PathManagerStub{}
marshalizer := &mock.MarshalizerMock{}
hasher := &hashingMocks.HasherMock{}
uit64Cvt := &mock.Uint64ByteSliceConverterMock{}
nodeTypeProvider := &nodeTypeProviderMock.NodeTypeProviderStub{}

mtStrHandler, _ := NewMetaStorageHandler(gCfg, prefsConfig, coordinator, pathManager, marshalizer, hasher, 1, uit64Cvt, nodeTypeProvider)
args := createStorageHandlerArgs()
mtStrHandler, _ := NewMetaStorageHandler(args)

hdr1 := &block.Header{Nonce: 1}
hdr2 := &block.Header{Nonce: 2}
hdrHash1, _ := core.CalculateHash(marshalizer, hasher, hdr1)
hdrHash2, _ := core.CalculateHash(marshalizer, hasher, hdr2)
hdrHash1, _ := core.CalculateHash(args.Marshaller, args.Hasher, hdr1)
hdrHash2, _ := core.CalculateHash(args.Marshaller, args.Hasher, hdr2)

hdr3 := &block.MetaBlock{
Nonce: 3,
Expand All @@ -118,16 +103,8 @@ func TestMetaStorageHandler_saveTriggerRegistry(t *testing.T) {
_ = os.RemoveAll("./Epoch_0")
}()

gCfg := testscommon.GetGeneralConfig()
prefsConfig := config.PreferencesConfig{}
coordinator := &mock.ShardCoordinatorStub{}
pathManager := &testscommon.PathManagerStub{}
marshalizer := &mock.MarshalizerMock{}
hasher := &hashingMocks.HasherMock{}
uit64Cvt := &mock.Uint64ByteSliceConverterMock{}
nodeTypeProvider := &nodeTypeProviderMock.NodeTypeProviderStub{}

mtStrHandler, _ := NewMetaStorageHandler(gCfg, prefsConfig, coordinator, pathManager, marshalizer, hasher, 1, uit64Cvt, nodeTypeProvider)
args := createStorageHandlerArgs()
mtStrHandler, _ := NewMetaStorageHandler(args)

components := &ComponentsNeededForBootstrap{
EpochStartMetaBlock: &block.MetaBlock{Nonce: 3},
Expand All @@ -143,16 +120,8 @@ func TestMetaStorageHandler_saveDataToStorage(t *testing.T) {
_ = os.RemoveAll("./Epoch_0")
}()

gCfg := testscommon.GetGeneralConfig()
prefsConfig := config.PreferencesConfig{}
coordinator := &mock.ShardCoordinatorStub{}
pathManager := &testscommon.PathManagerStub{}
marshalizer := &mock.MarshalizerMock{}
hasher := &hashingMocks.HasherMock{}
uit64Cvt := &mock.Uint64ByteSliceConverterMock{}
nodeTypeProvider := &nodeTypeProviderMock.NodeTypeProviderStub{}

mtStrHandler, _ := NewMetaStorageHandler(gCfg, prefsConfig, coordinator, pathManager, marshalizer, hasher, 1, uit64Cvt, nodeTypeProvider)
args := createStorageHandlerArgs()
mtStrHandler, _ := NewMetaStorageHandler(args)

components := &ComponentsNeededForBootstrap{
EpochStartMetaBlock: &block.MetaBlock{Nonce: 3},
Expand Down