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

[R4R]: new implement of BEP-127 #3

Merged
merged 23 commits into from
Feb 25, 2022
Merged

Conversation

gothery001
Copy link

BEP-127: Temporary Maintenance Mode for Validators

1. Summary

This BEP introduces the Temporary Maintenance mode for validators on the Binance Smart Chain.

2. Abstract

Temporary Maintenance is supposed to last one or a few hours. The validator seat will be temporarily dropped from the block producing rotation during the maintenance. Since long-time offline maintenance is not encouraged, the validator will still be slashed if the maintenance lasts too long. To lower the impact from poorly-operating validators who forget to claim its maintenance, they will be forced to enter Temporary Maintenance mode too.

3. Status

Draft.

4. Motivation

Due to the design of Parlia consensus, the absence of the validator, even if it is due to scheduled maintenance, will cause instability and capacity loss of BSC due to the extra waiting time and chain reorganization for other validators. Introducing Temporary Maintenance mode will stabilize the blocking rotation and maintain the capacity of BSC.

5. Specification

Current Slash Mechanisms

The slash contract will record the missed blocking metrics of each validator.

  • Once the metrics are above the predefined threshold, the blocking reward for validator will not be relayed to BC for distribution but shared with other better validators.
  • If the metrics remain above another higher level of threshold, the validator will be dropped from the rotation, and put as “in jail”. This will be propagated back to Binance Chain, where a predefined amount of BNB would be slashed from the self-delegated BNB of the validator.

Temporary Maintenance Mode

Proactive Maintenance

Validator can claim itself to enter scheduled maintenance by sending a transaction signed by the consensus key. The validator can claim itself to exit maintenance by sending another transaction. The slash cleaning work will be done within the exit transaction:

SlashCount = (MaintenanceEndHeight - MaintenanceStartHeight)/len(currentValidatorSet)/Scale

Scale is a governable parameter, the initial setting is 2, usually it should be larger than 1. If SlashCount is larger than a predefined value, the validator will still be slashed. The validator can get more time to bring the node back before being slashed if it claims itself to enter maintenance. Validator is encouraged to claim itself to exit maintenance even if it will be put in jail, since it can send the unjail transaction earlier.

Passive Maintenance

Once the number of missed blocks is above a predefined threshold, the validator will enter maintenance automatically. The validator still gets a chance to catch up and claim itself online again.

Limit

  1. The number of maintained validators has an upper limit at the same time. Once exceeded, the following proactive/passive claim request will be rejected.
  2. A validator can only enter maintenance once per day.

ValidatorSet Change

The validators election will repeat every 24 hours, the maintenance will end immediately once election happens.

Impact to Validator Maintainers

Validator maintainers can claim the validator to enter maintenance mode once the node runs into unexpected issues. Validator maintainers need to send transactions to exit maintenance mode even if the validator is enforced into maintenance, otherwise, the validator may be put in jail.

6. License

The content is licensed under CC0.

@gothery001 gothery001 changed the title [WIP]: new implement of BEP-127 [R4R]: new implement of BEP-127 Feb 24, 2022
NashBC
NashBC previously approved these changes Feb 24, 2022
Copy link

@NashBC NashBC left a comment

Choose a reason for hiding this comment

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

LGTM

forcodedancing
forcodedancing previously approved these changes Feb 25, 2022
}

// 2. clear all maintain info
numOfMaintaining = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Duplicated code here, since doupdate will do this.

Copy link
Author

Choose a reason for hiding this comment

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

fixed

realuncle
realuncle previously approved these changes Feb 25, 2022
@NashBC
Copy link

NashBC commented Feb 25, 2022

LGTM. Another little suggestion, can we reorg the commit, really no need to show so many commits.

@gothery001
Copy link
Author

LGTM. Another little suggestion, can we reorg the commit, really no need to show so many commits.

It will be squash merged, no worry

