Skip to content
Open
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
41 changes: 5 additions & 36 deletions core/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ use crate::task::TaskExt;
use crate::tx_sender::TxSenderClient;
use crate::utils::{timed_request, timed_try_join_all};
use crate::{
builder::{self},
config::BridgeConfig,
database::Database,
errors::BridgeError,
musig2::aggregate_partial_signatures,
rpc::{
self,
clementine::{
Expand All @@ -31,12 +29,10 @@ use crate::{
},
},
};
use bitcoin::hashes::Hash;
use bitcoin::secp256k1::{schnorr, Message, PublicKey};
use bitcoin::secp256k1::PublicKey;
use bitcoin::XOnlyPublicKey;
use eyre::Context;
use futures::future::join_all;
use secp256k1::musig::{AggregatedNonce, PartialSignature};
use std::future::Future;
use tokio::sync::RwLock;
use tonic::{Request, Status};
Expand Down Expand Up @@ -413,7 +409,10 @@ impl Aggregator {
debug_span!("get_deposit_keys", id=%OperatorId(operator_xonly_pk)),
)
.await
.wrap_err(Status::internal("Operator key retrieval failed"))?
.wrap_err(Status::internal(format!(
"Operator {} key retrieval failed",
operator_xonly_pk
)))?
.into_inner();

// A send error means that all receivers are closed,
Expand Down Expand Up @@ -523,36 +522,6 @@ impl Aggregator {
Ok(())
}

#[tracing::instrument(skip(self), err(level = tracing::Level::ERROR), ret(level = tracing::Level::TRACE))]
async fn _aggregate_move_partial_sigs(
&self,
deposit_data: &mut DepositData,
agg_nonce: &AggregatedNonce,
partial_sigs: Vec<PartialSignature>,
) -> Result<schnorr::Signature, BridgeError> {
let tx = builder::transaction::create_move_to_vault_txhandler(
deposit_data,
self.config.protocol_paramset(),
)?;

let message = Message::from_digest(
tx.calculate_script_spend_sighash_indexed(0, 0, bitcoin::TapSighashType::Default)?
.to_byte_array(),
);

let verifiers_public_keys = deposit_data.get_verifiers();

let final_sig = aggregate_partial_signatures(
verifiers_public_keys,
None,
*agg_nonce,
&partial_sigs,
message,
)?;

Ok(final_sig)
}

/// Returns a list of verifier clients that are participating in the deposit.
pub async fn get_participating_verifiers(
&self,
Expand Down
54 changes: 40 additions & 14 deletions core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ pub trait ErrorExt: Sized {
/// returns the first [`tonic::Status`] error. If it can't find one, it will
/// return an Status::internal with the Display representation of the error.
fn into_status(self) -> tonic::Status;
/// Converts the error into a tonic::Status::internal with the Display representation of the error.
/// Always returns the full error chain as the message.
fn into_full_internal_status(self) -> tonic::Status;
}

/// Extension traits for results to easily convert them to eyre::Report and
Expand All @@ -200,6 +203,7 @@ pub trait ResultExt: Sized {

fn map_to_eyre(self) -> Result<Self::Output, eyre::Report>;
fn map_to_status(self) -> Result<Self::Output, tonic::Status>;
fn map_to_full_internal_status(self) -> Result<Self::Output, tonic::Status>;
}

impl<T: Into<BridgeError>> ErrorExt for T {
Expand All @@ -212,6 +216,9 @@ impl<T: Into<BridgeError>> ErrorExt for T {
fn into_status(self) -> tonic::Status {
self.into().into()
}
fn into_full_internal_status(self) -> tonic::Status {
self.into().into_full_internal_status()
}
}

impl<U: Sized, T: Into<BridgeError>> ResultExt for Result<U, T> {
Expand All @@ -224,26 +231,45 @@ impl<U: Sized, T: Into<BridgeError>> ResultExt for Result<U, T> {
fn map_to_status(self) -> Result<Self::Output, tonic::Status> {
self.map_err(ErrorExt::into_status)
}

fn map_to_full_internal_status(self) -> Result<Self::Output, tonic::Status> {
self.map_err(ErrorExt::into_full_internal_status)
}
}

impl BridgeError {
fn into_full_internal_status(self) -> tonic::Status {
tonic::Status::internal(match self {
BridgeError::Eyre(report) => report
.chain()
.map(|e| e.to_string())
.collect::<Vec<String>>()
.join(" | "),
_ => self.to_string(),
})
}
}

impl From<BridgeError> for tonic::Status {
fn from(val: BridgeError) -> Self {
let eyre_report = val.into_eyre();
val.into_full_internal_status()
// TODO: maybe uncomment later, first check how this works out
// let eyre_report = val.into_eyre();

// eyre::Report can cast any error in the chain to a Status, so we use its downcast method to get the first Status.
eyre_report.downcast::<Status>().unwrap_or_else(|report| {
// We don't want this case to happen, all casts to Status should contain a Status that contains a user-facing error message.
tracing::error!(
"Returning internal error on RPC call, full error: {:?}",
report
);
// // eyre::Report can cast any error in the chain to a Status, so we use its downcast method to get the first Status.
// eyre_report.downcast::<Status>().unwrap_or_else(|report| {
// // We don't want this case to happen, all casts to Status should contain a Status that contains a user-facing error message.
// tracing::error!(
// "Returning internal error on RPC call, full error: {:?}",
// report
// );

let mut status = tonic::Status::internal(report.to_string());
status.set_source(Into::into(
Into::<Box<dyn std::error::Error + Send + Sync>>::into(report),
));
status
})
// let mut status = tonic::Status::internal(report.to_string());
// status.set_source(Into::into(
// Into::<Box<dyn std::error::Error + Send + Sync>>::into(report),
// ));
// status
// })
}
}

Expand Down
18 changes: 9 additions & 9 deletions core/src/header_chain_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ impl HeaderChainProver {
.map_to_eyre()?;
tracing::debug!("Genesis chain state (verbose): {:?}", genesis_chain_state);

let genesis_chain_state_hash = genesis_chain_state.to_hash();
if genesis_chain_state_hash != config.protocol_paramset().genesis_chain_state_hash {
return Err(eyre::eyre!(
"Genesis chain state hash mismatch: {} != {}",
hex::encode(genesis_chain_state_hash),
hex::encode(config.protocol_paramset().genesis_chain_state_hash)
)
.into());
}
// let genesis_chain_state_hash = genesis_chain_state.to_hash();
// if genesis_chain_state_hash != config.protocol_paramset().genesis_chain_state_hash {
// return Err(eyre::eyre!(
// "Genesis chain state hash mismatch: {} != {}",
// hex::encode(genesis_chain_state_hash),
// hex::encode(config.protocol_paramset().genesis_chain_state_hash)
// )
// .into());
// }

let proof = HeaderChainProver::prove_genesis_block(
genesis_chain_state,
Expand Down
Loading
Loading