Skip to content

Commit 374e387

Browse files
authored
Merge pull request #939 from graphprotocol/mde/pr939-fix-oz-l-02
fix: clear vote for earlier rounds (OZ L-02)
2 parents 0698989 + 1ce46f0 commit 374e387

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

packages/contracts/contracts/rewards/SubgraphAvailabilityManager.sol

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,15 @@ contract SubgraphAvailabilityManager is Governed {
197197
) private {
198198
uint256 timestamp = block.timestamp;
199199

200-
// corresponding votes based on _deny for a subgraph deployment
201-
uint256[NUM_ORACLES] storage lastVoteForSubgraph = _deny
202-
? lastDenyVote[currentNonce][_subgraphDeploymentID]
203-
: lastAllowVote[currentNonce][_subgraphDeploymentID];
204-
lastVoteForSubgraph[_oracleIndex] = timestamp;
200+
if (_deny) {
201+
lastDenyVote[currentNonce][_subgraphDeploymentID][_oracleIndex] = timestamp;
202+
// clear opposite vote for a subgraph deployment if it exists
203+
lastAllowVote[currentNonce][_subgraphDeploymentID][_oracleIndex] = 0;
204+
} else {
205+
lastAllowVote[currentNonce][_subgraphDeploymentID][_oracleIndex] = timestamp;
206+
// clear opposite vote for a subgraph deployment if it exists
207+
lastDenyVote[currentNonce][_subgraphDeploymentID][_oracleIndex] = 0;
208+
}
205209

206210
emit OracleVote(_subgraphDeploymentID, _deny, _oracleIndex, timestamp);
207211

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)