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

Filter auction nodes list #3822

Merged
merged 26 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a0cdfc5
FEAT: Add first ugly version
mariusmihaic Feb 18, 2022
200f17d
Merge branch 'EN-11661-staking-v4-init' into EN-11662-filter-new-nodes
mariusmihaic Feb 22, 2022
60e4e3a
FEAT: Add temporary test
mariusmihaic Feb 23, 2022
bd9d101
FEAT: Change ProcessSystemSmartContract func interface to accept rand
mariusmihaic Feb 23, 2022
a838a7f
FEAT: Sort by pubKey XOR rand if multiple nodes have same top up per …
mariusmihaic Feb 23, 2022
ef30472
FIX: Top up per node in tests
mariusmihaic Feb 23, 2022
caa682d
FEAT: Display auction list, refactor interface + tests
mariusmihaic Feb 24, 2022
40ff5a7
FIX: Refactor tests
mariusmihaic Feb 24, 2022
02160ad
FIX: Refactor code pt. 1
mariusmihaic Feb 24, 2022
5ae3d73
FIX: Refactor code pt. 2
mariusmihaic Feb 25, 2022
2a2dc29
FEAT: Add tests for error paths
mariusmihaic Feb 28, 2022
473896e
FIX: Small refactor
mariusmihaic Feb 28, 2022
e51f952
FEAT: Add flag in toml file
mariusmihaic Feb 28, 2022
638a23b
Merge branch 'EN-11661-staking-v4-init' into EN-11662-filter-new-nodes
mariusmihaic Feb 28, 2022
a8fef77
Merge remote-tracking branch 'origin/EN-11661-staking-v4-init' into E…
mariusmihaic Mar 1, 2022
27aa5f8
Merge branch 'EN-11661-staking-v4-init' into EN-11662-filter-new-nodes
mariusmihaic Mar 1, 2022
69bc7c5
FIX: Review findings
mariusmihaic Mar 1, 2022
53befc7
Merge branch 'feat/liquid-staking' into EN-11662-filter-new-nodes
mariusmihaic Mar 2, 2022
23675b0
FIX: Review findings
mariusmihaic Mar 3, 2022
9639aa5
FIX: Review findings pt. 2
mariusmihaic Mar 4, 2022
196ffdb
Merge branch 'feat/liquid-staking' into EN-11662-filter-new-nodes
mariusmihaic Mar 4, 2022
42b0528
FIX: One review finding
mariusmihaic Mar 4, 2022
3df6cfb
FIX: Integration test
mariusmihaic Mar 9, 2022
c3abbdb
FIX: Broken tests
mariusmihaic Mar 9, 2022
47c7712
FEAT: Move selected nodes from AuctionList to SelectedFromAuctionList
mariusmihaic Mar 9, 2022
20535f3
FIX: Review findings
mariusmihaic Mar 9, 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
3 changes: 3 additions & 0 deletions cmd/node/config/enableEpochs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@
# all nodes from staking queue are moved in the auction list
StakingV4InitEnableEpoch = 4

# StakingV4EnableEpoch represents the epoch when staking v4 is enabled. Should have a greater value than StakingV4InitEnableEpoch
StakingV4EnableEpoch = 5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this should always be StakingV4InitEnableEpoch + 1? What happens if we wrongly configure this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically, code should not panic or anything. If EnableEpoch < InitEpoch => auction list will be empty => no sorting/selection will be made.
Logic-wise, if they are inverted it shouldn't cause any bugs for NOW. I'm not sure how the implementation on nodes coordinator side will look like to give an educated opinion. Depending how it will be designed, it might cause some bugs


# MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch
MaxNodesChangeEnableEpoch = [
{ EpochEnable = 0, MaxNumNodes = 36, NodesToShufflePerShard = 4 },
Expand Down
4 changes: 4 additions & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const NewList PeerType = "new"
// based on their top up stake
const AuctionList PeerType = "auction"

// SelectedFromAuctionList represents the list of peers which have been selected from AuctionList based on
// their top up to be distributed on the WaitingList in the next epoch
const SelectedFromAuctionList PeerType = "selectedFromAuction"
sasurobert marked this conversation as resolved.
Show resolved Hide resolved

// CombinedPeerType - represents the combination of two peerTypes
const CombinedPeerType = "%s (%s)"

Expand Down
1 change: 1 addition & 0 deletions config/epochConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type EnableEpochs struct {
AddFailedRelayedTxToInvalidMBsDisableEpoch uint32
StakeLimitsEnableEpoch uint32
StakingV4InitEnableEpoch uint32
StakingV4EnableEpoch uint32
}

// GasScheduleByEpochs represents a gas schedule toml entry that will be applied from the provided epoch
Expand Down
3 changes: 3 additions & 0 deletions epochStart/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,6 @@ var ErrNilScheduledDataSyncerFactory = errors.New("nil scheduled data syncer fac

// ErrCouldNotInitLiquidStakingSystemSC signals that liquid staking system sc init failed
var ErrCouldNotInitLiquidStakingSystemSC = errors.New("could not init liquid staking system sc")

// ErrSortAuctionList signals that an error occurred while trying to sort auction list
var ErrSortAuctionList = errors.New("error while trying to sort auction list")
3 changes: 2 additions & 1 deletion epochStart/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ type StakingDataProvider interface {
GetTotalStakeEligibleNodes() *big.Int
GetTotalTopUpStakeEligibleNodes() *big.Int
GetNodeStakedTopUp(blsKey []byte) (*big.Int, error)
PrepareStakingDataForRewards(keys map[uint32][][]byte) error
PrepareStakingData(keys map[uint32][][]byte) error
FillValidatorInfo(blsKey []byte) error
ComputeUnQualifiedNodes(validatorInfos map[uint32][]*state.ValidatorInfo) ([][]byte, map[string][][]byte, error)
GetBlsKeyOwner(blsKey []byte) (string, error)
Clean()
IsInterfaceNil() bool
}
Expand Down
11 changes: 6 additions & 5 deletions epochStart/metachain/stakingDataProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (sdp *stakingDataProvider) GetTotalTopUpStakeEligibleNodes() *big.Int {

// GetNodeStakedTopUp returns the owner of provided bls key staking stats for the current epoch
func (sdp *stakingDataProvider) GetNodeStakedTopUp(blsKey []byte) (*big.Int, error) {
owner, err := sdp.getBlsKeyOwner(blsKey)
owner, err := sdp.GetBlsKeyOwner(blsKey)
if err != nil {
log.Debug("GetOwnerStakingStats", "key", hex.EncodeToString(blsKey), "error", err)
return nil, err
Expand All @@ -105,8 +105,8 @@ func (sdp *stakingDataProvider) GetNodeStakedTopUp(blsKey []byte) (*big.Int, err
return ownerInfo.topUpPerNode, nil
}

// PrepareStakingDataForRewards prepares the staking data for the given map of node keys per shard
func (sdp *stakingDataProvider) PrepareStakingDataForRewards(keys map[uint32][][]byte) error {
// PrepareStakingData prepares the staking data for the given map of node keys per shard
func (sdp *stakingDataProvider) PrepareStakingData(keys map[uint32][][]byte) error {
sdp.Clean()

for _, keysList := range keys {
Expand Down Expand Up @@ -163,7 +163,7 @@ func (sdp *stakingDataProvider) FillValidatorInfo(blsKey []byte) error {
}

func (sdp *stakingDataProvider) getAndFillOwnerStatsFromSC(blsKey []byte) (*ownerStats, error) {
owner, err := sdp.getBlsKeyOwner(blsKey)
owner, err := sdp.GetBlsKeyOwner(blsKey)
if err != nil {
log.Debug("error fill owner stats", "step", "get owner from bls", "key", hex.EncodeToString(blsKey), "error", err)
return nil, err
Expand Down Expand Up @@ -195,7 +195,8 @@ func (sdp *stakingDataProvider) loadDataForBlsKey(blsKey []byte) error {
return nil
}

func (sdp *stakingDataProvider) getBlsKeyOwner(blsKey []byte) (string, error) {
// GetBlsKeyOwner returns the owner's public key of the provided bls key
func (sdp *stakingDataProvider) GetBlsKeyOwner(blsKey []byte) (string, error) {
vmInput := &vmcommon.ContractCallInput{
VMInput: vmcommon.VMInput{
CallerAddr: vm.ValidatorSCAddress,
Expand Down
2 changes: 1 addition & 1 deletion epochStart/metachain/stakingDataProvider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func TestStakingDataProvider_PrepareStakingDataForRewards(t *testing.T) {

keys := make(map[uint32][][]byte)
keys[0] = append(keys[0], []byte("owner"))
err := sdp.PrepareStakingDataForRewards(keys)
err := sdp.PrepareStakingData(keys)
require.NoError(t, err)
}

Expand Down