Skip to content

Commit

Permalink
Remove kulupu controller
Browse files Browse the repository at this point in the history
  • Loading branch information
emostov committed Dec 2, 2020
1 parent be66056 commit 19a66e7
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 195 deletions.
40 changes: 22 additions & 18 deletions src/chains-config/defaultControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ import { ControllerConfig } from '../types/chains-config';
* the optimal controller selection for Polkadot and Kusama.
*/
export const defaultControllers: ControllerConfig = {
Blocks: true,
KulupuBlocks: false,
AccountsStakingPayouts: true,
AccountsBalanceInfo: true,
AccountsStakingInfo: true,
AccountsVestingInfo: true,
NodeNetwork: true,
NodeVersion: true,
NodeTransactionPool: true,
RuntimeCode: true,
RuntimeSpec: true,
RuntimeMetadata: true,
TransactionDryRun: true,
TransactionMaterial: true,
TransactionFeeEstimate: true,
TransactionSubmit: true,
PalletsStakingProgress: true,
PalletsStorage: true,
controllers: {
Blocks: true,
AccountsStakingPayouts: true,
AccountsBalanceInfo: true,
AccountsStakingInfo: true,
AccountsVestingInfo: true,
NodeNetwork: true,
NodeVersion: true,
NodeTransactionPool: true,
RuntimeCode: true,
RuntimeSpec: true,
RuntimeMetadata: true,
TransactionDryRun: true,
TransactionMaterial: true,
TransactionFeeEstimate: true,
TransactionSubmit: true,
PalletsStakingProgress: true,
PalletsStorage: true,
},
options: {
finalizes: true,
},
};
24 changes: 15 additions & 9 deletions src/chains-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { defaultControllers } from './defaultControllers';
import { kulupuControllers } from './kulupuControllers';
import { mandalaControllers } from './mandalaControllers';

const specToControllerMap = {
kulupu: kulupuControllers,
mandala: mandalaControllers,
};

