Skip to content
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

fix: Support deleted object in ledger_entry #1483

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from

Conversation

Kassaking7
Copy link
Collaborator

@Kassaking7 Kassaking7 commented Jun 21, 2024

Fixes #1306

* created query to fetch last two entries

* fix duplicate query
* created query to fetch last two entries

* fix duplicate query

* add db fetch func

* adding db fetching func

* changed Blob to pair<uint, Blob> to catch sequence as well
* added deleted_ledger_index logic to extract last two ledger objects

* fixed a bug on index, should be non-negative

* optimize the logic

* fixed a previous bug in doFetchLastTwoLedgerObjects and develped the new API for entry ledger

* fix tag_invoke default value for deleted_ledger_index & add some log info

* add RPC field for include deleted and improve a style issue

* remove an impossible case for LedgerEntry

* fix an assignment issue on deleted_ledger_index

* add a comment
* init unit test cases

* add a new case and change a test name

* add a new test case

* added comments to each test and remove redudant code

* change {} to Blob{} to improve readability
Copy link
Collaborator

@cindyyan317 cindyyan317 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the include_deleted is optional, I would suggest to try to utilize our cache as much as possible. Maybe we don't need to land on DB every time.

1 Keep using 'fetchLedgerObject' to get the last object by seq (This method will use cache effectively)
2 If include_deleted is true and the object from 1 is empty , use fetchLedgerObject + the seq_from_object_1 -1 getting the second one.
I think it might be easier and no need extra CQL statement. I am happy to discuss it offline if needed.

BTW, please assign the issue to yourself when you start doing that. In case other people may pick it as no one works on it.

@cindyyan317 cindyyan317 changed the title Project defi 129 branch Support deleted object in ledger_entry Jun 24, 2024
@Kassaking7 Kassaking7 changed the title Support deleted object in ledger_entry Fix: Support deleted object in ledger_entry Jun 25, 2024
Copy link
Collaborator

@godexsoft godexsoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving a few nits 👍

src/data/BackendInterface.cpp Show resolved Hide resolved
src/rpc/handlers/LedgerEntry.cpp Outdated Show resolved Hide resolved
src/rpc/handlers/LedgerEntry.cpp Outdated Show resolved Hide resolved
src/data/BackendInterface.hpp Outdated Show resolved Hide resolved
src/rpc/handlers/LedgerEntry.cpp Outdated Show resolved Hide resolved
src/rpc/handlers/LedgerEntry.hpp Outdated Show resolved Hide resolved
src/rpc/handlers/LedgerEntry.hpp Show resolved Hide resolved
tests/unit/rpc/handlers/LedgerEntryTests.cpp Outdated Show resolved Hide resolved
tests/unit/rpc/handlers/LedgerEntryTests.cpp Outdated Show resolved Hide resolved
@Kassaking7 Kassaking7 changed the title Fix: Support deleted object in ledger_entry fix: Support deleted object in ledger_entry Jun 25, 2024
Copy link

codecov bot commented Jun 25, 2024

Codecov Report

Attention: Patch coverage is 81.81818% with 4 lines in your changes missing coverage. Please review.

Project coverage is 68.18%. Comparing base (aa86075) to head (5c8388b).
Report is 2 commits behind head on develop.

Files Patch % Lines
src/rpc/handlers/LedgerEntry.cpp 87.50% 0 Missing and 2 partials ⚠️
src/data/BackendInterface.cpp 80.00% 0 Missing and 1 partial ⚠️
src/rpc/handlers/LedgerEntry.hpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1483      +/-   ##
===========================================
+ Coverage    68.13%   68.18%   +0.04%     
===========================================
  Files          236      236              
  Lines         9558     9576      +18     
  Branches      5308     5320      +12     
===========================================
+ Hits          6512     6529      +17     
- Misses        1660     1661       +1     
  Partials      1386     1386              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@godexsoft godexsoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a few more small improvements. This PR looks very close though - great job 🙇

src/rpc/handlers/LedgerEntry.cpp Outdated Show resolved Hide resolved
src/rpc/handlers/LedgerEntry.cpp Outdated Show resolved Hide resolved
src/rpc/handlers/LedgerEntry.cpp Show resolved Hide resolved
src/rpc/handlers/LedgerEntry.hpp Show resolved Hide resolved
Copy link
Collaborator

@cindyyan317 cindyyan317 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the seq you are using to query the second latest object is not right. You need the seq which the object is modified at.
You can find more info about 'objects' table from here

@Kassaking7
Copy link
Collaborator Author

I give a change on the logic:

  1. Try to fetch the object with a given sequence
  2. If failed, it means the sequence it deleted is at least <= current given sequence
  3. Use a new created function to fetch the sequence that the object deleted (no need for new CQL statement)
  4. Use the new sequence-1 to fetch the latest object that is not deleted

Hope this time it works good :) I created a unit test for this case and looks good to me.

Copy link
Collaborator

@cindyyan317 cindyyan317 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Thanks 🙇
Just some nits to fix, then we are ready to go

if (!ledgerObject || ledgerObject->empty()) {
if (not input.includeDeleted)
return Error{Status{"entryNotFound"}};
auto const deletedSeq = sharedPtrBackend_->fetchLedgerObjectSeq(key, lgrInfo.seq, ctx.yield);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check deletedSeq, it can be nullopt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support deleted object in ledger_entry
3 participants