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

ibc: compute IBC heights from revision number derived by chain id #3100

Merged
merged 2 commits into from
Sep 28, 2023
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
8 changes: 5 additions & 3 deletions crates/bin/pd/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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,14 +79,17 @@ impl Info {
.unwrap_or_default()
.try_into()?;

tracing::info!(?info, state_version = ?state.version(), app_version = ?last_block_height, "reporting height in info query");
// likewise, we want to return 0 if we can't get the revision number
let app_version = state.get_revision_number().await.unwrap_or_default();

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()?;

Ok(response::Info {
data: "penumbra".to_string(),
version: ABCI_INFO_VERSION.to_string(),
app_version: APP_VERSION,
app_version,
last_block_height,
last_block_app_hash,
})
Expand Down
8 changes: 8 additions & 0 deletions crates/core/component/chain/src/component/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::str::FromStr;

use anyhow::{anyhow, Context, Result};
use async_trait::async_trait;
use ibc_types::core::connection::ChainId;
use penumbra_proto::{StateReadProto, StateWriteProto};
use penumbra_storage::{StateRead, StateWrite};
use tendermint::Time;
Expand Down Expand Up @@ -54,6 +55,13 @@ pub trait StateReadExt: StateRead {
self.get_chain_params().await.map(|params| params.chain_id)
}

/// Gets the chain revision number, from the chain ID
async fn get_revision_number(&self) -> Result<u64> {
let cid_str = self.get_chain_id().await?;

Ok(ChainId::from_string(&cid_str).version())
}

/// Gets the current block height from the JMT
async fn get_block_height(&self) -> Result<u64> {
let height_bytes: u64 = self
Expand Down
12 changes: 9 additions & 3 deletions crates/core/component/ibc/src/component/ibc_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use async_trait::async_trait;
use ibc_types::{
core::client::Height, lightclients::tendermint::ConsensusState as TendermintConsensusState,
};
use penumbra_chain::component::StateReadExt;
use penumbra_chain::genesis;
use penumbra_component::Component;
use penumbra_storage::StateWrite;
Expand Down Expand Up @@ -48,9 +49,14 @@ 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())
.expect("block height cannot be zero");
let height = Height::new(
state
.get_revision_number()
.await
.expect("must be able to get revision number in begin block"),
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 @@ -194,7 +194,10 @@ 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(
state.get_revision_number().await?,
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 @@ -203,7 +203,10 @@ 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(
state.get_revision_number().await?,
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 @@ -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(state.get_revision_number().await?, 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 @@ -396,7 +396,7 @@ mod inner {

TendermintClientState::verify_delay_passed(
current_timestamp.into(),
Height::new(0, current_height)?,
Height::new(self.get_revision_number().await?, current_height)?,
processed_time,
processed_height,
delay_period_time,
Expand Down
5 changes: 2 additions & 3 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, StateReadExt};
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 Expand Up @@ -48,7 +47,7 @@ impl Info {
Ok(abci::response::Info {
data: "penumbra".to_string(),
version: ABCI_INFO_VERSION.to_string(),
app_version: APP_VERSION,
app_version: state.get_revision_number().await?,
last_block_height,
last_block_app_hash,
})
Expand Down