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

Staking V4: Refactor stakingDataProvider to pre-fill auction data #4155

Merged

Conversation

mariusmihaic
Copy link
Contributor

@mariusmihaic mariusmihaic commented Jun 3, 2022

Moved all logic related to OwnerData pre-fill from auctionListSelector to stakingDataProvider

What's new

  • Added OwnerData dto
  • FillValidatorInfo now expects a state.ValidatorInfoHandler instead of blsKey
  • For each validator data info filled, we increment numOfValidatorsInCurrEpoch, which is the number of validators (waiting + eligible) in the current epoch, needed for auctionListSelector. For each unqualified validator, we decrement this counter.

Refactor

  • SelectNodesFromAuctionList now does not need unqualifiedOwners as input param, since this info is provided by stakingDataProvider
  • Removed GetTotalTopUp & GetNumStakedNodes from stakingDataProvider along with their tests
  • PrepareStakingDataCalled now expects a state.ShardValidatorsInfoMapHandler instead of map[uint32][][]byte
  • ComputeUnQualifiedNode sets qualified owner's data flag

@mariusmihaic mariusmihaic changed the title FEAT: First version, failing tests Staking V4: Refactor stakingDataProvider to pre-fill auction data Jun 3, 2022
@mariusmihaic mariusmihaic self-assigned this Jun 3, 2022
@mariusmihaic mariusmihaic marked this pull request as ready for review June 3, 2022 14:05
@sasurobert sasurobert self-requested a review June 7, 2022 12:35
Base automatically changed from EN-12196-implement-soft-auction to feat/liquid-staking June 8, 2022 07:28
type OwnerData struct {
NumStakedNodes int64
NumActiveNodes int64
NumAuctionNodes int64
Copy link
Contributor

Choose a reason for hiding this comment

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

I think NumAuctionNodes can be removed because are duplicated information with the len(AuctionList)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, good suggestion; removed it from here and from stakingDataProvider.
However, I've kept it in auctionListSelector, since there we do a lot of iterations and I don't want to re-calculate len every time.

flagStakingV4Enable atomic.Flag
mutStakingData sync.RWMutex
cache map[string]*ownerStats
numOfValidatorsInCurrEpoch uint32
Copy link
Contributor

Choose a reason for hiding this comment

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

numOfValidatorsInCurrEpoch can be moved near stakingV4EnableEpoch in order to group variables of the same type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored as suggested

numEligible int
numStakedNodes int64
numActiveNodes int64
numAuctionNodes int64
Copy link
Contributor

Choose a reason for hiding this comment

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

Also here I think you can remove this variable
This adds extra complexity because you have to maintain 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.

Right, good suggestion; removed it from here and from stakingDataProvider.
However, I've kept it in auctionListSelector, since there we do a lot of iterations and I don't want to re-calculate len every time.

@@ -377,7 +458,7 @@ func (sdp *stakingDataProvider) createMapBLSKeyStatus(validatorsInfo state.Shard
return mapBLSKeyStatus, nil
}

func (sdp *stakingDataProvider) selectKeysToUnStake(sortedKeys map[string][][]byte, numToSelect int64) [][]byte {
func (sdp *stakingDataProvider) selectKeysToUnStake(sortedKeys map[string][][]byte, numToSelect int64) ([][]byte, int) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe this function can be renamed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMHO, the name is good and reflects its purpose; I would leave it as it is, unless you have a stronger opinion on why it should be renamed

selectedKeys, removedValidators := sdp.selectKeysToUnStake(sortedKeys, numKeysToUnStake)

@@ -536,3 +536,5 @@ func TestStakingV4_StakeNewNodes(t *testing.T) {
requireMapContains(t, currNodesConfig.waiting, owner3StakingQueue)
requireSliceContains(t, currNodesConfig.auction, owner1StakingQueue)
}

// TODO: test unstake with 1 owner -> 1 bls key in auction => numStakedNodes = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

do not forget about this TODO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Already taken care of in future PRs

@raduchis raduchis self-requested a review June 15, 2022 06:39

return nil
}

// TODO: Move this in elrond-go-core
func safeSub(a, b uint32) (uint32, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we have safeSub for uint64 already in go-core

epochStart/metachain/auctionListSelector_test.go Outdated Show resolved Hide resolved
epochStart/metachain/stakingDataProvider.go Outdated Show resolved Hide resolved
epochStart/metachain/stakingDataProvider.go Outdated Show resolved Hide resolved
@mariusmihaic mariusmihaic merged commit 3082b57 into feat/liquid-staking Jun 16, 2022
@mariusmihaic mariusmihaic deleted the refactor-stakingv4-auction-data-preparation branch June 16, 2022 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants