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

namestate: improve "stats" object for transfers, expiry and revoke #555

Merged
merged 4 commits into from Sep 28, 2023

Conversation

pinheadmz
Copy link
Member

@pinheadmz pinheadmz commented Feb 9, 2021

Adds an expired state to the "stats" object, refactors the toStats() method in namestate.js.

    "stats": {
      "blocksSinceExpired": 21
    }

@coveralls
Copy link

coveralls commented Feb 9, 2021

Coverage Status

coverage: 68.637% (+0.01%) from 68.623% when pulling 7da5443 on pinheadmz:expired1 into 4e87fb1 on handshake-org:master.

@pinheadmz pinheadmz added this to the v2.4.0 milestone Mar 13, 2021
@pinheadmz pinheadmz marked this pull request as ready for review March 25, 2021 18:46
lib/covenants/namestate.js Outdated Show resolved Hide resolved
lib/covenants/namestate.js Show resolved Hide resolved
@pinheadmz

This comment has been minimized.

@pinheadmz pinheadmz force-pushed the expired1 branch 2 times, most recently from e9627fd to b7a50a0 Compare May 25, 2021 20:14
@pinheadmz pinheadmz changed the title namestate: check for expiration when returning JSON namestate: improve "stats" object for transfers, expiry and revoke May 25, 2021
lib/covenants/namestate.js Outdated Show resolved Hide resolved
Copy link
Contributor

@nodech nodech left a comment

Choose a reason for hiding this comment

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

Is it okay to have negative numbers in blocksUntilExpire ? (Maybe have better alias if we want to keep this for backwards compatibility reasons)

test/namestate-test.js Outdated Show resolved Hide resolved
test/namestate-test.js Show resolved Hide resolved
test/namestate-test.js Outdated Show resolved Hide resolved
@pinheadmz
Copy link
Member Author

@nodech you're right on about negative blocksUntilExpire, I had a bug given that claimed names don't expire until the 4-year claim period is over. That is fixed in f82f783

@nodech nodech added covenants part of the codebase enhancement general - improving existing feature tests part of the codebase breaking-minor Backwards compatible - Release version labels Dec 2, 2021
@pinheadmz
Copy link
Member Author

I just realized hsd has never reported expiration date correctly for reserved names. A reserved name does not expire until AFTER the reserved name period if over (four years). The logic can be seen in namestate.isExpired():

// Can only renew once we reach the closed state.
if (!this.isClosed(height, network))
return false;
// Claimed names can only expire once the claim period is over.
if (this.isClaimable(height, network))
return false;
// If we haven't been renewed in a year, start over.
if (height >= this.renewal + network.names.renewalWindow)
return true;

(note the typo in the comment, line 212 should say "two years")

However, this API tells me that the reserved name torrentfreak will expire in less than two months:

# hsd-rpc getnameinfo torrentfreak
{
  "start": {
    "reserved": true,
    "week": 17,
    "start": 19152
  },
  "info": {
    "name": "torrentfreak",
    "nameHash": "ea821088b72047a89e1defa25f91194760493a6c2070a289fa8c9a73c6428861",
    "state": "CLOSED",
    "height": 5670,
    "renewal": 15104,
    "owner": {
      "hash": "b2e9a0a48438ca58050a8b77cb1ebb6d8c1767c2de24135b33431501f46f3863",
      "index": 0
    },
    "value": 0,
    "highest": 0,
    "data": "0001036e733103646e73046c6976650001036e7332c00601036e7333c00606011a723d68747470733a2f2f746f7272656e74667265616b2e636f6d0601316e61636c3d527774776f3750472b736b6233356d6c6d6f7a32756356457677355063304b495855434a594d5a6833766b3d",
    "transfer": 0,
    "revoked": 0,
    "claimed": 1,
    "renewals": 0,
    "registered": true,
    "expired": false,
    "weak": true,
    "stats": {
      "renewalPeriodStart": 15104,
      "renewalPeriodEnd": 120224,
      "blocksUntilExpire": 8057,
      "daysUntilExpire": 55.95
    }
  }
}

@nodech
Copy link
Contributor

nodech commented Sep 26, 2023

Fixed expire date as it needs to be: Max(claimPeriodEnd, normal end). If claimed name has been transferred or renewed, it wont expire on claim period end, instead when it should normally expire. But if it has not been transfer/renewed then it will expire on claimPeriod end.

@nodech nodech merged commit 7fe7ce4 into handshake-org:master Sep 28, 2023
6 checks passed
@nodech nodech deleted the expired1 branch October 2, 2023 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-minor Backwards compatible - Release version covenants part of the codebase enhancement general - improving existing feature tests part of the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants