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

Batch update slash or take signatures #249

Merged
merged 1 commit into from
Aug 30, 2024
Merged
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
35 changes: 23 additions & 12 deletions core/src/database/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,23 +399,34 @@ impl Database {
Ok(())
}

pub async fn save_slash_or_take_sig(
pub async fn save_slash_or_take_sigs(
&self,
deposit_outpoint: OutPoint,
kickoff_utxo: UTXO,
slash_or_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 slash_or_take_sig = $3
WHERE deposit_outpoint = $1 AND kickoff_utxo = $2;",
SET slash_or_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(slash_or_take_sig))
.push_values(
kickoff_utxos_and_sigs,
|mut builder, (kickoff_utxo, slash_or_take_sig)| {
builder
.push_bind(sqlx::types::Json(UTXODB {
outpoint_db: OutPointDB(kickoff_utxo.outpoint),
txout_db: TxOutDB(kickoff_utxo.txout),
}))
.push_bind(SignatureDB(slash_or_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
19 changes: 9 additions & 10 deletions core/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,16 +364,15 @@ where
})
.collect::<Vec<_>>();

for (index, kickoff_utxo) in kickoff_utxos.iter().enumerate() {
self.db
.save_slash_or_take_sig(
deposit_outpoint,
kickoff_utxo.clone(),
slash_or_take_sigs[index],
)
.await
.unwrap();
}
let kickoff_utxos_with_sigs = kickoff_utxos
.iter()
.enumerate()
.map(|(index, kickoff_utxo)| (kickoff_utxo.clone(), slash_or_take_sigs[index]));

self.db
.save_slash_or_take_sigs(deposit_outpoint, kickoff_utxos_with_sigs)
.await
.unwrap();

// println!("Operator takes sighashes: {:?}", operator_takes_sighashes);
let nonces = self
Expand Down
Loading