Skip to content
This repository has been archived by the owner on Oct 18, 2018. It is now read-only.

Interfaces and Data Types

Luis de Leon edited this page Apr 3, 2018 · 24 revisions

Here we will define the base interfaces and data types used in the Pocket Network Protocol. The following notation syntax belongs to the Solidity programming language.

Data Types

Relay

It contains all information regarding each transaction relayed by bytes32 nodeNonce;. bytes32 txHash; Is a hashed representation of the transaction relayed (the transaction format is to be determined, but it should include the token id as part of the header of the transaction), and also serves as a unique nonce for the Relay. All verifications in the mapping (bytes32 => bool) verifications; are signed by every one of the verifiers Nodes, hence the key bytes32.

struct Relay {
    bytes8 token;
    bytes32 txHash;
    address sender;
    bytes32 nodeNonce;
    mapping (bytes32 => bool) verifications;
}

Epoch

This is a timeframe within the network where multiple mapping (bytes32 => Relay) relays; executed by a Node happened. Each Epoch is delimited by it's uint blockStart; and uint blockEnd; which are the block numbers at which it started and ended. Each Epoch is uniquely identified by a uint256 nonce;.

struct Epoch {
    uint256 nonce;
    uint256 blockStart;
    uint256 blockEnd;
    mapping (bytes32 => Relay) relays;
    mapping (bytes32 => bytes32[]) relaysPerNode;
}

Node

Entity which performs or verifies every Relay operation, and expects a monetary reward from the aforementioned work in POKT. Each Node has a address owner;, a list of bytes8[] networks;, and the bytes32 endpoint; information encoded using the Multiaddr Format. Each Node is uniquely identified by a bytes32 nonce;.

struct Node {
    bytes32 nonce;
    address owner;
    bytes8[] networks;
    bytes32 endpoint;
}

Interfaces

NodeRegistry

Records the unique list of Nodes in the network. The NodeRegistry keeps a public mapping of mapping (bytes32 => Node) public nodes; where the key is a unique bytes32 nonce; which is a hash of the owner, networks and endpoint values. Also the NodeRegistry exposes a bytes32[] public nodesIndex; which helps find the Node in the mapping easily. To access a list of Node per owner, we have the mapping (address => bytes32[]) public nodesPerAccount;. In regard to functions, we have the function register(bytes8[] _networks, bytes32 _endpoint) public returns(bytes32) {} which allows to register a new Node, returning a bytes32 nonce for the Node, if it doesn't exist already, in which case it will error out. We can also verify ownership of each node by calling into the function isOwner(address _possibleOwner, bytes32 _nodeNonce) public returns(bool) {} which returns a bool indicating wheter or not the address _possibleOwner is the owner of the bytes32 _nodeNonce Node. And finally we have function isNode(bytes32 _nodeNonce) public returns(bool) {} to verify existence of a given Node nonce. The function getOwnerNodes(address _owner, uint256 _page) public view returns (bytes32[]) {} returns a paginated list of 10 Node nonces, which can be used with the function getNode(bytes32 _nodeNonce) public view returns (bytes32, address, bytes8[], string) {} to get the information of each individual Node.

contract NodeRegistry {
    // State
    mapping (bytes32 => Models.Node) public nodes;
    mapping (address => bytes32[]) public nodesPerAccount;
    bytes32[] public nodesIndex;
    
    // Functions
    function register(bytes8[] _networks, string _endpoint) public returns(bytes32) {}
    function isNode(bytes32 _nodeNonce) public view returns(bool) {}
    function isOwner(address _possibleOwner, bytes32 _nodeNonce) public view returns(bool) {}
    function getNodeOwner(bytes32 _nodeNonce) public view returns(address) {}
    function getOwnerNodes(address _owner, uint256 _page) public view returns (bytes32[]) {}
    function getNode(bytes32 _nodeNonce) public view returns (bytes32, address, bytes8[], string) {}
    function getNodesIndexLength() public view returns (uint256) {}
}

EpochRegistry

Records the list of Epochs recorded in the network, each Epoch can contain 0-N Relays. Contains a mapping (uint256 => Epoch) public epochs; of every Epoch that passes since the instantiation of the contract, paired with a uint256[] public epochsIndex; for ease of traversal. The uint256 public currentEpoch; is indicated by the order in which it happened, and the uint256 public blocksPerEpoch; determine how much length is between the uint256 blockStart; and the uint256 blockEnd; of the next Epoch. Any given Node can then go ahead and perform any of the following operations:

  • function addRelayToCurrentEpoch(bytes8 _token, bytes32 _txHash, address _sender, bytes32 _nodeNonce) public returns(bytes32) {} which inserts a new Relay on the uint256 public currentEpoch;.
  • function verifyRelayInEpoch(uint256 _epoch, bytes32 _relayNonce, bytes32 _nodeNonce, bool _verificationResult) public {} which adds a bool _verificationResult for the given bytes32 _relayTx.
contract EpochRegistry {
    // State
    mapping (uint256 => Epoch) public epochs;
    uint256[] public epochsIndex;
    uint256 public currentEpoch;
    uint256 public blocksPerEpoch;

    // Functions
    function addRelayToCurrentEpoch(bytes8 _token, bytes32 _txHash, address _sender, bytes32 _nodeNonce) public returns(bytes32) {}
    function verifyRelayInEpoch(uint256 _epoch, bytes32 _relayNonce, bytes32 _nodeNonce, bool _verificationResult) public {}
}
Clone this wiki locally