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

FEAT: Allow to update epoch period #93

Merged
merged 5 commits into from
May 10, 2024
Merged

Conversation

ChainDev931105
Copy link
Contributor

@ChainDev931105 ChainDev931105 commented May 8, 2024

Context

Closes: #91
Closes: #94


Reviewers

@ChainDev931105 ChainDev931105 requested a review from a team May 8, 2024 19:04
@ChainDev931105 ChainDev931105 marked this pull request as draft May 8, 2024 19:04
@ChainDev931105 ChainDev931105 marked this pull request as ready for review May 9, 2024 12:52
@ChainDev931105 ChainDev931105 changed the title DRAFT: Allow to update epoch period FEAT: Allow to update epoch period May 9, 2024
@@ -114,4 +114,9 @@ interface ILagrangeCommittee {

// Fired on successful rotation of committee
event UpdateCommittee(uint256 indexed chainID, uint256 indexed epochNumber, bytes32 current);

// Event fired on writing epoch history
event EpochHistoryWritten(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
event EpochHistoryWritten(
event EpochPeriodUpdated(

@@ -21,6 +22,15 @@ contract LagrangeCommittee is Initializable, OwnableUpgradeable, ILagrangeCommit
uint32[] public chainIDs;
// ChainID => Committee
mapping(uint32 => CommitteeDef) public committeeParams;

// committees is also used for external storage for epoch period modification
// committees[chainID][uint256.max].leafCount = modified times of epoch
Copy link
Contributor

Choose a reason for hiding this comment

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

current index of epoch period


// committees is also used for external storage for epoch period modification
// committees[chainID][uint256.max].leafCount = modified times of epoch
// committees[chainID][uint256.max - 1] : original epoch_period
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// committees[chainID][uint256.max - 1] : original epoch_period
// committees[chainID][uint256.max - 1] : 0-index
// committees[chainID][uint256.max - 2] : 1-index
// ....

@@ -57,6 +67,18 @@ contract LagrangeCommittee is Initializable, OwnableUpgradeable, ILagrangeCommit
_transferOwnership(initialOwner);
}

// Initializes epoch history
// @dev This function can be called for the chainID registered in the previous version
function initEpochHistory(uint32 chainID) public onlyOwner {
Copy link
Contributor

Choose a reason for hiding this comment

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

setFirstEpochPeriod

committeeParams[_chainID] = CommitteeDef(
_startBlock, _l1Bias, _genesisBlock, _duration, _freezeDuration, _quorumNumber, _minWeight, _maxWeight
);

Copy link
Contributor

Choose a reason for hiding this comment

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

move down

if (_isEpochPeriodUpdating) {
uint32 _historyCount = _getEpochHistoryCount(_chainID);
uint256 _flagEpoch = _getEpochNumber(_chainID, block.number - 1) + 1;
(,, uint256 _flagBlock) = _getEpochInterval(_chainID, _flagEpoch - 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
(,, uint256 _flagBlock) = _getEpochInterval(_chainID, _flagEpoch - 1);
(,, uint256 _flagEpochEndBlock) = _getEpochInterval(_chainID, _flagEpoch - 1);

return committees[_chainID][type(uint256).max].leafCount;
}

function _setEpochHistoryCount(uint32 _chainID, uint32 _count) internal {
Copy link
Contributor

Choose a reason for hiding this comment

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

get rid of it

if (_blockNumber < committeeParams[_chainID].genesisBlock) {
return 0;
}
// We assume that _historyHistoryCount is not bigger than 10
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// We assume that _historyHistoryCount is not bigger than 10
// epoch period would be updated rarely

@ChainDev931105
Copy link
Contributor Author

@cool-develope , Thanks for your review.

I've fixed them. Could you review again?


// Get epoch period Period
// @note 1-indexed
function getPastEpochPeriod(uint32 chainID, uint32 index)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
function getPastEpochPeriod(uint32 chainID, uint32 index)
function getEpochPeriodByIndex(uint32 chainID, uint32 index)

emit UpdateCommitteeParams(
_chainID, _quorumNumber, _l1Bias, _genesisBlock, _duration, _freezeDuration, _minWeight, _maxWeight
);
}

// ------------ Internal functions for Epoch Number ------------ //
function _getEpochPeriodCount(uint32 _chainID) internal view returns (uint32) {
Copy link
Contributor

Choose a reason for hiding this comment

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

remove it

committees[_chainID][type(uint256).max].leafCount = _count;
}

function _readEpochPeriod(uint32 _chainID, uint32 _index)
Copy link
Contributor

Choose a reason for hiding this comment

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

make public

@@ -323,18 +343,12 @@ contract LagrangeCommittee is Initializable, OwnableUpgradeable, ILagrangeCommit
}

// Computes epoch number for a chain's committee at a given block
function getEpochNumber(uint32 chainID, uint256 blockNumber) public view returns (uint256) {
function getEpochNumber(uint32 chainID, uint256 l1BlockNumber) public view returns (uint256 epochNumber) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
function getEpochNumber(uint32 chainID, uint256 l1BlockNumber) public view returns (uint256 epochNumber) {
function getEpochNumber(uint32 chainID, uint256 blockNumber) public view returns (uint256 epochNumber) {

Copy link
Contributor

@cool-develope cool-develope left a comment

Choose a reason for hiding this comment

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

LGTM!

@ChainDev931105 ChainDev931105 merged commit 28bc7c3 into develop May 10, 2024
2 checks passed
@ChainDev931105 ChainDev931105 deleted the feat/epoch_period_modify branch May 10, 2024 00:19
ChainDev931105 added a commit that referenced this pull request Jun 3, 2024
* fix: clean up and add LICENSE (#78)

* clean up code

* clean build

* update license

* add audit reports

* fix committee.test.js (#79)

* revert epoch (#85)

* adjust operator count (#84)

* add workflow (#89)

* feat: update the BLS key and signer address (#88)

* allow to update the bls keys and signer address

* add tests

---------

Co-authored-by: Master Engineer <104206186+mastereng12@users.noreply.github.com>

* FEAT: Allow to update epoch period (#93)

* epoch_modifi draft

* update epoch formula

* fix reviewed issues

* fix reviewed issues

* fix naming of getEpochNumber

* epoch period modify unit test (#97)

* CHORE: Epoch period modify simulation (#98)

* simulation test for epoch period modify

* fix issue in redeloy script

* format

* fix: avoid to remove all bls pub keys (#102)

* fix the remove bls keys

* more tests

* fix audit issues

* add audit report

* add redeploy script

* update script for redeploy

---------

Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com>
Co-authored-by: Master Engineer <104206186+mastereng12@users.noreply.github.com>
ChainDev931105 added a commit that referenced this pull request Jul 30, 2024
* fix: clean up and add LICENSE (#78)

* clean up code

* clean build

* update license

* add audit reports

* fix committee.test.js (#79)

* revert epoch (#85)

* adjust operator count (#84)

* add workflow (#89)

* feat: update the BLS key and signer address (#88)

* allow to update the bls keys and signer address

* add tests

---------

Co-authored-by: Master Engineer <104206186+mastereng12@users.noreply.github.com>

* FEAT: Allow to update epoch period (#93)

* epoch_modifi draft

* update epoch formula

* fix reviewed issues

* fix reviewed issues

* fix naming of getEpochNumber

* epoch period modify unit test (#97)

* CHORE: Epoch period modify simulation (#98)

* simulation test for epoch period modify

* fix issue in redeloy script

* format

* fix: avoid to remove all bls pub keys (#102)

* fix the remove bls keys

* more tests

* Workflow with solhint (#101)

* solhint cli

* update solhint checkpoints

* Update contracts/protocol/VoteWeigher.sol

Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com>

---------

Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com>

* FEAT: eject operator (#105)

* feat eject operator

* fix reviewed errors

* strengthen test

* unsubscribe multiple operators

* FEAT: Deploy to Sepolia (#106)

* deploy sepolia

* testnet deploy script

Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com>

* add eigen sepolia addresses

---------

Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com>

* add fork test for rotate and revert (#107)

* Docker workflow (#109)

* push-docker yml

* add permission makefile

* push-docker-test

* install forge build

* remove test yml

* CHORE: Script for register chain (#108)

* add register chain script

* update epoch period

* update min/max weight

* update genersis block

* add basescript

* script eject op

* [FIX] Register operator sleep (#110)

* fix register-operator sleep

* remove test yml

* archive mode geth (#112)

* fix: geth docker cmd (#113)

* archive mode geth

* fix

* [Fix] audited issues (#115)

* fix audit issues

* add audit report

* Make epoch period flexible (#118)

* epoch period flexible

* test for epoch period flex

* add simulation test for flex period

* fix epoch period for prior blocks

* flow auto release (#127)

* add issue templates (#130)

* Script - Transfer ownership (#121)

* forge install: safe-smart-account

499b17ad0191b575fcadc5cb5b8e3faeae5391ae

* script transfer ownership

* Override for testnet committee - L1 Block Number (#123)

* testnet l1bias override

* fix annoying function naming

* feat: bls key ownership check (#138)

* bls key ownership check

* unit test & inherit checker

* optimize epoch number search

* fork test bls own check

* update storage hash

---------

Co-authored-by: ChainDev931105 <ethanackerland@gmail.com>

* epic sequencer bls key (#140)

* Revert "epic sequencer bls key (#140)" (#141)

This reverts commit 1e57449.

* fix deploy-register (#142)

* fix

* [FIX] Audit Issues - Main (#149)

* Update README.md (#136)

* [FIX] script redeploy testnet (#144)

* fix script redeploy testnet

* fix get_updated_l1_block

* solc version 0.8.20, blsKeyChecker issue

* digest hash add version field

* hardhat solidity version update

---------

Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com>

---------

Co-authored-by: Master Engineer <104206186+mastereng12@users.noreply.github.com>
Co-authored-by: ChainDev <76214877+ChainDev931105@users.noreply.github.com>
Co-authored-by: Kashish Shah <kashish@lagrange.dev>
Co-authored-by: ChainDev931105 <ethanackerland@gmail.com>
ChainDev931105 added a commit that referenced this pull request Aug 26, 2024
* fix: clean up and add LICENSE (#78)

* clean up code

* clean build

* update license

* add audit reports

* fix committee.test.js (#79)

* revert epoch (#85)

* adjust operator count (#84)

* add workflow (#89)

* feat: update the BLS key and signer address (#88)

* allow to update the bls keys and signer address

* add tests

---------

Co-authored-by: Master Engineer <104206186+mastereng12@users.noreply.github.com>

* FEAT: Allow to update epoch period (#93)

* epoch_modifi draft

* update epoch formula

* fix reviewed issues

* fix reviewed issues

* fix naming of getEpochNumber

* epoch period modify unit test (#97)

* CHORE: Epoch period modify simulation (#98)

* simulation test for epoch period modify

* fix issue in redeloy script

* format

* fix: avoid to remove all bls pub keys (#102)

* fix the remove bls keys

* more tests

* Workflow with solhint (#101)

* solhint cli

* update solhint checkpoints

* Update contracts/protocol/VoteWeigher.sol

Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com>

---------

Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com>

* FEAT: eject operator (#105)

* feat eject operator

* fix reviewed errors

* strengthen test

* unsubscribe multiple operators

* FEAT: Deploy to Sepolia (#106)

* deploy sepolia

* testnet deploy script

Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com>

* add eigen sepolia addresses

---------

Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com>

* add fork test for rotate and revert (#107)

* Docker workflow (#109)

* push-docker yml

* add permission makefile

* push-docker-test

* install forge build

* remove test yml

* CHORE: Script for register chain (#108)

* add register chain script

* update epoch period

* update min/max weight

* update genersis block

* add basescript

* script eject op

* [FIX] Register operator sleep (#110)

* fix register-operator sleep

* remove test yml

* archive mode geth (#112)

* fix: geth docker cmd (#113)

* archive mode geth

* fix

* [Fix] audited issues (#115)

* fix audit issues

* add audit report

* Make epoch period flexible (#118)

* epoch period flexible

* test for epoch period flex

* add simulation test for flex period

* fix epoch period for prior blocks

* flow auto release (#127)

* add issue templates (#130)

* Script - Transfer ownership (#121)

* forge install: safe-smart-account

499b17ad0191b575fcadc5cb5b8e3faeae5391ae

* script transfer ownership

* Override for testnet committee - L1 Block Number (#123)

* testnet l1bias override

* fix annoying function naming

* feat: bls key ownership check (#138)

* bls key ownership check

* unit test & inherit checker

* optimize epoch number search

* fork test bls own check

* update storage hash

---------

Co-authored-by: ChainDev931105 <ethanackerland@gmail.com>

* epic sequencer bls key (#140)

* Revert "epic sequencer bls key (#140)" (#141)

This reverts commit 1e57449.

* fix deploy-register (#142)

* update readme

---------

Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com>
Co-authored-by: Master Engineer <104206186+mastereng12@users.noreply.github.com>
Co-authored-by: Kashish Shah <kashish@lagrange.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants