From 0001706bb4acfba1a99f6d5117e6355cc57c4e68 Mon Sep 17 00:00:00 2001 From: lamafab <42901763+lamafab@users.noreply.github.com> Date: Wed, 7 Sep 2022 15:01:53 +0000 Subject: [PATCH 01/13] expand consensus digest item struct --- .../03_transition/03_state-replication.adoc | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/01_host/03_transition/03_state-replication.adoc b/01_host/03_transition/03_state-replication.adoc index 612f8793d..76f0450d1 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 @@ -165,6 +166,64 @@ types: empty: {} ++++ +TODO: Move to proper section +++++ +enums: + babe_consensus_enum: + 1: next_epoch_data + 2: on_disabled + 3: next_epoch_descriptor +types: + consensus_message: + seq: + - id: id + contents: ["BABE", "FRNK", "BEEF"] + - id: content + type: scale::bytes + babe_consensus_message: + seq: + - id: enum_id + type: u1 + enum: babe_consensus_enum + - id: message + type: + switch-on: enum_id + cases: + 'babe_consensus_enum::next_epoch_data': next_epoch_data + 'babe_consensus_enum::on_disabled': u1 + 'babe_consensus_enum::next_epoch_descriptor': u1 + enums: + next_epoch_descriptor_enum: + 1: default + types: + next_epoch_data: + seq: + - id: authority_set + type: u1 + - id: randomness + type: u1 + on_disabled: + seq: + - id: authority_id + type: u4 + next_epoch_descriptor: + seq: + - id: enum_id + type: u1 + enum: next_epoch_descriptor_enum + - id: content + type: + switch-on: enum_id + cases: + 'next_epoch_descriptor_enum::default': babe_slot_descriptor + babe_slot_descriptor: + seq: + - id: nominator + type: u1 + - id: denominator + type: u1 +++++ + [#defn-block-header-hash] .<> ==== From 81448a82ec0ddaee15b2ad7f6118a5adf3cdb466 Mon Sep 17 00:00:00 2001 From: lamafab <42901763+lamafab@users.noreply.github.com> Date: Wed, 7 Sep 2022 15:19:27 +0000 Subject: [PATCH 02/13] expand enum types for next epoch descriptor --- .../03_transition/03_state-replication.adoc | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/01_host/03_transition/03_state-replication.adoc b/01_host/03_transition/03_state-replication.adoc index 76f0450d1..8d5fa0aa5 100644 --- a/01_host/03_transition/03_state-replication.adoc +++ b/01_host/03_transition/03_state-replication.adoc @@ -190,11 +190,15 @@ types: switch-on: enum_id cases: 'babe_consensus_enum::next_epoch_data': next_epoch_data - 'babe_consensus_enum::on_disabled': u1 - 'babe_consensus_enum::next_epoch_descriptor': u1 + 'babe_consensus_enum::on_disabled': u4 + 'babe_consensus_enum::next_epoch_descriptor': next_epoch_descriptor enums: next_epoch_descriptor_enum: 1: default + secondary_slot_enum: + 0: no_secondary_slot + 1: plain_secondary_slot + 2: secondary_slot_with_vrf_output types: next_epoch_data: seq: @@ -222,6 +226,20 @@ types: type: u1 - id: denominator type: u1 + - id: enum_id + type: u1 + enum: secondary_slot_enum + - id: enum_content + type: + switch-on: enum_id + cases: + 'secondary_slot_enum::no_secondary_slot': empty + 'secondary_slot_enum::no_secondary_slot': empty + 'secondary_slot_enum::no_secondary_slot': empty + empty: + seq: + - id: empty + size: 0 ++++ [#defn-block-header-hash] From 3c75c8d8c7257779366b0a070d5be9a8156ccd76 Mon Sep 17 00:00:00 2001 From: lamafab <42901763+lamafab@users.noreply.github.com> Date: Fri, 9 Sep 2022 11:38:35 +0000 Subject: [PATCH 03/13] use generic scale::bytes for consensus_message_enum --- 01_host/03_transition/03_state-replication.adoc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/01_host/03_transition/03_state-replication.adoc b/01_host/03_transition/03_state-replication.adoc index 8d5fa0aa5..5035ea335 100644 --- a/01_host/03_transition/03_state-replication.adoc +++ b/01_host/03_transition/03_state-replication.adoc @@ -176,10 +176,22 @@ enums: types: consensus_message: seq: - - id: id - contents: ["BABE", "FRNK", "BEEF"] + - id: consensus_message_enum + size: 4 - id: content type: scale::bytes + grandpa_consensus_message: + seq: + - id: enum_id + type: u1 + enum: grandpa_consensus_type + enums: + grandpa_consensus_type: + 1: scheduled_change + 2: forded_change + 3: on_disabled + 4: pause + 5: resume babe_consensus_message: seq: - id: enum_id From 654cd1f82c4d78e08d2fee319a82ea9114d31e24 Mon Sep 17 00:00:00 2001 From: lamafab <42901763+lamafab@users.noreply.github.com> Date: Fri, 9 Sep 2022 11:55:21 +0000 Subject: [PATCH 04/13] extend kaitai struct to GRANDPA Consensus Message --- .../03_transition/03_state-replication.adoc | 38 ++++++++++++++++++- 01_host/05_consensus/01_common.adoc | 7 +++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/01_host/03_transition/03_state-replication.adoc b/01_host/03_transition/03_state-replication.adoc index 5035ea335..227473fb1 100644 --- a/01_host/03_transition/03_state-replication.adoc +++ b/01_host/03_transition/03_state-replication.adoc @@ -185,13 +185,49 @@ types: - id: enum_id type: u1 enum: grandpa_consensus_type + - id: message + type: + switch-on: enum_id + cases: + 'grandpa_consensus_type::scheduled_change': scheduled_change + 'grandpa_consensus_type::forced_change': forced_change + 'grandpa_consensus_type::on_disabled': on_disabled + 'grandpa_consensus_type::pause': pause + 'grandpa_consensus_type::resume': resume enums: grandpa_consensus_type: 1: scheduled_change - 2: forded_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 babe_consensus_message: seq: - id: enum_id diff --git a/01_host/05_consensus/01_common.adoc b/01_host/05_consensus/01_common.adoc index de7e3e415..b5ef5dc94 100644 --- a/01_host/05_consensus/01_common.adoc +++ b/01_host/05_consensus/01_common.adoc @@ -125,7 +125,7 @@ s_"2nd" = { ==== [#defn-consensus-message-grandpa] -.<> +.<> ==== stem:["CM"_g], the consensus message for GRANDPA, is of the following format: @@ -134,6 +134,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 From 06c2a8de9d459d0b73c4920dd87cb6ee1cbb9ad2 Mon Sep 17 00:00:00 2001 From: lamafab <42901763+lamafab@users.noreply.github.com> Date: Fri, 9 Sep 2022 13:29:20 +0000 Subject: [PATCH 05/13] add beefy consensus message --- .../03_transition/03_state-replication.adoc | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/01_host/03_transition/03_state-replication.adoc b/01_host/03_transition/03_state-replication.adoc index 227473fb1..2b5d15498 100644 --- a/01_host/03_transition/03_state-replication.adoc +++ b/01_host/03_transition/03_state-replication.adoc @@ -180,6 +180,38 @@ types: size: 4 - id: content type: scale::bytes + beefy_consensus_message: + seq: + - id: enum_id + type: u1 + enum: beefy_consensus_type + - id: message + type: + switch-on: enum_id + cases: + 'beefy_consensus_type::authority_change': authority_change + 'beefy_consensus_type::on_disabled': on_disabled + 'beefy_consensus_type::mmr_root': mmr_root + enums: + beefy_consensus_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 grandpa_consensus_message: seq: - id: enum_id From 92ba5ba7de55399c68135f96396b5e9e162003e3 Mon Sep 17 00:00:00 2001 From: lamafab <42901763+lamafab@users.noreply.github.com> Date: Fri, 9 Sep 2022 13:31:02 +0000 Subject: [PATCH 06/13] reorder message --- .../03_transition/03_state-replication.adoc | 126 +++++++++--------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/01_host/03_transition/03_state-replication.adoc b/01_host/03_transition/03_state-replication.adoc index 2b5d15498..e62261572 100644 --- a/01_host/03_transition/03_state-replication.adoc +++ b/01_host/03_transition/03_state-replication.adoc @@ -180,38 +180,66 @@ types: size: 4 - id: content type: scale::bytes - beefy_consensus_message: + babe_consensus_message: seq: - id: enum_id type: u1 - enum: beefy_consensus_type + enum: babe_consensus_enum - id: message type: switch-on: enum_id cases: - 'beefy_consensus_type::authority_change': authority_change - 'beefy_consensus_type::on_disabled': on_disabled - 'beefy_consensus_type::mmr_root': mmr_root + 'babe_consensus_enum::next_epoch_data': next_epoch_data + 'babe_consensus_enum::on_disabled': u4 + 'babe_consensus_enum::next_epoch_descriptor': next_epoch_descriptor enums: - beefy_consensus_type: - 1: authority_change - 2: on_disabled - 3: mmr_root + next_epoch_descriptor_enum: + 1: default + secondary_slot_enum: + 0: no_secondary_slot + 1: plain_secondary_slot + 2: secondary_slot_with_vrf_output types: - authority_change: + next_epoch_data: seq: - - id: authorities - type: scale::bytes - - id: set_id - type: u4 + - id: authority_set + type: u1 + - id: randomness + type: u1 on_disabled: seq: - id: authority_id type: u4 - mmr_root: + next_epoch_descriptor: seq: - - id: root - size: 32 + - id: enum_id + type: u1 + enum: next_epoch_descriptor_enum + - id: content + type: + switch-on: enum_id + cases: + 'next_epoch_descriptor_enum::default': babe_slot_descriptor + babe_slot_descriptor: + seq: + - id: nominator + type: u1 + - id: denominator + type: u1 + - id: enum_id + type: u1 + enum: secondary_slot_enum + - id: enum_content + type: + switch-on: enum_id + cases: + 'secondary_slot_enum::no_secondary_slot': empty + 'secondary_slot_enum::no_secondary_slot': empty + 'secondary_slot_enum::no_secondary_slot': empty + empty: + seq: + - id: empty + size: 0 grandpa_consensus_message: seq: - id: enum_id @@ -260,66 +288,38 @@ types: seq: - id: delay_of type: u4 - babe_consensus_message: + beefy_consensus_message: seq: - id: enum_id type: u1 - enum: babe_consensus_enum - - id: message + enum: beefy_consensus_type + - id: message type: switch-on: enum_id cases: - 'babe_consensus_enum::next_epoch_data': next_epoch_data - 'babe_consensus_enum::on_disabled': u4 - 'babe_consensus_enum::next_epoch_descriptor': next_epoch_descriptor + 'beefy_consensus_type::authority_change': authority_change + 'beefy_consensus_type::on_disabled': on_disabled + 'beefy_consensus_type::mmr_root': mmr_root enums: - next_epoch_descriptor_enum: - 1: default - secondary_slot_enum: - 0: no_secondary_slot - 1: plain_secondary_slot - 2: secondary_slot_with_vrf_output + beefy_consensus_type: + 1: authority_change + 2: on_disabled + 3: mmr_root types: - next_epoch_data: + authority_change: seq: - - id: authority_set - type: u1 - - id: randomness - type: u1 + - id: authorities + type: scale::bytes + - id: set_id + type: u4 on_disabled: seq: - id: authority_id type: u4 - next_epoch_descriptor: - seq: - - id: enum_id - type: u1 - enum: next_epoch_descriptor_enum - - id: content - type: - switch-on: enum_id - cases: - 'next_epoch_descriptor_enum::default': babe_slot_descriptor - babe_slot_descriptor: - seq: - - id: nominator - type: u1 - - id: denominator - type: u1 - - id: enum_id - type: u1 - enum: secondary_slot_enum - - id: enum_content - type: - switch-on: enum_id - cases: - 'secondary_slot_enum::no_secondary_slot': empty - 'secondary_slot_enum::no_secondary_slot': empty - 'secondary_slot_enum::no_secondary_slot': empty - empty: + mmr_root: seq: - - id: empty - size: 0 + - id: root + size: 32 ++++ [#defn-block-header-hash] From 757eea31dd6254a55d00f8130c7db03c19295386 Mon Sep 17 00:00:00 2001 From: lamafab <42901763+lamafab@users.noreply.github.com> Date: Fri, 9 Sep 2022 13:33:47 +0000 Subject: [PATCH 07/13] renames --- .../03_transition/03_state-replication.adoc | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/01_host/03_transition/03_state-replication.adoc b/01_host/03_transition/03_state-replication.adoc index e62261572..afcc062ed 100644 --- a/01_host/03_transition/03_state-replication.adoc +++ b/01_host/03_transition/03_state-replication.adoc @@ -176,7 +176,7 @@ enums: types: consensus_message: seq: - - id: consensus_message_enum + - id: enum_id size: 4 - id: content type: scale::bytes @@ -193,9 +193,9 @@ types: 'babe_consensus_enum::on_disabled': u4 'babe_consensus_enum::next_epoch_descriptor': next_epoch_descriptor enums: - next_epoch_descriptor_enum: + next_epoch_descriptor_type: 1: default - secondary_slot_enum: + secondary_slot_type: 0: no_secondary_slot 1: plain_secondary_slot 2: secondary_slot_with_vrf_output @@ -205,7 +205,7 @@ types: - id: authority_set type: u1 - id: randomness - type: u1 + size: 32 on_disabled: seq: - id: authority_id @@ -214,12 +214,12 @@ types: seq: - id: enum_id type: u1 - enum: next_epoch_descriptor_enum + enum: next_epoch_descriptor_type - id: content type: switch-on: enum_id cases: - 'next_epoch_descriptor_enum::default': babe_slot_descriptor + 'next_epoch_descriptor_type::default': babe_slot_descriptor babe_slot_descriptor: seq: - id: nominator @@ -228,14 +228,14 @@ types: type: u1 - id: enum_id type: u1 - enum: secondary_slot_enum + enum: secondary_slot_type - id: enum_content type: switch-on: enum_id cases: - 'secondary_slot_enum::no_secondary_slot': empty - 'secondary_slot_enum::no_secondary_slot': empty - 'secondary_slot_enum::no_secondary_slot': empty + 'secondary_slot_type::no_secondary_slot': empty + 'secondary_slot_type::no_secondary_slot': empty + 'secondary_slot_type::no_secondary_slot': empty empty: seq: - id: empty From 65683fefb340a08afa06bc83b235b8529ccf9d01 Mon Sep 17 00:00:00 2001 From: lamafab <42901763+lamafab@users.noreply.github.com> Date: Fri, 9 Sep 2022 13:46:15 +0000 Subject: [PATCH 08/13] kaitai spec pre-runtime digest --- .../03_transition/03_state-replication.adoc | 34 +++++++++++++++++++ 01_host/05_consensus/02_block-production.adoc | 4 +-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/01_host/03_transition/03_state-replication.adoc b/01_host/03_transition/03_state-replication.adoc index afcc062ed..d7d5d2895 100644 --- a/01_host/03_transition/03_state-replication.adoc +++ b/01_host/03_transition/03_state-replication.adoc @@ -180,6 +180,40 @@ types: size: 4 - id: content type: scale::bytes + pre_runtime_digest: + seq: + - id: enum_id + type: u1 + enum: pre_runtime_digest_type + - id: digest + type: + switch-on: enum_id + cases: + 'pre_runtime_digest_type::primary_vrf': vrf_digest + 'pre_runtime_digest_type::primary_plain': plain_digest + 'pre_runtime_digest_type::secondary_vrf': vrf_digest + enums: + pre_runtime_digest_type: + 1: primary_vrf + 2: primary_plain + 3: secondary_vrf + types: + vrf_digest: + seq: + - id: authority_id + type: u1 + - id: slot_number + type: u1 + - id: vrf_out + size: 32 + - id: vrf_proof + size: 64 + plain_digest: + seq: + - id: authority_id + type: u1 + - id: slot_number + type: u1 babe_consensus_message: seq: - id: enum_id diff --git a/01_host/05_consensus/02_block-production.adoc b/01_host/05_consensus/02_block-production.adoc index c25f46339..ab3c35b48 100644 --- a/01_host/05_consensus/02_block-production.adoc +++ b/01_host/05_consensus/02_block-production.adoc @@ -407,9 +407,9 @@ 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)]. From b7b340a4fcb610af16ccac7ee9965893c1c9dd10 Mon Sep 17 00:00:00 2001 From: lamafab <42901763+lamafab@users.noreply.github.com> Date: Fri, 9 Sep 2022 13:47:29 +0000 Subject: [PATCH 09/13] add empty type to RuntimeEnvironmentUpdated digest item --- 01_host/03_transition/03_state-replication.adoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/01_host/03_transition/03_state-replication.adoc b/01_host/03_transition/03_state-replication.adoc index d7d5d2895..4c11255e8 100644 --- a/01_host/03_transition/03_state-replication.adoc +++ b/01_host/03_transition/03_state-replication.adoc @@ -270,10 +270,6 @@ types: 'secondary_slot_type::no_secondary_slot': empty 'secondary_slot_type::no_secondary_slot': empty 'secondary_slot_type::no_secondary_slot': empty - empty: - seq: - - id: empty - size: 0 grandpa_consensus_message: seq: - id: enum_id @@ -354,6 +350,10 @@ types: seq: - id: root size: 32 + empty: + seq: + - id: empty + size: 0 ++++ [#defn-block-header-hash] From bae3697b9e57e6aad10c2d23ce22a83211deff5f Mon Sep 17 00:00:00 2001 From: lamafab <42901763+lamafab@users.noreply.github.com> Date: Fri, 9 Sep 2022 13:52:10 +0000 Subject: [PATCH 10/13] move pre_runtime_digest close to bottom --- .../03_transition/03_state-replication.adoc | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/01_host/03_transition/03_state-replication.adoc b/01_host/03_transition/03_state-replication.adoc index 4c11255e8..95ff79830 100644 --- a/01_host/03_transition/03_state-replication.adoc +++ b/01_host/03_transition/03_state-replication.adoc @@ -180,40 +180,6 @@ types: size: 4 - id: content type: scale::bytes - pre_runtime_digest: - seq: - - id: enum_id - type: u1 - enum: pre_runtime_digest_type - - id: digest - type: - switch-on: enum_id - cases: - 'pre_runtime_digest_type::primary_vrf': vrf_digest - 'pre_runtime_digest_type::primary_plain': plain_digest - 'pre_runtime_digest_type::secondary_vrf': vrf_digest - enums: - pre_runtime_digest_type: - 1: primary_vrf - 2: primary_plain - 3: secondary_vrf - types: - vrf_digest: - seq: - - id: authority_id - type: u1 - - id: slot_number - type: u1 - - id: vrf_out - size: 32 - - id: vrf_proof - size: 64 - plain_digest: - seq: - - id: authority_id - type: u1 - - id: slot_number - type: u1 babe_consensus_message: seq: - id: enum_id @@ -350,6 +316,40 @@ types: seq: - id: root size: 32 + pre_runtime_digest: + seq: + - id: enum_id + type: u1 + enum: pre_runtime_digest_type + - id: digest + type: + switch-on: enum_id + cases: + 'pre_runtime_digest_type::primary_vrf': vrf_digest + 'pre_runtime_digest_type::primary_plain': plain_digest + 'pre_runtime_digest_type::secondary_vrf': vrf_digest + enums: + pre_runtime_digest_type: + 1: primary_vrf + 2: primary_plain + 3: secondary_vrf + types: + vrf_digest: + seq: + - id: authority_id + type: u1 + - id: slot_number + type: u1 + - id: vrf_out + size: 32 + - id: vrf_proof + size: 64 + plain_digest: + seq: + - id: authority_id + type: u1 + - id: slot_number + type: u1 empty: seq: - id: empty From d6f0e190735c13693942e2af104ba651c31da655 Mon Sep 17 00:00:00 2001 From: Fabio Lama Date: Fri, 23 Sep 2022 08:37:36 +0000 Subject: [PATCH 11/13] fix type declarations --- 01_host/03_transition/03_state-replication.adoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/01_host/03_transition/03_state-replication.adoc b/01_host/03_transition/03_state-replication.adoc index 95ff79830..8063af993 100644 --- a/01_host/03_transition/03_state-replication.adoc +++ b/01_host/03_transition/03_state-replication.adoc @@ -174,6 +174,10 @@ enums: 2: on_disabled 3: next_epoch_descriptor types: + seal: + seq: + - id: seal + size: 64 consensus_message: seq: - id: enum_id From 2b89ec4ab4d0b735a6a220df5dfa74c0fa25c6fb Mon Sep 17 00:00:00 2001 From: Fabio Lama Date: Fri, 23 Sep 2022 08:44:24 +0000 Subject: [PATCH 12/13] update ids and enum references --- .../03_transition/03_state-replication.adoc | 86 +++++++++---------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/01_host/03_transition/03_state-replication.adoc b/01_host/03_transition/03_state-replication.adoc index 8063af993..7d74e7b40 100644 --- a/01_host/03_transition/03_state-replication.adoc +++ b/01_host/03_transition/03_state-replication.adoc @@ -169,7 +169,7 @@ types: TODO: Move to proper section ++++ enums: - babe_consensus_enum: + babe_consensus_ty: 1: next_epoch_data 2: on_disabled 3: next_epoch_descriptor @@ -180,26 +180,26 @@ types: size: 64 consensus_message: seq: - - id: enum_id + - id: consensus_engine size: 4 - id: content type: scale::bytes babe_consensus_message: seq: - - id: enum_id + - id: babe_consensus_ty_id type: u1 - enum: babe_consensus_enum + enum: babe_consensus_ty - id: message type: - switch-on: enum_id + switch-on: babe_consensus_ty_id cases: - 'babe_consensus_enum::next_epoch_data': next_epoch_data - 'babe_consensus_enum::on_disabled': u4 - 'babe_consensus_enum::next_epoch_descriptor': next_epoch_descriptor + 'babe_consensus_ty::next_epoch_data': next_epoch_data + 'babe_consensus_ty::on_disabled': u4 + 'babe_consensus_ty::next_epoch_descriptor': next_epoch_descriptor enums: - next_epoch_descriptor_type: + next_epoch_descriptor_ty: 1: default - secondary_slot_type: + secondary_slot_ty: 0: no_secondary_slot 1: plain_secondary_slot 2: secondary_slot_with_vrf_output @@ -216,46 +216,46 @@ types: type: u4 next_epoch_descriptor: seq: - - id: enum_id + - id: next_epoch_descriptor_ty_id type: u1 - enum: next_epoch_descriptor_type + enum: next_epoch_descriptor_ty - id: content type: - switch-on: enum_id + switch-on: next_epoch_descriptor_ty_id cases: - 'next_epoch_descriptor_type::default': babe_slot_descriptor + 'next_epoch_descriptor_ty::default': babe_slot_descriptor babe_slot_descriptor: seq: - id: nominator type: u1 - id: denominator type: u1 - - id: enum_id + - id: secondary_slot_ty_id type: u1 - enum: secondary_slot_type + enum: secondary_slot_ty - id: enum_content type: - switch-on: enum_id + switch-on: secondary_slot_ty_id cases: - 'secondary_slot_type::no_secondary_slot': empty - 'secondary_slot_type::no_secondary_slot': empty - 'secondary_slot_type::no_secondary_slot': empty + 'secondary_slot_ty::no_secondary_slot': empty + 'secondary_slot_ty::no_secondary_slot': empty + 'secondary_slot_ty::no_secondary_slot': empty grandpa_consensus_message: seq: - - id: enum_id + - id: grandpa_consensus_ty_id type: u1 - enum: grandpa_consensus_type + enum: grandpa_consensus_ty - id: message type: - switch-on: enum_id + switch-on: grandpa_consensus_ty_id cases: - 'grandpa_consensus_type::scheduled_change': scheduled_change - 'grandpa_consensus_type::forced_change': forced_change - 'grandpa_consensus_type::on_disabled': on_disabled - 'grandpa_consensus_type::pause': pause - 'grandpa_consensus_type::resume': resume + 'grandpa_consensus_ty::scheduled_change': scheduled_change + 'grandpa_consensus_ty::forced_change': forced_change + 'grandpa_consensus_ty::on_disabled': on_disabled + 'grandpa_consensus_ty::pause': pause + 'grandpa_consensus_ty::resume': resume enums: - grandpa_consensus_type: + grandpa_consensus_ty: 1: scheduled_change 2: forced_change 3: on_disabled @@ -290,18 +290,18 @@ types: type: u4 beefy_consensus_message: seq: - - id: enum_id + - id: beefy_consensus_ty_id type: u1 - enum: beefy_consensus_type + enum: beefy_consensus_ty - id: message type: - switch-on: enum_id + switch-on: beefy_consensus_ty_id cases: - 'beefy_consensus_type::authority_change': authority_change - 'beefy_consensus_type::on_disabled': on_disabled - 'beefy_consensus_type::mmr_root': mmr_root + 'beefy_consensus_ty::authority_change': authority_change + 'beefy_consensus_ty::on_disabled': on_disabled + 'beefy_consensus_ty::mmr_root': mmr_root enums: - beefy_consensus_type: + beefy_consensus_ty: 1: authority_change 2: on_disabled 3: mmr_root @@ -322,18 +322,18 @@ types: size: 32 pre_runtime_digest: seq: - - id: enum_id + - id: pre_runtime_digest_ty_id type: u1 - enum: pre_runtime_digest_type + enum: pre_runtime_digest_ty - id: digest type: - switch-on: enum_id + switch-on: pre_runtime_digest_ty_id cases: - 'pre_runtime_digest_type::primary_vrf': vrf_digest - 'pre_runtime_digest_type::primary_plain': plain_digest - 'pre_runtime_digest_type::secondary_vrf': vrf_digest + 'pre_runtime_digest_ty::primary_vrf': vrf_digest + 'pre_runtime_digest_ty::primary_plain': plain_digest + 'pre_runtime_digest_ty::secondary_vrf': vrf_digest enums: - pre_runtime_digest_type: + pre_runtime_digest_ty: 1: primary_vrf 2: primary_plain 3: secondary_vrf From 283890982ab9e3c11683342fa6f4341a90de4b5a Mon Sep 17 00:00:00 2001 From: Florian Franzen Date: Thu, 10 Nov 2022 12:09:13 +0100 Subject: [PATCH 13/13] kaitai: split and cleanup digest definitions --- .../03_transition/03_state-replication.adoc | 194 ------------------ 01_host/05_consensus/01_common.adoc | 163 +++++++++++++++ 01_host/05_consensus/02_block-production.adoc | 37 ++++ 3 files changed, 200 insertions(+), 194 deletions(-) diff --git a/01_host/03_transition/03_state-replication.adoc b/01_host/03_transition/03_state-replication.adoc index 7d74e7b40..88013634b 100644 --- a/01_host/03_transition/03_state-replication.adoc +++ b/01_host/03_transition/03_state-replication.adoc @@ -166,200 +166,6 @@ types: empty: {} ++++ -TODO: Move to proper section -++++ -enums: - babe_consensus_ty: - 1: next_epoch_data - 2: on_disabled - 3: next_epoch_descriptor -types: - seal: - seq: - - id: seal - size: 64 - consensus_message: - seq: - - id: consensus_engine - size: 4 - - id: content - type: scale::bytes - babe_consensus_message: - seq: - - id: babe_consensus_ty_id - type: u1 - enum: babe_consensus_ty - - id: message - type: - switch-on: babe_consensus_ty_id - cases: - 'babe_consensus_ty::next_epoch_data': next_epoch_data - 'babe_consensus_ty::on_disabled': u4 - 'babe_consensus_ty::next_epoch_descriptor': next_epoch_descriptor - enums: - next_epoch_descriptor_ty: - 1: default - secondary_slot_ty: - 0: no_secondary_slot - 1: plain_secondary_slot - 2: secondary_slot_with_vrf_output - types: - next_epoch_data: - seq: - - id: authority_set - type: u1 - - id: randomness - size: 32 - on_disabled: - seq: - - id: authority_id - type: u4 - next_epoch_descriptor: - seq: - - id: next_epoch_descriptor_ty_id - type: u1 - enum: next_epoch_descriptor_ty - - id: content - type: - switch-on: next_epoch_descriptor_ty_id - cases: - 'next_epoch_descriptor_ty::default': babe_slot_descriptor - babe_slot_descriptor: - seq: - - id: nominator - type: u1 - - id: denominator - type: u1 - - id: secondary_slot_ty_id - type: u1 - enum: secondary_slot_ty - - id: enum_content - type: - switch-on: secondary_slot_ty_id - cases: - 'secondary_slot_ty::no_secondary_slot': empty - 'secondary_slot_ty::no_secondary_slot': empty - 'secondary_slot_ty::no_secondary_slot': empty - grandpa_consensus_message: - seq: - - id: grandpa_consensus_ty_id - type: u1 - enum: grandpa_consensus_ty - - id: message - type: - switch-on: grandpa_consensus_ty_id - cases: - 'grandpa_consensus_ty::scheduled_change': scheduled_change - 'grandpa_consensus_ty::forced_change': forced_change - 'grandpa_consensus_ty::on_disabled': on_disabled - 'grandpa_consensus_ty::pause': pause - 'grandpa_consensus_ty::resume': resume - enums: - grandpa_consensus_ty: - 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 - beefy_consensus_message: - seq: - - id: beefy_consensus_ty_id - type: u1 - enum: beefy_consensus_ty - - id: message - type: - switch-on: beefy_consensus_ty_id - cases: - 'beefy_consensus_ty::authority_change': authority_change - 'beefy_consensus_ty::on_disabled': on_disabled - 'beefy_consensus_ty::mmr_root': mmr_root - enums: - beefy_consensus_ty: - 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 - pre_runtime_digest: - seq: - - id: pre_runtime_digest_ty_id - type: u1 - enum: pre_runtime_digest_ty - - id: digest - type: - switch-on: pre_runtime_digest_ty_id - cases: - 'pre_runtime_digest_ty::primary_vrf': vrf_digest - 'pre_runtime_digest_ty::primary_plain': plain_digest - 'pre_runtime_digest_ty::secondary_vrf': vrf_digest - enums: - pre_runtime_digest_ty: - 1: primary_vrf - 2: primary_plain - 3: secondary_vrf - types: - vrf_digest: - seq: - - id: authority_id - type: u1 - - id: slot_number - type: u1 - - id: vrf_out - size: 32 - - id: vrf_proof - size: 64 - plain_digest: - seq: - - id: authority_id - type: u1 - - id: slot_number - type: u1 - empty: - seq: - - id: empty - size: 0 -++++ - [#defn-block-header-hash] .<> ==== diff --git a/01_host/05_consensus/01_common.adoc b/01_host/05_consensus/01_common.adoc index b5ef5dc94..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,6 +140,65 @@ 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] @@ -169,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] @@ -193,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 ab3c35b48..ff510c393 100644 --- a/01_host/05_consensus/02_block-production.adoc +++ b/01_host/05_consensus/02_block-production.adoc @@ -413,6 +413,43 @@ block. 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 +++++ ==== ****