Skip to content

Commit

Permalink
async packet relay working now, refactored into build_penumbra_tx
Browse files Browse the repository at this point in the history
  • Loading branch information
avahowell committed Feb 21, 2024
1 parent e939d0f commit de17c3d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 37 deletions.
1 change: 1 addition & 0 deletions config-preview-testnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ trust_threshold = { numerator = '1', denominator = '3' }
kms_config = { spend_key = "XXXXXXX" }



[[chains]]
id = 'penumbra-testnet-deimos-2'
type = 'Penumbra'
Expand Down
65 changes: 28 additions & 37 deletions crates/relayer/src/chain/penumbra/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use ibc_relayer_types::core::ics24_host::path::{
use ibc_relayer_types::core::ics24_host::Path;
use once_cell::sync::Lazy;
use penumbra_proto::core::component::ibc::v1::IbcRelay as ProtoIbcRelay;
use penumbra_proto::DomainType as _;
use std::str::FromStr;
use std::sync::Arc;
use std::thread;
Expand Down Expand Up @@ -66,7 +67,6 @@ use penumbra_proto::{
GasPricesRequest,
},
};
use penumbra_transaction::gas::GasCost;
use penumbra_view::{ViewClient, ViewServer};
use penumbra_wallet::plan::Planner;
use signature::rand_core::OsRng;
Expand Down Expand Up @@ -291,11 +291,10 @@ impl PenumbraChain {
Ok((begin_block_events, end_block_events))
}

async fn send_messages_in_penumbratx(
async fn build_penumbra_tx(
&mut self,
tracked_msgs: TrackedMsgs,
wait_for_commit: bool,
) -> Result<penumbra_transaction::txhash::TransactionId, Error> {
) -> Result<penumbra_transaction::Transaction, anyhow::Error> {
let mut view_client = self.view_client.lock().await.clone();
let gas_prices = view_client
.gas_prices(GasPricesRequest {})
Expand Down Expand Up @@ -327,29 +326,27 @@ impl PenumbraChain {
planner.ibc_action(ibc_action);
}

let plan = planner
.plan(&mut view_client, AddressIndex::new(0))
.await
.map_err(|e| Error::temp_penumbra_error(e.to_string()))?;
let plan = planner.plan(&mut view_client, AddressIndex::new(0)).await?;

let tx = penumbra_wallet::build_transaction(
penumbra_wallet::build_transaction(
&self.config.kms_config.spend_key.full_viewing_key(),

Check failure on line 332 in crates/relayer/src/chain/penumbra/chain.rs

View workflow job for this annotation

GitHub Actions / clippy-no-default-features

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> crates/relayer/src/chain/penumbra/chain.rs:332:13 | 332 | &self.config.kms_config.spend_key.full_viewing_key(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `self.config.kms_config.spend_key.full_viewing_key()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `-D clippy::needless-borrow` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]`

Check failure on line 332 in crates/relayer/src/chain/penumbra/chain.rs

View workflow job for this annotation

GitHub Actions / clippy-no-default-features

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> crates/relayer/src/chain/penumbra/chain.rs:332:13 | 332 | &self.config.kms_config.spend_key.full_viewing_key(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `self.config.kms_config.spend_key.full_viewing_key()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `-D clippy::needless-borrow` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]`

Check failure on line 332 in crates/relayer/src/chain/penumbra/chain.rs

View workflow job for this annotation

GitHub Actions / clippy-all-features

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> crates/relayer/src/chain/penumbra/chain.rs:332:13 | 332 | &self.config.kms_config.spend_key.full_viewing_key(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `self.config.kms_config.spend_key.full_viewing_key()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `-D clippy::needless-borrow` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]`

Check failure on line 332 in crates/relayer/src/chain/penumbra/chain.rs

View workflow job for this annotation

GitHub Actions / clippy-all-features

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> crates/relayer/src/chain/penumbra/chain.rs:332:13 | 332 | &self.config.kms_config.spend_key.full_viewing_key(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `self.config.kms_config.spend_key.full_viewing_key()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `-D clippy::needless-borrow` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]`
&mut view_client,
&mut self.custody_client,
plan,
)
.await
.map_err(|e| Error::temp_penumbra_error(e.to_string()))?;

let gas_cost = tx.gas_cost();
let fee = gas_prices.fee(&gas_cost);
}

assert!(
tx.transaction_parameters().fee.amount() >= fee,
"paid fee {} must be greater than minimum fee {}",
tx.transaction_parameters().fee.amount(),
fee
);
async fn send_messages_in_penumbratx(
&mut self,
tracked_msgs: TrackedMsgs,
wait_for_commit: bool,
) -> Result<penumbra_transaction::txhash::TransactionId, Error> {
let view_client = self.view_client.lock().await.clone();
let tx = self.build_penumbra_tx(tracked_msgs).await.map_err(|e| {
tracing::error!("error building penumbra transaction: {}", e);
Error::temp_penumbra_error(e.to_string())
})?;

let penumbra_txid = self
.submit_transaction(tx, wait_for_commit, &mut view_client.clone())
Expand Down Expand Up @@ -637,26 +634,20 @@ impl ChainEndpoint for PenumbraChain {
tracked_msgs: TrackedMsgs,
) -> Result<Vec<tendermint_rpc::endpoint::broadcast::tx_sync::Response>, Error> {
let runtime = self.rt.clone();
let txid = runtime.block_on(self.send_messages_in_penumbratx(tracked_msgs, false))?;
let tm_txid = txid.0.to_vec().try_into().unwrap();
let tm_tx = runtime.block_on(async move {
self.tendermint_rpc_client
.tx(tm_txid, false)
.await
.map_err(|e| {
tracing::error!("error querying transaction: {}", e);
Error::temp_penumbra_error(e.to_string())
})
})?;
let penumbra_tx = runtime
.block_on(self.build_penumbra_tx(tracked_msgs.clone()))
.map_err(|e| {
tracing::error!("error building penumbra transaction: {}", e);
Error::temp_penumbra_error(e.to_string())
})?;

let txsync_response = tendermint_rpc::endpoint::broadcast::tx_sync::Response {
code: tm_tx.tx_result.code,
data: tm_tx.tx_result.data,
log: tm_tx.tx_result.log,
hash: tm_tx.hash,
};
let tx_bytes = penumbra_tx.encode_to_vec();

let res = runtime
.block_on(self.tendermint_rpc_client.broadcast_tx_sync(tx_bytes))
.map_err(|e| Error::rpc(self.config.rpc_addr.clone(), e))?;

Ok(vec![txsync_response])
Ok(vec![res])
}

fn verify_header(
Expand Down
1 change: 1 addition & 0 deletions crates/relayer/src/event/source/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ impl EventSource {
}

let latest_height = latest_height(&self.rpc_client).await?;
let latest_height = (latest_height.value() - 1).try_into().unwrap();

let batches = if latest_height > self.last_fetched_height {
trace!(
Expand Down

0 comments on commit de17c3d

Please sign in to comment.