Skip to content

Commit

Permalink
Backport adjusting the BABE epoch index (#991)
Browse files Browse the repository at this point in the history
* Backport adjusting the BABE epoch index

* PR link
  • Loading branch information
tomaka authored Aug 8, 2023
1 parent c9a1693 commit abc961e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/src/verify/babe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,16 @@ pub fn verify_header(config: VerifyConfig) -> Result<VerifySuccess, VerifyError>
}
};

// TODO: check that we didn't entirely skip an epoch?
// Calculate the epoch index of the epoch of the block.
// This is the vast majority of the time equal to `block_epoch_info.epoch_index`. However,
// if no block has been produced for an entire epoch, the value needs to be increased by the
// number of skipped epochs.
let block_epoch_index = block_epoch_info.epoch_index
+ block_epoch_info
.start_slot_number
.map_or(0, |start_slot_number| {
(slot_number - start_slot_number) / config.slots_per_epoch
});

// TODO: in case of epoch change, should also check the randomness value; while the runtime
// checks that the randomness value is correct, light clients in particular do not
Expand Down Expand Up @@ -354,7 +363,7 @@ pub fn verify_header(config: VerifyConfig) -> Result<VerifySuccess, VerifyError>
let epoch_transition_target = match config.header.digest.babe_epoch_information() {
None => None,
Some((info, None)) => Some(chain_information::BabeEpochInformation {
epoch_index: block_epoch_info.epoch_index.checked_add(1).unwrap(),
epoch_index: block_epoch_index.checked_add(1).unwrap(),
start_slot_number: Some(
block_epoch_info
.start_slot_number
Expand All @@ -368,7 +377,7 @@ pub fn verify_header(config: VerifyConfig) -> Result<VerifySuccess, VerifyError>
allowed_slots: block_epoch_info.allowed_slots,
}),
Some((info, Some(epoch_cfg))) => Some(chain_information::BabeEpochInformation {
epoch_index: block_epoch_info.epoch_index.checked_add(1).unwrap(),
epoch_index: block_epoch_index.checked_add(1).unwrap(),
start_slot_number: Some(
block_epoch_info
.start_slot_number
Expand Down Expand Up @@ -426,7 +435,7 @@ pub fn verify_header(config: VerifyConfig) -> Result<VerifySuccess, VerifyError>
let transcript = {
let mut transcript = merlin::Transcript::new(&b"BABE"[..]);
transcript.append_u64(b"slot number", slot_number);
transcript.append_u64(b"current epoch", block_epoch_info.epoch_index);
transcript.append_u64(b"current epoch", block_epoch_index);
transcript.append_message(b"chain randomness", &block_epoch_info.randomness[..]);
transcript
};
Expand Down
4 changes: 4 additions & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- The `operation-body-done`, `operation-call-done`, `operation-storage-done`, `operation-storage-items`, `operation-waiting-for-continue`, `operation-inaccessible`, and `operation-error` events, and the `closest-descendant-merkle-value`, `descendants-values`, and `descendants-hashes` item types of the new JSON-RPC API have been renamed and are now camelCased (`operationBodyDone`, `operationStorageItems`, `descendantsValues`, etc.), in accordance with the latest changes in the JSON-RPC API specification. ([#973](https://github.com/smol-dot/smoldot/pull/973))
- The `chainSpec_unstable` JSON-RPC functions have been renamed to `chainSpec_v1`, in accordance with the latest changes in the JSON-RPC API specification. ([#989](https://github.com/smol-dot/smoldot/pull/989))

### Fixed

- A change in the logic of BABE has been backported. Smoldot no longer considers blocks as invalid after no block has been authored for an entire epoch. ([#991](https://github.com/smol-dot/smoldot/pull/991))

## 1.0.14 - 2023-07-26

### Changed
Expand Down

0 comments on commit abc961e

Please sign in to comment.