Skip to content

Commit

Permalink
app: create event for when app parameters change
Browse files Browse the repository at this point in the history
It's unfortunate that we can't put this somewhere else to avoid including
cnidarium, and thus rocksdb, when you just want to read the event.
A refactoring of the app crate to allow consuming it "as a component"
can be added later.
  • Loading branch information
cronokirby committed Feb 27, 2025
1 parent 88a021e commit 3ffe595
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 0 deletions.
Binary file modified crates/cnidarium/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
38 changes: 38 additions & 0 deletions crates/core/app/src/event.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use anyhow::{anyhow, Context};
use penumbra_proto::{penumbra::core::app::v1 as pb, DomainType};
use prost::Name as _;

use crate::params::AppParameters;

#[derive(Clone, Debug)]
struct EventAppParametersChange {
new_parameters: AppParameters,
}

impl TryFrom<pb::EventAppParametersChange> for EventAppParametersChange {
type Error = anyhow::Error;

fn try_from(value: pb::EventAppParametersChange) -> Result<Self, Self::Error> {
fn inner(value: pb::EventAppParametersChange) -> anyhow::Result<EventAppParametersChange> {
Ok(EventAppParametersChange {
new_parameters: value
.new_parameters
.ok_or(anyhow!("missing `new_parameters`"))?
.try_into()?,
})
}
inner(value).context(format!("parsing {}", pb::EventAppParametersChange::NAME))
}
}

impl From<EventAppParametersChange> for pb::EventAppParametersChange {
fn from(value: EventAppParametersChange) -> Self {
Self {
new_parameters: Some(value.new_parameters.into()),
}
}
}

impl DomainType for EventAppParametersChange {
type Proto = pb::EventAppParametersChange;
}
1 change: 1 addition & 0 deletions crates/core/app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

pub mod app;
pub mod event;
pub mod genesis;
pub mod metrics;
pub mod params;
Expand Down
15 changes: 15 additions & 0 deletions crates/proto/src/gen/penumbra.core.app.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,21 @@ impl ::prost::Name for GenesisContent {
::prost::alloc::format!("penumbra.core.app.v1.{}", Self::NAME)
}
}
/// An event triggering when the app parameters change.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EventAppParametersChange {
/// The new parameters, in their entirety.
#[prost(message, optional, tag = "1")]
pub new_parameters: ::core::option::Option<AppParameters>,
}
impl ::prost::Name for EventAppParametersChange {
const NAME: &'static str = "EventAppParametersChange";
const PACKAGE: &'static str = "penumbra.core.app.v1";
fn full_name() -> ::prost::alloc::string::String {
::prost::alloc::format!("penumbra.core.app.v1.{}", Self::NAME)
}
}
/// Generated client implementations.
#[cfg(feature = "rpc")]
pub mod query_service_client {
Expand Down
96 changes: 96 additions & 0 deletions crates/proto/src/gen/penumbra.core.app.v1.serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,102 @@ impl<'de> serde::Deserialize<'de> for AppParametersResponse {
deserializer.deserialize_struct("penumbra.core.app.v1.AppParametersResponse", FIELDS, GeneratedVisitor)
}
}
impl serde::Serialize for EventAppParametersChange {
#[allow(deprecated)]
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
use serde::ser::SerializeStruct;
let mut len = 0;
if self.new_parameters.is_some() {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.core.app.v1.EventAppParametersChange", len)?;
if let Some(v) = self.new_parameters.as_ref() {
struct_ser.serialize_field("newParameters", v)?;
}
struct_ser.end()
}
}
impl<'de> serde::Deserialize<'de> for EventAppParametersChange {
#[allow(deprecated)]
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
const FIELDS: &[&str] = &[
"new_parameters",
"newParameters",
];

#[allow(clippy::enum_variant_names)]
enum GeneratedField {
NewParameters,
__SkipField__,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
where
D: serde::Deserializer<'de>,
{
struct GeneratedVisitor;

impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
type Value = GeneratedField;

fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(formatter, "expected one of: {:?}", &FIELDS)
}

#[allow(unused_variables)]
fn visit_str<E>(self, value: &str) -> std::result::Result<GeneratedField, E>
where
E: serde::de::Error,
{
match value {
"newParameters" | "new_parameters" => Ok(GeneratedField::NewParameters),
_ => Ok(GeneratedField::__SkipField__),
}
}
}
deserializer.deserialize_identifier(GeneratedVisitor)
}
}
struct GeneratedVisitor;
impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
type Value = EventAppParametersChange;

fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str("struct penumbra.core.app.v1.EventAppParametersChange")
}

fn visit_map<V>(self, mut map_: V) -> std::result::Result<EventAppParametersChange, V::Error>
where
V: serde::de::MapAccess<'de>,
{
let mut new_parameters__ = None;
while let Some(k) = map_.next_key()? {
match k {
GeneratedField::NewParameters => {
if new_parameters__.is_some() {
return Err(serde::de::Error::duplicate_field("newParameters"));
}
new_parameters__ = map_.next_value()?;
}
GeneratedField::__SkipField__ => {
let _ = map_.next_value::<serde::de::IgnoredAny>()?;
}
}
}
Ok(EventAppParametersChange {
new_parameters: new_parameters__,
})
}
}
deserializer.deserialize_struct("penumbra.core.app.v1.EventAppParametersChange", FIELDS, GeneratedVisitor)
}
}
impl serde::Serialize for GenesisAppState {
#[allow(deprecated)]
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
Expand Down
Binary file modified crates/proto/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
6 changes: 6 additions & 0 deletions proto/penumbra/penumbra/core/app/v1/app.proto
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,9 @@ message GenesisContent {
// Auction component genesis state.
core.component.auction.v1.GenesisContent auction_content = 12;
}

// An event triggering when the app parameters change.
message EventAppParametersChange {
// The new parameters, in their entirety.
AppParameters new_parameters = 1;
}

0 comments on commit 3ffe595

Please sign in to comment.