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

consortium: implement rotating validators #412

Merged
merged 10 commits into from
May 21, 2024
Merged

Conversation

minh-bq
Copy link
Contributor

@minh-bq minh-bq commented Mar 7, 2024

This branch is used for rotating validators development

@minh-bq minh-bq force-pushed the feat/rotating-validator branch 2 times, most recently from 765982e to 178c382 Compare April 22, 2024 08:27
@minh-bq minh-bq marked this pull request as ready for review May 20, 2024 10:02
minh-bq and others added 10 commits May 21, 2024 17:18
* consortium-v2: implement RLP encoding for header extra data

* consortium-v2: integrate new RLP encoder/decoder for header extra data

* consortium-v2: optimize extra data rlp encoding

* consortium-v2: benchmark for new rlp encoding

* consortium-v2: clean up unit test

---------

Co-authored-by: Bui Quang Minh <minh.bui@skymavis.com>
Currently, only block producers can participate in voting process. However, after Tripp, vote permission is granted to a wider range of validator candidates (up to 64). Therefore, this PR differentiates block producers from validator candidates and enables logic for wider voter set. Moreover, voter weight is also introduced in order to determine reward distribution for every eligible candidates. Voter weight is computed based on candidates's staked amounts, according to the formula represented in: https://github.com/phuctd95/REPs/blob/main/REP-0010/REP-0010.md.

Additionally, after Tripp, the logic for getting validator set is also changed such that:

At the start of period, the first checkpoint block after 00:00 UTC, the list of validator candidates will be get from the contract once for whole period (~1 day).
At the start of epoch, the list of block producers will be get from the contract once for every epoch (~10 minutes).

* consortium-v2: make finality vote weight proportional to staked amount

Currently, the finality vote weights of all validators are the same. After this
commit, the finality vote weight is based on the staked amount of the validator.
The rule of finality vote weight follows what is stated in REP-0010: Introducing
Rotating Validators

	- If the staked amount of a validator is smaller than or equal to 1/22
	  of total stake, the weight is directly proportional to the staked
amount.
	- If the staked amount of a validator is bigger than 1/22 of total
	  stake, the weight equals 1/22 of total stake.

* consortium-v2: add period concept

After Tripp, the number of voters for finality block increases and the
set of voters is changed at the first checkpoint block of the new day
(in UTC time); therefore, it is necessary to introduce Period concept-
the first checkpoint block after the 00:00 UTC time.

* consortium-v2: get validator candidates from contract

Before, only block producers can vote for finality block. However, after
Tripp, most of validator candidates can participate in voting
process. Hence, this commit provides function to query validator
candidates from smart contract.

* consortium-v2: add list of block producers and staked amount of validators to extra data

Add two fields to header extra data and fix rlp encoder/decoder to
accommodate these fields.

* consortium-v2: add logic to get validators based on period and epoch

After Tripp, validator candidates are read only once at the start of new
period, whereas block producer address is read at the start of every
epoch.

* fix: replace deep copy with assignment and remove sig equality

* consortium-v2: use vote weight in validatorWithBlsPub, rename some functions

* consortium-v2: add assembleFinalityVote test, remove rlp optional tag

* consortium-v2: update logic checking period block

As recursively finding previous epoch is expensive, we provide to store
the current period in the snapshot, speeding up reading past current
period. In case the past snapshot with absent current period, we retrieved
in recursive manner.

* consortium-v2: update the NormalizeFinalityVoteWeight

* fix: add more check to verifyCascadingFields and log for period check

* consortium-v2: make finality vote change effective after Tripp period

The finality vote rule change is not effective right after Tripp hardfork but at
the start of following period. This commit adds TrippPeriod config to set period
of TrippBlock, the finality vote rule change is effective after the current
period is higher than that number.

* fix: compute isShillin once and remove unnecessary check in encoder

* chore: fix float number and add unit test for checking tripp block

---------

Co-authored-by: Bui Quang Minh <minh.bui@skymavis.com>
…eader (#447)

After Tripp is effective, the checkpoint validators in header's extra data is
set only at the period block, not at all checkpoint blocks anymore. So only
update snapshot's validator with bls public key when checkpoint validator is not
empty.
#449)

* consortium-v2: define MarshalJSON on a non-pointer ValidatorWithBlsPub

We want json.Marshal to invoke our custom MarshalJSON when be called with
non-pointer ValidatorWithBlsPub. In order to do that, we need to define
MarshalJSON on a non-pointer receiver.

* consortium-v2: add missing weight field to our customized json marshal
…425)

* consortium-v2: support consensus address change in profile contract

This commit adds a step to query profile id from consensus address to support
the consensus change feature. It also switches the function call to get BLS
public key to another function due to the breaking change in getId2Profile.

* consortium/contract: create contract call helper function

Make the contract call a helper function to clean up the code.

* consortium-v2: pass **big.Int into contract call's output

The maxValidatorNumber returns a *big.Int as an output. In order to get the
output value, we must pass an **big.Int to the contratCall not *big.Int.

Co-authored-by: andicrypt <keepgoing0901@gmail.com>

* consortium-v2: add unit tests for new contract call functions

---------

Co-authored-by: andicrypt <keepgoing0901@gmail.com>
@minh-bq minh-bq merged commit df81414 into master May 21, 2024
1 check passed
@minh-bq minh-bq deleted the feat/rotating-validator branch May 21, 2024 10:39
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

2 participants