Skip to content

Commit 269f373

Browse files
committed
Remove unnecessary genesis params and migration func
1 parent 1bc06aa commit 269f373

File tree

6 files changed

+15
-96
lines changed

6 files changed

+15
-96
lines changed

contracts/interfaces/ISFC.sol

+1-10
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,7 @@ interface ISFC {
166166
address _owner
167167
) external;
168168

169-
function setGenesisValidator(
170-
address auth,
171-
uint256 validatorID,
172-
bytes calldata pubkey,
173-
uint256 status,
174-
uint256 createdEpoch,
175-
uint256 createdTime,
176-
uint256 deactivatedEpoch,
177-
uint256 deactivatedTime
178-
) external;
169+
function setGenesisValidator(address auth, uint256 validatorID, bytes calldata pubkey, uint256 createdTime) external;
179170

180171
function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake) external;
181172

contracts/sfc/NodeDriver.sol

+2-20
Original file line numberDiff line numberDiff line change
@@ -88,26 +88,8 @@ contract NodeDriver is Initializable {
8888

8989
// Methods which are called only by the node
9090

91-
function setGenesisValidator(
92-
address _auth,
93-
uint256 validatorID,
94-
bytes calldata pubkey,
95-
uint256 status,
96-
uint256 createdEpoch,
97-
uint256 createdTime,
98-
uint256 deactivatedEpoch,
99-
uint256 deactivatedTime
100-
) external onlyNode {
101-
backend.setGenesisValidator(
102-
_auth,
103-
validatorID,
104-
pubkey,
105-
status,
106-
createdEpoch,
107-
createdTime,
108-
deactivatedEpoch,
109-
deactivatedTime
110-
);
91+
function setGenesisValidator(address auth, uint256 validatorID, bytes calldata pubkey, uint256 createdTime) external onlyNode {
92+
backend.setGenesisValidator(auth, validatorID, pubkey, createdTime);
11193
}
11294

11395
function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake) external onlyNode {

contracts/sfc/NodeDriverAuth.sol

+2-20
Original file line numberDiff line numberDiff line change
@@ -116,26 +116,8 @@ contract NodeDriverAuth is Initializable, Ownable {
116116
driver.updateValidatorPubkey(validatorID, pubkey);
117117
}
118118

119-
function setGenesisValidator(
120-
address _auth,
121-
uint256 validatorID,
122-
bytes calldata pubkey,
123-
uint256 status,
124-
uint256 createdEpoch,
125-
uint256 createdTime,
126-
uint256 deactivatedEpoch,
127-
uint256 deactivatedTime
128-
) external onlyDriver {
129-
sfc.setGenesisValidator(
130-
_auth,
131-
validatorID,
132-
pubkey,
133-
status,
134-
createdEpoch,
135-
createdTime,
136-
deactivatedEpoch,
137-
deactivatedTime
138-
);
119+
function setGenesisValidator(address auth, uint256 validatorID, bytes calldata pubkey, uint256 createdTime) external onlyDriver {
120+
sfc.setGenesisValidator(auth, validatorID, pubkey, createdTime);
139121
}
140122

141123
function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake) external onlyDriver {

contracts/sfc/SFC.sol

+5-26
Original file line numberDiff line numberDiff line change
@@ -238,18 +238,6 @@ contract SFC is Initializable, Ownable, Version {
238238
revert TransfersNotAllowed();
239239
}
240240

241-
function migrateValidatorPubkeyUniquenessFlag(uint256 start, uint256 end) external {
242-
for (uint256 vid = start; vid < end; vid++) {
243-
bytes memory pubkey = getValidatorPubkey[vid];
244-
if (pubkey.length > 0 && pubkeyHashToValidatorID[keccak256(pubkey)] != vid) {
245-
if (pubkeyHashToValidatorID[keccak256(pubkey)] != 0) {
246-
revert PubkeyUsedByOtherValidator();
247-
}
248-
pubkeyHashToValidatorID[keccak256(pubkey)] = vid;
249-
}
250-
}
251-
}
252-
253241
function updateValidatorPubkey(bytes calldata pubkey) external {
254242
if (pubkey.length != 66 || pubkey[0] != 0xc0) {
255243
revert MalformedPubkey();
@@ -351,25 +339,16 @@ contract SFC is Initializable, Ownable, Version {
351339
node.updateMinGasPrice(minGasPrice);
352340
}
353341

354-
function setGenesisValidator(
355-
address auth,
356-
uint256 validatorID,
357-
bytes calldata pubkey,
358-
uint256 status,
359-
uint256 createdEpoch,
360-
uint256 createdTime,
361-
uint256 deactivatedEpoch,
362-
uint256 deactivatedTime
363-
) external onlyDriver {
342+
function setGenesisValidator(address auth, uint256 validatorID, bytes calldata pubkey, uint256 createdTime) external onlyDriver {
364343
_rawCreateValidator(
365344
auth,
366345
validatorID,
367346
pubkey,
368-
status,
369-
createdEpoch,
347+
OK_STATUS,
348+
0, // createdEpoch
370349
createdTime,
371-
deactivatedEpoch,
372-
deactivatedTime
350+
0, // deactivatedEpoch - not deactivated
351+
0 // deactivatedTime - not deactivated
373352
);
374353
if (validatorID > lastValidatorID) {
375354
lastValidatorID = validatorID;

test/NodeDriver.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,7 @@ describe('NodeDriver', () => {
123123
account,
124124
1,
125125
account.publicKey,
126-
0,
127-
await this.sfc.currentEpoch(),
128126
Date.now(),
129-
0,
130-
0,
131127
),
132128
).to.be.revertedWithCustomError(this.nodeDriver, 'NotNode');
133129
});
@@ -143,7 +139,7 @@ describe('NodeDriver', () => {
143139
it('Should revert when not node', async function () {
144140
const account = ethers.Wallet.createRandom();
145141
await expect(
146-
this.nodeDriver.setGenesisDelegation(account, 1, 100, 0, 0, 0, 0, 0, 1000),
142+
this.nodeDriver.setGenesisDelegation(account, 1, 100),
147143
).to.be.revertedWithCustomError(this.nodeDriver, 'NotNode');
148144
});
149145
});

test/SFC.ts

+4-15
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,9 @@ describe('SFC', () => {
6060
validator.address,
6161
1,
6262
validator.publicKey,
63-
1 << 3,
64-
await this.sfc.currentEpoch(),
6563
Date.now(),
66-
0,
67-
0,
6864
);
65+
await this.sfc.deactivateValidator(1, 1 << 3);
6966
await this.sfc.disableNonNodeCalls();
7067
});
7168

@@ -319,18 +316,14 @@ describe('SFC', () => {
319316
validator,
320317
1,
321318
validator.publicKey,
322-
0,
323-
await this.sfc.currentEpoch(),
324319
Date.now(),
325-
0,
326-
0,
327320
),
328321
).to.be.revertedWithCustomError(this.sfc, 'NotDriverAuth');
329322
});
330323

331324
it('Should revert when setGenesisDelegation is not called not node', async function () {
332325
const delegator = ethers.Wallet.createRandom();
333-
await expect(this.sfc.setGenesisDelegation(delegator, 1, 100, 0, 0, 0, 0, 0, 1000)).to.be.revertedWithCustomError(
326+
await expect(this.sfc.setGenesisDelegation(delegator, 1, 100)).to.be.revertedWithCustomError(
334327
this.sfc,
335328
'NotDriverAuth',
336329
);
@@ -981,18 +974,14 @@ describe('SFC', () => {
981974
this.delegator,
982975
1,
983976
key,
984-
1 << 3,
985-
await this.sfc.currentEpoch(),
986977
Date.now(),
987-
0,
988-
0,
989978
),
990979
).to.be.revertedWithCustomError(this.nodeDriverAuth, 'NotDriver');
991980
});
992981

993982
it('Should revert when calling setGenesisDelegation if not NodeDriver', async function () {
994983
await expect(
995-
this.nodeDriverAuth.setGenesisDelegation(this.delegator, 1, 100, 0, 0, 0, 0, 0, 1000),
984+
this.nodeDriverAuth.setGenesisDelegation(this.delegator, 1, 100),
996985
).to.be.revertedWithCustomError(this.nodeDriverAuth, 'NotDriver');
997986
});
998987

@@ -1131,7 +1120,7 @@ describe('SFC', () => {
11311120
});
11321121

11331122
it('Should succeed and setGenesisDelegation Validator', async function () {
1134-
await this.sfc.setGenesisDelegation(this.delegator, this.validatorId, ethers.parseEther('1'), 0, 0, 0, 0, 0, 100);
1123+
await this.sfc.setGenesisDelegation(this.delegator, this.validatorId, ethers.parseEther('1'));
11351124
// delegator has already delegated 0.4 in fixture
11361125
expect(await this.sfc.getStake(this.delegator, this.validatorId)).to.equal(ethers.parseEther('1.4'));
11371126
});

0 commit comments

Comments
 (0)