Skip to content

Commit c6de314

Browse files
authored
fix: do not display revoked pool delegations (#2357)
1 parent f82efbc commit c6de314

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/datastore/pg-store.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,19 +2051,25 @@ export class PgStore extends BasePgStore {
20512051
>`
20522052
WITH ordered_pox_events AS (
20532053
SELECT
2054-
stacker, pox_addr, amount_ustx, unlock_burn_height::integer, tx_id,
2054+
stacker, pox_addr, amount_ustx, unlock_burn_height::integer, tx_id, name,
20552055
block_height, microblock_sequence, tx_index, event_index
20562056
FROM ${sql(args.poxTable)}
20572057
WHERE
2058-
canonical = true AND microblock_canonical = true AND
2059-
name = ${SyntheticPoxEventName.DelegateStx} AND delegate_to = ${args.delegator} AND
2060-
block_height <= ${args.blockHeight} AND block_height > ${args.afterBlockHeight} AND
2061-
(unlock_burn_height > ${args.burnBlockHeight} OR unlock_burn_height IS NULL)
2058+
canonical = true
2059+
AND microblock_canonical = true
2060+
AND delegate_to = ${args.delegator}
2061+
AND name IN (
2062+
${SyntheticPoxEventName.DelegateStx},
2063+
${SyntheticPoxEventName.RevokeDelegateStx}
2064+
)
2065+
AND block_height <= ${args.blockHeight}
2066+
AND block_height > ${args.afterBlockHeight}
2067+
AND (unlock_burn_height > ${args.burnBlockHeight} OR unlock_burn_height IS NULL)
20622068
ORDER BY stacker, block_height DESC, microblock_sequence DESC, tx_index DESC, event_index DESC
20632069
),
20642070
distinct_rows AS (
20652071
SELECT DISTINCT ON (stacker)
2066-
stacker, pox_addr, amount_ustx, unlock_burn_height, tx_id,
2072+
stacker, pox_addr, amount_ustx, unlock_burn_height, tx_id, name,
20672073
block_height, microblock_sequence, tx_index, event_index
20682074
FROM ordered_pox_events
20692075
ORDER BY stacker, block_height DESC, microblock_sequence DESC, tx_index DESC, event_index DESC
@@ -2072,6 +2078,7 @@ export class PgStore extends BasePgStore {
20722078
stacker, pox_addr, amount_ustx, unlock_burn_height, block_height::integer, tx_id,
20732079
COUNT(*) OVER()::integer AS total_rows
20742080
FROM distinct_rows
2081+
WHERE name = ${SyntheticPoxEventName.DelegateStx}
20752082
ORDER BY block_height DESC, microblock_sequence DESC, tx_index DESC, event_index DESC
20762083
LIMIT ${args.limit}
20772084
OFFSET ${args.offset}

tests/2.5/pox-4-delegate-revoked-stacking.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
fetchGet,
2525
readOnlyFnCall,
2626
standByForPoxCycle,
27-
standByForPoxCycleEnd,
2827
standByForTx,
2928
standByForTxSuccess,
3029
testEnv,
@@ -207,6 +206,19 @@ describe('PoX-4 - Delegate Revoked Stacking', () => {
207206
);
208207
const delegatedAmount = BigInt(getDelegationInfo.data['amount-ustx'].value);
209208
expect(delegatedAmount).toBe(DELEGATE_HALF_AMOUNT);
209+
210+
// validate pool delegations
211+
const stackersRes: any = await fetchGet(`/extended/v1/pox4/${POOL.stxAddr}/delegations`);
212+
expect(stackersRes).toBeDefined();
213+
expect(stackersRes.total).toBe(1);
214+
expect(stackersRes.results).toHaveLength(1);
215+
expect(stackersRes.results[0]).toEqual({
216+
amount_ustx: DELEGATE_HALF_AMOUNT.toString(),
217+
pox_addr: STACKER.btcTestnetAddr,
218+
stacker: STACKER.stxAddr,
219+
tx_id: delegateStxDbTx.tx_id,
220+
block_height: delegateStxDbTx.block_height,
221+
});
210222
});
211223

212224
test('Perform delegate-stack-stx', async () => {
@@ -311,6 +323,12 @@ describe('PoX-4 - Delegate Revoked Stacking', () => {
311323
const coreBalanceInfo = await testEnv.client.getAccount(STACKER.stxAddr);
312324
expect(BigInt(coreBalanceInfo.locked)).toBe(DELEGATE_HALF_AMOUNT);
313325
expect(coreBalanceInfo.unlock_height).toBeGreaterThan(0);
326+
327+
// validate pool delegation no longer exists
328+
const stackersRes: any = await fetchGet(`/extended/v1/pox4/${POOL.stxAddr}/delegations`);
329+
expect(stackersRes).toBeDefined();
330+
expect(stackersRes.total).toBe(0);
331+
expect(stackersRes.results).toHaveLength(0);
314332
});
315333

316334
test('Try to perform delegate-stack-stx - while revoked', async () => {

0 commit comments

Comments
 (0)