Skip to content

Commit a372c32

Browse files
authored
Merge pull request #59 from casper-network/sse_endpoint_documentation
Introducing monitor-and-consume-events.md with contemporary SSE event…
2 parents 114e8ef + 8b57f1b commit a372c32

File tree

6 files changed

+682
-54
lines changed

6 files changed

+682
-54
lines changed

versioned_docs/version-2.0.0/concepts/serialization/primitives.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ enum CLType {
2121
String, // e.g. "Hello, World!"
2222
URef, // unforgeable reference (see above)
2323
Key, // global state key (see above)
24-
PublicKey // A Casper system PublicKey type
24+
PublicKey, // A Casper system PublicKey type
2525
Option(CLType), // optional value of the given type
2626
List(CLType), // list of values of the given type (e.g. Vec in rust)
2727
ByteArray(CLType, u32), // same as `List` above, but number of elements

versioned_docs/version-2.0.0/concepts/serialization/structures.md

+82-43
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Account {#serialization-standard-account}
44

5-
An Account is a structure that represented a user on a legacy Casper network. Alongside the Condor protocol release, `Accounts` were replaced with `AddressableEntities` of the type `Account`. The account structure consists of the following fields:
5+
An Account is a structure that represented a user on a legacy Casper network. Alongside the Casper 2.0 protocol release, `Accounts` were replaced with `AddressableEntities` of the type `Account`. The account structure consists of the following fields:
66

77
- [`account_hash`](./types.md#account-hash)
88

@@ -17,53 +17,50 @@ An Account is a structure that represented a user on a legacy Casper network. Al
1717
## AddressableEntity {#addressable-entity}
1818

1919
An Addressable Entity is a structure that represents an entity on a Casper network. The addressable entity consists of the following fields:
20-
2120
- [`package_hash`](./types.md#package-hash)
2221

2322
- [`byte_code_hash`](./types.md#byte-code-hash)
2423

25-
- [`entry_points`](./types.md#entrypoints)
26-
2724
- [`protocol_version`](./types.md#protocolversion)
2825

29-
- `main_purse`: The entity's main purse `URef`. You may find information on `URef` serialization [here](./primitives.md#clvalue-uref).
26+
- [`main_purse`]: The entity's main purse `URef`. You may find information on `URef` serialization [here](./primitives.md#clvalue-uref).
3027

3128
- [`associated_keys`](./types.md#associatedkey)
3229

3330
- [`action_thresholds`](./types.md#entity-action-thresholds)
3431

35-
- [`message_topics`](./types.md#message-topics)
36-
3732
- [`entity_kind`](./types.md#entity-kind)
3833

34+
3935
## Block {#serialization-standard-block}
4036

4137
A block is the core component of the Casper linear blockchain, used in two contexts:
4238

4339
1. A data structure containing a collection of transactions. Blocks form the primary structure of the blockchain.
4440
2. A message that is exchanged between nodes containing the data structure as explained in (1).
4541

46-
Each block has a globally unique ID, achieved by hashing the contents of the block.
47-
48-
Each block points to its parent. An exception is the first block, which has no parent.
49-
50-
A block is structurally defined as follows:
51-
52-
- `hash`: A hash over the header of the block.
53-
- `header`: The header of the block that contains information about the contents of the block with additional metadata.
54-
- `body`: The block's body contains the proposer of the block and hashes of deploys and transfers contained within it.
42+
The block is a polymorphic structure that assumes one of the well-defined variants:
43+
* `V1` which type is `BlockV1` (it has a binary `prefix` of 0)
44+
* `V2` which type is `BlockV2` (it has a binary `prefix` of 1)
5545

56-
Further, a block may consist of one of the following types:
46+
To byte-serialize a `Block` you first need to serialize it's binary prefix and then write the bytes of the byte-serialized representation of it's variant.
5747

58-
- `Version1`: A legacy block created prior to the Condor upgrade.
48+
## BlockV1 {#block-v1}
5949

60-
- `Version2`: A modern block.
50+
This type:
51+
* encapsulates block data that used to be produced in versions of the nodes prior to 2.0.
52+
* represents a historical block that was produced prior to 2.0
53+
Each block:
54+
* has a globally unique ID, achieved by hashing the contents of the block.
55+
* points to its parent. An exception is the first block, which has no parent.
6156

62-
### BlockHash {#block-hash}
57+
A block is structurally defined as follows:
6358

64-
The block hash is a `Digest` over the contents of the block Header. The `BlockHash` serializes as the byte representation of the hash itself.
59+
- `hash`: A hash over the header of the block. It's type is `BlockHash`
60+
- `header`: The header of the block that contains information about the contents of the block with additional metadata. It's type is `BlockHeaderV1`.
61+
- `body`: The block's body contains the proposer of the block and hashes of deploys and transfers contained within it. It's type is `BlockBodyV1`.
6562

66-
### BlockHeader {#block-header}
63+
### BlockHeaderV1 {#block-header-v1}
6764

6865
The header portion of a block, structurally, is defined as follows:
6966

@@ -72,15 +69,13 @@ The header portion of a block, structurally, is defined as follows:
7269
- `body_hash` the hash of the block body. It serializes to the byte representation of the body hash. The serialized buffer of the `body_hash` is 32 bytes long.
7370
- `random_bit` is a boolean needed for initializing a future era. It is serialized as a single byte; true maps to 1, while false maps to 0.
7471
- `accumulated_seed` is a seed needed for initializing a future era. It serializes to the byte representation of the parent Hash. The serialized buffer of the `accumulated_hash` is 32 bytes long.
75-
- `era_end` contains equivocation and reward information to be included in the terminal finalized block. It is an optional field. Thus if the field is set as `None`, it serializes to _0_. The serialization of the other case is described in the EraEnd.
72+
- `era_end` contains equivocation and reward information to be included in the terminal finalized block. It is an optional field. Thus if the field is set as `None`, it serializes to _0_. The serialization of the other case is described in the `EraEndV1`.
7673
- `timestamp` The timestamp from when the block was proposed. It serializes as a single `u64` value. The serialization of a `u64` value is described in the CLValues section.
7774
- `era_id` Era ID in which this block was created. It serializes as a single `u64` value.
7875
- `height` The height of this block, i.e., the number of ancestors. It serializes as a single `u64` value.
7976
- `protocol_version` The version of the Casper network when this block was proposed. It is 3-element tuple containing `u32` values. It serializes as a buffer containing the three `u32` serialized values. Refer to the CLValues section on how `u32` values are serialized.
8077

81-
Both `BlockHeaderV1` and `BlockHeaderV2` serialize in the same way.
82-
83-
### EraEndV1 {#eraendV1}
78+
#### EraEndV1 {#eraendV1}
8479

8580
`EraEndV1` as represented within the block header, is a struct containing two fields.
8681

@@ -102,21 +97,9 @@ When serializing the overarching struct of `EraEndV1`, we first allocate a buffe
10297

10398
Note that `EraEndV1` is an optional field. Thus the above scheme only applies if there is an `EraEndV1`; if there is no era end, the field simply serializes to _0_.
10499

105-
### EraEndV2 {#eraendV2}
106-
107-
`EraEndV1` as represented within the block header, is a struct containing four fields.
108-
109-
- `equivocators`: A vector of `PublicKey` listing equivocators for the era.
110-
- `inactive_validators`: A list of inactive validators for the era.
111-
- `next_era_validator_weights`: A map of validators and their weights for the era to follow.
112-
- `rewards`: A Binary Tree Map of `PublicKey` and `u64`.
113-
- `next_era_gas_price`: The next era's gas price as a `u8`.
114-
115-
Note that `EraEndV2` is an optional field. Thus the above scheme only applies if there is an `EraEndV2`; if there is no era end, the field simply serializes to _0_.
116-
117100
### BlockBodyV1 {#blockbodyV1}
118101

119-
The body portion of a block, prior to the Condor upgrade, is structurally defined as:
102+
The body portion of a block, prior to the Casper 2.0 upgrade, is structurally defined as:
120103

121104
- `proposer`: The PublicKey which proposed this block.
122105
- `deploy_hashes`: Is a vector of hex-encoded hashes identifying Deploys included in this block.
@@ -128,6 +111,52 @@ When we serialize the `BlockBodyV1`, we create a buffer that contains the serial
128111
- `deploy_hashes` serializes to the byte representation of all the deploy_hashes within the block header. Its length is `32 * n`, where n denotes the number of deploy hashes present within the body.
129112
- `transfer_hashes` serializes to the byte representation of all the deploy_hashes within the block header. Its length is `32 * n`, where n denotes the number of transfers present within the body.
130113

114+
## BlockV2 {#block-v2}
115+
116+
This type represents a contemporary block that is produced by the network. A block is the core component of the Casper linear blockchain, used in two contexts:
117+
1. A data structure containing a collection of transactions. Blocks form the primary structure of the blockchain.
118+
2. A message that is exchanged between nodes containing the data structure as explained in (1).
119+
120+
Each block has a globally unique ID, achieved by hashing the contents of the block.
121+
122+
Each block points to its parent. An exception is the first block, which has no parent.
123+
124+
A block is structurally defined as follows:
125+
126+
- `hash`: A hash over the header of the block. It's type is `BlockHash`
127+
- `header`: The header of the block that contains information about the contents of the block with additional metadata. It's type is `BlockHeaderV2`.
128+
- `body`: The block's body contains the proposer of the block and hashes of deploys and transfers contained within it. It's type is `BlockBodyV2`.
129+
130+
### BlockHeaderV2 {#block-header-v2}
131+
132+
The header portion of a block, structurally, is defined as follows:
133+
134+
- `parent_hash` is the hash of the parent block. It serializes to the byte representation of the parent hash. The serialized buffer of the `parent_hash` is 32 bytes long.
135+
- `state_root_hash` is the global state root hash produced by executing this block's body. It serializes to the byte representation of the `state root hash`. The serialized buffer of the `state_root_hash` is 32 bytes long.
136+
- `body_hash` the hash of the block body. It serializes to the byte representation of the body hash. The serialized buffer of the `body_hash` is 32 bytes long.
137+
- `random_bit` is a boolean needed for initializing a future era. It is serialized as a single byte; true maps to 1, while false maps to 0.
138+
- `accumulated_seed` is a seed needed for initializing a future era. It serializes to the byte representation of the parent Hash. The serialized buffer of the `accumulated_hash` is 32 bytes long.
139+
- `era_end` contains equivocation and reward information to be included in the terminal finalized block. It is an optional field. Thus if the field is set as `None`, it serializes to _0_. The serialization of the other case is described in the `EraEndV2`.
140+
- `timestamp` The timestamp from when the block was proposed. It serializes as a single `u64` value. The serialization of a `u64` value is described in the CLValues section.
141+
- `era_id` Era ID in which this block was created. It serializes as a single `u64` value.
142+
- `height` The height of this block, i.e., the number of ancestors. It serializes as a single `u64` value.
143+
- `protocol_version` The version of the Casper network when this block was proposed. It is 3-element tuple containing `u32` values. It serializes as a buffer containing the three `u32` serialized values. Refer to the CLValues section on how `u32` values are serialized.
144+
- `proposer` public key of the proposer of the block. It's type is `PublicKey`
145+
- `current_gas_price` gas price of the block. It is an unsigned 8 bit number.
146+
- `last_switch_block_hash` it is an optional block hash pointing to the last switch block. It's type is `BlockHash`, but since it's optional, rules of serializing (optional fields)[./primitives.md#clvalue-option] apply.
147+
148+
### EraEndV2 {#eraendV2}
149+
150+
`EraEndV2` as represented within the block header, is a struct containing four fields.
151+
152+
- `equivocators`: A vector of `PublicKey` listing equivocators for the era.
153+
- `inactive_validators`: A list of inactive validators for the era.
154+
- `next_era_validator_weights`: A map of validators and their weights for the era to follow.
155+
- `rewards`: A Binary Tree Map of `PublicKey` and `u64`.
156+
- `next_era_gas_price`: The next era's gas price as a `u8`.
157+
158+
Note that `EraEndV2` is an optional field. Thus the above scheme only applies if there is an `EraEndV2`; if there is no era end, the field simply serializes to _0_.
159+
131160
### BlockBodyV2 {blockbodyv2}
132161

133162
A modern block is structurally defined as:
@@ -136,6 +165,20 @@ A modern block is structurally defined as:
136165

137166
- [`rewarded_signatures`](./types.md#rewarded-signatures): A list of identifiers for finality signatures for a particular past block. It serializes as a vector of `SingleBlockRewardedSignatures` which describes signatures for a single ancestor block. The first entry represents the signatures for the parent block, the second for the parent of the parent, and so on.
138167

168+
169+
## BlockHash {#block-hash}
170+
171+
The block hash is a `Digest` over the contents of the block Header. The `BlockHash` serializes as the byte representation of the hash itself.
172+
173+
174+
## ByteCodeAddr {#byte-code-addr}
175+
176+
An address for ByteCode records stored in global state. Comes in one of three variants:
177+
- `Empty`. It serializes as a `u8` tag of `0`.
178+
- `V1CasperWasm`. It serializes as a `u8` tag of `1` followed by 32 bytes interpreted as hex-encoded address.
179+
- `V2CasperWasm`. It serializes as a `u8` tag of `2` followed by 32 bytes interpreted as hex-encoded address.
180+
181+
139182
## Contract {#contract}
140183

141184
A contract struct containing the following fields:
@@ -406,10 +449,6 @@ The scheduling mode of a transaction, serialized as a [`u8`](./primitives.md#clv
406449

407450
- `Standard` serializes as a `0`.
408451

409-
- `FutureEra` serializes as a `1` followed by a future [`era_id`](./types.md#eraid).
410-
411-
- `FutureTimestamp` serializes as a `2` followed by a future [`timestamp`](./types.md#timestamp).
412-
413452
### TransactionInvocationTarget {#transactioninvocationtarget}
414453

415454
The identifier of a `stored` transaction target, serialized as one of the following:

versioned_docs/version-2.0.0/concepts/serialization/types.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ Hex-encoded bytes serialized as a `u32` value describing the length of the bytes
214214

215215
## ByteCodeKind
216216

217-
The type of byte code, serialized as a single `u8` value. A `0` indicates empty byte code, while a `1` indicates a `V1CasperWasm` to be executed with the first version of the Casper execution engine.
217+
The type of byte code, serialized as a single `u8` value. A `0` indicates empty byte code. `1` indicates a `V1CasperWasm` to be executed with the first version of the Casper execution engine. `2` indicates a `V2CasperWasm` to be executed with the first version of the Casper execution engine
218218

219219
## Caller {#caller}
220220

@@ -252,6 +252,9 @@ ChainspecRegistry is a unique key variant which contains a mapping of file names
252252

253253
The checksum registry. It serializes as a `BTreeMap` where the first 4 bytes represent a `u32` value describing the number of checksum names as strings and [digests](#digest) held within. The remainder consists of a repeating pattern of serialized strings and then digests of the length dictated by the first four bytes.
254254

255+
## ContractRuntimeTag {#contract-runtime-tag}
256+
A tag for the contracts runtime tag, serialized as a single `u8` tag of 0 for `VmCasperV1`, 1 for `VmCasperV2`.
257+
255258
## Delegator {#delegator}
256259

257260
Represents a party delegating their stake to a validator (or "delegatee"). The structure consists of the following fields:
@@ -368,7 +371,7 @@ An `enum` specifying who pays for the invocation and execution of an entry point
368371

369372
- `Caller`: Serializes as a 0 and indicates that the caller must cover the cost.
370373

371-
- `SelfOnly`: Serializes as a 1 and indicates that the contract will pay the cost to execute itself, but no subsequent invoked contracts.
374+
- `DirectInvocationOnly`: Serializes as a 1 and indicates that the contract will pay the cost to execute itself, but no subsequent invoked contracts.
372375

373376
- `SelfOnward`: Serializes as a 2 and indicates that the contract will pay for executing itself and any subsequent invocations.
374377

@@ -378,9 +381,9 @@ The context of method execution. It serializes as one of the following:
378381

379382
- `Caller`: Serializes as a single `u8`, `0b00000000`
380383

381-
- `Called`: Serializes as a single `u8`, `0b00000001`
384+
- `DirectInvocationOnly`: Serializes as a single `u8`, `0b00000001`
382385

383-
- `Factory`: Serializes as a single `u8`, `0b10000000`
386+
- `SelfOnward`: Serializes as a single `u8`, `0b10000000`
384387

385388
## EntrypointV2
386389

@@ -770,9 +773,9 @@ Entity types for system contracts, serialized as a single `u8` tag identifying t
770773
| Tag | System Contract |
771774
| --- | --------------- |
772775
| 0 | `Mint` |
773-
| 1 | `Auction` |
776+
| 1 | `HandlePayment` |
774777
| 2 | `StandardPayment` |
775-
| 3 | `HandlePayment` |
778+
| 3 | `Auction` |
776779

777780
## TimeDiff {#timediff}
778781

versioned_docs/version-2.0.0/developers/cli/opcode-costs.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ All costs in this table are in [motes](/concepts/glossary/M/#motes), not CSPR, a
1414
<!--TODO update the link when 2.0 ships to Testnet/Mainnet. -->
1515
:::
1616

17-
## Storage Costs
17+
## StorageCosts
1818

1919
|Attribute |Description | Cost |
2020
|----------------- |-----------------------------------------------|-----------------|
2121
|gas_per_byte | Gas charged per byte stored in global state. | 1_117_587|
2222

23-
## OpCode Costs
23+
## OpCodeCosts
2424

2525
|Attribute |Description | Cost |
2626
|----------------- |-----------------------------------------------|-----------------|
@@ -40,7 +40,7 @@ All costs in this table are in [motes](/concepts/glossary/M/#motes), not CSPR, a
4040
|current_memory | Get the current memory operation multiplier. | 290|
4141
|grow_memory | Grow memory cost per page (64 kB). | 240_000|
4242

43-
## Control Flow Operation Costs
43+
## ControlFlowCost
4444

4545
|Attribute |Description | Cost |
4646
|----------------- |-----------------------------------------------|-----------------|

versioned_docs/version-2.0.0/developers/json-rpc/types_chain.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ Required Parameters:
423423

424424
## ByteCodeHash
425425

426-
The hex-encoded address of a smart contract [`AddressableEntity`](#addressableentity).
426+
A type wrapping a `HashAddr` which is the raw bytes of the ByteCodeHash. Serializes as `HashAddr`
427427

428428
## ByteCodeKind
429429

0 commit comments

Comments
 (0)