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

Directory Sevices v2.1 #4903

Merged
merged 23 commits into from
Oct 11, 2024
Merged

Directory Sevices v2.1 #4903

merged 23 commits into from
Oct 11, 2024

Conversation

jstuczyn
Copy link
Contributor

@jstuczyn jstuczyn commented Sep 19, 2024

CHANGES

Higher Level Relevant changes

Okay. This is yet another godzilla PR. It's the final (I hope) step in the project smoosh (™️) which introduces Nym Nodes into the mixnet contract and deprecates standalone gateways/mixnodes. Any new bonded node will provide only the bare minimum information: host, identity key and optionally custom port of its HTTP api. everything else will be discovered via the self-described API for maximum flexibility. this also includes the sphinx key, meaning if the API is not exposed, the node will be unable to route any traffic. Furthermore, this allows to arbitrary change your mixnode into a gateway (and vice versa) without losing any delegations.

The contract changes also mean the rewarding is getting (kinda) revamped. Rather than just mixnodes, or nodes with assigned mixing roles, getting rewards, gateways now also added into the pool. However, to be eligible for gateway rewarding, one must migrate into a Nym Node (or bond a new nodde). Currently the rewards are split equally, i.e. every node being assigned 1/240 work factor with the usual scaling by performance, stake. etc.

Below I've listed some detailed API changes for the nym-api and the mixnet contract so that the consumers of those could migrate accordingly.

For any additional context and details of some of the changes, please refer to the internal document I shared a while back. ping me for the link if you lost it.

nym-api

High Level Changes

Added:

  • all new routes that return multiple nodes/entries/etc now wrap their responses to expect pagination. Currently, however, full data is returned for each of the endpoints since I haven't actually implemented the pagination yet : ) But at least once we add it, it won't be a breaking API change.
  • I might have created a small monster when attempting to parallelise querying all self-described endpoints concurrently (of a single node) in a type-safe way. If you ever stumble upon that code, here be dragons, I warned you.

Removed:

  • rocket support has been completely removed. all routes are now always served via axum

Changed:

  • getting anything to do with all nodes (including gateways) requires knowing their node_id. for legacy gateway endpoints, we have a helper method that translates identity key to the node_id
  • rewarded set is no longer populated with just mixnodes. instead legacy mixnodes, legacy gateways and nym-nodes are assigned to eligible roles (based on stake and performance) in the following order:
    • entry gateways
    • exit gateways
    • mixnodes
    • standby
  • a lot of legacy routes got deprecated. while technically they still "work" and return data, they only return data for legacy mixnodes/gateways. what it means is that as operators are migrating their nodes (in the smart contract), those endpoints will start running dry
  • since layers are only assigned during rewarded set assignment, for the purposes of network monitor (v1) and legacy mixnode routes, layerless nodes are put on random layers during annotation
  • all legacy gateway queries now also include additional field in their respones: node_id that indicate the id pre-assigned during contract migration
  • Nym Node performance is a bit iffy. when network monitors (v1 and v2) were made, there was no concept of a Nym Node. So what I'm doing is checking "is there any mixnode performance for node with this id", if so I return it. Otherwise I grab the equivalent gateway performance. In the future it should probably be averaged or maybe split into explicit mix/gateway performance metrics

API Changes

Added:

  • a small QoL for myself: root route: / now redirects to /swagger

  • Nym Nodes routes:

    • /v1/nym-nodes/annotation/{node_id} - get annotation about particular Nym Node, as gathered by this nym-api. currently this just includes last 24h performance metric and the current node role
    • /v1/nym-nodes/bonded - get bond information about Nym Nodes, as present in the mixnet contract
    • /v1/nym-nodes/described - get described information about Nym Nodes, as present on their self-described API
    • /v1/nym-nodes/historical-performance/{node_id} - return historical performance of this Nym Node on the provided date
    • /v1/nym-nodes/performance-history/{node_id} - return performance history of this Nym Node (as a 0 - 1 float)
    • /v1/nym-nodes/uptime-history/{node_id} - return current uptime of this Nym Node (as a 0 - 100 u8); added for compatibility with existing APIs using that data format
    • /v1/nym-nodes/performance/{node_id} - return current performance of this Nym Node
  • Unstable Nym Nodes Routes:

    • /v1/unstable/nym-nodes/noise - returns information basic information needed for the noise protocol between nodes
    • /v1/unstable/nym-nodes/skimmed/active - returns all Nym Nodes AND legacy mixnodes AND legacy gateways that are currently in the active set, unless no-legacy parameter is used
    • /v1/unstable/nym-nodes/skimmed/mixnodes/active - returns all Nym Nodes AND legacy mixnodes that are currently in the active set, unless no-legacy parameter is used
    • /v1/unstable/nym-nodes/skimmed/mixnodes/all - returns all Nym Nodes AND legacy mixnodes that are currently bonded and support mixing role, unless no-legacy parameter is used
    • /v1/unstable/nym-nodes/skimmed/entry-gateways/active - returns all Nym Nodes AND legacy gateways that are currently in the active set and are assigned the entry role, unless no-legacy parameter is used
    • /v1/unstable/nym-nodes/skimmed/exit-gateways/active - returns all Nym Nodes AND legacy gateways that are currently in the active set and are assigned the exit role, unless no-legacy parameter is used
    • /v1/unstable/nym-nodes/skimmed/entry-gateways/all - returns all Nym Nodes AND legacy gateways that are currently bonded and support entry gateway role, unless no-legacy parameter is used
    • /v1/unstable/nym-nodes/skimmed/exit-gateways/all - returns all Nym Nodes AND legacy gateways that are currently bonded and support exit gateway role, unless no-legacy parameter is used

Deprecated (will be removed eventually, so please migrate away from their usage):

Some endpoints got purposely deprecated without any equivalent reimplemented since they do not belong on nym-api. This includes for example /stake-saturation (which can be obtained directly from the contract instead) or /inclusion-probability (for this run your own Monte Carlo simulation)

  • contract-cache routes - all of the below got deprecated as they will only return legacy mixnode/gateway data:

    • /v1/gateways
    • /v1/gateways/blacklisted
    • /v1/mixnodes
    • /v1/mixnodes/active - just to restate the obvious, it will only return a small SUBSET of the active set that since it will ignore active Nym Nodes
    • /v1/mixnodes/active/detailed
    • /v1/mixnodes/blacklisted
    • /v1/mixnodes/detailed
    • /v1/mixnodes/rewarded
    • /v1/mixnodes/rewarded/detailed
  • status routes - all of the below got deprecated as they will only return legacy mixnode/gateway data:

    • /v1/status/gateway/{identity}/report
    • /v1/status/gateway/{identity}/history
    • /v1/status/gateway/{identity}/core-status-count
    • /v1/status/gateway/{identity}/avg_uptime
    • /v1/status/gateways/detailed
    • /v1/status/gateways/detailed-unfiltered
    • /v1/status/mixnode/{mix_id}/report
    • /v1/status/mixnode/{mix_id}/history
    • /v1/status/mixnode/{mix_id}/core-status-count
    • /v1/status/mixnode/{mix_id}/avg_uptime
    • /v1/status/mixnodes/detailed
    • /v1/status/mixnodes/detailed-unfiltered
    • /v1/status/mixnode/{mix_id}/status
    • /v1/status/mixnode/{mix_id}/reward-estimation
    • /v1/status/mixnode/{mix_id}/compute-reward-estimation
    • /v1/status/mixnode/{mix_id}/stake-saturation
    • /v1/status/mixnode/{mix_id}/inclusion-probability
    • /v1/status/mixnodes/inclusion_probability
    • /v1/status/mixnodes/rewarded/detailed
    • /v1/status/mixnodes/active/detailed
  • Nym Nodes routes - all of the below got deprecated as they will only return legacy mixnode/gateway data:

    • /v1/gateways/described
    • /v1/mixnodes/described
  • Unstable Nym Nodes Routes:

    • /v1/unstable/nym-nodes/mixnodes/skimmed - due to inconsistency in behaviour (i.e. active vs all) it is now redirected to /v1/unstable/nym-nodes/mixnodes/skimmed/active and unwraps the pagination
    • /v1/unstable/nym-nodes/gateways/skimmed - due to inconsistency in behaviour (i.e. active vs all) it is now redirected to /v1/unstable/nym-nodes/entry-gateways/skimmed/all and unwraps the pagination

Changed:

  • Unstable Nym Nodes Routes:
    • /v1/unstable/nym-nodes/skimmed - now works with exit parameter
    • /v1/unstable/nym-nodes/skimmed - introduced no-legacy flag to ignore legacy mixnodes/gateways (where applicable)
    • /v1/unstable/nym-nodes/skimmed - will now return ALL nodes if no query parameter is provided

