NodeRegistry

Git Source

Inherits: INodeRegistry, Migratable, ERC721Upgradeable

This contract is responsible for minting NFTs and assigning them to node owners. Each node is minted as an NFT with a unique ID (starting at 100 and increasing by 100 with each new node). In addition to the standard ERC721 functionality, the contract supports node-specific features, including node property updates.

All nodes on the network periodically check this contract to determine which nodes they should connect to.

State Variables

NODE_INCREMENT

The increment for node IDs, which allows for 100 shard node IDs per node in the future (modulus 100).

uint32 public constant NODE_INCREMENT = 100;

_FORWARD_SLASH

bytes1 internal constant _FORWARD_SLASH = 0x2f;

parameterRegistry

The address of the parameter registry.

address public immutable parameterRegistry;

_NODE_REGISTRY_STORAGE_LOCATION

bytes32 internal constant _NODE_REGISTRY_STORAGE_LOCATION =
    0xd48713bc7b5e2644bcb4e26ace7d67dc9027725a9a1ee11596536cc6096a2000;

Functions

_getNodeRegistryStorage

function _getNodeRegistryStorage() internal pure returns (NodeRegistryStorage storage $);

onlyAdmin

modifier onlyAdmin();

constructor

Constructor for the implementation contract, such that the implementation cannot be initialized.

The parameter registry must not be the zero address.

The parameter registry is immutable so that it is inlined in the contract code, and has minimal gas cost.

constructor(address parameterRegistry_);

Parameters

NameTypeDescription
parameterRegistry_addressThe address of the parameter registry.

initialize

Initializes the contract.

function initialize() public initializer;

addNode

Adds a new node to the registry and mints its corresponding ERC721 token.

Node IDs start at 100 and increase by 100 for each new node.

function addNode(address owner_, bytes calldata signingPublicKey_, string calldata httpAddress_)
    external
    onlyAdmin
    returns (uint32 nodeId_, address signer_);

Parameters

NameTypeDescription
owner_addressThe address that will own the new node node/NFT.
signingPublicKey_bytesThe public key used for node signing/verification.
httpAddress_stringThe node’s HTTP address.

Returns

NameTypeDescription
nodeId_uint32The unique identifier of the newly added node.
signer_addressThe address derived by the signing public key, for convenience.

addToNetwork

Adds a node to the canonical network.

function addToNetwork(uint32 nodeId_) external onlyAdmin;

Parameters

NameTypeDescription
nodeId_uint32The unique identifier of the node.

removeFromNetwork

Removes a node from the canonical network.

function removeFromNetwork(uint32 nodeId_) external onlyAdmin;

Parameters

NameTypeDescription
nodeId_uint32The unique identifier of the node.

setBaseURI

Set the base URI for the node NFTs.

function setBaseURI(string calldata baseURI_) external onlyAdmin;

Parameters

NameTypeDescription
baseURI_stringThe new base URI. Has to end with a trailing slash.

setHttpAddress

Set the HTTP address of an existing node.

function setHttpAddress(uint32 nodeId_, string calldata httpAddress_) external;

Parameters

NameTypeDescription
nodeId_uint32The unique identifier of the node.
httpAddress_stringThe new HTTP address.

updateAdmin

Updates the admin by referring to the admin parameter from the parameter registry.

function updateAdmin() external;

updateMaxCanonicalNodes

Updates the max canonical nodes by referring to the max canonical nodes parameter from the parameter registry.

function updateMaxCanonicalNodes() external;

migrate

Initiates a migration of the proxy, in a way defined by the implementation.

Normally, the implementation has a way of determining the migrator that needs to be delegatecalled.

function migrate() external;

admin

The address of the admin.

function admin() external view returns (address admin_);

adminParameterKey

The parameter registry key used to fetch the admin.

function adminParameterKey() public pure returns (string memory key_);

maxCanonicalNodesParameterKey

The parameter registry key used to fetch the max canonical nodes.

function maxCanonicalNodesParameterKey() public pure returns (string memory key_);

