Skip to content

Commit 5994040

Browse files
authored
Merge pull request #59 from Convex-Dev/develop
Updates for latest docs
2 parents 381419e + e4901d6 commit 5994040

File tree

11 files changed

+378
-54
lines changed

11 files changed

+378
-54
lines changed

docs/cad/003_encoding/README.md

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -627,34 +627,20 @@ Implementations which require more than 63 fields MAY adopt their own scheme to
627627
- Have the Record specify one field which contains a vector of additional fields
628628
- Use the first field (index 0) to specify the interpretation of following fields (which may contain arbitrary values as sub-structures)
629629

630-
### `0xB0` - `0xB1` Byte Flags (Boolean)
631-
632-
The possible Boolean values are `true` and `false`, which are coded as 1-byte Byte Flags.
633-
634-
```
635-
Encoded as:
636-
0xB0 <=> false
637-
0xB1 <=> true
638-
```
639-
640-
The two Boolean Values `true` or `false` have the Encodings `0xb1` and `0xb0` respectively.
641-
642-
Note: These Tags are chosen to aid human readability, such that the first hexadecimal digit `b` suggests "binary" or "boolean", and the second hexadecimal digit represents the bit value.
643-
644-
### `0xB2`-`0xBF` Byte Flags (Extensible)
630+
### `0xB0`-`0xBF` Byte Flags (Extensible)
645631

646632
Byte flags are one byte encodings (similar to Booleans) available for application specific use.
647633

648634
```
649635
`0xBn`
650636
651637
Where
652-
- n = a hex value from 2-15
638+
- n = a hex value from 0-15
653639
```
654640

655641
Applications MAY use byte flags as a efficient single byte value, i.e. the complete value encoding is always exactly one byte. For example, the encoding `0xb2` might represent an "unknown" value in ternary logic.
656642

657-
Values `0xb0` and `0xb1` are already reserved for the two boolean values, though an application MAY repurpose these as single byte values (along with `0x00` and `0x10`) providing these values are not needed for some other purpose.
643+
Values `0xb0` and `0xb1` are typically used for the two boolean values, though an application MAY repurpose these as single byte values (along with `0x00` and `0x10`) providing these values are not needed for some other purpose.
658644

659645
Fun Idea: A 1-byte Lisp where `0x10` is an opening paren, `0x00` is a closing paren and `0xb0 - 0xbf` are the allowable tokens.
660646

@@ -721,6 +707,10 @@ Examples:
721707
- an application might define `0xE5` as an extension where the value references a known JSON schema.
722708
- another application might define `0xE0` as an enum where the values are the possible states of a finite state machine
723709

710+
### `0xF0` - `0xFE` Reserved
711+
712+
These values are reserved for possible future CAD3 extensions. at present they are illegal
713+
724714
### `0xFF` Illegal
725715

726716
The `0xFF` tag is always illegal as a tag byte in any encoding.

docs/cad/015_peercomms/README.md

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,47 @@ Objectives:
1414
- Asynchronous model supported by default
1515
- Flexibility to adapt to different transport protocols
1616
- Consistency with lattice data principles
17+
- Usage of CAD3 data for message payloads
1718

1819
## Messages
1920

2021
Peers communicate via messages. A message is an atomic, asynchronous piece of data passed from a sender to a receiver.
2122

22-
A Message consists of:
23+
Each message has a CAD3 payload.
24+
25+
### Message Encoding
26+
27+
The Message encoding format is designed to efficiently encode a CAD3 payload. Since CAD3 structures can contain multiple branches, each with their own encoding, the key idea is to send the top level encoding first, then follow this with any required child branches.
28+
29+
A Message is normally encoded as a Blob of bytes consisting of the following:
2330

24-
- A Message Type tag (one byte)
25-
- Encoded message payload (according to Cell encoding rules)
31+
- Encoded top level message payload (according to CAD3 Cell encoding rules)
2632
- Optional: One or more additional branch cell encodings
2733
- A VLC encoded length
2834
- Branch cell encoding (according to Cell encoding rules)
2935

30-
Encoded message data depends on the message type.
31-
32-
Each individual cell encoding MUST fit within a fixed size buffer (currently 8192 bytes). However, by including the additional branch cell encodings, it is possible to include branch cells referenced by the payload. In this way:
36+
Each individual cell encoding MUST fit within a fixed size buffer (currently 16383 bytes). However, by including the additional branch cell encodings, it is possible to include branch cells referenced by the payload. In this way:
3337
- Large data structures can be passed in a single message
34-
- Branch cells can be omitted, in which case the message is regarded as **partial**. Partial messages are appropriate for values such as lattice deltas where the recipient is expected to already be in possession of the omitted branches.
38+
- Branch cells can be omitted, in which case the message is regarded as **partial**. Partial messages are appropriate for values such as lattice deltas where the recipient is expected to already be in possession of the omitted branches. A partial message is valid, however the receiver may not be able to access the full payload immediately.
3539

36-
The overall size of the message is not part of the message itself, but will be provided by the transport mechanism e.g.:
40+
The overall size of the message is not part of the message itself, but will typically be provided by the transport mechanism e.g.:
3741
- For binary protocol messages, the message length precedes the message
3842
- For HTTP messages of type `application/cvx-raw` the message length is specified in the HTTP `Content-Length` header.
3943
- For messages passed as an octet stream, the message length is naturally delineated by the end of the stream
4044

4145
### Message Types
4246

47+
The type of the message can be inferred from the payload. Any CAD3 value may form a valid Message, so the interpretation of these values is part of the peer protocol (i.e. application specific).
48+
49+
Currently recognised message types follow:
50+
4351
#### BELIEF
4452

53+
```
54+
CAD3 Payload:
55+
Belief
56+
```
57+
4558
This message specifies a belief from an other peer that is being shared as part of the CPoS consensus algorithm.
4659

4760
Receiving peers SHOULD validate this belief message, and if valid perform a belief merge with their current belief.
@@ -50,12 +63,13 @@ Receiving peers MAY ignore beliefs if they are experiencing high demand and need
5063

5164
Receiving peers SHOULD ignore and/or minimise processing for beliefs that have already been received and merged. This is safe because belief merges are idempotent.
5265

53-
#### DATA
54-
55-
This message type provides one or more encoded cells of data. Usually, this will be a component part of a longer message or a response to a `MISSING_DATA` message.
56-
5766
#### QUERY
5867

68+
```
69+
CAD3 Payload:
70+
[:QR msg-id form address?]
71+
```
72+
5973
This message represents a request for a peer to compute the results of a query (considered as a read-only transaction).
6074

6175
Peers SHOULD make a best effort attempt to respond to queries from authorised clients.
@@ -64,6 +78,11 @@ Peers MAY reject queries if they are experiencing high demand. In such cases pee
6478

6579
#### TRANSACT
6680

81+
```
82+
CAD3 Payload:
83+
[:TX msg-id signed-transaction]
84+
```
85+
6786
This message represents a request for a Peer to process a transaction by incorporating it into a subsequent Block that the Peer proposes to the Network.
6887

6988
Peers MUST reject transactions that are not correctly signed. Failure to do so may result in slashing.
@@ -72,27 +91,42 @@ Peers MUST reject transactions that have a previously used sequence number.
7291

7392
#### RESULT
7493

94+
```
95+
CAD3 Payload:
96+
Result
97+
```
98+
7599
This message represents the result of another message request (usually a transaction or query).
76100

77-
A Result message MUST reference the message ID of the original message.
101+
A Result message MUST reference the message ID of the original message. Results that do not correspond to a pending outgoing request ID should normally be ignored.
78102

79103
#### STATUS
80104

105+
```
106+
CAD3 Payload:
107+
[:SR msg-id]
108+
```
109+
81110
This message represents a request for a Peer to provide information about its current status, including data about latest consensus state.
82111

83112
Peers SHOULD respond to the status request immediately if able.
84113

85114
Peers MAY cache their most recent status response for efficiency reasons.
86115

87-
#### MISSING_DATA
116+
#### DATA_REQUEST
117+
118+
```
119+
CAD3 Payload:
120+
[:DR msg-id hash0 hash1 .....]
121+
```
88122

89123
This message represents a request for missing data. Usually, this is sent by a peer when it is attempting to process a partial message but some data is missing locally, and it needs to acquire the missing data before proceeding.
90124