@gothery001 gothery001 merged commit 1dd4ce1 into Blockorus:develop Feb 25, 2022
gothery001 added a commit to gothery001/bsc-genesis-contract that referenced this pull request Apr 28, 2022
* [R4R]: new implement of BEP-127 (Blockorus#3)

* feat: new implement of bep-127 and test

* fix: review comments

* fix: add re-init for validatorExtraSet

* fix: template file sync

* fix: validatorExtraSet should init at the same time as `maxNumOfMaintaining` init

* modify config

* fix: maintainInfo leak at next 24-hours

* chores: add comment

* fix: `isCurrentValidator` error before `validatorExtraSet` init

* chore

* test: add test case for BSCValidatorSet

* test: add view test case for BSCValidatorSet

* chore: modify comments

* fix: numOfMaintaining modification on edge case

* fix: review comments

* test: add code size log

* chore: optimize new ValidatorExtra

* fix: numOfMaintaining edge case

* fix: add exitMaintenance event

* fix: add exitMaintenance event

* chore

* fix: remove unused code

* chore

* implement bep-131

* update ut

* update logic of felony function

* update the getMiningValidators function

* update logic of the update maxNumOfCandidates function

* fix calculating epoch number

* update _exitMaintenance

* fix comments

* update readme

* fix testcase on slash and validator contract

* fix update maxNumOfMaintaining

* fix: bug that validatorSet order was changed incorrectly while _felony in _forceMaintainingValidatorsExit, using numOfCabinets not init

* feat: modify slots number

* chore: rename var in loop

* Fix audit report of BEP-127 and BEP-131 (Blockorus#17)

* fix: issue #BSC-007, add more comment to explain `enterMaintenanceHeight` check

* fix: issue #BSC-001 and #BSC-002, #BSC-003, improve code to save gas

* fix: issue #BSC-008, add comment to explain this

* feat: sync template code with origin code

* feat: rename len to validatorsNum

* chore: modify comment for check

* chore: sync template code

* chore: add more comments to explain `24-hour period`

* fix: k = 0 => k

* fix: j = 0 => j

* feat: sync template code for SlashIndicator.template

Co-authored-by: gothery001 <gothery001>

* fix: Bug fix that incorrectly modification of fixing audit report (Blockorus#18)

* fix: incorrectly modified `initValidatorExtraSet`

* chore: sync template code

Co-authored-by: gothery001 <gothery001>

* fix: bug that slash count calculation problem while update validator set (Blockorus#19)

* feat: add more test case to test slashCount calc problem

* fix: fix workValidatorCount calc incorrectly changed while updateValidatorSet

* chores: sync tmeplate code

* feat: add generate-qa script

* feat: close gas report as default

* feat: modify tests

* chores: add more comments

* chores: add more comments

Co-authored-by: gothery001 <gothery001>

Co-authored-by: dean65 <dean950605@gmail.com>
Co-authored-by: dean <97718205+dean65@users.noreply.github.com>
Co-authored-by: realuncle <walt@nodereal.io>
Co-authored-by: realuncle <90668111+realuncle@users.noreply.github.com>
Co-authored-by: realuncle <uncledude@sina.com>
Co-authored-by: gothery001 <gothery001>
realuncle referenced this pull request in node-real/bsc-genesis-contract Apr 28, 2022
* Implement bep-127 and bep-131 (bnb-chain#131)

* [R4R]: new implement of BEP-127 (#3)

* feat: new implement of bep-127 and test

* fix: review comments

* fix: add re-init for validatorExtraSet

* fix: template file sync

* fix: validatorExtraSet should init at the same time as `maxNumOfMaintaining` init

* modify config

* fix: maintainInfo leak at next 24-hours

* chores: add comment

* fix: `isCurrentValidator` error before `validatorExtraSet` init

* chore

* test: add test case for BSCValidatorSet

* test: add view test case for BSCValidatorSet

* chore: modify comments

* fix: numOfMaintaining modification on edge case

* fix: review comments

* test: add code size log

* chore: optimize new ValidatorExtra

* fix: numOfMaintaining edge case

* fix: add exitMaintenance event

* fix: add exitMaintenance event

* chore

* fix: remove unused code

* chore

* implement bep-131

* update ut

* update logic of felony function

* update the getMiningValidators function

* update logic of the update maxNumOfCandidates function

* fix calculating epoch number

* update _exitMaintenance

* fix comments

* update readme

* fix testcase on slash and validator contract

* fix update maxNumOfMaintaining

* fix: bug that validatorSet order was changed incorrectly while _felony in _forceMaintainingValidatorsExit, using numOfCabinets not init

* feat: modify slots number

* chore: rename var in loop

* Fix audit report of BEP-127 and BEP-131 (Blockorus#17)

* fix: issue #BSC-007, add more comment to explain `enterMaintenanceHeight` check

* fix: issue #BSC-001 and #BSC-002, #BSC-003, improve code to save gas

* fix: issue #BSC-008, add comment to explain this

* feat: sync template code with origin code

* feat: rename len to validatorsNum

* chore: modify comment for check

* chore: sync template code

* chore: add more comments to explain `24-hour period`

* fix: k = 0 => k

* fix: j = 0 => j

* feat: sync template code for SlashIndicator.template

Co-authored-by: gothery001 <gothery001>

* fix: Bug fix that incorrectly modification of fixing audit report (Blockorus#18)

* fix: incorrectly modified `initValidatorExtraSet`

* chore: sync template code

Co-authored-by: gothery001 <gothery001>

* fix: bug that slash count calculation problem while update validator set (Blockorus#19)

* feat: add more test case to test slashCount calc problem

* fix: fix workValidatorCount calc incorrectly changed while updateValidatorSet

* chores: sync tmeplate code

* feat: add generate-qa script

* feat: close gas report as default

* feat: modify tests

* chores: add more comments

* chores: add more comments

Co-authored-by: gothery001 <gothery001>

Co-authored-by: dean65 <dean950605@gmail.com>
Co-authored-by: dean <97718205+dean65@users.noreply.github.com>
Co-authored-by: realuncle <walt@nodereal.io>
Co-authored-by: realuncle <90668111+realuncle@users.noreply.github.com>
Co-authored-by: realuncle <uncledude@sina.com>
Co-authored-by: gothery001 <gothery001>

* chore: modify generate script line in package.json (bnb-chain#139)

* chore: modify generate script line in package.json, generate latest genesis.json for mainnet

* chore: modify readme

Co-authored-by: cosinlink <cosinlink>

Co-authored-by: Gothery <90246878+gothery001@users.noreply.github.com>
Co-authored-by: dean65 <dean950605@gmail.com>
Co-authored-by: dean <97718205+dean65@users.noreply.github.com>
Co-authored-by: realuncle <walt@nodereal.io>
Co-authored-by: realuncle <90668111+realuncle@users.noreply.github.com>
Co-authored-by: realuncle <uncledude@sina.com>
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