/**
* Return an array of instantiated controller instances based off of a `specName`.
*
Expand All @@ -18,14 +23,13 @@ export function getControllersForSpec(
api: ApiPromise,
specName: string
): AbstractController<AbstractService>[] {
switch (specName) {
case 'kulupu':
return getControllersFromConfig(api, kulupuControllers);
case 'mandala':
return getControllersFromConfig(api, mandalaControllers);
default:
return getControllersFromConfig(api, defaultControllers);
if (specToControllerMap[specName]) {
return getControllersFromConfig(api, specToControllerMap[specName]);
}

// If we don't have the specName in the specToControllerMap we use the default
// contoller config
return getControllersFromConfig(api, defaultControllers);
}

/**
Expand All @@ -37,14 +41,16 @@ export function getControllersForSpec(
*/
function getControllersFromConfig(api: ApiPromise, config: ControllerConfig) {
// If we don't typecast here, tsc thinks its just [string, any][]
const controllersToInclude = Object.entries(config) as [
const controllersToInclude = Object.entries(config.controllers) as [
keyof typeof controllers,
boolean
][];

return controllersToInclude.reduce((acc, [controllerName, shouldMount]) => {
if (shouldMount) {
acc.push(new controllers[controllerName](api));
acc.push(
new controllers[controllerName](api, config.options.finalizes)
);
}

return acc;
Expand Down
40 changes: 22 additions & 18 deletions src/chains-config/kulupuControllers.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import { ControllerConfig } from '../types/chains-config';

export const kulupuControllers: ControllerConfig = {
Blocks: false,
KulupuBlocks: true,
AccountsStakingPayouts: false,
AccountsBalanceInfo: true,
AccountsStakingInfo: false,
AccountsVestingInfo: false,
NodeNetwork: true,
NodeVersion: true,
NodeTransactionPool: true,
RuntimeCode: true,
RuntimeSpec: true,
RuntimeMetadata: true,
TransactionDryRun: true,
TransactionMaterial: true,
TransactionFeeEstimate: true,
TransactionSubmit: true,
PalletsStakingProgress: false,
PalletsStorage: true,
controllers: {
Blocks: true,
AccountsStakingPayouts: false,
AccountsBalanceInfo: true,
AccountsStakingInfo: false,
AccountsVestingInfo: false,
NodeNetwork: true,
NodeVersion: true,
NodeTransactionPool: true,
RuntimeCode: true,
RuntimeSpec: true,
RuntimeMetadata: true,
TransactionDryRun: true,
TransactionMaterial: true,
TransactionFeeEstimate: true,
TransactionSubmit: true,
PalletsStakingProgress: false,
PalletsStorage: true,
},
options: {
finalizes: false,
},
};
40 changes: 22 additions & 18 deletions src/chains-config/mandalaControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@ import { ControllerConfig } from '../types/chains-config';
* Controllers for mandala, acala's test network.
*/
export const mandalaControllers: ControllerConfig = {
Blocks: true,
KulupuBlocks: false,
AccountsStakingPayouts: true,
AccountsBalanceInfo: true,
AccountsStakingInfo: true,
AccountsVestingInfo: true,
NodeNetwork: true,
NodeVersion: true,
NodeTransactionPool: true,
RuntimeCode: true,
RuntimeSpec: true,
RuntimeMetadata: true,
TransactionDryRun: true,
TransactionMaterial: true,
TransactionFeeEstimate: true,
TransactionSubmit: true,
PalletsStakingProgress: true,
PalletsStorage: true,
controllers: {
Blocks: true,
AccountsStakingPayouts: true,
AccountsBalanceInfo: true,
AccountsStakingInfo: true,
AccountsVestingInfo: true,
NodeNetwork: true,
NodeVersion: true,
NodeTransactionPool: true,
RuntimeCode: true,
RuntimeSpec: true,
RuntimeMetadata: true,
TransactionDryRun: true,
TransactionMaterial: true,
TransactionFeeEstimate: true,
TransactionSubmit: true,
PalletsStakingProgress: true,
PalletsStorage: true,
},
options: {
finalizes: true,
},
};
4 changes: 2 additions & 2 deletions src/controllers/blocks/BlocksController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import AbstractController from '../AbstractController';
* - `OnFinalize`: https://crates.parity.io/frame_support/traits/trait.OnFinalize.html
*/
export default class BlocksController extends AbstractController<BlocksService> {
constructor(api: ApiPromise) {
constructor(api: ApiPromise, private finalizes = true) {
super(api, '/blocks', new BlocksService(api));
this.initRoutes();
}
Expand All @@ -91,7 +91,7 @@ export default class BlocksController extends AbstractController<BlocksService>
const extrsinsicDocsArg = extrinsicDocs === 'true';

const hash =
finalized === 'false'
finalized === 'false' || !this.finalizes
? (await this.api.rpc.chain.getHeader()).hash
: await this.api.rpc.chain.getFinalizedHead();

Expand Down
121 changes: 0 additions & 121 deletions src/controllers/chains/KulupuBlocksController.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/controllers/chains/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
AccountsVestingInfo,
} from './accounts';
import { Blocks } from './blocks';
import { KulupuBlocks } from './chains';
import { NodeNetwork, NodeTransactionPool, NodeVersion } from './node';
import { PalletsStakingProgress, PalletsStorage } from './pallets';
import { RuntimeCode, RuntimeMetadata, RuntimeSpec } from './runtime';
Expand All @@ -25,7 +24,6 @@ export const controllers = {
AccountsStakingInfo,
AccountsVestingInfo,
AccountsStakingPayouts,
KulupuBlocks,
PalletsStakingProgress,
PalletsStorage,
NodeNetwork,
Expand Down
15 changes: 14 additions & 1 deletion src/types/chains-config/ControllerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,18 @@ import { controllers } from '../../controllers';
* Controller mounting configuration as an object where the keys are the
* controller class names and the values are booleans indicating whether or not
* to include the controller.
*
* There is an additional `finalizes` field that is used to indicate wether or
* not a chain has finalized blocks. Practically, this only affects if
* `BlocksController` defaults to getFinalizedHead (in the case it finalizes) or
* getHeader (in the case it does not finalize)
*/
export type ControllerConfig = Record<keyof typeof controllers, boolean>;
export interface ControllerConfig {
controllers: Record<keyof typeof controllers, boolean>;
/**
* Wether or not the chain finalizes blocks
*/
options: {
finalizes: boolean;
};
}

0 comments on commit 19a66e7

Please sign in to comment.