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

feat(consortium-static): new consortium plugin #3471

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

eduv09
Copy link
Contributor

@eduv09 eduv09 commented Aug 9, 2024

  • New plugin consortium-static, based on consortium-manual.
    Long story short, the plugin allows for the addition of Cacti Nodes to consortium at runtime. New node entities must belong to one of the consortium entities (organizations) that were specified on consortium creation. So it allows to add new nodes 'CactusNode', but not new 'ConsortiumMember' entities.

  • New feature: add CactusNode to consortium at runtime
    The code is based on the plugin-consortium-manual, with the new features built on top of it. The process of adding a new node is conducted as follows:

    1. The new node forges a request with information about itself and sends it to any Node in the consortium
    2. The receiver verifies the request, and if it is approved, broadcasts it to the rest of the consortium Nodes.
    3. Each node verifies the same request, and adds the new node to the consortium database. At the same time, the receiver node from point 2 sends the consortium data to the new node, who updates it's database.
  • Includes a new policy model
    The package includes a policy model, which was developed based on the ideas of the Policy Core Information Model RFC3060 . The idea was to introduce the idea of a multi-purpose policy framework that can be leveraged by other packages in cacti.

Copy link
Member

@petermetz petermetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eduv09 Please include all details in the commit message not just the PR description

Copy link
Member

@petermetz petermetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eduv09 Looks like a high quality PR, thank you very much! I have some nit-picks in the comments above and a couple requests here:

  1. Remove the changelog file, it doesn't make sense to have it in a new package - it gets auto-generated when we issue a release.
  2. Add a CI job in ci.yaml that runs the Jest tests so that it can be verified to keep working after each PR. Note that the github action versions to use are changing so make sure to use the up to date versions as shown in this otherwise unrelated PR: ci(github): upgrade [email protected] [email protected] [email protected] #3478

@petermetz
Copy link
Member

@eduv09 One more thing: if you run yarn lint it will apply the automatic formatting to the openapi spec file (the CI will fail otherwise) so you need to run yarn lint and then commit the changes it makes. This is what the diff looks like on my machine:

image

Copy link
Contributor

@RafaelAPB RafaelAPB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very high-quality work, thanks for your contribution! I've left a few comments, most things should be relatively easy to fix. Please also refer to @petermz 's comments. Besides that, LGTM!

@eduv09 eduv09 force-pushed the cacti-consortium-update branch 3 times, most recently from c75f8b2 to 1eb0da1 Compare August 15, 2024 11:56
@eduv09
Copy link
Contributor Author

eduv09 commented Aug 15, 2024

@RafaelAPB @petermetz I think I addressed all of the changes you requested. Let me know if I missed something, or of any other recommendations. Thank you !

@RafaelAPB
Copy link
Contributor

@eduv09 please rebase and fix any conflicts or errors

@eduv09 eduv09 force-pushed the cacti-consortium-update branch 2 times, most recently from cb313ff to 0388f09 Compare August 23, 2024 09:29
@eduv09
Copy link
Contributor Author

eduv09 commented Aug 23, 2024

@RafaelAPB Done

@RafaelAPB
Copy link
Contributor

LGTM, let's wait for @petermetz 's re-review. Cheers

@petermetz petermetz self-requested a review August 26, 2024 22:30
Copy link
Member

@petermetz petermetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eduv09 @RafaelAPB LGTM, thank you for addressing my nit-picks!

For the JWSGeneral casting question, please see my analysis here (short answer, let's merge this as is and I'll work on fixing the casting) => #3471 (comment)

