Skip to content

Commit

Permalink
Add support for the "fron" log item (#2150)
Browse files Browse the repository at this point in the history
* Add support for the "fron" log item

* Add CHANGELOG entry

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
tomaka and mergify[bot] authored Mar 18, 2022
1 parent b4fe650 commit 05d582a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
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

0 comments on commit 05d582a

Please sign in to comment.