Skip to content

Commit

Permalink
fix: add check on isParticipatingInUpcomingRound (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xCardinalError authored Sep 9, 2024
1 parent e70c3cd commit 3dad39e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Redistribution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -801,11 +801,17 @@ contract Redistribution is AccessControl, Pausable {
* @param _depth The storage depth the applicant intends to report.
*/
function isParticipatingInUpcomingRound(address _owner, uint8 _depth) public view returns (bool) {
uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(_owner);

if (currentPhaseReveal()) {
revert WrongPhase();
}

if (Stakes.lastUpdatedBlockNumberOfAddress(_owner) >= block.number - 2 * ROUND_LENGTH) {
if (_lastUpdate == 0) {
revert NotStaked();
}

if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) {
revert MustStake2Rounds();
}

Expand Down
10 changes: 10 additions & 0 deletions test/Redistribution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ describe('Redistribution', function () {
await expect(r_node_0.commit(obfuscatedHash_0, currentRound)).to.be.revertedWith(errors.commit.notStaked);
});

it('should not participation with unstaked node', async function () {
expect(await redistribution.currentPhaseCommit()).to.be.true;

const r_node_0 = await ethers.getContract('Redistribution', node_0);
const currentRound = await r_node_0.currentRound();
await expect(r_node_0['isParticipatingInUpcomingRound(address,uint8)'](node_0, depth_0)).to.be.revertedWith(
errors.commit.notStaked
);
});

it('should not create a commit with recently staked node', async function () {
const sr_node_0 = await ethers.getContract('StakeRegistry', node_0);
await mintAndApprove(deployer, node_0, sr_node_0.address, stakeAmount_0);
Expand Down

0 comments on commit 3dad39e

Please sign in to comment.