One more thing: If you hit the re-request review button it will automatically land back in my PR review queue (which I try to check daily even when I don't have time to process discord messages) so I recommend hitting that every time a PR I reviewed is ready for some more attention. Tagging me on Discord and on GitHub also helps so I recommend you also keep doing that of course!
image

petermetz added a commit to petermetz/cacti that referenced this pull request Aug 27, 2024
1. createAjvTypeGuard<T>() is the lower level utility which can be used
to construct the more convenient, higher level type predicates/type guards
such as createIsJwsGeneralTypeGuard() which uses createAjvTypeGuard<JwsGeneral>
under the hood.
2. This commit is also meant to be establishing a larger, more generic
pattern of us being able to create type guards out of the Open API specs
in a convenient way instead of having to write the validation code by hand.

An example usage of the new createAjvTypeGuard<T>() utility is the
createIsJwsGeneralTypeGuard() function itself.

An example usage of the new createIsJwsGeneralTypeGuard() can be found
in packages/cactus-plugin-consortium-manual/src/main/typescript/plugin-consortium-manual.ts

The code documentation contains examples as well for maximum discoverabilty
and I'll also include it here:

```typescript
import { JWSGeneral } from "@hyperledger/cactus-core-api";
import { createIsJwsGeneralTypeGuard } from "@hyperledger/cactus-core-api";

export class PluginConsortiumManual {
  private readonly isJwsGeneral: (x: unknown) => x is JWSGeneral;

  constructor() {
    // Creating the type-guard function is relatively costly due to the Ajv schema
    // compilation that needs to happen as part of it so it is good practice to
    // cache the type-guard function as much as possible, for examle by adding it
    // as a class member on a long-lived object such as a plugin instance which is
    // expected to match the life-cycle of the API server NodeJS process itself.
    // The specific anti-pattern would be to create a new type-guard function
    // for each request received by a plugin as this would affect performance
    // negatively.
    this.isJwsGeneral = createIsJwsGeneralTypeGuard();
  }

  public async getNodeJws(): Promise<JWSGeneral> {
    // rest of the implementation that produces a JWS ...
    const jws = await joseGeneralSign.sign();

    if (!this.isJwsGeneral(jws)) {
      throw new TypeError("Jose GeneralSign.sign() gave non-JWSGeneral type");
    }
    return jws;
  }
}
```

Relevant discussion took place here:
hyperledger#3471 (comment)

Signed-off-by: Peter Somogyvari <[email protected]>
petermetz added a commit to petermetz/cacti that referenced this pull request Aug 27, 2024
1. createAjvTypeGuard<T>() is the lower level utility which can be used
to construct the more convenient, higher level type predicates/type guards
such as createIsJwsGeneralTypeGuard() which uses createAjvTypeGuard<JwsGeneral>
under the hood.
2. This commit is also meant to be establishing a larger, more generic
pattern of us being able to create type guards out of the Open API specs
in a convenient way instead of having to write the validation code by hand.

An example usage of the new createAjvTypeGuard<T>() utility is the
createIsJwsGeneralTypeGuard() function itself.

An example usage of the new createIsJwsGeneralTypeGuard() can be found
in packages/cactus-plugin-consortium-manual/src/main/typescript/plugin-consortium-manual.ts

The code documentation contains examples as well for maximum discoverabilty
and I'll also include it here:

```typescript
import { JWSGeneral } from "@hyperledger/cactus-core-api";
import { createIsJwsGeneralTypeGuard } from "@hyperledger/cactus-core-api";

export class PluginConsortiumManual {
  private readonly isJwsGeneral: (x: unknown) => x is JWSGeneral;

  constructor() {
    // Creating the type-guard function is relatively costly due to the Ajv schema
    // compilation that needs to happen as part of it so it is good practice to
    // cache the type-guard function as much as possible, for examle by adding it
    // as a class member on a long-lived object such as a plugin instance which is
    // expected to match the life-cycle of the API server NodeJS process itself.
    // The specific anti-pattern would be to create a new type-guard function
    // for each request received by a plugin as this would affect performance
    // negatively.
    this.isJwsGeneral = createIsJwsGeneralTypeGuard();
  }

  public async getNodeJws(): Promise<JWSGeneral> {
    // rest of the implementation that produces a JWS ...
    const jws = await joseGeneralSign.sign();

    if (!this.isJwsGeneral(jws)) {
      throw new TypeError("Jose GeneralSign.sign() gave non-JWSGeneral type");
    }
    return jws;
  }
}
```

Relevant discussion took place here:
hyperledger#3471 (comment)

Signed-off-by: Peter Somogyvari <[email protected]>
* New plugin consortium-static, based on consortium-manual.
Long story short, the plugin allows for the addition of Cacti Nodes to
consortium at runtime. New node entities must belong to one of the
consortium entities (organizations) that were specified on consortium
creation. So it allows to add new nodes 'CactusNode', but not new
'ConsortiumMember' entities.

* New feature: add CactusNode to consortium at runtime
The code is based on the plugin-consortium-manual, with the new features
built on top of it. The process of adding a new node is conducted as
follows:
   1. The new node forges a request with information about itself and
   sends it to any Node in the consortium
   2. The receiver verifies the request, and if it is approved,
   broadcasts it to the rest of the consortium Nodes.
   3. Each node verifies the same request, and adds the new node to the
   consortium database. At the same time, the receiver node from point 2
   sends the consortium data to the new node, who updates it's database.

* Includes a new policy model
The package includes a policy model, which was developed based on the
ideas of the Policy Core Information Model
[RFC3060](https://www.rfc-editor.org/rfc/rfc3060) . The idea was to
introduce the idea of a multi-purpose policy framework that can be
leveraged by other packages in cacti.

Signed-off-by: eduv09 <[email protected]>
@eduv09
Copy link
Contributor Author

eduv09 commented Aug 28, 2024

@petermetz fixed the CI workflow issue. I think it's good to go. Thank you for the assist 🙏

@eduv09 eduv09 requested a review from petermetz August 28, 2024 18:06
@eduv09 eduv09 requested a review from RafaelAPB August 28, 2024 18:07
@petermetz petermetz merged commit db3475f into hyperledger:main Aug 28, 2024
145 of 146 checks passed
@petermetz
Copy link
Member

@petermetz fixed the CI workflow issue. I think it's good to go. Thank you for the assist 🙏

@eduv09 You got it! Thank you very much for the contribution!

petermetz added a commit to petermetz/cacti that referenced this pull request Aug 30, 2024
1. createAjvTypeGuard<T>() is the lower level utility which can be used
to construct the more convenient, higher level type predicates/type guards
such as createIsJwsGeneralTypeGuard() which uses createAjvTypeGuard<JwsGeneral>
under the hood.
2. This commit is also meant to be establishing a larger, more generic
pattern of us being able to create type guards out of the Open API specs
in a convenient way instead of having to write the validation code by hand.

An example usage of the new createAjvTypeGuard<T>() utility is the
createIsJwsGeneralTypeGuard() function itself.

An example usage of the new createIsJwsGeneralTypeGuard() can be found
in packages/cactus-plugin-consortium-manual/src/main/typescript/plugin-consortium-manual.ts

The code documentation contains examples as well for maximum discoverabilty
and I'll also include it here:

```typescript
import { JWSGeneral } from "@hyperledger/cactus-core-api";
import { createIsJwsGeneralTypeGuard } from "@hyperledger/cactus-core-api";

export class PluginConsortiumManual {
  private readonly isJwsGeneral: (x: unknown) => x is JWSGeneral;

  constructor() {
    // Creating the type-guard function is relatively costly due to the Ajv schema
    // compilation that needs to happen as part of it so it is good practice to
    // cache the type-guard function as much as possible, for examle by adding it
    // as a class member on a long-lived object such as a plugin instance which is
    // expected to match the life-cycle of the API server NodeJS process itself.
    // The specific anti-pattern would be to create a new type-guard function
    // for each request received by a plugin as this would affect performance
    // negatively.
    this.isJwsGeneral = createIsJwsGeneralTypeGuard();
  }

  public async getNodeJws(): Promise<JWSGeneral> {
    // rest of the implementation that produces a JWS ...
    const jws = await joseGeneralSign.sign();

    if (!this.isJwsGeneral(jws)) {
      throw new TypeError("Jose GeneralSign.sign() gave non-JWSGeneral type");
    }
    return jws;
  }
}
```

Relevant discussion took place here:
hyperledger#3471 (comment)

Signed-off-by: Peter Somogyvari <[email protected]>
petermetz added a commit that referenced this pull request Sep 2, 2024
1. createAjvTypeGuard<T>() is the lower level utility which can be used
to construct the more convenient, higher level type predicates/type guards
such as createIsJwsGeneralTypeGuard() which uses createAjvTypeGuard<JwsGeneral>
under the hood.
2. This commit is also meant to be establishing a larger, more generic
pattern of us being able to create type guards out of the Open API specs
in a convenient way instead of having to write the validation code by hand.

An example usage of the new createAjvTypeGuard<T>() utility is the
createIsJwsGeneralTypeGuard() function itself.

An example usage of the new createIsJwsGeneralTypeGuard() can be found
in packages/cactus-plugin-consortium-manual/src/main/typescript/plugin-consortium-manual.ts

The code documentation contains examples as well for maximum discoverabilty
and I'll also include it here:

```typescript
import { JWSGeneral } from "@hyperledger/cactus-core-api";
import { createIsJwsGeneralTypeGuard } from "@hyperledger/cactus-core-api";

export class PluginConsortiumManual {
  private readonly isJwsGeneral: (x: unknown) => x is JWSGeneral;

  constructor() {
    // Creating the type-guard function is relatively costly due to the Ajv schema
    // compilation that needs to happen as part of it so it is good practice to
    // cache the type-guard function as much as possible, for examle by adding it
    // as a class member on a long-lived object such as a plugin instance which is
    // expected to match the life-cycle of the API server NodeJS process itself.
    // The specific anti-pattern would be to create a new type-guard function
    // for each request received by a plugin as this would affect performance
    // negatively.
    this.isJwsGeneral = createIsJwsGeneralTypeGuard();
  }

  public async getNodeJws(): Promise<JWSGeneral> {
    // rest of the implementation that produces a JWS ...
    const jws = await joseGeneralSign.sign();

    if (!this.isJwsGeneral(jws)) {
      throw new TypeError("Jose GeneralSign.sign() gave non-JWSGeneral type");
    }
    return jws;
  }
}
```

Relevant discussion took place here:
#3471 (comment)

Signed-off-by: Peter Somogyvari <[email protected]>
@eduv09 eduv09 deleted the cacti-consortium-update branch September 3, 2024 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants