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

bugFix/only-staked-nodes-to-validators #1771

Merged
merged 25 commits into from
May 21, 2020

Conversation

sasurobert
Copy link
Contributor

Save only staked nodes to validators trie.
Add storage updates to smart contract results only for staking smart contract

iulianpascalau
iulianpascalau previously approved these changes May 20, 2020
blsPubKey []byte,
nonce uint64,
) error {
if stakingData.StakedNonce == math.MaxUint64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

ugly hardcoded thing. Will think about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes - will try to get rid of this component and make the stakingSC to write directly into the validator trie - but there are a few issues right now with it. Like like reverting and journalizing of those elements.

@@ -1702,6 +1701,7 @@ func TestAuctionStakingSC_ChangeRewardAddress(t *testing.T) {
changeRewardAddress(t, sc, stakerAddress, newRewardAddr, vmcommon.Ok)
}

/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe t.Skip with description instead commented code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

forgot t.skip :)

iulianpascalau
iulianpascalau previously approved these changes May 20, 2020
@miiu96 miiu96 closed this May 21, 2020
@miiu96 miiu96 deleted the bugFix/save-only-staked-nodes branch May 21, 2020 06:08
@AdoAdoAdo AdoAdoAdo restored the bugFix/save-only-staked-nodes branch May 21, 2020 06:14
@@ -701,11 +715,23 @@ func (s *stakingAuctionSC) unStake(args *vmcommon.ContractCallInput) vmcommon.Re
}

for _, blsKey := range blsKeys {
if registrationData.NumStaked == 0 {
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

why not break?

return ed.maxGasLimitPerBlock
}

// MaxGasLimitPerMetaBlock will return maximum gas limit allowed per block
func (ed *EconomicsData) MaxGasLimitPerMetaBlock() uint64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need this method for? MaxGasLimitPerBlock is enogh for the job.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -701,11 +715,23 @@ func (s *stakingAuctionSC) unStake(args *vmcommon.ContractCallInput) vmcommon.Re
}

