Skip to content
Closed
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
10 changes: 2 additions & 8 deletions src/escrow/escrow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,20 +584,14 @@ export class EscrowService {
recipients: Array<[string, number]>,
manager?: EntityManager,
): Promise<ContractInvocationResult> {
return this.invokeOnLockedEscrow(escrow, operation, () =>
this.soroban.invoke(
'release',
// `release(issue_id: u64, recipients)` — u64-typed on-chain (#301).
[u64(this.onChainKeyFor(escrow)), recipients],
this.contractOpts(escrow),
),
return this.invokeOnLockedEscrow(
escrow,
operation,
() =>
this.soroban.invoke(
'release',
[this.onChainKeyFor(escrow), recipients],
// `release(issue_id: u64, recipients)` — u64-typed on-chain (#301).
[u64(this.onChainKeyFor(escrow)), recipients],
this.contractOpts(escrow),
),
manager,
Expand Down
3 changes: 3 additions & 0 deletions src/github/github-webhooks.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,9 @@ describe('GithubWebhooksService', () => {

expect(bountiesService.markInReview).not.toHaveBeenCalled();
expect(bountiesService.markMergedAndRelease).not.toHaveBeenCalled();
});
});

// #308: a redelivered X-GitHub-Delivery used to hit the unique constraint
// on webhook_events.deliveryId and escape handleEvent as a 500, so every
// redelivery of that event failed forever.
Expand Down
13 changes: 12 additions & 1 deletion src/maintenance-pool/maintenance-pool.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ describe('MaintenancePoolService', () => {
it('rejects when the pool has no funded escrow yet', async () => {
poolRepo.findOne.mockResolvedValue({
id: 'pool-1',
status: MaintenancePoolStatus.ACTIVE,
balance: '100',
escrowId: null,
});
Expand All @@ -315,6 +316,7 @@ describe('MaintenancePoolService', () => {
it('rejects when the requested amount exceeds the pool balance', async () => {
poolRepo.findOne.mockResolvedValue({
id: 'pool-1',
status: MaintenancePoolStatus.ACTIVE,
balance: '50',
escrowId: 'escrow-1',
});
Expand All @@ -337,6 +339,7 @@ describe('MaintenancePoolService', () => {
it('releases the reward and atomically decrements the balance', async () => {
poolRepo.findOne.mockResolvedValue({
id: 'pool-1',
status: MaintenancePoolStatus.ACTIVE,
balance: '100',
escrowId: 'escrow-1',
});
Expand Down Expand Up @@ -373,6 +376,7 @@ describe('MaintenancePoolService', () => {
it('rejects a reward for a non-maintenance issue before releasing funds', async () => {
poolRepo.findOne.mockResolvedValue({
id: 'pool-1',
status: MaintenancePoolStatus.ACTIVE,
balance: '100',
escrowId: 'escrow-1',
});
Expand All @@ -391,6 +395,7 @@ describe('MaintenancePoolService', () => {
it('rejects an issue outside the pool repository', async () => {
poolRepo.findOne.mockResolvedValue({
id: 'pool-1',
status: MaintenancePoolStatus.ACTIVE,
repositoryId: 'repository-1',
balance: '100',
escrowId: 'escrow-1',
Expand All @@ -410,6 +415,7 @@ describe('MaintenancePoolService', () => {
it('rejects when the issue has already received a reward from this pool (#273)', async () => {
poolRepo.findOne.mockResolvedValue({
id: 'pool-1',
status: MaintenancePoolStatus.ACTIVE,
balance: '100',
escrowId: 'escrow-1',
});
Expand Down Expand Up @@ -437,9 +443,14 @@ describe('MaintenancePoolService', () => {
// time — not a value cached from an earlier read — and neither
// decrement is lost.
it('two concurrent assignReward calls both apply — no lost decrement (#51)', async () => {
const sharedPoolRow: { balance: string; escrowId: string } = {
const sharedPoolRow: {
balance: string;
escrowId: string;
status: MaintenancePoolStatus;
} = {
balance: '1000.0000000',
escrowId: 'escrow-1',
status: MaintenancePoolStatus.ACTIVE,
};
poolRepo.findOne.mockImplementation(() =>
Promise.resolve({ id: 'pool-1', ...sharedPoolRow }),
Expand Down
11 changes: 10 additions & 1 deletion src/maintenance-pool/maintenance-pool.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,17 @@ export class MaintenancePoolService {
.execute();

if (updateResult.affected === 0) {
// `pool.balance` was read BEFORE the conditional UPDATE — under the
// concurrency this guard exists for (#274) it's stale and can read
// higher than the real balance. Re-read the live value so the error
// reports the actual current balance, not the pre-update one (#608).
const current = await this.poolRepo.findOne({
where: { id },
select: ['balance'],
});
const balance = current?.balance ?? pool.balance;
throw new BadRequestException(
`Requested reward ${amount} exceeds pool balance ${pool.balance}`,
`Requested reward ${amount} exceeds pool balance ${balance}`,
);
}

Expand Down
21 changes: 0 additions & 21 deletions src/sponsors/sponsors.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,6 @@ function validatePage(limit?: number, offset?: number) {
throw new BadRequestException('offset must be >= 0');
}
return { limit, offset };
/**
* Parse optional limit/offset query params, rejecting NaN, negatives,
* non-integers, and limits above MAX_PAGE_LIMIT with a 400 (#280).
*/
function parsePagination(limit?: string, offset?: string) {
const parse = (name: string, raw: string | undefined, min: number, max: number) => {
if (raw === undefined || raw === '') return undefined;
const n = Number(raw);
if (!Number.isInteger(n) || n < min || n > max) {
throw new BadRequestException(
`${name} must be an integer between ${min} and ${max}`,
);
}
return n;
};
return {
limit: parse('limit', limit, 1, MAX_PAGE_LIMIT),
offset: parse('offset', offset, 0, Number.MAX_SAFE_INTEGER),
};
}

@ApiTags('sponsors')
Expand Down Expand Up @@ -73,7 +54,6 @@ export class SponsorsController {
) {
this.assertOwnsSponsor(user, id);
return this.sponsorsService.dashboard(id, validatePage(limit, offset));
return this.sponsorsService.dashboard(id, parsePagination(limit, offset));
}

@ApiBearerAuth()
Expand All @@ -91,6 +71,5 @@ export class SponsorsController {
id,
validatePage(limit, offset),
);
return this.sponsorsService.milestoneProgress(id, parsePagination(limit, offset));
}
}