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
Problem: Outputs API doesn't respond with correct unspent/spent outputs #2567
Conversation
Solution: Fix fastquery such that embedded document is queried properly
Codecov Report
@@ Coverage Diff @@
## master #2567 +/- ##
==========================================
+ Coverage 93.63% 93.64% +<.01%
==========================================
Files 45 45
Lines 2623 2626 +3
==========================================
+ Hits 2456 2459 +3
Misses 167 167 |
bigchaindb/common/transaction.py
Outdated
@@ -274,6 +274,15 @@ def to_dict(self): | |||
'output_index': self.output, | |||
} | |||
|
|||
def to_query(self): | |||
if self.txid is None and self.output is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for just one of these to be None
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, these fields cannot be None
. I started off with to_dict
, this code is leftover
Solution: remove to unnecesary if conditional
bigchaindb/common/transaction.py
Outdated
@@ -274,6 +274,12 @@ def to_dict(self): | |||
'output_index': self.output, | |||
} | |||
|
|||
def to_query(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about changing the transaction query the following way? The current approach disguises the caveat from the reader.
'$and': [
{
'inputs.fulfills.transaction_id': {
'$in': transaction_ids,
},
'inputs.fulfills.output_index': {
'$in': output_indexes,
},
}
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, $and
is applied to fulfills
so:
{
'inputs.fulfills: {
'$and': [{
transaction_id': {
'$in': transaction_ids,
},
'output_index': {
'$in': output_indexes,
},
}]
}
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, and we also seem to need $elemMatch
.
Solution: get_spent queries embedded documents which respect key order. This is not expected by the application hence the query should be altered to query any kind of key order
Solution: Simplify query using $elemMatch
Solution: Add test for `get_spending_transactions` to check that correct matching is done when querying documents with multiple inputs
Solution: assert tranasction ids
Solution: Fix
fastquery
such that embedded document is queried properlyFixes #2552
Fixes #2568