diff --git a/01_host/03_transition/03_state-replication.adoc b/01_host/03_transition/03_state-replication.adoc index 612f8793d..88013634b 100644 --- a/01_host/03_transition/03_state-replication.adoc +++ b/01_host/03_transition/03_state-replication.adoc @@ -1,5 +1,6 @@ [#sect-state-replication] === State Replication +:kaitai-imports: scale Polkadot nodes replicate each other’s state by syncing the history of the extrinsics. This, however, is only practical if a large set of transactions are diff --git a/01_host/05_consensus/01_common.adoc b/01_host/05_consensus/01_common.adoc index de7e3e415..d00421e3d 100644 --- a/01_host/05_consensus/01_common.adoc +++ b/01_host/05_consensus/01_common.adoc @@ -35,6 +35,24 @@ stem:[C]. The authorities and their corresponding weights can be retrieved from the Runtime (<>). + +[kaitai#authority_set] +++++ +seq: + - id: num_items + type: scale::compact_int + - id: items + type: authority_item + repeat: expr + repeat-expr: num_items.value +types: + authority_item: + seq: + - id: key + type: scale::bytes + - id: weight + type: u8 +++++ ==== [#sect-consensus-message-digest] @@ -122,10 +140,69 @@ s_"2nd" = { (2,->,"secondary slot with VRF output") :} ++++ + +[kaitai#babe_message, kaitai-dependencies=authority_set] +++++ +seq: + - id: type_id + type: u1 + enum: message_type + - id: message + type: + switch-on: type_id + cases: + 'message_type::next_epoch_data': next_epoch_data + 'message_type::on_disabled': on_disabled + 'message_type::next_epoch_descriptor': next_epoch_descriptor +enums: + message_type: + 1: next_epoch_data + 2: on_disabled + 3: next_epoch_descriptor +types: + next_epoch_data: + seq: + - id: authority_set + type: authority_set + - id: randomness + size: 32 + on_disabled: + seq: + - id: authority_id + type: u4 + next_epoch_descriptor: + seq: + - id: type_id + type: u1 + enum: descriptor_type + - id: content + type: + switch-on: type_id + cases: + 'descriptor_type::default': default_descriptor + enums: + descriptor_type: + 1: default + types: + default_descriptor: + seq: + - id: nominator + type: u8 + - id: denominator + type: u8 + - id: secondary_slot + type: u1 + enum: secondary_type + enums: + secondary_type: + 0: no_slot + 1: plain_slot + 2: vrf_slot +++++ ==== [#defn-consensus-message-grandpa] -.<> +.<> ==== stem:["CM"_g], the consensus message for GRANDPA, is of the following format: @@ -134,6 +211,11 @@ stem:["CM"_g], the consensus message for GRANDPA, is of the following format: "CM"_g = {(1,("Auth"_C,N_("delay"))),(2,(m,"Auth"_C,N_("delay"))),(3,"A"_i),(4,N_("delay")),(5,N_("delay")):} ++++ +TODO: +* Define stem:["Auth_C"]. +* Define stem:[m]. +* All variants need explicit type definition. + where:: [horizontal] asciimath:[N_"delay"]:: is an unsigned 32-bit integer indicating how deep in the @@ -164,6 +246,57 @@ voting. given delay of stem:[N_("delay") := |"SubChain"(B,B')|] where stem:[B'] is the block where the change is applied. Once applied, the authorities should resume voting. + +[kaitai#grandpa_message] +++++ +seq: + - id: type_id + type: u1 + enum: message_type + - id: message + type: + switch-on: type_id + cases: + 'message_type::scheduled_change': scheduled_change + 'message_type::forced_change': forced_change + 'message_type::on_disabled': on_disabled + 'message_type::pause': pause + 'message_type::resume': resume +enums: + message_type: + 1: scheduled_change + 2: forced_change + 3: on_disabled + 4: pause + 5: resume +types: + scheduled_change: + seq: + - id: authority_list + type: scale::bytes + - id: delay_of + type: u4 + forced_change: + seq: + - id: starting_at + type: u4 + - id: authority_list + type: scale::bytes + - id: delay + type: u4 + on_disabled: + seq: + - id: to_disable + type: u4 + pause: + seq: + - id: delay_of + type: u4 + resume: + seq: + - id: delay_of + type: u4 +++++ ==== [#defn-consensus-message-beefy] @@ -188,4 +321,39 @@ identifier of the remote validator set. 2:: implies **on disabled**: an index to the individual authorty in stem:[V_B] that should be immediately disabled until the next authority change. 3:: implies **MMR root**: a 32-byte array containing the MMR root. + +[kaitai#beefy_message] +++++ +seq: + - id: type + type: u1 + enum: message_type + - id: message + type: + switch-on: type + cases: + 'message_type::authority_change': authority_change + 'message_type::on_disabled': on_disabled + 'message_type::mmr_root': mmr_root +enums: + message_type: + 1: authority_change + 2: on_disabled + 3: mmr_root +types: + authority_change: + seq: + - id: authorities + type: scale::bytes + - id: set_id + type: u4 + on_disabled: + seq: + - id: authority_id + type: u4 + mmr_root: + seq: + - id: root + size: 32 +++++ ==== diff --git a/01_host/05_consensus/02_block-production.adoc b/01_host/05_consensus/02_block-production.adoc index c25f46339..ff510c393 100644 --- a/01_host/05_consensus/02_block-production.adoc +++ b/01_host/05_consensus/02_block-production.adoc @@ -407,12 +407,49 @@ authority in the authority set (<>) who authored the block. * stem:[s] is the slot number (<>). * stem:[o] is VRF output (<> respectively -<>). +<>). * stem:[p] is VRF proof (<> respectively -<>). +<>). The Pre-Digest must be included as a digest item of Pre-Runtime type in the header digest (<>) stem:[H_d(B)]. + +[kaitai#pre_runtime] +++++ +seq: + - id: type_id + type: u1 + enum: message_type + - id: digest + type: + switch-on: type_id + cases: + 'message_type::primary_vrf': vrf_digest + 'message_type::primary_plain': plain_digest + 'message_type::secondary_vrf': vrf_digest +enums: + message_type: + 1: primary_vrf + 2: primary_plain + 3: secondary_vrf +types: + vrf_digest: + seq: + - id: authority_id + type: u4 + - id: slot_number + type: u8 + - id: vrf_out + size: 32 + - id: vrf_proof + size: 64 + plain_digest: + seq: + - id: authority_id + type: u4 + - id: slot_number + type: u8 +++++ ==== ****