diff --git a/packages/contracts/contracts/staking/Staking.sol b/packages/contracts/contracts/staking/Staking.sol index 2139160da..6878dad0c 100644 --- a/packages/contracts/contracts/staking/Staking.sol +++ b/packages/contracts/contracts/staking/Staking.sol @@ -812,18 +812,18 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M // Get allocation Allocation memory alloc = __allocations[_allocationID]; - // Validate that an allocation cannot be closed before one epoch alloc.closedAtEpoch = epochManager().currentEpoch(); + + // Allocation duration in epochs uint256 epochs = MathUtils.diffOrZero(alloc.closedAtEpoch, alloc.createdAtEpoch); - require(epochs > 0, " 0) { // Distribute rewards if proof of indexing was presented by the indexer or operator - if (isIndexer && _poi != 0) { + // and the allocation is at least one epoch old (most indexed chains require the EBO + // posting epoch block numbers to produce a valid POI which happens once per epoch) + if (isIndexerOrOperator && _poi != 0 && epochs > 0) { _distributeRewards(_allocationID, alloc.indexer); } else { _updateRewards(alloc.subgraphDeploymentID); @@ -858,7 +860,7 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M _allocationID, msg.sender, _poi, - !isIndexer + !isIndexerOrOperator ); } diff --git a/packages/contracts/test/staking/allocation.test.ts b/packages/contracts/test/staking/allocation.test.ts index c4a104312..26281ff6b 100644 --- a/packages/contracts/test/staking/allocation.test.ts +++ b/packages/contracts/test/staking/allocation.test.ts @@ -876,9 +876,23 @@ describe('Staking:Allocation', () => { await expect(tx).revertedWith('!active') }) - it('reject close before at least one epoch has passed', async function () { + it('allow close before one epoch has passed', async function () { + const currentEpoch = await epochManager.currentEpoch() + const beforeAlloc = await staking.getAllocation(allocationID) + const tx = staking.connect(indexer).closeAllocation(allocationID, poi) - await expect(tx).revertedWith(' { it('should close an allocation (by public) only if allocation is non-zero', async function () { // Reject to close if public address and under max allocation epochs const tx1 = staking.connect(me).closeAllocation(allocationID, poi) - await expect(tx1).revertedWith('