-
Notifications
You must be signed in to change notification settings - Fork 282
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
txdb lock balance accounting fixes. #780
Conversation
b26bbd0
to
13e0a19
Compare
c1c0741
to
137534e
Compare
d19b487
to
77a57f8
Compare
misc: Log name instead of number for covenants.
const GRIND_NAME_LEN = 10; | ||
const hardFee = 1e4; | ||
|
||
// TODO: Add insert w/ block only tests(no unconfirmed step). | ||
// TODO: Add claim test. | ||
// TODO: (Re)Move and merge wallet-test lock balance checks. | ||
// TODO: Add double spend and double spend/erase of chained txs. | ||
// - Test when we have spent tracking(layout.s) but not spendCoin(layoud.d) |
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.
typo: "layout"
86c5627
to
e74ac10
Compare
@nodech rebased on master and discovered another failed test from #781 I don't know if this issue is recoverable. I'm using these extra log statements to monitor the un/lock balance activity: https://gist.github.com/pinheadmz/9af90d54e7ac934a7aa331ccd6501f28 |
/** | ||
* @typedef {import('./walletdb')} WalletDB | ||
*/ | ||
|
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.
CI didn't like this.
ERROR: Unable to parse a tag's type expression for source file /home/runner/work/hsd/hsd/lib/wallet/txdb.js in line 27 with tag title "typedef" and text "{import('./walletdb')} WalletDB": Invalid type expression "import('./walletdb')": Expected "!", "=", "?", "[]", "|", or end of input but "(" found.
Error: Process completed with exit code 1.
if (!credit) { | ||
credit = Credit.fromTX(tx, i, height); | ||
await this.removeCredit(b, credit, path); | ||
continue; |
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.
The continue
here makes sense, but we already know there is no Credit, so I don't understand the purpose of removeCredit()
? All tests pass without it
The assertions were only there in the first place because of weird covenant accounting: for some covenants like REVEAL, we dig up the corresponding BID from the database and we MUST HAVE THAT DATA or we can't compute the change to the wallet's locked balance.
The new approach is: we process all inputs and all outputs of every TX, meaning that the BID in the input of the transaction is applied to our balance mere moments before we process the REVEAL in the output of the same transaction. This simplifies balance locking really well (we eliminate DB lookups and the functions are no longer
async/await
).The assertion errors we've been getting almost daily from users occurs when the BID is not in the database yet because we don't recognize our own address because it's a wallet recovery and we haven't generated the address yet.
What this PR does is "not care": if we see a REVEAL before we see the BID, then we have a negative locked balance. Yep that really sucks but it can be fixed with a rescan or two... and no one's node has to crash.
There is one other drawback to this, which is why I'm pausing here and opening as draft:
TODO:
class Balance
in txdb needs to allow negative values. Removeassert >= 0
and switch allwriteU64
towriteI64
which interestingly, because it's javascript, I think means we don't need a migration ... ?!