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

hack: print full proof for contracts testing #510

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bitcoin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ light-client = []

[dependencies]
thiserror = "1.0"
bitcoincore-rpc = { git = "https://github.com/rust-bitcoin/rust-bitcoincore-rpc", rev = "7bd815f1e1ae721404719ee8e6867064b7c68494" }
bitcoincore-rpc = { git = "https://github.com/interlay/rust-bitcoincore-rpc", rev = "671a78f638179c8951c9932061fd2bb348313a2c" }
hex = "0.4.2"
async-trait = "0.1.40"
tokio = { version = "1.0", features = ["full"] }
Expand Down
12 changes: 12 additions & 0 deletions bitcoin/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ impl BitcoinOpts {
}
}

pub async fn new_walletless(
&self,
wallet_name: Option<String>,
) -> Result<Arc<dyn BitcoinCoreApi + Send + Sync>, Error> {
let bitcoin_core = self
.new_client_builder(wallet_name)
.build_and_connect(Duration::from_millis(self.bitcoin_connection_timeout_ms))
.await?;
bitcoin_core.sync().await?;
Ok(Arc::new(bitcoin_core))
}

pub fn new_client_with_network(
&self,
wallet_name: Option<String>,
Expand Down
8 changes: 5 additions & 3 deletions bitcoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub const DEFAULT_MAX_TX_COUNT: usize = 100_000_000;
/// the bitcoin core version.
/// See https://github.com/bitcoin/bitcoin/blob/833add0f48b0fad84d7b8cf9373a349e7aef20b4/src/rpc/net.cpp#L627
/// and https://github.com/bitcoin/bitcoin/blob/833add0f48b0fad84d7b8cf9373a349e7aef20b4/src/clientversion.h#L33-L37
pub const BITCOIN_CORE_VERSION_23: usize = 230_000;
pub const BITCOIN_CORE_VERSION_26: usize = 260_000;
const NOT_IN_MEMPOOL_ERROR_CODE: i32 = BitcoinRpcError::RpcInvalidAddressOrKey as i32;

// Time to sleep before retry on startup.
Expand Down Expand Up @@ -283,7 +283,7 @@ async fn connect(rpc: &Client, connection_timeout: Duration) -> Result<Network,
info!("Connected to {}", chain);
info!("Bitcoin version {}", version);

if version >= BITCOIN_CORE_VERSION_23 {
if version >= BITCOIN_CORE_VERSION_26 {
return Err(Error::IncompatibleVersion(version))
}

Expand Down Expand Up @@ -1052,7 +1052,9 @@ impl BitcoinCoreApi for BitcoinCore {
} else {
info!("Creating wallet {wallet_name}...");
// wallet does not exist, create
let result = self.rpc.create_wallet(wallet_name, None, None, None, None)?;
let result = self
.rpc
.create_wallet(wallet_name, None, None, None, None, Some(false))?;
if let Some(warning) = result.warning {
if !warning.is_empty() {
warn!("Received warning while creating wallet {wallet_name}: {warning}");
Expand Down
6 changes: 3 additions & 3 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ pub use retry::{notify_retry, RetryPolicy};
#[cfg(feature = "testing-utils")]
pub use rpc::SudoPallet;
pub use rpc::{
BtcRelayPallet, CollateralBalancesPallet, FeePallet, FeeRateUpdateReceiver, InterBtcParachain, IssuePallet,
OraclePallet, RedeemPallet, ReplacePallet, SecurityPallet, TimestampPallet, UtilFuncs, VaultRegistryPallet,
DEFAULT_SPEC_NAME, SS58_PREFIX,
encoded_tx_proof, BtcRelayPallet, CollateralBalancesPallet, FeePallet, FeeRateUpdateReceiver, InterBtcParachain,
IssuePallet, OraclePallet, RedeemPallet, ReplacePallet, SecurityPallet, TimestampPallet, UtilFuncs,
VaultRegistryPallet, DEFAULT_SPEC_NAME, SS58_PREFIX,
};
pub use shutdown::{ShutdownReceiver, ShutdownSender};
pub use sp_arithmetic::{traits as FixedPointTraits, FixedI128, FixedPointNumber, FixedU128};
Expand Down
5 changes: 5 additions & 0 deletions runtime/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1937,6 +1937,11 @@ impl SudoPallet for InterBtcParachain {
}
}

pub fn encoded_tx_proof(raw_proof: &RawTransactionProof) -> Result<Vec<u8>, Error> {
let proof = build_full_tx_proof(raw_proof)?;
Ok(proof.encode())
}

pub fn build_full_tx_proof(raw_proof: &RawTransactionProof) -> Result<Static<FullTransactionProof>, Error> {
Ok(Static(FullTransactionProof {
user_tx_proof: PartialTransactionProof {
Expand Down
1 change: 0 additions & 1 deletion runtime/src/utils/account_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use codec::{Decode, Encode};
use serde::{Deserialize, Serialize};
use sp_core::crypto::{AccountId32 as Sp_AccountId32, Ss58Codec};
use subxt::utils::Static;

#[derive(
Hash,
Clone,
Expand Down
38 changes: 37 additions & 1 deletion vault/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bitcoin::{Network, PrivateKey};
use bitcoin::{BitcoinCoreApi, BlockHash, Network, PrivateKey, Txid};
use clap::Parser;
use futures::Future;
use runtime::{
Expand All @@ -12,6 +12,8 @@ use std::{
io::Write,
net::{Ipv4Addr, SocketAddr},
path::PathBuf,
str::FromStr,
sync::Arc,
};
use sysinfo::{System, SystemExt};
use tokio_stream::StreamExt;
Expand All @@ -38,6 +40,8 @@ enum Commands {
GenerateBitcoinKey(GenerateBitcoinKeyOpts),
/// Generate the sr25519 parachain key pair.
GenerateParachainKey(GenerateParachainKeyOpts),
/// Get proof for a given txid
GetProof(GetProofOpts),
/// Run the Vault client (default).
#[clap(name = "run")]
RunVault(Box<RunVaultOpts>),
Expand Down Expand Up @@ -80,6 +84,35 @@ impl GenerateBitcoinKeyOpts {
}
}

#[derive(Debug, Parser, Clone)]
struct GetProofOpts {
#[clap(long)]
txid: String,
#[clap(long)]
num_confirmations: u32,
/// Connection settings for Bitcoin Core.
#[clap(flatten)]
pub bitcoin: bitcoin::cli::BitcoinOpts,
}

impl GetProofOpts {
pub async fn print_proof(&self) -> Result<(), Error> {
let bitcoin_rpc = self.bitcoin.new_walletless(None).await?;
let txid = Txid::from_str(&self.txid).unwrap();

let raw_proof = bitcoin_rpc
.wait_for_transaction_metadata(txid, self.num_confirmations, None, false)
.await?
.proof;
println!("user tx: {}", hex::encode(&raw_proof.raw_user_tx));
println!("coinbase tx: {}", hex::encode(&raw_proof.raw_coinbase_tx));

let interlay_proof = runtime::encoded_tx_proof(&raw_proof)?;
println!("full proof: {}", hex::encode(interlay_proof));
Ok(())
}
}

#[derive(Debug, Parser, Clone)]
struct GenerateParachainKeyOpts {
/// Output file name or stdout if unspecified.
Expand Down Expand Up @@ -161,6 +194,9 @@ async fn start() -> Result<(), Error> {
Some(Commands::GenerateParachainKey(opts)) => {
return opts.generate_and_write();
}
Some(Commands::GetProof(sub_opts)) => {
return sub_opts.print_proof().await;
}
_ => (),
}

Expand Down