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

Integration tests staking v4 #3951

Merged

Conversation

mariusmihaic
Copy link
Contributor

@mariusmihaic mariusmihaic commented Mar 30, 2022

What's new

  • StakingV4DistributeAuctionToWaitingEpoch activation flag = epoch in which selected nodes from auction will be distributed to waiting list (used in node shuffler)
  • Added a new entry in MaxNodesChangeEnableEpoch config, which will have enable epoch = StakingV4DistributeAuctionToWaitingEpoch and will decrease the max nodes config with the number of shuffled out validators from all shards (e.g. from 3200 -> 2880, since we shuffle out 80 eligible validators per 4 shards)
  • Computation of available slots for auction nodes which will be selected based on topup as following:
availableSlots = maxNodes - currentNumberOfValidators - numOfNodesWhichWillBeShuffledOut

Integration tests

  • Added TestMetaProcessor struct which will create a predefined nodes configuration with provided params:
        numOfMetaNodes uint32,
	numOfShards uint32,
	numOfEligibleNodesPerShard uint32,
	numOfWaitingNodesPerShard uint32,
	numOfNodesToShufflePerShard uint32,
	shardConsensusGroupSize int,
	metaConsensusGroupSize int,
	numOfNodesInStakingQueue uint32,
  1. All generated address have a fixed length which starts from index = 0 -> maxNumNodes (e.g. 00address-0 -> 0address-50)
  2. Every node in waiting/eligible is associated with a different owner
  3. All nodes in staking queue are owned by a single owner
  4. Every node has the same top-up per node
  5. It can Process n number of rounds by committing blocks in each of them and will display nodes config each time.
  • Added 2 integration tests:
  1. TestStakingV4 which simulates a mainnet nodes configuration (400 meta nodes + 400 eligible and waiting/shard + 60 nodes in staking queue, each of them having the same topup per node) going through stakingV4Init, stakingV4Enable, stakingV4DistributeAuctionToWaiting epochs.
  2. TestStakingV4MetaProcessor_ProcessMultipleNodesWithSameSetupExpectSameRootHash which simulates multiple TestMetaProcessor starting to process n epochs with the same initial setup. It is expected that there is not root hash mismatch at any epoch

Bugfixes

  • Deactivated flagCorrectNumNodesToStake flag in legacySystemSCs.go upon staking v4 enable epoch, since it used code related to staking queue (which is now obsolete)
  • Fixed a bug in which two nodes with the same top up would not be correctly sorted/compared by pubKey XOR randomness, resulting in root hash mismatches between meta shard nodes
  • Uint32 substraction underflow when computing available slots from auction list
  • setNodesPerShards in indexHashedNodesCoordinatorLite.go to also save shuffled out nodes
  • Race condition in already existing code from process/block/displayMetaBlock.go by adding a mutex for peakTPS

Refactor

  • Moved some testing code related to staking from systemSCs_test.go to testscommon/stakingCommon.go to be used in stakingV4 integration tests
  • NewFeeAccumulator constructor to return directly a new instance of *feeHandler instead of (*feeHandler, error) , since it could have never returned an error
  • Several stubs so that code in tests would not panic because of uninitialized memory

@mariusmihaic mariusmihaic changed the title FEAT: Add file placeholder Integration tests staking v4 Mar 31, 2022
@mariusmihaic mariusmihaic self-assigned this Apr 7, 2022
@mariusmihaic mariusmihaic marked this pull request as ready for review April 14, 2022 14:13
factory2 "github.com/ElrondNetwork/elrond-go/factory"
"github.com/ElrondNetwork/elrond-go/integrationTests"
mock2 "github.com/ElrondNetwork/elrond-go/integrationTests/mock"
factory3 "github.com/ElrondNetwork/elrond-go/node/mock/factory"
Copy link
Contributor

Choose a reason for hiding this comment

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

rename factory 2, factory 3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed them

"github.com/ElrondNetwork/elrond-go/epochStart"
"github.com/ElrondNetwork/elrond-go/epochStart/metachain"
factory2 "github.com/ElrondNetwork/elrond-go/factory"
mock2 "github.com/ElrondNetwork/elrond-go/integrationTests/mock"
Copy link
Contributor

