-
Notifications
You must be signed in to change notification settings - Fork 199
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
Conversation
blsPubKey []byte, | ||
nonce uint64, | ||
) error { | ||
if stakingData.StakedNonce == math.MaxUint64 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) | |||
} | |||
|
|||
/* |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forgot t.skip :)
…nto bugFix/save-only-staked-nodes
c6e7e25
…nto bugFix/save-only-staked-nodes
vm/systemSmartContracts/auction.go
Outdated
@@ -701,11 +715,23 @@ func (s *stakingAuctionSC) unStake(args *vmcommon.ContractCallInput) vmcommon.Re | |||
} | |||
|
|||
for _, blsKey := range blsKeys { | |||
if registrationData.NumStaked == 0 { | |||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not break?
process/economics/economicsData.go
Outdated
return ed.maxGasLimitPerBlock | ||
} | ||
|
||
// MaxGasLimitPerMetaBlock will return maximum gas limit allowed per block | ||
func (ed *EconomicsData) MaxGasLimitPerMetaBlock() uint64 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
vm/systemSmartContracts/auction.go
Outdated
@@ -701,11 +715,23 @@ func (s *stakingAuctionSC) unStake(args *vmcommon.ContractCallInput) vmcommon.Re | |||
} | |||
|
|||
for _, blsKey := range blsKeys { | |||
if registrationData.NumStaked == 0 { | |||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
break
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
vm/systemSmartContracts/auction.go
Outdated
@@ -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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reformulate this comment :)
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ErrInvalidMaxGasLimitPerMetaBlock ?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
System tests passed.
Save only staked nodes to validators trie.
Add storage updates to smart contract results only for staking smart contract