Skip to content

Discovery Refactoring - Derived from JOSE replacement #493

@CMCDragonkai

Description

@CMCDragonkai

Specification

This spec is less well-baked compared to the GestaltGraph because this is my initial review of the discovery domain.

The discovery domain depends on:

  1. NodeManager for connecting to nodes and asking about their sigchain
  2. TaskManager to run background tasks
  3. GestaltGraph to update the links they discover
  4. KeyRing to know if we are finding our own NodeId.
  5. Sigchain to add its own sigchain into the GestaltGraph

There are several major changes here required:

GestaltId instead of GestaltKey

The GestaltGraph now uses GestaltId, it does not expose the GestaltKey, all operations must now use the GestaltId when interacting with the Sigchain.

Querying the Sigchain of remote node

When connecting to the remote node in order to discover their sigchain, it must be understood as a stream of claims. Rather than one giant claim array. This means instead of calling NodeManager.requestChainData, it should be using the NCM and connecting to it.

We know that the NCM is a supervisor over node connection pools. It should be the primary way by which downstream domains attempt contact to other nodes and to call them.

The NM by contrast can also use the NCM and expose a variety of high-level functionality over the nodes. However in this case, the only user of NodeManager.requestChainData is the Discovery and it makes more sense for the Discovery to directly operate the NodeConnection and its encapsulated GRPC client.

Therefore the Discovery should be relying on the NodeConnectionManager and not the NodeManager.

On the GRPC service handler, the nodesChainDataGet should be changed to a server stream. This stream will yield SignedClaim.

On the other side, when querying the own Sigchain, it should not just call Sigchain.getClaims, but get only the "latest" (and unrevoked) claim per node ID or identity ID. To do this, the Sigchain will need some sort of indexing to keep track of this (#327).

Processing own Node

With respect to #319, it should be processing its own sigchain immediately on start and adding such data to the GestaltGraph.

The Sigchain can be mutated by itself during the claiming process for node to node and node to identity. This claiming process cannot be initiated by the Sigchain.

This part is currently a bit confusing.

For node to node claims, this all starts in NodeManager.claimNode, which itself ends up calling the Sigchain.

But for node to identity claims, this is done by the GRPC handler identitiesClaim which orchestrates operations between the Sigchain and Provider.

We need to clarify on a few things here:

  1. Should the Discovery be responsible for managing the node's own Sigchain and putting its data into the GestaltGraph?
  2. How should the Discovery crawl its GestaltGraph and does it also try to discover its own vertex?
  3. We decided long ago, that GRPC handlers (service layer) should be thin wrappers around domain models (business layer) doing the bulk of the business logic. This means claiming an identity should be in the identities domain just like claiming a node is in the nodes domain.
  4. The Sigchain is not aware of the GestaltGraph and the GestaltGraph is not aware of the Sigchain. This is good, because we can do object composition here. Given that any claiming process will involve the Sigchain, should the GestaltGraph also be updated by the claiming process?

Here's one possible answer to the question:

discovery and claiming

Here you can see that claiming an identity or a node is what ends up updating the GestaltGraph. It's not a reactive thing, because claiming updates both our own Sigchain and our own gestalt in the GestaltGraph.

The claimNode and claimIdentity are now part of the domain models. In the case of claimIdentity, this needs to be part of the Provider. In fact, as an abstract class, we would expect that these dependencies to be injected into the Provider for it to be used during the claiming process. This may not be entirely good design if we expect provider plugins. In the case of plugins, we have 2 choices, we are either calling into it, or it is calling into us. If we give it the Sigchain and GestaltGraph, we are giving it quite a lot of power, thus allowing it to call into us, is like providing an entire scripting environment. A safer model is that we call into it. In that case, it would be part of the IdentitiesManager.

Note that the diagram above renames IdentitiesManager as ProviderManager atm because it doesn't do anything except manager Provider. But if the claiming process is a "don't call us, we'll call you", then it can be left as IdentitiesManager.

Finally Discovery does not actually need access to the Sigchain nor to the KeyRing. The discovery does not need discover its own node, because any changes to its own node's gestalt would be reflected immediately during the claimNode and claimIdentity operations. The discovery only needs to discover the node's own neighbours, which can it do by querying the gestalt graph and prioritising based on TTLs (which are yet to be implemented). There are still some questions as to how does the discovery become aware about the new nodes in the gestalt? This can either be push-based or pull-based. I believe right now it is pull-based, which means there's a timer-based polling onto the GestaltGraph and we have talked about making the Discovery reactive to the GestaltGraph.

Deliberate Operations for Discovery

It needs to be reviewed how exactly users can directly tell the Discovery to start its discovery process against a given NodeId or ProviderIdentityId.

GestaltLinkNode for doubly signed claims

See: #493 (comment)

Notifications for Claiming Nodes

See: #493 (comment)

Additional context

Tasks

  1. 1. Replace GestaltKey usage with GestaltId.
  2. 2. Discovery logic needs to refactored and cleaned up
  3. 3. Streaming claims when connecting to remote nodes and identities.
  4. 4. Don't process your own node, It should be added to the GestaltGraph when claims are made. This is done for both claim node and claim identity.
  5. 5. claimNode needs to be a part of the nodes domain along with the handler logic for it. The logic behind this needs to be refactored to use the new claims/token changes.
  6. 6. Likewise the claimIdentity logic and handler needs to be apart of the IdentityManager or Provider.
  7. 7. Existing tests need to be updated and coverted to using fast check.
  8. 8. New test needs to be created to do a more complex model based testing using all of the available Discovery commands.
  9. 9. Index claim read, when requesting claims we can request only the claims newer that the provided Id.
  10. 10. Notifications needs to be updated to make use of the new tokens. \
  11. Claiming nodes needs to respect permissions.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions