Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add vrfDelay as a phase return value for ongoing auctions to reflect VRFdelays in polkadot #593

Merged
merged 7 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion docs/dist/app.bundle.js

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions docs/src/openapi-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2338,12 +2338,15 @@ components:
phase:
type: string
enum:
- opening
- starting
- ending
- delay
TarikGul marked this conversation as resolved.
Show resolved Hide resolved
description: |
Whether the auction is in the `opening` or `ending` phase. The
`ending` phase is where the eventual winners are retroactively
picked from. `null` if there is no ongoing auction.
An auction can be in one of 4 phases. Both `starting` and `ending` denoting
an ongoing auction. `delay` is part of the VRFDelay inside of Substrate which is a Period
`finishEnd` block number where contributions are no longer accepted. After this `delay` phase
the auction is officially finalized and a winner is declared. If `null` is returned
this means the auction has not started yet.
TarikGul marked this conversation as resolved.
Show resolved Hide resolved
auctionIndex:
type: string
format: unsignedInteger
Expand Down
49 changes: 42 additions & 7 deletions src/services/paras/ParasService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import BN from 'bn.js';

import { sanitizeNumbers } from '../../sanitize/sanitizeNumbers';
import { polkadotRegistry } from '../../test-helpers/registries';
import {
auctionsInfoAt,
blockHash20000,
blockHash789629,
emptyVectorLeases,
mockApi,
mockBlock789629,
noneAuctionsInfoAt,
slotsLeasesAt,
} from '../test-helpers/mock';
Expand Down Expand Up @@ -170,7 +173,7 @@ describe('ParasService', () => {

describe('ParasService.auctionsCurrent', () => {
it('Should return the correct data during an ongoing auction', async () => {
const leasePeriodIndex = new BN(1000);
const leasePeriodIndex = new BN(39);
const leaseIndexArray =
parasService['enumerateLeaseSets'](leasePeriodIndex);
// Remove the first two entries with splice because we have them in the expectedResponse.
Expand All @@ -183,27 +186,27 @@ describe('ParasService', () => {

const expectedResponse = {
at: expectedAt,
beginEnd: '39',
finishEnd: '20039',
phase: 'ending',
beginEnd: '1000',
finishEnd: '21000',
phase: 'delay',
TarikGul marked this conversation as resolved.
Show resolved Hide resolved
auctionIndex: '4',
leasePeriods: ['1000', '1001', '1002', '1003'],
leasePeriods: ['39', '40', '41', '42'],
winning: [
{
bid: {
accountId: '5CXFhuwT7A1ge4hCa23uCmZWQUebEZSrFdBEE24C41wmAF4N',
amount: '1000000',
paraId: '199',
},
leaseSet: ['1000'],
leaseSet: ['39'],
},
{
bid: {
accountId: '5ESEa1HV8hyG6RTXgwWNUhu5fXvkHBfEJKjw3hKmde7fXdHQ',
amount: '2000000',
paraId: '200',
},
leaseSet: ['1000', '1001'],
leaseSet: ['39', '40'],
},
...additionalWinningOptions,
],
Expand All @@ -214,6 +217,38 @@ describe('ParasService', () => {
expect(sanitizeNumbers(response)).toMatchObject(expectedResponse);
});

/**
* The goal of this test is to manipulate the number of the finalized block so that it is less than
* the expected `finishHead`, but higher the `beginEnd` which would denote we are in the `ending` phase
*/
it('Should return the correct `ending` phase', async () => {
const overrideHeader = {
parentHash:
'0x3d489d71f8fd2e15259df5059a1497436e6b73497500a303b1a705993e25cb27',
number: 20000,
stateRoot:
'0xa0089595e48850a8a00081dd987a4735d0e8f94ac98af89030521f23f6cb8e31',
extrinsicsRoot:
'0x2d5d3fdb96b487d480b08b64ed69a65433c1713ae3579dd23704cb790aa3b2ae',
digest: {},
};
const header = polkadotRegistry.createType('Header', overrideHeader);

// Override the mockApi
(mockApi.rpc.chain.getHeader as unknown) = () =>
Promise.resolve().then(() => header);

const expectedResponse = 'ending';
TarikGul marked this conversation as resolved.
Show resolved Hide resolved

const response = await parasService.auctionsCurrent(blockHash20000);

expect(response.phase).toBe(expectedResponse);

// Set the MockApi back to its original self
(mockApi.rpc.chain.getHeader as unknown) = () =>
Promise.resolve().then(() => mockBlock789629.header);
});

it('Should return the correct null values when `auctionInfo` is `None`', async () => {
(mockApi.query.auctions.auctionInfo.at as unknown) = noneAuctionsInfoAt;

Expand Down
7 changes: 6 additions & 1 deletion src/services/paras/ParasService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,12 @@ export class ParasService extends AbstractService {
}

finishEnd = beginEnd.add(endingPeriod);
phase = beginEnd.gt(blockNumber) ? 'starting' : 'ending';

if (finishEnd.lt(blockNumber)) {
phase = 'delay';
TarikGul marked this conversation as resolved.
Show resolved Hide resolved
} else {
phase = beginEnd.gt(blockNumber) ? 'starting' : 'ending';
TarikGul marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
leasePeriodIndex = null;
beginEnd = null;
Expand Down
2 changes: 1 addition & 1 deletion src/services/test-helpers/mock/mockApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ export const auctionsInfoAt = (): Promise<Option<Vec<BlockNumber>>> =>
const beingEnd = rococoRegistry.createType('BlockNumber', 1000);
const leasePeriodIndex = rococoRegistry.createType('BlockNumber', 39);
const vectorAuctions = rococoTypeFactory.vecOf([
beingEnd,
leasePeriodIndex,
beingEnd,
]);
const optionAuctions = rococoTypeFactory.optionOf(vectorAuctions);

Expand Down
8 changes: 8 additions & 0 deletions src/services/test-helpers/mock/mockBlock789629.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ export const blockHash789629 = polkadotRegistry.createType(
'0x7b713de604a99857f6c25eacc115a4f28d2611a23d9ddff99ab0e4f1c17a8578'
);

/**
* BlockHash for polkadot block #20000
*/
export const blockHash20000 = polkadotRegistry.createType(
'BlockHash',
'0x1c309003c5737bb473fa04dc3cce638122d5ffd64497e024835bce71587c4d46'
);

/**
* Mock for polkadot forked block #789629.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/types/responses/Paras.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import BN from 'bn.js';
import { IOption } from '../util';
import { IAt } from './';

export type AuctionPhase = 'starting' | 'ending';
export type AuctionPhase = 'starting' | 'ending' | 'delay';
TarikGul marked this conversation as resolved.
Show resolved Hide resolved

export type ParaType = 'parachain' | 'parathread';

Expand Down