migratorParameterKey

The parameter registry key used to fetch the migrator.

function migratorParameterKey() public pure returns (string memory key_);

maxCanonicalNodes

The maximum number of nodes that can be part of the canonical network.

function maxCanonicalNodes() external view returns (uint8 maxCanonicalNodes_);

canonicalNodesCount

The number of nodes that are part of the canonical network.

function canonicalNodesCount() external view returns (uint8 canonicalNodesCount_);

getAllNodes

Gets all nodes regardless of their health status.

function getAllNodes() external view returns (NodeWithId[] memory allNodes_);

Returns

NameTypeDescription
allNodes_NodeWithId[]An array of all nodes in the registry.

getAllNodesCount

Gets the total number of nodes in the registry.

function getAllNodesCount() external view returns (uint32 nodeCount_);

Returns

NameTypeDescription
nodeCount_uint32The total number of nodes.

getCanonicalNodes

Gets all canonical nodes IDs.

function getCanonicalNodes() external view returns (uint32[] memory canonicalNodes_);

Returns

NameTypeDescription
canonicalNodes_uint32[]An array of all canonical nodes.

getNode

Retrieves the details of a given node.

function getNode(uint32 nodeId_) external view returns (Node memory node_);

Parameters

NameTypeDescription
nodeId_uint32The unique identifier of the node.

Returns

NameTypeDescription
node_NodeThe Node struct containing the node's details.

getIsCanonicalNode

Retrieves whether a node is part of the canonical network.

function getIsCanonicalNode(uint32 nodeId_) external view returns (bool isCanonicalNode_);

Parameters

NameTypeDescription
nodeId_uint32The unique identifier of the node.

Returns

NameTypeDescription
isCanonicalNode_boolA boolean indicating whether the node is part of the canonical network.

getSigner

Retrieves the signer of a node.

function getSigner(uint32 nodeId_) external view returns (address signer_);

Parameters

NameTypeDescription
nodeId_uint32The unique identifier of the node.

Returns

NameTypeDescription
signer_addressThe address of the signer.

version

Returns semver version string

function version() external pure returns (string memory version_);

Returns

NameTypeDescription
version_stringThe semver version string

contractName

Returns contract name

function contractName() external pure returns (string memory contractName_);

Returns

NameTypeDescription
contractName_stringThe contract name

_baseURI

function _baseURI() internal view override returns (string memory baseURI_);

_getSignerFromPublicKey

Returns the signer address from a public key.

Validates uncompressed public key format: 0x04 + 32 bytes X + 32 bytes Y = 65 bytes total

function _getSignerFromPublicKey(bytes calldata publicKey_) internal pure returns (address signer_);

Parameters

NameTypeDescription
publicKey_bytesThe public key.

Returns

NameTypeDescription
signer_addressThe signer address.

_isZero

function _isZero(address input_) internal pure returns (bool isZero_);

_revertIfNotAdmin

function _revertIfNotAdmin() internal view;

_revertIfNotNodeOwner

function _revertIfNotNodeOwner(uint32 nodeId_) internal view;

Structs

NodeRegistryStorage

The UUPS storage for the node registry.

Note: storage-location: erc7201:xmtp.storage.NodeRegistry

struct NodeRegistryStorage {
    address admin;
    uint8 maxCanonicalNodes;
    uint8 canonicalNodesCount;
    uint32 nodeCount;
    mapping(uint32 tokenId => Node node) nodes;
    string baseURI;
    EnumerableSet.UintSet canonicalNodes;
}

Properties

NameTypeDescription
adminaddressThe admin address.
maxCanonicalNodesuint8The maximum number of canonical nodes.
canonicalNodesCountuint8Not used, use canonicalNodes.length() instead.
nodeCountuint32The current number of nodes.
nodesmapping(uint32 tokenId => Node node)A mapping of node/token IDs to nodes.
baseURIstringThe base component of the token URI.
canonicalNodesEnumerableSet.UintSetA set of the canonical node IDs.