Skip to content

Commit

Permalink
ibc: use APP_VERSION when construction IBC heights
Browse files Browse the repository at this point in the history
  • Loading branch information
avahowell committed Sep 28, 2023
1 parent 4db2ef3 commit b967dfb
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 13 deletions.
8 changes: 5 additions & 3 deletions crates/bin/pd/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ use ibc_types::core::channel::{ChannelId, PortId};
use ibc_types::core::client::ClientId;
use ibc_types::core::connection::ConnectionId;
use ibc_types::core::connection::IdentifiedConnectionEnd;
use penumbra_chain::component::{AppHashRead, StateReadExt};
use penumbra_chain::{
component::{AppHashRead, StateReadExt},
APP_VERSION,
};
use penumbra_ibc::component::ChannelStateReadExt as _;
use penumbra_ibc::component::ClientStateReadExt as _;
use penumbra_ibc::component::ConnectionStateReadExt as _;
Expand All @@ -44,7 +47,6 @@ use tracing::Instrument;
use penumbra_tower_trace::v034::RequestExt;

const ABCI_INFO_VERSION: &str = env!("VERGEN_GIT_SEMVER");
const APP_VERSION: u64 = 1;

/// Implements service traits for Tonic gRPC services.
///
Expand Down Expand Up @@ -80,7 +82,7 @@ impl Info {
.unwrap_or_default()
.try_into()?;

tracing::info!(?info, state_version = ?state.version(), app_version = ?last_block_height, "reporting height in info query");
tracing::info!(?info, state_version = ?state.version(), last_block_height = ?last_block_height, "reporting height in info query");

let last_block_app_hash = state.app_hash().await?.0.to_vec().try_into()?;

Expand Down
5 changes: 5 additions & 0 deletions crates/core/component/chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ mod note_source;
#[cfg(feature = "component")]
pub mod component;

// This corresponds to the "revision number" in Cosmos SDK chains, and the "app_version" field in the Tendermint RPC.
// Currently, we don't use a revision number, because we don't have
// any further namespacing of blocks than the block height. So, we just set this to 0.
pub const APP_VERSION: u64 = 0;

pub mod genesis;
pub mod params;
pub mod state_key;
Expand Down
3 changes: 1 addition & 2 deletions crates/core/component/ibc/src/component/ibc_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ impl Component for IBCComponent {

// Currently, we don't use a revision number, because we don't have
// any further namespacing of blocks than the block height.
let revision_number = 0;
let height = Height::new(revision_number, begin_block.header.height.into())
let height = Height::new(APP_VERSION, begin_block.header.height.into())
.expect("block height cannot be zero");

state.put_penumbra_consensus_state(height, cs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use ibc_types::core::{
};
use ibc_types::lightclients::tendermint::client_state::ClientState as TendermintClientState;
use ibc_types::path::{ClientConsensusStatePath, ClientStatePath, ConnectionPath};
use penumbra_chain::component::{StateReadExt as _, PENUMBRA_COMMITMENT_PREFIX};
use penumbra_chain::{
component::{StateReadExt as _, PENUMBRA_COMMITMENT_PREFIX},
APP_VERSION,
};
use penumbra_storage::{StateRead, StateWrite};

use crate::component::{
Expand Down Expand Up @@ -194,7 +197,7 @@ async fn consensus_height_is_correct<S: StateRead>(
state: S,
msg: &MsgConnectionOpenAck,
) -> anyhow::Result<()> {
let current_height = Height::new(0, state.get_block_height().await?)?;
let current_height = Height::new(APP_VERSION, state.get_block_height().await?)?;
if msg.consensus_height_of_a_on_b > current_height {
anyhow::bail!("consensus height is greater than the current block height",);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use ibc_types::{
},
};
use penumbra_chain::component::{StateReadExt as _, PENUMBRA_COMMITMENT_PREFIX};
use penumbra_chain::APP_VERSION;
use penumbra_storage::{StateRead, StateWrite};

use crate::component::{
Expand Down Expand Up @@ -203,7 +204,7 @@ async fn consensus_height_is_correct<S: StateRead>(
state: S,
msg: &MsgConnectionOpenTry,
) -> anyhow::Result<()> {
let current_height = IBCHeight::new(0, state.get_block_height().await?)?;
let current_height = IBCHeight::new(APP_VERSION, state.get_block_height().await?)?;
if msg.consensus_height_of_b_on_a > current_height {
anyhow::bail!("consensus height is greater than the current block height",);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ibc_types::core::{
client::Height as IBCHeight,
connection::State as ConnectionState,
};
use penumbra_chain::component::StateReadExt;
use penumbra_chain::{component::StateReadExt, APP_VERSION};
use penumbra_storage::StateWrite;

use crate::component::{
Expand Down Expand Up @@ -65,7 +65,7 @@ impl MsgHandler for MsgRecvPacket {
}

let block_height = state.get_block_height().await?;
let height = IBCHeight::new(0, block_height)?;
let height = IBCHeight::new(APP_VERSION, block_height)?;

if self.packet.timeout_height_on_b.has_expired(height) {
anyhow::bail!("packet has timed out");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ pub trait PacketProofVerifier: StateReadExt + inner::Inner {
impl<T: StateRead> PacketProofVerifier for T {}

mod inner {
use penumbra_chain::APP_VERSION;

use super::*;

#[async_trait]
Expand Down Expand Up @@ -396,7 +398,7 @@ mod inner {

TendermintClientState::verify_delay_passed(
current_timestamp.into(),
Height::new(0, current_height)?,
Height::new(APP_VERSION, current_height)?,
processed_time,
processed_height,
delay_period_time,
Expand Down
3 changes: 1 addition & 2 deletions crates/narsil/narsil/src/ledger/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use futures::FutureExt;
use penumbra_chain::component::AppHashRead;
use penumbra_chain::{component::AppHashRead, APP_VERSION};
use penumbra_storage::Storage;
use penumbra_tower_trace::v034::RequestExt;
use tendermint::v0_34::abci::{self, response::Echo, InfoRequest, InfoResponse};
Expand All @@ -14,7 +14,6 @@ use tracing::Instrument;

// const ABCI_INFO_VERSION: &str = env!("VERGEN_GIT_SEMVER");
const ABCI_INFO_VERSION: &str = "wut";
const APP_VERSION: u64 = 1;

/// Implements service traits for Tonic gRPC services.
///
Expand Down

0 comments on commit b967dfb

Please sign in to comment.