From 19ab6e1c2660d918a78282008aef3beebe501d8f Mon Sep 17 00:00:00 2001 From: JK Date: Fri, 1 Nov 2024 06:01:43 +0100 Subject: [PATCH] Remove unnecessary genesis params and migration func --- contracts/interfaces/ISFC.sol | 21 ++------------------- contracts/sfc/NodeDriver.sol | 22 ++-------------------- contracts/sfc/NodeDriverAuth.sol | 22 ++-------------------- contracts/sfc/SFC.sol | 31 +++++-------------------------- test/NodeDriver.ts | 6 +----- test/SFC.ts | 19 ++++--------------- 6 files changed, 16 insertions(+), 105 deletions(-) diff --git a/contracts/interfaces/ISFC.sol b/contracts/interfaces/ISFC.sol index 1a5a304..f7ac262 100644 --- a/contracts/interfaces/ISFC.sol +++ b/contracts/interfaces/ISFC.sol @@ -32,9 +32,7 @@ interface ISFC { uint256 endTime, uint256 endBlock, uint256 epochFee, - uint256 totalBaseRewardWeight, - uint256 totalTxRewardWeight, - uint256 _baseRewardPerSecond, + uint256 baseRewardPerSecond, uint256 totalStake, uint256 totalSupply ); @@ -138,10 +136,6 @@ interface ISFC { function restakeRewards(uint256 toValidatorID) external; - function updateBaseRewardPerSecond(uint256 value) external; - - function updateOfflinePenaltyThreshold(uint256 blocksNum, uint256 time) external; - function updateSlashingRefundRatio(uint256 validatorID, uint256 refundRatio) external; function updateTreasuryAddress(address v) external; @@ -166,16 +160,7 @@ interface ISFC { address _owner ) external; - function setGenesisValidator( - address auth, - uint256 validatorID, - bytes calldata pubkey, - uint256 status, - uint256 createdEpoch, - uint256 createdTime, - uint256 deactivatedEpoch, - uint256 deactivatedTime - ) external; + function setGenesisValidator(address auth, uint256 validatorID, bytes calldata pubkey, uint256 createdTime) external; function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake) external; @@ -185,8 +170,6 @@ interface ISFC { function updateValidatorPubkey(bytes calldata pubkey) external; - function migrateValidatorPubkeyUniquenessFlag(uint256 start, uint256 end) external; - function setRedirectionAuthorizer(address v) external; function announceRedirection(address to) external; diff --git a/contracts/sfc/NodeDriver.sol b/contracts/sfc/NodeDriver.sol index 99f1a69..0867abb 100644 --- a/contracts/sfc/NodeDriver.sol +++ b/contracts/sfc/NodeDriver.sol @@ -88,26 +88,8 @@ contract NodeDriver is Initializable { // Methods which are called only by the node - function setGenesisValidator( - address _auth, - uint256 validatorID, - bytes calldata pubkey, - uint256 status, - uint256 createdEpoch, - uint256 createdTime, - uint256 deactivatedEpoch, - uint256 deactivatedTime - ) external onlyNode { - backend.setGenesisValidator( - _auth, - validatorID, - pubkey, - status, - createdEpoch, - createdTime, - deactivatedEpoch, - deactivatedTime - ); + function setGenesisValidator(address auth, uint256 validatorID, bytes calldata pubkey, uint256 createdTime) external onlyNode { + backend.setGenesisValidator(auth, validatorID, pubkey, createdTime); } function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake) external onlyNode { diff --git a/contracts/sfc/NodeDriverAuth.sol b/contracts/sfc/NodeDriverAuth.sol index eab3348..be1eca8 100644 --- a/contracts/sfc/NodeDriverAuth.sol +++ b/contracts/sfc/NodeDriverAuth.sol @@ -116,26 +116,8 @@ contract NodeDriverAuth is Initializable, Ownable { driver.updateValidatorPubkey(validatorID, pubkey); } - function setGenesisValidator( - address _auth, - uint256 validatorID, - bytes calldata pubkey, - uint256 status, - uint256 createdEpoch, - uint256 createdTime, - uint256 deactivatedEpoch, - uint256 deactivatedTime - ) external onlyDriver { - sfc.setGenesisValidator( - _auth, - validatorID, - pubkey, - status, - createdEpoch, - createdTime, - deactivatedEpoch, - deactivatedTime - ); + function setGenesisValidator(address auth, uint256 validatorID, bytes calldata pubkey, uint256 createdTime) external onlyDriver { + sfc.setGenesisValidator(auth, validatorID, pubkey, createdTime); } function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake) external onlyDriver { diff --git a/contracts/sfc/SFC.sol b/contracts/sfc/SFC.sol index 55a740a..5bf72b4 100644 --- a/contracts/sfc/SFC.sol +++ b/contracts/sfc/SFC.sol @@ -238,18 +238,6 @@ contract SFC is Initializable, Ownable, Version { revert TransfersNotAllowed(); } - function migrateValidatorPubkeyUniquenessFlag(uint256 start, uint256 end) external { - for (uint256 vid = start; vid < end; vid++) { - bytes memory pubkey = getValidatorPubkey[vid]; - if (pubkey.length > 0 && pubkeyHashToValidatorID[keccak256(pubkey)] != vid) { - if (pubkeyHashToValidatorID[keccak256(pubkey)] != 0) { - revert PubkeyUsedByOtherValidator(); - } - pubkeyHashToValidatorID[keccak256(pubkey)] = vid; - } - } - } - function updateValidatorPubkey(bytes calldata pubkey) external { if (pubkey.length != 66 || pubkey[0] != 0xc0) { revert MalformedPubkey(); @@ -351,25 +339,16 @@ contract SFC is Initializable, Ownable, Version { node.updateMinGasPrice(minGasPrice); } - function setGenesisValidator( - address auth, - uint256 validatorID, - bytes calldata pubkey, - uint256 status, - uint256 createdEpoch, - uint256 createdTime, - uint256 deactivatedEpoch, - uint256 deactivatedTime - ) external onlyDriver { + function setGenesisValidator(address auth, uint256 validatorID, bytes calldata pubkey, uint256 createdTime) external onlyDriver { _rawCreateValidator( auth, validatorID, pubkey, - status, - createdEpoch, + OK_STATUS, + 0, // createdEpoch createdTime, - deactivatedEpoch, - deactivatedTime + 0, // deactivatedEpoch - not deactivated + 0 // deactivatedTime - not deactivated ); if (validatorID > lastValidatorID) { lastValidatorID = validatorID; diff --git a/test/NodeDriver.ts b/test/NodeDriver.ts index 75b1ee3..f9a25c1 100644 --- a/test/NodeDriver.ts +++ b/test/NodeDriver.ts @@ -123,11 +123,7 @@ describe('NodeDriver', () => { account, 1, account.publicKey, - 0, - await this.sfc.currentEpoch(), Date.now(), - 0, - 0, ), ).to.be.revertedWithCustomError(this.nodeDriver, 'NotNode'); }); @@ -143,7 +139,7 @@ describe('NodeDriver', () => { it('Should revert when not node', async function () { const account = ethers.Wallet.createRandom(); await expect( - this.nodeDriver.setGenesisDelegation(account, 1, 100, 0, 0, 0, 0, 0, 1000), + this.nodeDriver.setGenesisDelegation(account, 1, 100), ).to.be.revertedWithCustomError(this.nodeDriver, 'NotNode'); }); }); diff --git a/test/SFC.ts b/test/SFC.ts index b4623c8..692e7c9 100644 --- a/test/SFC.ts +++ b/test/SFC.ts @@ -60,12 +60,9 @@ describe('SFC', () => { validator.address, 1, validator.publicKey, - 1 << 3, - await this.sfc.currentEpoch(), Date.now(), - 0, - 0, ); + await this.sfc.deactivateValidator(1, 1 << 3); await this.sfc.disableNonNodeCalls(); }); @@ -319,18 +316,14 @@ describe('SFC', () => { validator, 1, validator.publicKey, - 0, - await this.sfc.currentEpoch(), Date.now(), - 0, - 0, ), ).to.be.revertedWithCustomError(this.sfc, 'NotDriverAuth'); }); it('Should revert when setGenesisDelegation is not called not node', async function () { const delegator = ethers.Wallet.createRandom(); - await expect(this.sfc.setGenesisDelegation(delegator, 1, 100, 0, 0, 0, 0, 0, 1000)).to.be.revertedWithCustomError( + await expect(this.sfc.setGenesisDelegation(delegator, 1, 100)).to.be.revertedWithCustomError( this.sfc, 'NotDriverAuth', ); @@ -981,18 +974,14 @@ describe('SFC', () => { this.delegator, 1, key, - 1 << 3, - await this.sfc.currentEpoch(), Date.now(), - 0, - 0, ), ).to.be.revertedWithCustomError(this.nodeDriverAuth, 'NotDriver'); }); it('Should revert when calling setGenesisDelegation if not NodeDriver', async function () { await expect( - this.nodeDriverAuth.setGenesisDelegation(this.delegator, 1, 100, 0, 0, 0, 0, 0, 1000), + this.nodeDriverAuth.setGenesisDelegation(this.delegator, 1, 100), ).to.be.revertedWithCustomError(this.nodeDriverAuth, 'NotDriver'); }); @@ -1131,7 +1120,7 @@ describe('SFC', () => { }); it('Should succeed and setGenesisDelegation Validator', async function () { - await this.sfc.setGenesisDelegation(this.delegator, this.validatorId, ethers.parseEther('1'), 0, 0, 0, 0, 0, 100); + await this.sfc.setGenesisDelegation(this.delegator, this.validatorId, ethers.parseEther('1')); // delegator has already delegated 0.4 in fixture expect(await this.sfc.getStake(this.delegator, this.validatorId)).to.equal(ethers.parseEther('1.4')); });