-
Notifications
You must be signed in to change notification settings - Fork 198
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
jailed-node-backward-compatible #2303
Conversation
process/peer/process.go
Outdated
@@ -200,7 +211,7 @@ func (vs *validatorStatistics) saveUpdatesForList( | |||
return err | |||
} | |||
|
|||
if peerType == core.InactiveList && peerAcc.GetUnStakedEpoch() == core.DefaultUnstakedEpoch { | |||
if vs.flagSwitchEnabled.IsSet() && peerType == core.InactiveList && peerAcc.GetUnStakedEpoch() == core.DefaultUnstakedEpoch { |
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 extract in a bool variable?
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
@@ -421,16 +432,38 @@ func (vs *validatorStatistics) getValidatorDataFromLeaves( | |||
return validators, nil | |||
} | |||
|
|||
func getActualList(peerAccount state.PeerAccountHandler) string { |
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.
guess we can't continue without this function :D
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.
best function ever.
process/peer/process.go
Outdated
@@ -609,6 +642,10 @@ func (vs *validatorStatistics) ResetValidatorStatisticsAtNewEpoch(vInfos map[uin | |||
} | |||
peerAccount.ResetAtNewEpoch() | |||
|
|||
if vs.flagSwitchEnabled.IsSet() && validator.List == string(core.JailedList) && peerAccount.GetList() != string(core.JailedList) { |
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.
bool var?
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
process/peer/process.go
Outdated
|
||
// EpochConfirmed is called whenever a new epoch is confirmed | ||
func (vs *validatorStatistics) EpochConfirmed(epoch uint32) { | ||
vs.flagSwitchEnabled.Toggle(epoch >= vs.switchEnableEpoch) |
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.
Wondering if there is an chicken-egg problem when using this mechanism in this particular implementation:
Does peer processor is called before or after the epoch change? Because if it is after the epoch change, the new start of epoch block will contain the modified peer changes. Otherwise, it will keep the old processing way. Since the shards do not care about the peer statuses I guess it's ok the processing there.
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.
before any processing is called. thus is 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.
Will test this by doing an unjail tx on the testnet and then repaying everything using the import-db feature.
@@ -609,6 +646,11 @@ func (vs *validatorStatistics) ResetValidatorStatisticsAtNewEpoch(vInfos map[uin | |||
} | |||
peerAccount.ResetAtNewEpoch() | |||
|
|||
shouldBeJailed := vs.flagJailedEnabled.IsSet() && validator.List == string(core.JailedList) && peerAccount.GetList() != string(core.JailedList) | |||
if shouldBeJailed { | |||
peerAccount.SetListAndIndex(validator.ShardId, validator.List, validator.Index) |
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 replace validator.List with string(core.JailedList) to be more clear what is about to do here
epochStart/metachain/systemSCs.go
Outdated
@@ -40,6 +44,8 @@ type systemSCProcessor struct { | |||
validatorInfoCreator epochStart.ValidatorInfoCreator | |||
endOfEpochCallerAddress []byte | |||
stakingSCAddress []byte | |||
switchUnJailEnableEpoch uint32 |
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.
switchJailWaitingEnableEpoch or switchEnableEpoch ?
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
epochStart/metachain/systemSCs.go
Outdated
// EpochConfirmed is called whenever a new epoch is confirmed | ||
func (s *systemSCProcessor) EpochConfirmed(epoch uint32) { | ||
s.flagSwitchEnabled.Toggle(epoch >= s.switchUnJailEnableEpoch) | ||
log.Debug("systemSCProcessor: switch unJail", "enabled", s.flagSwitchEnabled.IsSet()) |
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.
: switch jail waiting ?
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
@@ -68,6 +71,8 @@ type validatorStatistics struct { | |||
genesisNonce uint64 | |||
ratingEnableEpoch uint32 | |||
lastFinalizedRootHash []byte | |||
switchEnableEpoch uint32 | |||
flagJailedEnabled atomic.Flag |
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.
flagSwitchEnabled ?
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.
renamed to jailedEnableEpoch
process/peer/process.go
Outdated
// EpochConfirmed is called whenever a new epoch is confirmed | ||
func (vs *validatorStatistics) EpochConfirmed(epoch uint32) { | ||
vs.flagJailedEnabled.Toggle(epoch >= vs.switchEnableEpoch) | ||
log.Debug("validatorStatistics: switch", "enabled", vs.flagJailedEnabled.IsSet()) |
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.
: switch jail waiting ?
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.
renamed to jailed
} | ||
|
||
if stakingData.JailedNonce == nonce && account.GetList() != string(core.InactiveList) { | ||
account.SetListAndIndex(account.GetShardId(), string(core.LeavingList), uint32(stakingData.JailedNonce)) |
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.
LeavingList ?
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.
old code - not relevant - deleted
totalUnJailPrice := big.NewInt(0).Mul(auctionConfig.UnJailPrice, big.NewInt(int64(len(args.Arguments)))) | ||
|
||
if totalUnJailPrice.Cmp(args.CallValue) != 0 { | ||
s.eei.AddReturnMessage("insufficient funds sent for unJail") |
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.
insufficient or incorrect ?
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 is copied from mainnet version and should be left as it is.
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.
ok
# Conflicts: # vm/errors.go # vm/systemSmartContracts/auction.go
0c0c005
} | ||
if args.GenesisTotalSupply == nil || args.GenesisTotalSupply.Cmp(zero) <= 0 { | ||
return nil, fmt.Errorf("%w, value is %v", vm.ErrInvalidGenesisTotalSupply, args.GenesisTotalSupply) | ||
} |
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.
L210 is incompatible with the mainnet running version:
mainnet:
s.eei.AddReturnMessage("could not get all blsKeys from registration data: error " + err.Error())
err = errors.New("public key missmatch")
here:
s.eei.AddReturnMessage("could not get all blsKeys from registration data: " + vm.ErrBLSPublicKeyMissmatch.Error())
var ErrBLSPublicKeyMissmatch = errors.New("public key missmatch")
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.
pushed
@@ -50,6 +50,9 @@ var ErrInvalidMinStakeValue = errors.New("invalid min stake value") | |||
// ErrInvalidNodePrice signals that an invalid node price was provided | |||
var ErrInvalidNodePrice = errors.New("invalid node price") | |||
|
|||
// ErrInvalidMinStepValue signals that an invalid min step value was provided | |||
var ErrInvalidMinStepValue = errors.New("invalid min step value") |
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.
Should add comments on exported items in vm/consts.go
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.
that is from a pull request from Radu already merged in development./
# Conflicts: # cmd/node/factory/structs.go # integrationTests/testProcessorNode.go # process/scToProtocol/stakingToPeer.go # process/scToProtocol/stakingToPeer_test.go # vm/systemSmartContracts/staking.go
vm/systemSmartContracts/staking.go
Outdated
@@ -1336,6 +1336,52 @@ func (r *stakingSC) getRemainingUnbondPeriod(args *vmcommon.ContractCallInput) v | |||
return vmcommon.Ok | |||
} | |||
|
|||
func (r *stakingSC) getWaitingListRegisterNonceAndRewardAddress(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { |
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 should be unit tested in a future PR.
UnStakeNotEnabled = "unStake is not enabled" | ||
TransactionValueMustBeZero = "transaction value must be zero" | ||
CannotGetOrCreateRegistrationData = "cannot get or create registration data: error - " | ||
// InsufficientGasLimit defined constant for return message |
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.
"defines a constant" instead "defined constant" in all comments
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.
👍
making code backward compatible even if there was a jailed node