Skip to content

Commit

Permalink
Remove unnecessary genesis params and migration func
Browse files Browse the repository at this point in the history
  • Loading branch information
thaarok committed Nov 1, 2024
1 parent 1bc06aa commit 19ab6e1
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 105 deletions.
21 changes: 2 additions & 19 deletions contracts/interfaces/ISFC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ interface ISFC {
uint256 endTime,
uint256 endBlock,
uint256 epochFee,
uint256 totalBaseRewardWeight,
uint256 totalTxRewardWeight,
uint256 _baseRewardPerSecond,
uint256 baseRewardPerSecond,
uint256 totalStake,
uint256 totalSupply
);
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down
22 changes: 2 additions & 20 deletions contracts/sfc/NodeDriver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 2 additions & 20 deletions contracts/sfc/NodeDriverAuth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 5 additions & 26 deletions contracts/sfc/SFC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 1 addition & 5 deletions test/NodeDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand All @@ -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');
});
});
Expand Down
19 changes: 4 additions & 15 deletions test/SFC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down Expand Up @@ -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',
);
Expand Down Expand Up @@ -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');
});

Expand Down Expand Up @@ -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'));
});
Expand Down

0 comments on commit 19ab6e1

Please sign in to comment.