91-
The Missing Data request must include the Value ID (hash of encoding) for the missing data. Note: It is guaranteed that if a peer has received a partial message, it must be able to determine the hashes of any directly missing data (since they will be encoded as refs in the partial message).
125+
The Missing Data request must include the Value IDs (hash of encoding) for the missing data branches. Note: It is guaranteed that if a peer has received a partial message, it must be able to determine the hashes of any directly missing data (since they will be encoded as branch refs in the partial message).
92126

93127
Peer that send this message MAY suspend processing of a message pending receipt of missing data from the original sender. If the original sender is unable to satisfy this request in a timely manner, the suspended message SHOULD be discarded.
94128

95-
Receiving Peers SHOULD respond by sending a `DATA` message containing the missing data specified. Failure to do so may result in a previous message being ignored.
129+
Receiving Peers SHOULD respond by sending a `RESULT` message containing the missing data specified.
96130

97131
### Trust
98132

@@ -108,6 +142,10 @@ Peers MAY accept messages from any source, but if they do, they SHOULD prioritis
108142

109143
The standard mechanism for message passing is TCP connections established between peers.
110144

145+
Messages are sent as:
146+
- a VLQ encoded message length N
147+
- N bytes representing the Message encoding
148+
111149
### UDP Connections
112150

113151
UDP will be explored as a potential future transport protocol for efficiency and performance reasons.

docs/cad/017_peerops/README.md

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
Operating a peer is an important responsibility in the Convex Network.
66

7-
Anyone can run a peer, and they are responsible for maintaining the Consensus of the Network.
7+
Anyone can run a peer, and they are responsible for maintaining the Consensus of the Network. They must place a minimum stake of 1000 Convex Coins.
88

9-
Most users of the Convex Network do not need to run a peer - they connect to peers via clients software that submits transactions and queries information on their behalf.
9+
Most users of the Convex Network do not need to run a peer - they connect to peers via client software that submits transactions and queries information on their behalf. The peer API is open to client requests by default: Peer operators who wish to restrict this may need to set up additional configuration or infrastructure.
1010

1111
This document primarily contains recommendations for peer operators
1212

@@ -15,32 +15,54 @@ This document primarily contains recommendations for peer operators
1515
Running a Peer requires:
1616

1717
- An Internet-connected Server
18-
- At least 100 MBits/sec continuous bandwidth
18+
- At least 100 MBits/sec continuous network bi-directional bandwidth
1919
- A modern processor with at least 8 dedicated Cores
20-
- At least 8 GB RAM (32 Gb Recommended)
21-
- At least 2 TB fast Storage (NVMe Recommended)
20+
- At least 8 GB RAM (32 GB Recommended)
21+
- At least 1 TB fast Storage (NVMe Recommended)
2222
- A secure modern operating system (Linux recommended) with good support for memory mapped files
2323
- Java 21 or above
2424

2525
The network should be configured with:
26-
- a publicly accessible IP address (IPv4 or IPv6)
26+
- a publicly accessible IP address (IPv4 or IPv6). Dual stack networking support is required in the OS.
2727
- firewall access to the server via TCP on a chosen port (the Convex protocol default `18888` is recommended)
28-
- a trusted DNS entry (e.g. `peer.mycompany.com`)
28+
- a trusted DNS entry (e.g. `peer.mycompany.com`) is recommended
29+
- HTTPS certificates recommended for the HTTPS REST API
2930

3031
The DNS entry is optional, but it will help significantly with discoverability / user access to your peer.
3132

3233
## Configuration
3334

35+
### Accounts
36+
37+
In order to operate a peer you will need a Peer Controller account. This can be any account on the Convex network, e.g. `#1678` with at least 1000 Convex Coins.
38+
3439
### Peer Config
3540

3641
Peers can be configured at launch in various ways.
3742