for _, blsKey := range blsKeys {
if registrationData.NumStaked == 0 {
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

break

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.


err = s.saveRegistrationData(args.CallerAddr, registrationData)
if err != nil {
return vmcommon.UserError
Copy link
Contributor

Choose a reason for hiding this comment

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

It is ok to return vmcommon.UserError, if saving not worked but unStake and registrationData.NumStaked -= 1 has been done ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this error can be only marshalizing error. can't do anything if the final result cannot be saved to trie.

@@ -1034,8 +1076,8 @@ func shuffleList(list []string, random []byte) {
func isNumArgsCorrectToStake(args [][]byte) bool {
maxNodesToRun := big.NewInt(0).SetBytes(args[0]).Uint64()
areEnoughArgs := uint64(len(args)) >= 2*maxNodesToRun+1

return areEnoughArgs
areNotTooManyArgs := uint64(len(args)) <= 2*maxNodesToRun+1+2
Copy link
Contributor

Choose a reason for hiding this comment

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

use a var with a description for this: 2*maxNodesToRun+1+2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added comment.

@@ -22,7 +22,7 @@ func (fh *FeeHandler) MinGasPrice() uint64 {
}

// MaxGasLimitPerBlock return max uint64
Copy link
Contributor

Choose a reason for hiding this comment

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

Reformulate this comment :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it really returns max uint64 as it is a disabled handler.

@@ -48,7 +48,7 @@ func (fhs *FeeHandlerStub) SetMinGasLimit(minGasLimit uint64) {
}

// MaxGasLimitPerBlock -
func (fhs *FeeHandlerStub) MaxGasLimitPerBlock() uint64 {
func (fhs *FeeHandlerStub) MaxGasLimitPerBlock(uint32) uint64 {
return fhs.MaxGasLimitPerBlockCalled()
Copy link
Contributor

Choose a reason for hiding this comment

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

change the mock method signature also

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is not used rigth now - in any test it is only one value. there is no need.

@@ -32,7 +32,7 @@ func (fhs *FeeHandlerStub) DeveloperPercentage() float64 {
}

// MaxGasLimitPerBlock -
func (fhs *FeeHandlerStub) MaxGasLimitPerBlock() uint64 {
func (fhs *FeeHandlerStub) MaxGasLimitPerBlock(uint32) uint64 {
return fhs.MaxGasLimitPerBlockCalled()
Copy link
Contributor

Choose a reason for hiding this comment

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

change the mock method signature also

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is not used rigth now - in any test it is only one value. there is no need.

@@ -108,6 +111,11 @@ func convertValues(economics *config.EconomicsConfig) (*EconomicsData, error) {
return nil, process.ErrInvalidMaxGasLimitPerBlock
}

maxGasLimitPerMetaBlock, err := strconv.ParseUint(economics.FeeSettings.MaxGasLimitPerMetaBlock, conversionBase, bitConversionSize)
if err != nil {
return nil, process.ErrInvalidMaxGasLimitPerBlock
Copy link
Contributor

Choose a reason for hiding this comment

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

ErrInvalidMaxGasLimitPerMetaBlock ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no need to add one more.

@@ -12,6 +12,7 @@ type TestEconomicsData struct {
// SetMaxGasLimitPerBlock sets the maximum gas limit allowed per one block
func (ted *TestEconomicsData) SetMaxGasLimitPerBlock(maxGasLimitPerBlock uint64) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you can add another parameter to this method maxGasLimitPerMetaBlock uint64, so in this way we can test with different values if we want this. Or better to create another method to SetMaxGasLimitPerMetaBlock

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is not used rigth now - in any test it is only one value. there is no need. When there will be a test to especially change these values - it will be created.

@@ -48,7 +48,7 @@ func (fhs *FeeHandlerStub) SetMinGasLimit(minGasLimit uint64) {
}

// MaxGasLimitPerBlock -
func (fhs *FeeHandlerStub) MaxGasLimitPerBlock() uint64 {
func (fhs *FeeHandlerStub) MaxGasLimitPerBlock(uint32) uint64 {
return fhs.MaxGasLimitPerBlockCalled()
Copy link
Contributor

Choose a reason for hiding this comment

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

change the mock method signature also

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is not used rigth now - in any test it is only one value. there is no need.

@@ -79,7 +79,7 @@ func (service *SCQueryService) createVMCallInput(query *process.SCQuery, gasPric
CallerAddr: query.ScAddress,
CallValue: big.NewInt(0),
GasPrice: gasPrice,
GasProvided: service.economicsFee.MaxGasLimitPerBlock(),
GasProvided: service.economicsFee.MaxGasLimitPerBlock(0),
Copy link
Contributor

Choose a reason for hiding this comment

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

It is ok to be harded here to shard 0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is a query service it does not matter.

@@ -134,7 +134,7 @@ func (service *SCQueryService) ComputeScCallGasLimit(tx *transaction.Transaction
return 0, err
}

gasConsumed := service.economicsFee.MaxGasLimitPerBlock() - vmOutput.GasRemaining
gasConsumed := service.economicsFee.MaxGasLimitPerBlock(0) - vmOutput.GasRemaining
Copy link
Contributor

Choose a reason for hiding this comment

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

It is ok to be harded here to shard 0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is a query service - it does not matter.

registrationData.BlsPubKeys[len(registrationData.BlsPubKeys)-1] = nil
registrationData.BlsPubKeys = registrationData.BlsPubKeys[:len(registrationData.BlsPubKeys)-1]
lastIndex := len(registrationData.BlsPubKeys) - 1
registrationData.BlsPubKeys[i] = registrationData.BlsPubKeys[lastIndex]
Copy link
Contributor

Choose a reason for hiding this comment

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

It is not a problem that you have changed the order of the registrationData.BlsPubKeys after the call of this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no - the order is not used in any place.

Copy link
Contributor

@LucianMincu LucianMincu left a comment

Choose a reason for hiding this comment

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

System tests passed.

@iulianpascalau iulianpascalau merged commit 8b7eb59 into development May 21, 2020
@iulianpascalau iulianpascalau deleted the bugFix/save-only-staked-nodes branch May 21, 2020 14:24
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.

5 participants