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(api): consider expiration return addresses for ledger updates #1314

Merged
merged 17 commits into from
Jan 24, 2024

Conversation

DaughterOfMars
Copy link
Collaborator

@DaughterOfMars DaughterOfMars commented Jan 9, 2024

This PR changes how the owning address is calculated for spent outputs. Rather than assume the address unlock condition for basic/NFT outputs, the spent timestamp is checked against the expiration unlock condition, if it exists. Therefore, in the case where the output was spent on or after the timestamp, we use the return address to index the output.

UPDATE: Rolled the changes for the balance endpoint in as well for simplicity. The endpoint now returns availableBalance instead of sigLockedBalance and the calculation has been adjusted to include outputs with timelock conditions that have become unlocked, as well as those with matching expiration return addresses that are expired.

Linked Issues

Notes to Reviewer

As a reviewer, please pay particular attention to the following areas when reviewing this PR and tick the above boxes after you have completed the steps.

API Changes

  • Test the ledger updates by address endpoint.

INX Changes

  • Run chronicle using an INX connection.

Database Changes

  • Review database queries for correctness/conciseness.
  • Review migration for correctness.

@DaughterOfMars DaughterOfMars linked an issue Jan 10, 2024 that may be closed by this pull request
@@ -142,13 +144,26 @@ pub enum Output {

impl Output {
/// Returns the [`Address`] that is in control of the output.
pub fn owning_address(&self) -> Option<&Address> {
pub fn owning_address(&self, spent_timestamp: impl Into<Option<MilestoneTimestamp>>) -> Option<&Address> {
Copy link
Collaborator

@Alex6323 Alex6323 Jan 15, 2024

Choose a reason for hiding this comment

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

Maybe I am misunderstanding something but isn't it the case that when the output is still unspent, but the latest milestone timestamp > expiration timestamp, then the owning address should already be the return address?

with the current logic the owner of an unspent output would still be the address in the address_unlock_condition despite we're passed the expiration.

so maybe this should just be a MilestoneTimestamp as the argument and if the output is already spent, then it would be the spent_timestamp like currently, but when the output is still unspent then this should be the latest milestone timestamp, and the logic could remain the same.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The problem is there's simply no good way for us to do this. We would have to update all unspent outputs every milestone, which is simply not performant. Spending proves definitively who the owner is, so we just update it then. Since this is only used in the explorer routes, this is fine. The only concern I have is with analytics, because we use it for active addresses, balance, and base token activity and those calculations may possibly be wrong now.

@DaughterOfMars
Copy link
Collaborator Author

https://chronicle-migr.stardust-mainnet.iotaledger.net/api/

This server can be used for testing the mainnet API before we commit to a migration.

@DaughterOfMars DaughterOfMars merged commit ca605a7 into main Jan 24, 2024
10 checks passed
@DaughterOfMars DaughterOfMars deleted the feat/owning-address branch January 24, 2024 14:13
@DaughterOfMars DaughterOfMars changed the title Consider expiration return addresses for ledger updates fix(api): consider expiration return addresses for ledger updates Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants