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

compact block: add epoch index to compact block #4100

Merged
merged 1 commit into from
Mar 26, 2024
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
Binary file modified crates/cnidarium/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
5 changes: 5 additions & 0 deletions crates/core/component/compact-block/src/compact_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub struct CompactBlock {
pub app_parameters_updated: bool,
/// Updated gas prices, if they have changed.
pub gas_prices: Option<GasPrices>,
// The epoch index
pub epoch_index: u64,
// **IMPORTANT NOTE FOR FUTURE HUMANS**: if you want to add new fields to the `CompactBlock`,
// you must update `CompactBlock::requires_scanning` to check for the emptiness of those fields,
// because the client will skip processing any compact block that is marked as not requiring
Expand All @@ -57,6 +59,7 @@ impl Default for CompactBlock {
swap_outputs: BTreeMap::new(),
app_parameters_updated: false,
gas_prices: None,
epoch_index: 0,
}
}
}
Expand Down Expand Up @@ -95,6 +98,7 @@ impl From<CompactBlock> for pb::CompactBlock {
swap_outputs: cb.swap_outputs.into_values().map(Into::into).collect(),
app_parameters_updated: cb.app_parameters_updated,
gas_prices: cb.gas_prices.map(Into::into),
epoch_index: cb.epoch_index,
}
}
}
Expand Down Expand Up @@ -132,6 +136,7 @@ impl TryFrom<pb::CompactBlock> for CompactBlock {
proposal_started: value.proposal_started,
app_parameters_updated: value.app_parameters_updated,
gas_prices: value.gas_prices.map(TryInto::try_into).transpose()?,
epoch_index: value.epoch_index,
})
}
}
Expand Down
8 changes: 8 additions & 0 deletions crates/core/component/compact-block/src/component/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ trait Inner: StateWrite {
// Add all the pending nullifiers to the compact block
let nullifiers = self.pending_nullifiers().into_iter().collect();

//Get the index of the current epoch
let epoch_index = self
.get_current_epoch()
.await
.expect("epoch is always set")
.index;

let compact_block = CompactBlock {
height,
state_payloads,
Expand All @@ -124,6 +131,7 @@ trait Inner: StateWrite {
fmd_parameters,
app_parameters_updated,
gas_prices,
epoch_index,
};

self.nonverifiable_put_raw(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ pub struct CompactBlock {
/// Updated gas prices, if they have changed.
#[prost(message, optional, tag = "10")]
pub gas_prices: ::core::option::Option<super::super::fee::v1::GasPrices>,
/// The epoch index
#[prost(uint64, tag = "11")]
pub epoch_index: u64,
}
impl ::prost::Name for CompactBlock {
const NAME: &'static str = "CompactBlock";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ impl serde::Serialize for CompactBlock {
if self.gas_prices.is_some() {
len += 1;
}
if self.epoch_index != 0 {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.core.component.compact_block.v1.CompactBlock", len)?;
if self.height != 0 {
#[allow(clippy::needless_borrow)]
Expand Down Expand Up @@ -68,6 +71,10 @@ impl serde::Serialize for CompactBlock {
if let Some(v) = self.gas_prices.as_ref() {
struct_ser.serialize_field("gasPrices", v)?;
}
if self.epoch_index != 0 {
#[allow(clippy::needless_borrow)]
struct_ser.serialize_field("epochIndex", ToString::to_string(&self.epoch_index).as_str())?;
}
struct_ser.end()
}
}
Expand Down Expand Up @@ -96,6 +103,8 @@ impl<'de> serde::Deserialize<'de> for CompactBlock {
"appParametersUpdated",
"gas_prices",
"gasPrices",
"epoch_index",
"epochIndex",
];

#[allow(clippy::enum_variant_names)]
Expand All @@ -110,6 +119,7 @@ impl<'de> serde::Deserialize<'de> for CompactBlock {
SwapOutputs,
AppParametersUpdated,
GasPrices,
EpochIndex,
__SkipField__,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
Expand Down Expand Up @@ -142,6 +152,7 @@ impl<'de> serde::Deserialize<'de> for CompactBlock {
"swapOutputs" | "swap_outputs" => Ok(GeneratedField::SwapOutputs),
"appParametersUpdated" | "app_parameters_updated" => Ok(GeneratedField::AppParametersUpdated),
"gasPrices" | "gas_prices" => Ok(GeneratedField::GasPrices),
"epochIndex" | "epoch_index" => Ok(GeneratedField::EpochIndex),
_ => Ok(GeneratedField::__SkipField__),
}
}
Expand Down Expand Up @@ -171,6 +182,7 @@ impl<'de> serde::Deserialize<'de> for CompactBlock {
let mut swap_outputs__ = None;
let mut app_parameters_updated__ = None;
let mut gas_prices__ = None;
let mut epoch_index__ = None;
while let Some(k) = map_.next_key()? {
match k {
GeneratedField::Height => {
Expand Down Expand Up @@ -235,6 +247,14 @@ impl<'de> serde::Deserialize<'de> for CompactBlock {
}
gas_prices__ = map_.next_value()?;
}
GeneratedField::EpochIndex => {
if epoch_index__.is_some() {
return Err(serde::de::Error::duplicate_field("epochIndex"));
}
epoch_index__ =
Some(map_.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0)
;
}
GeneratedField::__SkipField__ => {
let _ = map_.next_value::<serde::de::IgnoredAny>()?;
}
Expand All @@ -251,6 +271,7 @@ impl<'de> serde::Deserialize<'de> for CompactBlock {
swap_outputs: swap_outputs__.unwrap_or_default(),
app_parameters_updated: app_parameters_updated__.unwrap_or_default(),
gas_prices: gas_prices__,
epoch_index: epoch_index__.unwrap_or_default(),
})
}
}
Expand Down
Binary file modified crates/proto/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ message CompactBlock {
bool app_parameters_updated = 9;
// Updated gas prices, if they have changed.
fee.v1.GasPrices gas_prices = 10;
// The epoch index
uint64 epoch_index = 11;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be grand to have a more descriptive docstring here, incorporating some of the context from #2689, that speaks to what this value represents, as well as why and how it might be used. Unfortunately, I'm a bit at a loss to suggest specific phrasing.

Copy link
Contributor Author

@aubrika aubrika Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also at a loss for what to say on this one ... maybe @hdevalence or perhaps @plaidfinch could shed some light on the "epoch index" for future readers of our documentation strings?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the counter that identifies/index each epoch similar to the height of a block

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but for epochs

}

// An encrypted payload, corresponding to a single commitment in the state commitment tree.
Expand Down
Loading