Skip to content

Commit

Permalink
Fund operators from the start for testing purposes (#267)
Browse files Browse the repository at this point in the history
* Fund operators from the start for testing purposes

* workflow: Add clementine service action.

* workflow: Use new action for debug mode.

* workflow: Update action.

* workflow: Specify shell.

* workflow: Use env vars.

* workspace: Delete mock_rpc test in regtest test.

* workflow: Change cache save steps.

* change cache to swatinem rust

* save cache also in test step

* test all saved cache

* test all saved cache again

* cache steps modified

* cache steps rerun on all cache

* change runner machines

* workflow: Change debug level to trace.

* action: Add missing fields.

* Change the kickoff_utxo creating tx logic (#265)

* Change the kickoff_utxo creating tx logic

* Remove unnecessary config files, apply review changes

* Fix small VarInt issue

* Add comment

* Fix CI check

* nits

* build yml fixed

* Refactor

---------

Co-authored-by: Ceyhun Şen <[email protected]>
Co-authored-by: Çetin <[email protected]>
  • Loading branch information
3 people authored Sep 2, 2024
1 parent 6876c4a commit d245171
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 48 deletions.
8 changes: 4 additions & 4 deletions core/src/extended_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,15 @@ where
pub fn check_deposit_utxo(
&self,
nofn_xonly_pk: &XOnlyPublicKey,
outpoint: &OutPoint,
deposit_outpoint: &OutPoint,
recovery_taproot_address: &Address<NetworkUnchecked>,
evm_address: &EVMAddress,
amount_sats: u64,
confirmation_block_count: u32,
network: bitcoin::Network,
user_takes_after: u32,
) -> Result<(), BridgeError> {
if self.confirmation_blocks(&outpoint.txid)? < confirmation_block_count {
if self.confirmation_blocks(&deposit_outpoint.txid)? < confirmation_block_count {
return Err(BridgeError::DepositNotFinalized);
}

Expand All @@ -305,14 +305,14 @@ where
);

if !self.check_utxo_address_and_amount(
outpoint,
deposit_outpoint,
&deposit_address.script_pubkey(),
amount_sats,
)? {
return Err(BridgeError::InvalidDepositUTXO);
}

if self.is_utxo_spent(outpoint)? {
if self.is_utxo_spent(deposit_outpoint)? {
return Err(BridgeError::UTXOSpent);
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ where
.signer
.sign(TapSighash::from_byte_array(kickoff_sig_hash));

// In a db tx, save the kickoff_utxo for this deposit_utxo
// In a db tx, save the kickoff_utxo for this deposit_outpoint
// and update the db with the new funding_utxo as the change

let db_transaction = self.db.begin_transaction().await?;
Expand Down Expand Up @@ -521,11 +521,11 @@ where
{
async fn new_deposit_rpc(
&self,
deposit_utxo: OutPoint,
deposit_outpoint: OutPoint,
recovery_taproot_address: Address<NetworkUnchecked>,
evm_address: EVMAddress,
) -> Result<(UTXO, secp256k1::schnorr::Signature), BridgeError> {
self.new_deposit(deposit_utxo, recovery_taproot_address, evm_address)
self.new_deposit(deposit_outpoint, recovery_taproot_address, evm_address)
.await
}

Expand Down
27 changes: 26 additions & 1 deletion core/src/servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
//! Utilities for operator and verifier servers.
use crate::mock::common;
use crate::traits::rpc::AggregatorServer;
use crate::{aggregator, create_extended_rpc};
use crate::traits::rpc::OperatorRpcClient;
use crate::{aggregator, create_extended_rpc, UTXO};
use crate::{
config::BridgeConfig,
create_test_config, create_test_config_with_thread_name,
Expand All @@ -14,6 +15,7 @@ use crate::{
traits::{self, rpc::VerifierRpcServer},
verifier::Verifier,
};
use bitcoin::Address;
use bitcoin_mock_rpc::RpcApiWrapper;
use errors::BridgeError;
use jsonrpsee::{
Expand Down Expand Up @@ -202,6 +204,29 @@ pub async fn create_verifiers_and_operators(
.await
.unwrap();

for (i, (operator_client, _, _)) in operator_endpoints.iter().enumerate() {
// Send operators some bitcoin so that they can afford the kickoff tx
let secp = bitcoin::secp256k1::Secp256k1::new();
let operator_internal_xonly_pk = config.operators_xonly_pks.get(i).unwrap();
let operator_address =
Address::p2tr(&secp, *operator_internal_xonly_pk, None, config.network);
let operator_funding_outpoint = rpc
.send_to_address(&operator_address, 2 * config.bridge_amount_sats)
.unwrap();
let operator_funding_txout = rpc
.get_txout_from_outpoint(&operator_funding_outpoint)
.unwrap();
let operator_funding_utxo = UTXO {
outpoint: operator_funding_outpoint,
txout: operator_funding_txout,
};

tracing::debug!("Operator {:?} funding utxo: {:?}", i, operator_funding_utxo);
operator_client
.set_funding_utxo_rpc(operator_funding_utxo)
.await
.unwrap();
}
let config = create_test_config_with_thread_name!(config_name);
let aggregator = create_aggregator_server(config.clone()).await.unwrap();

Expand Down
8 changes: 4 additions & 4 deletions core/src/traits/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub trait VerifierRpc {
/// - for every kickoff2_tx, partial sign burn_tx (ommitted for now)
async fn operator_kickoffs_generated_rpc(
&self,
deposit_utxo: OutPoint,
deposit_outpoint: OutPoint,
kickoff_utxos: Vec<UTXO>,
operators_kickoff_sigs: Vec<schnorr::Signature>,
agg_nonces: Vec<MuSigAggNonce>,
Expand All @@ -37,7 +37,7 @@ pub trait VerifierRpc {
/// sign operator_takes_txs
async fn burn_txs_signed_rpc(
&self,
deposit_utxo: OutPoint,
deposit_outpoint: OutPoint,
burn_sigs: Vec<schnorr::Signature>,
slash_or_take_sigs: Vec<schnorr::Signature>,
) -> Result<Vec<MuSigPartialSignature>, BridgeError>;
Expand All @@ -48,7 +48,7 @@ pub trait VerifierRpc {
/// sign move_tx
async fn operator_take_txs_signed_rpc(
&self,
deposit_utxo: OutPoint,
deposit_outpoint: OutPoint,
operator_take_sigs: Vec<schnorr::Signature>,
) -> Result<MuSigPartialSignature, BridgeError>;
}
Expand All @@ -59,7 +59,7 @@ pub trait OperatorRpc {
/// - Create kickoffUTXO, make sure to not send it to bitcoin yet
async fn new_deposit_rpc(
&self,
deposit_utxo: OutPoint,
deposit_outpoint: OutPoint,
recovery_taproot_address: Address<NetworkUnchecked>,
evm_address: EVMAddress,
) -> Result<(UTXO, secp256k1::schnorr::Signature), BridgeError>;
Expand Down
4 changes: 2 additions & 2 deletions core/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ where
self.config.user_takes_after,
);

let deposit_utxo = self
let deposit_outpoint = self
.rpc
.send_to_address(&deposit_address, self.config.bridge_amount_sats)?;

Ok((deposit_utxo, self.signer.xonly_public_key, evm_address))
Ok((deposit_outpoint, self.signer.xonly_public_key, evm_address))
}

pub fn get_deposit_address(&self, evm_address: EVMAddress) -> Result<Address, BridgeError> {
Expand Down
18 changes: 9 additions & 9 deletions core/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ where
// For now we multiply by 2 since we do not give signatures for burn_txs. // TODO: Change this in future.
let num_required_nonces = 2 * self.operator_xonly_pks.len() + 1;

// Check if we already have pub_nonces for this deposit_utxo.
// Check if we already have pub_nonces for this deposit_outpoint.
let pub_nonces_from_db = self.db.get_pub_nonces(deposit_outpoint).await?;
if let Some(pub_nonces) = pub_nonces_from_db {
if !pub_nonces.is_empty() {
Expand Down Expand Up @@ -529,23 +529,23 @@ where
{
async fn verifier_new_deposit_rpc(
&self,
deposit_utxo: OutPoint,
deposit_outpoint: OutPoint,
recovery_taproot_address: Address<NetworkUnchecked>,
evm_address: EVMAddress,
) -> Result<Vec<MuSigPubNonce>, BridgeError> {
self.new_deposit(deposit_utxo, recovery_taproot_address, evm_address)
self.new_deposit(deposit_outpoint, recovery_taproot_address, evm_address)
.await
}

async fn operator_kickoffs_generated_rpc(
&self,
deposit_utxo: OutPoint,
deposit_outpoint: OutPoint,
kickoff_utxos: Vec<UTXO>,
operators_kickoff_sigs: Vec<schnorr::Signature>,
agg_nonces: Vec<MuSigAggNonce>,
) -> Result<(Vec<MuSigPartialSignature>, Vec<MuSigPartialSignature>), BridgeError> {
self.operator_kickoffs_generated(
deposit_utxo,
deposit_outpoint,
kickoff_utxos,
operators_kickoff_sigs,
agg_nonces,
Expand All @@ -555,20 +555,20 @@ where

async fn burn_txs_signed_rpc(
&self,
deposit_utxo: OutPoint,
deposit_outpoint: OutPoint,
burn_sigs: Vec<schnorr::Signature>,
slash_or_take_sigs: Vec<schnorr::Signature>,
) -> Result<Vec<MuSigPartialSignature>, BridgeError> {
self.burn_txs_signed(deposit_utxo, burn_sigs, slash_or_take_sigs)
self.burn_txs_signed(deposit_outpoint, burn_sigs, slash_or_take_sigs)
.await
}

async fn operator_take_txs_signed_rpc(
&self,
deposit_utxo: OutPoint,
deposit_outpoint: OutPoint,
operator_take_sigs: Vec<schnorr::Signature>,
) -> Result<MuSigPartialSignature, BridgeError> {
self.operator_take_txs_signed(deposit_utxo, operator_take_sigs)
self.operator_take_txs_signed(deposit_outpoint, operator_take_sigs)
.await
}
}
26 changes: 1 addition & 25 deletions core/tests/common.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// //! # Common utilities for tests

use bitcoin::Address;
use bitcoin::OutPoint;
use clementine_core::actor::Actor;
use clementine_core::config::BridgeConfig;
Expand All @@ -14,7 +13,6 @@ use clementine_core::traits::rpc::OperatorRpcClient;
use clementine_core::traits::rpc::VerifierRpcClient;
use clementine_core::user::User;
use clementine_core::EVMAddress;
use clementine_core::UTXO;
use clementine_core::{
create_extended_rpc, create_test_config, create_test_config_with_thread_name,
};
Expand Down Expand Up @@ -83,29 +81,7 @@ pub async fn run_single_deposit(
let mut kickoff_utxos = Vec::new();
let mut signatures = Vec::new();

for (i, (client, _, _)) in operators.iter().enumerate() {
// Send operators some bitcoin so that they can afford the kickoff tx
let secp = bitcoin::secp256k1::Secp256k1::new();
let operator_internal_xonly_pk = config.operators_xonly_pks.get(i).unwrap();
let operator_address =
Address::p2tr(&secp, *operator_internal_xonly_pk, None, config.network);
let operator_funding_outpoint = rpc
.send_to_address(&operator_address, 2 * config.bridge_amount_sats)
.unwrap();
let operator_funding_txout = rpc
.get_txout_from_outpoint(&operator_funding_outpoint)
.unwrap();
let operator_funding_utxo = UTXO {
outpoint: operator_funding_outpoint,
txout: operator_funding_txout,
};

// tracing::debug!("Operator {:?} funding utxo: {:?}", i, operator_funding_utxo);
client
.set_funding_utxo_rpc(operator_funding_utxo)
.await
.unwrap();

for (client, _, _) in operators.iter() {
// Create deposit kickoff transaction
let (kickoff_utxo, signature) = client
.new_deposit_rpc(deposit_outpoint, signer_address.clone(), evm_address)
Expand Down

0 comments on commit d245171

Please sign in to comment.