diff --git a/lib/covenants/namestate.js b/lib/covenants/namestate.js index a4318132a1..dca3be7628 100644 --- a/lib/covenants/namestate.js +++ b/lib/covenants/namestate.js @@ -209,7 +209,7 @@ class NameState extends bio.Struct { if (this.isClaimable(height, network)) return false; - // If we haven't been renewed in a year, start over. + // If we haven't been renewed in two years, start over. if (height >= this.renewal + network.names.renewalWindow) return true; @@ -654,6 +654,7 @@ class NameState extends bio.Struct { if (height != null) { network = Network.get(network); + state = this.state(height, network); state = statesByVal[state]; stats = this.toStats(height, network); @@ -740,6 +741,14 @@ class NameState extends bio.Struct { const stats = {}; + if (this.isExpired(height, network)) { + const expired = this.renewal + network.names.renewalWindow; + stats.blocksSinceExpired = height - expired; + + // Exit early + return stats; + } + if (this.isOpening(height, network)) { const start = this.height; const end = this.height + openPeriod; diff --git a/test/auction-test.js b/test/auction-test.js index b210aeeace..428f21ef8a 100644 --- a/test/auction-test.js +++ b/test/auction-test.js @@ -423,6 +423,19 @@ describe('Auction', function() { blocksUntilValidFinalize = stats.blocksUntilValidFinalize; }); + it('should not have any stats after expiration', async () => { + const ns = await chain.db.getNameStateByName(NAME1); + const start = ns.renewal; + const expiration = start + network.names.renewalWindow; + + // Test the namestate JSON without advancing the chain + let json = ns.getJSON(expiration - 1, network); + assert.strictEqual(json.stats.blocksUntilExpire, 1); + + json = ns.getJSON(expiration, network); + assert.strictEqual(json.stats.blocksSinceExpired, 0); + }); + it('should finalize at expected height', async () => { const mtx = await winner.createFinalize(NAME1);