hsd icon indicating copy to clipboard operation
hsd copied to clipboard

Change txdb zap to use layoutp

Open rozaydin opened this issue 3 years ago • 3 comments

This PR changes the txdb zap method, instead of retrieving records from layout.m (which iterates over all txes i assume), it retrieves from layout.p (pending txes) to prevent unnecessary looping over all txs.

My understanding might be wrong, I am not quite sure about layout.m if it's used to store all txes with a timestamp or not. (if there is some documentation about leveldb layout for hsd that would be awesome) However if it makes sense, i would like to suggest the zap method to return (instead of just success: true) the list of txes it zapped. Which i can add to this PR if it makes sense ...

  • p[hash] -> dummy (pending flag)
  • m[time][hash] -> dummy (tx by time)

If you are on it, would be great to know what should be the relation between the mempool and zapped/abondaned txes

Thanks for the amazing software you are building ...

rozaydin avatar Nov 12 '21 20:11 rozaydin

Hey thanks for the contribution and for looking in to this. I'm not sure this is an improvement actually. The existing zap() function uses the m index in the DB which is transactions ordered by TIME, which is the only parameter accepted by the API call. The p index is ALL pending transactions ordered by txid (so, random). By passing a time value to the function, only transactions added to the DB within that window will be processed (not "all" txs).

I couldn't tell you why the "zap" function is constrained by TX age but I think instead of breaking it, if you want to ADD a "delete all pending txs" API using the method you started implementing here, that might make more sense for a pull request.

pinheadmz avatar Nov 15 '21 16:11 pinheadmz

I think if you continue working on this with the p index, you probably can remove this filter:

https://github.com/handshake-org/hsd/blob/afe8b4320efb401aa7f773c3da0e28a6226af11b/lib/wallet/txdb.js#L3194-L3195

pinheadmz avatar Nov 15 '21 16:11 pinheadmz

Pull Request Test Coverage Report for Build 1454650398

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.7%) to 62.361%

Totals Coverage Status
Change from base Build 1391687210: 0.7%
Covered Lines: 21238
Relevant Lines: 31825

💛 - Coveralls

coveralls avatar Nov 15 '21 16:11 coveralls