From c03cd2caca46af350d50e23d39747fef8f846bf7 Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Mon, 4 Jan 2021 19:26:50 -0800 Subject: [PATCH 1/2] feat(core-api): add consensus algorithms OpenAPI enum Enumerates a list of consensus algorithm families in existence. Does not intend to be an exhaustive list, just a practical one, meaning that we only include items here that are relevant to Hyperledger Cactus in fulfilling its own duties. This can be extended later as more sophisticated features of Cactus get implemented. This enum is meant to be first and foremest a useful abstraction for achieving practical tasks, not an encyclopedia and therefore we ask of everyone that this to be extended only in ways that serve a practical purpose for the runtime behavior of Cactus or Cactus plugins in general. The bottom line is that we can accept this enum being not 100% accurate as long as it 100% satisfies what it was designed to do. Fixes #359 Signed-off-by: Peter Somogyvari --- .../src/main/json/generated/openapi-spec.json | 9 ++++++++ .../generated/openapi/typescript-axios/api.ts | 11 ++++++++++ .../src/main/typescript/openapi-spec.ts | 22 +++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/packages/cactus-core-api/src/main/json/generated/openapi-spec.json b/packages/cactus-core-api/src/main/json/generated/openapi-spec.json index e7c2b65aaf..4f2e18f416 100644 --- a/packages/cactus-core-api/src/main/json/generated/openapi-spec.json +++ b/packages/cactus-core-api/src/main/json/generated/openapi-spec.json @@ -27,6 +27,15 @@ ], "components": { "schemas": { + "ConsensusAlgorithmFamily": { + "type": "string", + "description": "Enumerates a list of consensus algorithm families in existence. Does not intend to be an exhaustive list, just a practical one, meaning that we only include items here that are relevant to Hyperledger Cactus in fulfilling its own duties. This can be extended later as more sophisticated features of Cactus get implemented. This enum is meant to be first and foremest a useful abstraction for achieving practical tasks, not an encyclopedia and therefore we ask of everyone that this to be extended only in ways that serve a practical purpose for the runtime behavior of Cactus or Cactus plugins in general. The bottom line is that we can accept this enum being not 100% accurate as long as it 100% satisfies what it was designed to do.", + "enum": [ + "org.hyperledger.cactus.consensusalgorithm.PROOF_OF_AUTHORITY", + "org.hyperledger.cactus.consensusalgorithm.PROOF_OF_STAKE", + "org.hyperledger.cactus.consensusalgorithm.PROOF_OF_WORK" + ] + }, "PrimaryKey": { "type": "string", "minLength": 1, diff --git a/packages/cactus-core-api/src/main/typescript/generated/openapi/typescript-axios/api.ts b/packages/cactus-core-api/src/main/typescript/generated/openapi/typescript-axios/api.ts index 94e4d86caf..56da7bffed 100644 --- a/packages/cactus-core-api/src/main/typescript/generated/openapi/typescript-axios/api.ts +++ b/packages/cactus-core-api/src/main/typescript/generated/openapi/typescript-axios/api.ts @@ -124,6 +124,17 @@ export interface CactusNodeMeta { */ publicKeyPem: string; } +/** + * Enumerates a list of consensus algorithm families in existence. Does not intend to be an exhaustive list, just a practical one, meaning that we only include items here that are relevant to Hyperledger Cactus in fulfilling its own duties. This can be extended later as more sophisticated features of Cactus get implemented. This enum is meant to be first and foremest a useful abstraction for achieving practical tasks, not an encyclopedia and therefore we ask of everyone that this to be extended only in ways that serve a practical purpose for the runtime behavior of Cactus or Cactus plugins in general. The bottom line is that we can accept this enum being not 100% accurate as long as it 100% satisfies what it was designed to do. + * @export + * @enum {string} + */ +export enum ConsensusAlgorithmFamily { + AUTHORITY = 'org.hyperledger.cactus.consensusalgorithm.PROOF_OF_AUTHORITY', + STAKE = 'org.hyperledger.cactus.consensusalgorithm.PROOF_OF_STAKE', + WORK = 'org.hyperledger.cactus.consensusalgorithm.PROOF_OF_WORK' +} + /** * * @export diff --git a/packages/cactus-core-api/src/main/typescript/openapi-spec.ts b/packages/cactus-core-api/src/main/typescript/openapi-spec.ts index 71a156200b..c5ebeffd73 100644 --- a/packages/cactus-core-api/src/main/typescript/openapi-spec.ts +++ b/packages/cactus-core-api/src/main/typescript/openapi-spec.ts @@ -35,6 +35,28 @@ export const CACTUS_OPEN_API_JSON: OpenAPIV3.Document = { ], components: { schemas: { + ConsensusAlgorithmFamily: { + type: "string", + description: + "Enumerates a list of consensus algorithm families in " + + "existence. Does not intend to be an exhaustive list, just a " + + "practical one, meaning that we only include items here that are " + + "relevant to Hyperledger Cactus in fulfilling its own duties. " + + "This can be extended later as more sophisticated features " + + "of Cactus get implemented. " + + "This enum is meant to be first and foremest a useful abstraction " + + "for achieving practical tasks, not an encyclopedia and therefore " + + "we ask of everyone that this to be extended only in ways that " + + "serve a practical purpose for the runtime behavior of Cactus or " + + "Cactus plugins in general. The bottom line is that we can accept " + + "this enum being not 100% accurate as long as it 100% satisfies " + + "what it was designed to do.", + enum: [ + "org.hyperledger.cactus.consensusalgorithm.PROOF_OF_AUTHORITY", + "org.hyperledger.cactus.consensusalgorithm.PROOF_OF_STAKE", + "org.hyperledger.cactus.consensusalgorithm.PROOF_OF_WORK", + ], + }, PrimaryKey: { type: "string", minLength: 1, From 9f2d2c93aa5124328bd6ddae2b112174554dc8a1 Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Mon, 4 Jan 2021 19:27:05 -0800 Subject: [PATCH 2/2] feat(core-api): getConsensusAlgorithmFamily() on connector API The method is called getConsensusAlgorithmFamily() because we don't need (for now) the level of granularity that is provided by having a method that points to the exact algorithm used by the ledger (can be added later). Why? Because for now we are mostly interested in whether an algorithm family guarantees transaction finality or not and this can be determined just from the family since for example it does not make much of a difference if you are talking about Bitcon's or Ethereum 1's proof of work, they both just do not guarantee transaction finality the same way for all our intents and purposes at present. The added benefit of only dealing in families instead of specific algorithms is that we can hardcode the answers instead of having to query the ledger or rely on operators to provide this information via configuration (again, we'll probably end up needing this in the future anyway, but for the upcoming work the families should be enough). Fixes #355 Signed-off-by: Peter Somogyvari --- .../plugin/ledger-connector/i-plugin-ledger-connector.ts | 9 +++++++++ .../src/main/typescript/plugin-ledger-connector-besu.ts | 7 +++++++ .../main/typescript/plugin-ledger-connector-fabric.ts | 7 +++++++ .../main/typescript/plugin-ledger-connector-quorum.ts | 7 +++++++ 4 files changed, 30 insertions(+) diff --git a/packages/cactus-core-api/src/main/typescript/plugin/ledger-connector/i-plugin-ledger-connector.ts b/packages/cactus-core-api/src/main/typescript/plugin/ledger-connector/i-plugin-ledger-connector.ts index 30ed1a154b..f700d1b803 100644 --- a/packages/cactus-core-api/src/main/typescript/plugin/ledger-connector/i-plugin-ledger-connector.ts +++ b/packages/cactus-core-api/src/main/typescript/plugin/ledger-connector/i-plugin-ledger-connector.ts @@ -1,4 +1,5 @@ import { ICactusPlugin } from "../i-cactus-plugin"; +import { ConsensusAlgorithmFamily } from "../../generated/openapi/typescript-axios/api"; /** * Common interface to be implemented by plugins which are implementing the connection to ledgers. @@ -21,4 +22,12 @@ export interface IPluginLedgerConnector< * type of ledger this connectir is targeted at. */ transact(options?: TransactIn): Promise; + + /** + * Returns the family of algorithms in which the consensus algorithm used + * by the ledger (this connector is associated with) belongs in. + * + * @see {ConsensusAlgorithmFamily} + */ + getConsensusAlgorithmFamily(): Promise; } diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/plugin-ledger-connector-besu.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/plugin-ledger-connector-besu.ts index 663ce87a0f..1281523630 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/plugin-ledger-connector-besu.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/plugin-ledger-connector-besu.ts @@ -10,6 +10,7 @@ import { ContractSendMethod } from "web3-eth-contract"; import { TransactionReceipt } from "web3-eth"; import { + ConsensusAlgorithmFamily, IPluginLedgerConnector, IWebServiceEndpoint, IPluginWebService, @@ -168,6 +169,12 @@ export class PluginLedgerConnectorBesu return PluginAspect.LEDGER_CONNECTOR; } + public async getConsensusAlgorithmFamily(): Promise< + ConsensusAlgorithmFamily + > { + return ConsensusAlgorithmFamily.AUTHORITY; + } + public async invokeContract( req: InvokeContractV1Request ): Promise { diff --git a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts index 4b99a88359..bd8f43025a 100644 --- a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts +++ b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts @@ -16,6 +16,7 @@ import { import { Optional } from "typescript-optional"; import { + ConsensusAlgorithmFamily, IPluginLedgerConnector, PluginAspect, IPluginWebService, @@ -116,6 +117,12 @@ export class PluginLedgerConnectorFabric return Optional.empty(); } + public async getConsensusAlgorithmFamily(): Promise< + ConsensusAlgorithmFamily + > { + return ConsensusAlgorithmFamily.AUTHORITY; + } + /** * FIXME: Implement this feature of the connector. * diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts index 8dea603118..f36dba8b21 100644 --- a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts +++ b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts @@ -10,6 +10,7 @@ import { ContractSendMethod } from "web3-eth-contract"; import { TransactionReceipt } from "web3-eth"; import { + ConsensusAlgorithmFamily, IPluginLedgerConnector, IWebServiceEndpoint, IPluginWebService, @@ -152,6 +153,12 @@ export class PluginLedgerConnectorQuorum return PluginAspect.LEDGER_CONNECTOR; } + public async getConsensusAlgorithmFamily(): Promise< + ConsensusAlgorithmFamily + > { + return ConsensusAlgorithmFamily.AUTHORITY; + } + public async invokeContract( req: InvokeContractV1Request ): Promise {