Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the "fron" log item #2150

Merged
merged 3 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bin/wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Added

- Add support for parsing the "fron" (Frontier) consensus log items in headers. The content of these log items is ignored by the client.

## 0.6.5 - 2022-17-03

### Changed
Expand Down
32 changes: 30 additions & 2 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,9 @@ impl<'a> DigestRef<'a> {
has_runtime_environment_updated = true;
}
DigestItem::BabeSeal(_) => return Err(Error::SealIsntLastItem),
DigestItem::Beefy { .. } | DigestItem::PolkadotParachain { .. } => {}
DigestItem::Beefy { .. }
| DigestItem::PolkadotParachain { .. }
| DigestItem::Frontier { .. } => {}
}
}

Expand Down Expand Up @@ -724,7 +726,9 @@ impl<'a> DigestRef<'a> {
has_runtime_environment_updated = true;
}
DigestItemRef::BabeSeal(_) => return Err(Error::SealIsntLastItem),
DigestItemRef::Beefy { .. } | DigestItemRef::PolkadotParachain { .. } => {}
DigestItemRef::Beefy { .. }
| DigestItemRef::PolkadotParachain { .. }
| DigestItemRef::Frontier { .. } => {}
}
}

Expand Down Expand Up @@ -968,6 +972,12 @@ pub enum DigestItemRef<'a> {
opaque: &'a [u8],
},

/// Item related to the Frontier consensus engine.
Frontier {
/// Smoldot doesn't interpret the content of the log item at the moment.
opaque: &'a [u8],
},

/// Runtime of the chain has been updated in this block. This can include the runtime code or
/// the heap pages.
RuntimeEnvironmentUpdated,
Expand Down Expand Up @@ -1101,6 +1111,13 @@ impl<'a> DigestItemRef<'a> {
ret.extend_from_slice(opaque);
iter::once(ret)
}
DigestItemRef::Frontier { opaque } => {
let mut ret = vec![4];
ret.extend_from_slice(b"fron");
ret.extend_from_slice(util::encode_scale_compact_usize(opaque.len()).as_ref());
ret.extend_from_slice(opaque);
iter::once(ret)
}
DigestItemRef::RuntimeEnvironmentUpdated => iter::once(vec![8]),
}
}
Expand All @@ -1120,6 +1137,7 @@ impl<'a> From<&'a DigestItem> for DigestItemRef<'a> {
DigestItem::PolkadotParachain { opaque } => {
DigestItemRef::PolkadotParachain { opaque: &*opaque }
}
DigestItem::Frontier { opaque } => DigestItemRef::Frontier { opaque: &*opaque },
DigestItem::RuntimeEnvironmentUpdated => DigestItemRef::RuntimeEnvironmentUpdated,
}
}
Expand Down Expand Up @@ -1152,6 +1170,12 @@ pub enum DigestItem {
opaque: Vec<u8>,
},

/// See [`DigestItemRef::Frontier`].
Frontier {
/// Smoldot doesn't interpret the content of the log item at the moment.
opaque: Vec<u8>,
},

/// Runtime of the chain has been updated in this block. This can include the runtime code or
/// the heap pages.
RuntimeEnvironmentUpdated,
Expand Down Expand Up @@ -1181,6 +1205,9 @@ impl<'a> From<DigestItemRef<'a>> for DigestItem {
DigestItemRef::PolkadotParachain { opaque } => DigestItem::PolkadotParachain {
opaque: opaque.to_vec(),
},
DigestItemRef::Frontier { opaque } => DigestItem::Frontier {
opaque: opaque.to_vec(),
},
DigestItemRef::RuntimeEnvironmentUpdated => DigestItem::RuntimeEnvironmentUpdated,
}
}
Expand Down Expand Up @@ -1236,6 +1263,7 @@ fn decode_item_from_parts<'a>(
}
(4, b"BEEF") => DigestItemRef::Beefy { opaque: content },
(4, b"POL1") => DigestItemRef::PolkadotParachain { opaque: content },
(4, b"fron") => DigestItemRef::Frontier { opaque: content },
(4, e) => return Err(Error::UnknownConsensusEngine(*e)),
// 5 = Seal
(5, b"aura") => DigestItemRef::AuraSeal({
Expand Down