Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add check on isParticipatingInUpcomingRound #270

Merged
merged 4 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading