Skip to content

Commit

Permalink
fix(wallet): fixes bug in fetch_by_commitment (#4703)
Browse files Browse the repository at this point in the history
Description
---
Fixes request/response mismatch bug in fetch_by_commitment.
`fetch_by_commitment` can only ever return one value, or a not found error

Motivation and Context
---
This error is encountered during merge mining
```text
Output manager error: `Output manager storage error: `Unexpected result: `Unexpected result for database query Unspent Outputs Key. Response: Spent Output
```

This is caused by `fetch(DbKey::AnyOutputByCommitment)` returning `DbValue::SpentOutput` but the caller expects `DbKey::UnspentOutput`

How Has This Been Tested?
---
Merge mining works
  • Loading branch information
sdbondi authored Sep 20, 2022
1 parent 9768f02 commit 97b01c2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
10 changes: 1 addition & 9 deletions base_layer/wallet/src/output_manager_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,15 +1109,7 @@ where

// If there is no existing output available, we store the one we produced.
match self.resources.db.fetch_by_commitment(output.commitment.clone()) {
Ok(outs) => {
if outs.is_empty() {
self.resources
.db
.add_output_to_be_received(tx_id, output, Some(block_height))?;

self.confirm_encumberance(tx_id)?;
}
},
Ok(_) => {},
Err(OutputManagerStorageError::ValueNotFound) => {
self.resources
.db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,13 @@ where T: OutputManagerBackend + 'static
Ok(result)
}

pub fn fetch_by_commitment(
&self,
commitment: Commitment,
) -> Result<Vec<DbUnblindedOutput>, OutputManagerStorageError> {
let result = match self.db.fetch(&DbKey::AnyOutputByCommitment(commitment))? {
Some(DbValue::UnspentOutputs(outputs)) => outputs,
Some(other) => return unexpected_result(DbKey::UnspentOutputs, other),
None => vec![],
};
Ok(result)
pub fn fetch_by_commitment(&self, commitment: Commitment) -> Result<DbUnblindedOutput, OutputManagerStorageError> {
let req = DbKey::AnyOutputByCommitment(commitment);
match self.db.fetch(&req)? {
Some(DbValue::AnyOutput(output)) => Ok(*output),
Some(other) => unexpected_result(req, other),
None => Err(OutputManagerStorageError::ValueNotFound),
}
}

pub fn fetch_with_features(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl OutputManagerBackend for OutputManagerSqliteDatabase {
match OutputSql::find_by_commitment(&commitment.to_vec(), &conn) {
Ok(mut o) => {
self.decrypt_if_necessary(&mut o)?;
Some(DbValue::SpentOutput(Box::new(DbUnblindedOutput::try_from(o)?)))
Some(DbValue::AnyOutput(Box::new(DbUnblindedOutput::try_from(o)?)))
},
Err(e) => {
match e {
Expand Down

0 comments on commit 97b01c2

Please sign in to comment.