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

jailed-node-backward-compatible #2303

Merged
merged 17 commits into from
Sep 24, 2020

Conversation

sasurobert
Copy link
Contributor

making code backward compatible even if there was a jailed node

epochStart/metachain/systemSCs.go Show resolved Hide resolved
epochStart/metachain/systemSCs.go Outdated Show resolved Hide resolved
@@ -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 {
Copy link
Contributor

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?

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

@@ -421,16 +432,38 @@ func (vs *validatorStatistics) getValidatorDataFromLeaves(
return validators, nil
}

func getActualList(peerAccount state.PeerAccountHandler) string {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

best function ever.

@@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

bool var?

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


// EpochConfirmed is called whenever a new epoch is confirmed
func (vs *validatorStatistics) EpochConfirmed(epoch uint32) {
vs.flagSwitchEnabled.Toggle(epoch >= vs.switchEnableEpoch)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

iulianpascalau
iulianpascalau previously approved these changes Sep 21, 2020
iulianpascalau
iulianpascalau previously approved these changes Sep 22, 2020
iulianpascalau
iulianpascalau previously approved these changes Sep 23, 2020
Copy link
Contributor

@iulianpascalau iulianpascalau left a 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)
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 replace validator.List with string(core.JailedList) to be more clear what is about to do here

@@ -40,6 +44,8 @@ type systemSCProcessor struct {
validatorInfoCreator epochStart.ValidatorInfoCreator
endOfEpochCallerAddress []byte
stakingSCAddress []byte
switchUnJailEnableEpoch uint32
Copy link
Contributor

Choose a reason for hiding this comment

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

switchJailWaitingEnableEpoch or switchEnableEpoch ?

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

// 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())
Copy link
Contributor

Choose a reason for hiding this comment

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

: switch jail waiting ?

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

@@ -68,6 +71,8 @@ type validatorStatistics struct {
genesisNonce uint64
ratingEnableEpoch uint32
lastFinalizedRootHash []byte
switchEnableEpoch uint32
flagJailedEnabled atomic.Flag
Copy link
Contributor

Choose a reason for hiding this comment

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

flagSwitchEnabled ?

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 to jailedEnableEpoch

// 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())
Copy link
Contributor

Choose a reason for hiding this comment

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

: switch jail waiting ?

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 to jailed

}

if stakingData.JailedNonce == nonce && account.GetList() != string(core.InactiveList) {
account.SetListAndIndex(account.GetShardId(), string(core.LeavingList), uint32(stakingData.JailedNonce))
Copy link
Contributor

Choose a reason for hiding this comment

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

LeavingList ?

Copy link
Contributor Author

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")
Copy link
Contributor

Choose a reason for hiding this comment

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

insufficient or incorrect ?

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 is copied from mainnet version and should be left as it is.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

iulianpascalau
iulianpascalau previously approved these changes Sep 23, 2020
vm/systemSmartContracts/auction.go Show resolved Hide resolved
vm/systemSmartContracts/auction.go Show resolved Hide resolved
}
if args.GenesisTotalSupply == nil || args.GenesisTotalSupply.Cmp(zero) <= 0 {
return nil, fmt.Errorf("%w, value is %v", vm.ErrInvalidGenesisTotalSupply, args.GenesisTotalSupply)
}
Copy link
Contributor

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")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pushed

vm/systemSmartContracts/auction.go Outdated Show resolved Hide resolved
vm/systemSmartContracts/auction.go Show resolved Hide resolved
@@ -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")
Copy link
Contributor

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

Copy link
Contributor Author

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
@@ -1336,6 +1336,52 @@ func (r *stakingSC) getRemainingUnbondPeriod(args *vmcommon.ContractCallInput) v
return vmcommon.Ok
}

func (r *stakingSC) getWaitingListRegisterNonceAndRewardAddress(args *vmcommon.ContractCallInput) vmcommon.ReturnCode {
Copy link
Contributor

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
Copy link
Contributor

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

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.

👍

@LucianMincu LucianMincu merged commit 98b3820 into development Sep 24, 2020
@LucianMincu LucianMincu deleted the unJail-full-backward-compatible branch September 24, 2020 12:48
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