Mixnet Contract

High Level Changes

Added:

  • all new nodes are now bonded as NymNodes, even when using old BondMixnode or BondGateway messages (messages are getting translated)
  • you only announce your identity key, host and port to the directory. everything else is discovered via self-described endpoint (so you'd better make sure it works, otherwise you will be unroutable and thus won't get any rewards!)
  • all NymNodes in the rewarded set are eligible for rewards and staking. Even if they serve one of the gateway roles. Legacy mixnodes can still get rewards as before. Legacy gateways can't be staked on nor get rewards
  • all nodes, including legacy mixnodes and legacy gateways, are now uniquely identified by a monotonically increasing node_id
  • all legacy gateways are preassigned node_id durring the contract migration

Removed:

  • 🔥 all concepts of node families got purged, removed, deleted, thrown into the abyss. they simply no longer exist and the world is all better for it.

Changed:

  • bunch of types got changed/renamed with some fields being added/removed/deprecated. it's be quite a lot of work to list them here, so be careful for here be dragons. but whenever possible and feasible, they should be cross-compatible (but not always)
  • rewarded set is no longer just a "number". instead it has an explicit number of mixnodes, entry and exit gateways and standby nodes
  • rewarding is now based on two parameters: performance and work factor as opposed to performance and "is active" flag. However, in practice, during this transitional period, it is assumed that the work factor will be equivalent to what would have been calculated using the old "is active" flag

Transaction Messages Changes

Added:

  • BondNymNode - self-explanatory
  • UnbondNymNode - self-explanatory
  • UpdateNodeConfig - works as UpdateMixnodeConfig; it lets you change your announced host or http api port
  • MigrateMixnode - migrate your existing legacy mixnode into a Nym Node
  • MigrateGateway - migrate your exsting legacy gasteway into a Nym Node. enables staking and rewarding
  • AssignRoles - an additional step for epoch transition transactions. think of it as a replacement for AdvanceCurrentEpoch. it assigns nodes to particular roles for the given epoch

Removed:

  • as mentioned, all family-related things got killed off, so the following no longer exist: CreateFamily, JoinFamily, LeaveFamily, KickFamilyMember, CreateFamilyOnBehalf, JoinFamilyOnBehalf, LeaveFamilyOnBehalf, KickFamilyMemberOnBehalf
  • UpdateActiveSetSize - the rewarded/active set are now based on the role distribution
  • AssignNodeLayer - we're no longer explicitly assigning roles to all mixnodes, instead they get assigned mixing roles
  • AdvanceCurrentEpoch - the logic for advancing the epoch/assining active set has changed so this message was removed

Renamed/Changed:

  • UpdateMixnodeCostParams - is now called UpdateCostParams. Old variant, however, should still work through the magic of serde
  • DelegateToMixnode - is now called Delegate with the mix_id field being replaced by node_id. Old variant, however, should still work through the magic of serde
  • UndelegateFromMixnode - is now called Undelegate with the mix_id field being replaced by node_id. Old variant, however, should still work through the magic of serde
  • RewardMixnode - is now called RewardNode with the mix_id field being replaced by node_id. Old variant, however, should still work through the magic of serde
  • WithdrawDelegatorReward - the mix_id field is replaced by node_id. Old variant, however, should still work through the magic of serde

Query Changes

Added:

  • GetPreassignedGatewayIds - get node_id of an unmigrated legacy gateway that got assigned during contract migration
  • GetNymNodeBondsPaged
  • GetNymNodesDetailedPaged
  • GetUnbondedNymNode
  • GetUnbondedNymNodesPaged
  • GetUnbondedNymNodesByOwnerPaged
  • GetUnbondedNymNodesByIdentityKeyPaged
  • GetOwnedNymNode
  • GetNymNodeDetails
  • GetNymNodeDetailsByIdentityKey
  • GetNodeRewardingDetails
  • GetNodeStakeSaturation
  • GetRoleAssignment - get list of node_id of nodes that got assigned particular role for this epoch
  • GetRewardedSetMetadata - get metadata associated with the current rewarded set, such as number of nodes for given role, highest id, etc. not really useful for "average" user
  • GetNodeStakeSaturation - works the same way as old MixStakeSaturationResponse, but the response is ever so slightly different
  • GetPendingOperatorReward . it differs from GetPendingNodeOperatorReward

Removed:

  • GetRewardedSet
  • GetLayerDistribution

Renamed/Changed:

  • GetMixnodeDelegations - is now called GetNodeDelegations with the mix_id field being replaced by node_id. Old variant, however, should still work through the magic of serde
  • GetPendingMixNodeOperatorReward - is now called GetPendingNodeOperatorReward with the mix_id field being replaced by node_id. Old variant, however, should still work through the magic of serde

This change is Reviewable

@jstuczyn jstuczyn force-pushed the feature/directory-v3-purge-base branch from c91f42b to 2485d63 Compare September 19, 2024 15:27
Copy link

vercel bot commented Sep 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
nym-explorer ⬜️ Ignored (Inspect) Visit Preview Oct 10, 2024 2:42pm
nym-next-explorer ⬜️ Ignored (Inspect) Visit Preview Oct 10, 2024 2:42pm

@jstuczyn jstuczyn modified the milestones: Aero, MarsBar Sep 19, 2024
@jstuczyn jstuczyn marked this pull request as ready for review September 25, 2024 08:36
@jstuczyn jstuczyn force-pushed the feature/directory-v3-purge-base branch from e2fb52c to 25a8a27 Compare September 25, 2024 10:28
Copy link
Contributor

@octol octol 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 a beast of a PR, great work! :)
I've been trying to look at the big picture to get a feel for what the changes are and I like it!

@jstuczyn jstuczyn force-pushed the feature/directory-v3-purge-base branch from e9d990a to d53f841 Compare October 9, 2024 15:48
WIP; rebasing

Another branch squash

Squashing the v3 branch

changing min pledge amounts

logic for adding new nymnode into the contract

converting mixnode/gateway bonding into nym-node bonding

logic for migrating gateways into nymnodes

ibid for mixnodes

further nym-node work + fixed most existing unit tests

forbid nymnode migration with pending cost params changes

preassign nodeid for gateways

changing role assignment and epoch progression

changing role assignment and epoch progression

optional custom http port

logic for unbonding a nym-node

updating Delegation struct

logic for increasing pledge of either mixnode or nymnode

logic for decreasing pledge of either mixnode or a nym node

logic for changing cost params of either mixnode or a nym node

wip

initialise nymnodes storage

fixing transaction tests

fixed naive family tests

reward-compatibility related works

resolving delegation events

introduced rewarded set metadata

another iteration of restoring old tests

updated rewarding part of nym-api

parking the branch

unparking the branch

wip

purged families

added 'ExitGateway' role

passing explicit work factor for rewarding function

remove legacy layers storage

wip: node description queries

added announced ports to self-described api

step1 in gruelling journey of adding node_id to gateways

ensure epoch work never goes above 1.0

changed active set to contain role distribution

[theoretically] sending rewarding messages for the new rewarded set

[theoretically] assigning new rewarded set

reimplementing more nym-api features

remove legacy types

re-implement legacy network monitor

restoring further routes + minor refactor of NodeStatusCache

skimmed routes now return legacy nodes alongside nym-nodes

seemingly restored all functionalities in nym-api

removing more legacy things from the contract

initial contract cleanup

added nym-api endpoints to return generic annotations regardless of type

updated simulator to use new rewarding parameters

more contract cleanup

made existing mixnet contract tests compile

extra validation of nym-node bonding parameters

fixed additional compilation issues

fixed nym-api v3 database migration failure

added additional nym-node contract queries

updated the schema

made additional delegation/rewards queries compatible with both legacy mixnodes and nym-nodes

fixing existing unit tests in mixnet contract

wip

resolved first batch of 500 compiler errors

re-deprecating routes

making wallet's rust backend compile

fixed non-determinism in contract + nym-api build

fixes to the build

populating cotracts-cache with nym-nodes data

more missing nymnodes queries

temp mixnet contract methods + restored result submission in nym-api

allow deprecated routes

submitting correct results for mixnode results

removed deprecated re-export of AxumAppState and removed smurf naming

moved axum modules into support::http

cleaning up nym-api warnings

determine entry gateways before exits

exposed transaction to update nym-node config

missing memo for updating node config

 new routes

added routes to swagger and fixed relative paths

fixed some macro derivations

added nym-node commands to nym-cli
@jstuczyn jstuczyn force-pushed the feature/directory-v3-purge-base branch from 07c9501 to 45f4eee Compare October 10, 2024 14:38
@jstuczyn jstuczyn merged commit 8113948 into develop Oct 11, 2024
17 checks passed
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.

2 participants