Skip to content

Commit

Permalink
Don't double insert kickoff utxos
Browse files Browse the repository at this point in the history
  • Loading branch information
ekrembal committed Sep 4, 2024
1 parent 20c6d79 commit 4dbc547
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/database/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl Database {
// txout_db: TxOutDB(utxo.txout.clone()),
// }).unwrap());
sqlx::query(
"INSERT INTO deposit_kickoff_utxos (deposit_outpoint, kickoff_utxo) VALUES ($1, $2);",
"INSERT INTO deposit_kickoff_utxos (deposit_outpoint, kickoff_utxo) VALUES ($1, $2) ON CONFLICT (deposit_outpoint, kickoff_utxo) DO NOTHING;",
)
.bind(OutPointDB(deposit_outpoint))
.bind(sqlx::types::Json(UTXODB {
Expand Down
13 changes: 13 additions & 0 deletions core/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ where
operators_kickoff_sigs: Vec<secp256k1::schnorr::Signature>, // These are not transaction signatures, rather, they are to verify the operator's identity.
agg_nonces: Vec<MuSigAggNonce>, // This includes all the agg_nonces for the bridge operations.
) -> Result<(Vec<MuSigPartialSignature>, Vec<MuSigPartialSignature>), BridgeError> {
tracing::debug!(
"Operatos kickoffs generated is called with data: {:?}, {:?}, {:?}, {:?}",
deposit_outpoint,
kickoff_utxos,
operators_kickoff_sigs,
agg_nonces
);

if operators_kickoff_sigs.len() != kickoff_utxos.len() {
return Err(BridgeError::InvalidKickoffUtxo); // TODO: Better error
}
Expand Down Expand Up @@ -201,6 +209,11 @@ where
slash_or_take_sighashes.push(slash_or_take_tx_sighash.to_byte_array());
// let spend_kickoff_utxo_tx_handler = TransactionBuilder::create_slash_or_take_tx(deposit_outpoint, kickoff_outpoint, kickoff_txout, operator_address, operator_idx, nofn_xonly_pk, network)
}
tracing::debug!(
"Slash or take sighashes for verifier: {:?}: {:?}",
self.signer.xonly_public_key.to_string(),
slash_or_take_sighashes
);

let nonces = self
.db
Expand Down
2 changes: 1 addition & 1 deletion scripts/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ create table if not exists nonces (
deposit_outpoint text not null check (deposit_outpoint ~ '^[a-fA-F0-9]{64}:(0|[1-9][0-9]{0,9})$'),
pub_nonce bytea not null check (length(pub_nonce) = 66),
sec_nonce text not null check (sec_nonce ~ '^[a-fA-F0-9]{128}$'),
agg_nonce bytea check (length(pub_nonce) = 66),
agg_nonce bytea check (length(agg_nonce) = 66),
sighash text check (sighash ~ '^[a-fA-F0-9]{64}'), /* 32 bytes */
created_at timestamp not null default now()
);
Expand Down

0 comments on commit 4dbc547

Please sign in to comment.