Choose a reason for hiding this comment

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

rename mock2 and factory2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed them

"github.com/ElrondNetwork/elrond-go/common"
"github.com/ElrondNetwork/elrond-go/config"
factory2 "github.com/ElrondNetwork/elrond-go/factory"
mock2 "github.com/ElrondNetwork/elrond-go/integrationTests/mock"
Copy link
Contributor

Choose a reason for hiding this comment

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

rename factory2 and mock2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed them

"github.com/ElrondNetwork/elrond-go/config"
"github.com/ElrondNetwork/elrond-go/epochStart/metachain"
mock3 "github.com/ElrondNetwork/elrond-go/epochStart/mock"
factory2 "github.com/ElrondNetwork/elrond-go/factory"
Copy link
Contributor

Choose a reason for hiding this comment

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

rename factory2 mock3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed them

"github.com/ElrondNetwork/elrond-go/config"
"github.com/ElrondNetwork/elrond-go/dataRetriever"
"github.com/ElrondNetwork/elrond-go/epochStart/metachain"
factory2 "github.com/ElrondNetwork/elrond-go/factory"
Copy link
Contributor

Choose a reason for hiding this comment

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

rename factory2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed them

testscommon/rewardsCreatorStub.go Outdated Show resolved Hide resolved
epochStart/metachain/systemSCs.go Outdated Show resolved Hide resolved
epochStart/metachain/systemSCs.go Outdated Show resolved Hide resolved
testscommon/stakingcommon/stakingCommon.go Outdated Show resolved Hide resolved
factory/coreComponents.go Outdated Show resolved Hide resolved
epochStart/metachain/legacySystemSCs.go Show resolved Hide resolved
integrationTests/vm/staking/stakingV4_test.go Show resolved Hide resolved
epochStart/metachain/systemSCs.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Apr 29, 2022

Codecov Report

Merging #3951 (a98dcee) into feat/liquid-staking (2df534f) will increase coverage by 0.00%.
The diff coverage is 86.66%.

@@                 Coverage Diff                  @@
##           feat/liquid-staking    #3951   +/-   ##
====================================================
  Coverage                75.38%   75.38%           
====================================================
  Files                      622      622           
  Lines                    83134    83177   +43     
====================================================
+ Hits                     62668    62701   +33     
- Misses                   15748    15756    +8     
- Partials                  4718     4720    +2     
Impacted Files Coverage Δ
epochStart/metachain/systemSCs.go 71.65% <70.83%> (-1.75%) ⬇️
epochStart/metachain/legacySystemSCs.go 72.14% <100.00%> (+0.27%) ⬆️
factory/blockProcessorCreator.go 80.44% <100.00%> (+0.39%) ⬆️
factory/coreComponents.go 79.61% <100.00%> (-0.10%) ⬇️
process/block/displayMetaBlock.go 47.63% <100.00%> (+0.68%) ⬆️
process/block/postprocess/feeHandler.go 92.20% <100.00%> (ø)
sharding/nodesCoordinator/hashValidatorShuffler.go 93.02% <100.00%> (+0.11%) ⬆️
...ng/nodesCoordinator/indexHashedNodesCoordinator.go 82.20% <100.00%> (+0.02%) ⬆️
...odesCoordinator/indexHashedNodesCoordinatorLite.go 81.39% <100.00%> (ø)
p2p/libp2p/netMessenger.go 74.70% <0.00%> (-0.27%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2df534f...a98dcee. Read the comment docs.

@@ -179,6 +203,14 @@ func (s *systemSCProcessor) selectNodesFromAuctionList(validatorsInfoMap state.S
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 this for Uint64

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, but I didn't want to cast to uint64, but have a separate function for it. Will move it in elrond-go-core in a separate task

@mariusmihaic mariusmihaic merged commit a1dad37 into feat/liquid-staking May 2, 2022
@mariusmihaic mariusmihaic deleted the EN-11927-integration-tests-staking-v4 branch May 2, 2022 13:12
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

3 participants