Skip to content

Commit

Permalink
perf: Batch update operator take sigs
Browse files Browse the repository at this point in the history
  • Loading branch information
lemonpartee committed Aug 29, 2024
1 parent 7391928 commit 596d466
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
35 changes: 23 additions & 12 deletions core/src/database/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,23 +446,34 @@ impl Database {
}
}

pub async fn save_operator_take_sig(
pub async fn save_operator_take_sigs(
&self,
deposit_outpoint: OutPoint,
kickoff_utxo: UTXO,
operator_take_sig: schnorr::Signature,
kickoff_utxos_and_sigs: impl IntoIterator<Item = (UTXO, schnorr::Signature)>,
) -> Result<(), BridgeError> {
sqlx::query(
QueryBuilder::new(
"UPDATE deposit_kickoff_utxos
SET operator_take_sig = $3
WHERE deposit_outpoint = $1 AND kickoff_utxo = $2;",
SET operator_take_sig = batch.sig
FROM (",
)
.bind(OutPointDB(deposit_outpoint))
.bind(sqlx::types::Json(UTXODB {
outpoint_db: OutPointDB(kickoff_utxo.outpoint),
txout_db: TxOutDB(kickoff_utxo.txout),
}))
.bind(SignatureDB(operator_take_sig))
.push_values(
kickoff_utxos_and_sigs,
|mut builder, (kickoff_utxo, operator_take_sig)| {
builder
.push_bind(sqlx::types::Json(UTXODB {
outpoint_db: OutPointDB(kickoff_utxo.outpoint),
txout_db: TxOutDB(kickoff_utxo.txout),
}))
.push_bind(SignatureDB(operator_take_sig));
},
)
.push(
") AS batch (kickoff_utxo, sig)
WHERE deposit_kickoff_utxos.deposit_outpoint = ",
)
.push_bind(OutPointDB(deposit_outpoint))
.push(" AND deposit_kickoff_utxos.kickoff_utxo = batch.kickoff_utxo;")
.build()
.execute(&self.connection)
.await?;

Expand Down
20 changes: 10 additions & 10 deletions core/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,16 +461,16 @@ where
.unwrap();
});

for (index, kickoff_utxo) in kickoff_utxos.iter().enumerate() {
self.db
.save_operator_take_sig(
deposit_outpoint,
kickoff_utxo.clone(),
operator_take_sigs[index],
)
.await
.unwrap();
}
let kickoff_utxos = kickoff_utxos
.into_iter()
.enumerate()
.map(|(index, utxo)| (utxo, operator_take_sigs[index]));

self.db
.save_operator_take_sigs(deposit_outpoint, kickoff_utxos)
.await
.unwrap();

// println!("MOVE_TX: {:?}", move_tx_handler);
// println!("MOVE_TXID: {:?}", move_tx_handler.tx.compute_txid());
let move_tx_sighash =
Expand Down

0 comments on commit 596d466

Please sign in to comment.