Skip to content

Commit

Permalink
refactor sync time verification
Browse files Browse the repository at this point in the history
Instead of verifying txs at sync time in every backend, its moved to
script_sync to by default be available to any backend.
  • Loading branch information
rajarshimaitra committed Jan 21, 2022
1 parent 9484ca1 commit c738dd7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 51 deletions.
13 changes: 0 additions & 13 deletions src/blockchain/electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,6 @@ impl Blockchain for ElectrumBlockchain {
.output
.get(input.previous_output.vout as usize)
.ok_or_else(electrum_goof)?;
// Verify this input if requested via feature flag
#[cfg(feature = "verify")]
{
use crate::wallet::verify::VerifyError;
let serialized_tx = bitcoin::consensus::serialize(&tx);
bitcoinconsensus::verify(
txout.script_pubkey.to_bytes().as_ref(),
txout.value,
&serialized_tx,
input_index,
)
.map_err(|e| VerifyError::from(e))?;
}
input_index += 1;
Ok(Some(txout.clone()))
})
Expand Down
18 changes: 0 additions & 18 deletions src/blockchain/esplora/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,6 @@ impl Blockchain for EsploraBlockchain {
.request()
.map(|txid| {
let tx = tx_index.get(txid).expect("must be in index");
// Verify this transaction if requested via feature flag
#[cfg(feature = "verify")]
{
use crate::wallet::verify::VerifyError;
let prev_outs = tx.previous_outputs();
let tx_bytes = serialize(&tx.to_tx());
for (index, output) in prev_outs.iter().enumerate() {
if let Some(output) = output {
bitcoinconsensus::verify(
output.script_pubkey.to_bytes().as_ref(),
output.value,
&tx_bytes,
index,
)
.map_err(|e| VerifyError::from(e))?;
}
}
}
Ok((tx.previous_outputs(), tx.to_tx()))
})
.collect::<Result<_, Error>>()?;
Expand Down
18 changes: 0 additions & 18 deletions src/blockchain/esplora/ureq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,6 @@ impl Blockchain for EsploraBlockchain {
.request()
.map(|txid| {
let tx = tx_index.get(txid).expect("must be in index");
// Verify this transaction if requested via feature flag
#[cfg(feature = "verify")]
{
use crate::wallet::verify::VerifyError;
let prev_outs = tx.previous_outputs();
let tx_bytes = serialize(&tx.to_tx());
for (index, output) in prev_outs.iter().enumerate() {
if let Some(output) = output {
bitcoinconsensus::verify(
output.script_pubkey.to_bytes().as_ref(),
output.value,
&tx_bytes,
index,
)
.map_err(|e| VerifyError::from(e))?;
}
}
}
Ok((tx.previous_outputs(), tx.to_tx()))
})
.collect::<Result<_, Error>>()?;
Expand Down
18 changes: 16 additions & 2 deletions src/blockchain/script_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ impl<'a, D: BatchDatabase> TxReq<'a, D> {
let mut inputs_sum: u64 = 0;
let mut outputs_sum: u64 = 0;

for (txout, input) in vout.into_iter().zip(tx.input.iter()) {
for (txout, (input_index, input)) in
vout.into_iter().zip(tx.input.iter().enumerate())
{
let txout = match txout {
Some(txout) => txout,
None => {
Expand All @@ -190,7 +192,19 @@ impl<'a, D: BatchDatabase> TxReq<'a, D> {
continue;
}
};

// Verify this input if requested via feature flag
#[cfg(feature = "verify")]
{
use crate::wallet::verify::VerifyError;
let serialized_tx = bitcoin::consensus::serialize(&tx);
bitcoinconsensus::verify(
txout.script_pubkey.to_bytes().as_ref(),
txout.value,
&serialized_tx,
input_index,
)
.map_err(|e| VerifyError::from(e))?;
}
inputs_sum += txout.value;
if self.state.db.is_mine(&txout.script_pubkey)? {
sent += txout.value;
Expand Down

0 comments on commit c738dd7

Please sign in to comment.