38-
Peers SHOULD configure the number of concurrent outgoing Peer connections according to their available bandwidth. 20 recommended for Peers with fast connections.
43+
#### Outgoing connections
44+
45+
Peers MAY configure the number of concurrent outgoing Peer connections according to their available bandwidth. 20 (the default) recommended for Peers with sufficient outgoing bandwidth. There are trade-offs here:
46+
- With more outgoing connections, your transactions will reach consensus faster
47+
- You must weight this up against bandwidth costs
48+
- If the number is too low your published blocks may get lost if the destinations do not relay them.
49+
50+
TODO: describe mechanism to set connection count controls
3951

4052

4153

4254
## Startup
4355

56+
## Syncing
57+
58+
Your peer will need to synchronize with teh network by connecting to at least one existing peer.
59+
60+
The following peers are available at time of writing for synchronisation:
61+
```
62+
peer.convex.live:18888
63+
```
64+
65+
TODO: CLI commend top start peer with target host
4466

4567
## Shutdown
4668

@@ -56,7 +78,9 @@ It may occur that a peer becomes temporarily disconnected from the peer network.
5678

5779
Peers are designed to automatically recover from temporary network failure and re-establish connections when possible. Peers with normal configuration SHOULD periodically re-attempt to connect with other peers randomly until connection with the Network is re-established.
5880

59-
Peer Operators SHOULD provide for an alternative way to connect to the main network, if only for the purposes of withrawing the Peer's Stake (Peers are at risk of penalisation if they remain disconnected for too long).
81+
Peer Operators SHOULD provide for an alternative way to connect to the main network, if only for the purposes of withdrawing the Peer's Stake. For example, a peer operator may monitor the connectivity of their peer and use Convex Desktop to de-stake the peer if it loses connections.
82+
83+
TODO: describe best way to monitor this. Perhaps API peer health endpoint?
6084

6185
### Security Breach
6286

@@ -68,22 +92,34 @@ Peer Operators SHOULD attempt to withdraw their Stake immediately, possibly thro
6892

6993
Peers are required to post a Peer Stake to participate in consensus.
7094

95+
### Setting a stake
96+
97+
### Withdrawing stake
98+
99+
### Stake penalties
100+
101+
In Protonet, there is no slashing of stake (i.e. peers are not formally penalised for incorrect behaviour).
102+
103+
In the future peers may be automatically penalised for provably incorrect behaviour.
104+
71105
## Key Management
72106

73107
## Connection Management
74108

75109
A Convex Peer is designed to automatically manage P2P connections to the Network during normal operations. In most cases, assuming good network connectivity, a Peer should require no manual intervention to control connections to other Peers.
76110

111+
112+
77113
### Incoming Connections
78114

79-
Peers treat incoming connections as regular Clients, i.e. they afford no particular special priviledges to incoming connections from other Peers. The purpose of this is to ensure that Bad Peers have no particular ability to influence a Peer that they connect to.
115+
Peers treat incoming connections as regular Clients, i.e. they afford no particular special privileges to incoming connections from other Peers. The purpose of this is to ensure that Bad Peers have no particular ability to influence a Peer that they connect to.
80116

81117
### Outgoing connections
82118

83119
A Peer maintains a managed list of outgoing connections (i.e. connections to which they broadcast their Beliefs).
84120

85121
Outgoing connections follow the following rules:
86-
- **Validated hosts**: Peers MUST only connect to Peers accesible on the network via the host address specified for the destination Peer in the current consensus, **or** if they are explicitly instructed to connect to a specific host address by the Peer Operator (e.g. when joining the Network). This minimises the chance of connecting to Bad Peers.
122+
- **Validated hosts**: Peers MUST only connect to Peers accessible on the network via the host address specified for the destination Peer in the current consensus, **or** if they are explicitly instructed to connect to a specific host address by the Peer Operator (e.g. when joining the Network). This minimises the chance of connecting to Bad Peers.
87123
- **Random elimination**: Peers SHOULD eliminate connections at random for low-staked Peers. This allows the Peer network to stay dynamic, and give an opportunity for new Peers to be connected to
88124
- **Stake-weighted selection** Peers MUST connect to other Peers preferentially according to stake, so that Bad Peers do not have a significant chance of isolating a Peer
89125
- **Target connection count**: Peers should attempt to maintain a number of outgoing connections to Peers as configured by the Peer Operator. This allows Peer Operators to control their bandwidth usage.

0 commit comments

Comments
 (0)