Skip to content

Commit 582037b

Browse files
authored
Add epoch snapshot endBlock attribute (#72)
1 parent c0e1d9d commit 582037b

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

contracts/sfc/SFC.sol

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ contract SFC is SFCBase, Version {
7575
return getEpochSnapshot[epoch].offlineBlocks[validatorID];
7676
}
7777

78+
function getEpochEndBlock(uint256 epoch) public view returns (uint256) {
79+
return getEpochSnapshot[epoch].endBlock;
80+
}
81+
7882
function rewardsStash(address delegator, uint256 validatorID) public view returns (uint256) {
7983
Rewards memory stash = _rewardsStash[delegator][validatorID];
8084
return stash.lockupBaseReward + stash.lockupExtraReward + stash.unlockedReward;
@@ -361,6 +365,7 @@ contract SFC is SFCBase, Version {
361365

362366
currentSealedEpoch = currentEpoch();
363367
snapshot.endTime = _now();
368+
snapshot.endBlock = block.number;
364369
snapshot.baseRewardPerSecond = c.baseRewardPerSecond();
365370
snapshot.totalSupply = totalSupply;
366371
}

contracts/sfc/SFCI.sol

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ interface SFCI {
4444
view
4545
returns (
4646
uint256 endTime,
47+
uint256 endBlock,
4748
uint256 epochFee,
4849
uint256 totalBaseRewardWeight,
4950
uint256 totalTxRewardWeight,
@@ -137,6 +138,8 @@ interface SFCI {
137138

138139
function getEpochOfflineBlocks(uint256 epoch, uint256 validatorID) external view returns (uint256);
139140

141+
function getEpochEndBlock(uint256 epoch) external view returns (uint256);
142+
140143
function rewardsStash(address delegator, uint256 validatorID) external view returns (uint256);
141144

142145
function getLockedStake(address delegator, uint256 toValidatorID) external view returns (uint256);

contracts/sfc/SFCState.sol

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ contract SFCState is Initializable, Ownable {
7171
mapping(uint256 => uint256) offlineBlocks;
7272
uint256[] validatorIDs;
7373
uint256 endTime;
74+
uint256 endBlock;
7475
uint256 epochFee;
7576
uint256 totalBaseRewardWeight;
7677
uint256 totalTxRewardWeight;

contracts/test/UnitTestSFC.sol

+3
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ interface SFCUnitTestI {
120120
view
121121
returns (
122122
uint256 endTime,
123+
uint256 endBlock,
123124
uint256 epochFee,
124125
uint256 totalBaseRewardWeight,
125126
uint256 totalTxRewardWeight,
@@ -215,6 +216,8 @@ interface SFCUnitTestI {
215216

216217
function getEpochOfflineBlocks(uint256 epoch, uint256 validatorID) external view returns (uint256);
217218

219+
function getEpochEndBlock(uint256 epoch) external view returns (uint256);
220+
218221
function rewardsStash(address delegator, uint256 validatorID) external view returns (uint256);
219222

220223
function getLockedStake(address delegator, uint256 toValidatorID) external view returns (uint256);

test/SFC.ts

+10
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,16 @@ describe('SFC', () => {
413413
expect(await this.sfc.currentEpoch.call()).to.equal(6);
414414
expect(await this.sfc.currentSealedEpoch()).to.equal(5);
415415
});
416+
417+
it('Should succeed and return endBlock', async function () {
418+
const epochNumber = await this.sfc.currentEpoch();
419+
await this.sfc.enableNonNodeCalls();
420+
await this.sfc.sealEpoch([100, 101, 102], [100, 101, 102], [100, 101, 102], [100, 101, 102], 0);
421+
const lastBlock = await ethers.provider.getBlockNumber();
422+
// endBlock is on second position
423+
expect((await this.sfc.getEpochSnapshot(epochNumber))[1]).to.equal(lastBlock);
424+
expect(await this.sfc.getEpochEndBlock(epochNumber)).to.equal(lastBlock);
425+
});
416426
});
417427
});
418428

0 commit comments

Comments
 (0)