Skip to content

Commit a52066c

Browse files
committed
fix: clear vote for earlier rounds (OZ L-02)
1 parent f2aa2fa commit a52066c

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

packages/contracts/contracts/rewards/SubgraphAvailabilityManager.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ contract SubgraphAvailabilityManager is Governed {
203203
: lastAllowVote[currentNonce][_subgraphDeploymentID];
204204
lastVoteForSubgraph[_oracleIndex] = timestamp;
205205

206+
// clear opposite vote for a subgraph deployment if it exists
207+
uint256[NUM_ORACLES] storage oppositeVoteForSubgraph = _deny
208+
? lastAllowVote[currentNonce][_subgraphDeploymentID]
209+
: lastDenyVote[currentNonce][_subgraphDeploymentID];
210+
oppositeVoteForSubgraph[_oracleIndex] = 0;
211+
206212
emit OracleVote(_subgraphDeploymentID, _deny, _oracleIndex, timestamp);
207213

208214
// check if execution threshold is reached, if it is call the RewardsManager

packages/contracts/test/rewards/subgraphAvailability.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,31 @@ describe('SubgraphAvailabilityManager', () => {
329329
// previous votes are no longer valid
330330
expect(await rewardsManager.isDenied(subgraphDeploymentID1)).to.be.false
331331
})
332+
333+
it('clears opposite vote when voting', async () => {
334+
const denied = true
335+
await subgraphAvailabilityManager.connect(oracleOne).vote(subgraphDeploymentID1, denied, 0)
336+
await subgraphAvailabilityManager.connect(oracleTwo).vote(subgraphDeploymentID1, denied, 1)
337+
await subgraphAvailabilityManager.connect(oracleThree).vote(subgraphDeploymentID1, denied, 2)
338+
339+
// 3/5 oracles vote denied = true so subgraph is denied
340+
expect(await rewardsManager.isDenied(subgraphDeploymentID1)).to.be.true
341+
342+
// oracleOne changes its vote to denied = false
343+
await subgraphAvailabilityManager.connect(oracleOne).vote(subgraphDeploymentID1, false, 0)
344+
345+
// last deny vote should be 0 for oracleOne
346+
expect(
347+
await subgraphAvailabilityManager.lastDenyVote(0, subgraphDeploymentID1, 0),
348+
).to.be.equal(0)
349+
350+
// executionThreshold isn't met now since oracleOne changed its vote
351+
expect(await subgraphAvailabilityManager.checkVotes(subgraphDeploymentID1, denied)).to.be
352+
.false
353+
354+
// subgraph is still denied in rewards manager because only one oracle changed its vote
355+
expect(await rewardsManager.isDenied(subgraphDeploymentID1)).to.be.true
356+
})
332357
})
333358

334359
describe('vote many', async () => {

0 commit comments

Comments
 (0)