Add capability to extend expiration time of pre fork claims #137

Merged
kaykurokawa merged 2 commits from claim-expiration-fixes into master 2018-05-24 06:30:08 +02:00
kaykurokawa commented 2018-05-11 01:14:44 +02:00 (Migrated from github.com)

Details of hard fork for all:

The fork of the mainnet will be on block 400155 (will be around noon EST 7/9/18)

The fork of the testnet will be on block 280831 (will be around noon EST 5/21/18)

Claims made on and after the target hardfork blocks will expire after 2102400 blocks (approximately 10 years assuming block time 2.5 minutes).

Claims that were made before the hardfork and have not expired will have their expiration extended by the difference between the new expiration time and the previous expiration time (456 days).

Claims that already expired will remain expired.

Details for reviewers

This is further work off of : https://github.com/lbryio/lbrycrd/pull/115 in order to add the extension of claim expiration to already existing claims ( in #115 claims made before the hard fork would still expire at the old expiration time)

While working on this, I made two adjustments to #115. A) the first was that the new expiration time took effect 1 block after the target hard fork block, and not on the target hard fork block. It would be more intuitive if the new expiration time took effect on the target hard fork block. B) I fixed the logic of calling setExpirationTime() to only be called when we are at the target hard fork block, instead of on every block. This is more intuitive and in line with the soft-fork logic that is already present for Bitcoin. This means we need to also called setExpirationTime when we load the claimtrie from disk so I did that. The combination of A) and B) fixes a bug in #115 where if you loaded the claimtrie from disk (restarted lbrycrdd) than you expiration time for the first block after restart would be the old expiration time instead of the new one even after the hard fork.

The above work is on 2df3bb104b

While working on extending the expiration of existing claims, I realized that #110 had the problem where it would not properly be able to remove expirations from the expiration queue properly. This is because the function removeFromExpirationQueue() : https://github.com/lbryio/lbrycrd/blob/master/src/claimtrie.cpp#L1675 was not adjusted to consider the hard fork change in expiration time hence this line: https://github.com/lbryio/lbrycrd/blob/master/src/claimtrie.cpp#L1677 could calculate the wrong expiration time for a claim that was created before the hard fork an expires after the hard fork.

The way we extend the claim is fairly straight forward. When we encounter the hard fork block, we set the new expiration time, and we look at all the entries in the expiration queue either in the dirty queue (where entries that are not saved to disk resides) or the disk database. The entries are adjusted to have their expiration time extended by the difference between the new expiration time and the old expiration time. Effectively, this makes it look like all the claims share the same new expiration time so the issue I described is solved.

The above work on extending the expiraiton of existing claims is on
b3aa62c

For the unit tests, I added a series of tests to see if supports behaved properly, and also added tests to see if the claimtrie behaved properly on the hard fork if I simulated a restart (write claimtrie to disk, clear it in memory, and than read it from disk). 6621f50b98

The other commits should be straight forward.

**Details of hard fork for all:** The fork of the mainnet will be on block 400155 (will be around noon EST 7/9/18) The fork of the testnet will be on block 280831 (will be around noon EST 5/21/18) Claims made on and after the target hardfork blocks will expire after 2102400 blocks (approximately 10 years assuming block time 2.5 minutes). Claims that were made before the hardfork and have not expired will have their expiration extended by the difference between the new expiration time and the previous expiration time (456 days). Claims that already expired will remain expired. **Details for reviewers** This is further work off of : https://github.com/lbryio/lbrycrd/pull/115 in order to add the extension of claim expiration to already existing claims ( in #115 claims made before the hard fork would still expire at the old expiration time) While working on this, I made two adjustments to #115. A) the first was that the new expiration time took effect 1 block after the target hard fork block, and not on the target hard fork block. It would be more intuitive if the new expiration time took effect on the target hard fork block. B) I fixed the logic of calling setExpirationTime() to only be called when we are at the target hard fork block, instead of on every block. This is more intuitive and in line with the soft-fork logic that is already present for Bitcoin. This means we need to also called setExpirationTime when we load the claimtrie from disk so I did that. The combination of A) and B) fixes a bug in #115 where if you loaded the claimtrie from disk (restarted lbrycrdd) than you expiration time for the first block after restart would be the old expiration time instead of the new one even after the hard fork. The above work is on https://github.com/lbryio/lbrycrd/pull/137/commits/2df3bb104b29f5f1cd0615efbe33ab46bc1aca53 While working on extending the expiration of existing claims, I realized that #110 had the problem where it would not properly be able to remove expirations from the expiration queue properly. This is because the function removeFromExpirationQueue() : https://github.com/lbryio/lbrycrd/blob/master/src/claimtrie.cpp#L1675 was not adjusted to consider the hard fork change in expiration time hence this line: https://github.com/lbryio/lbrycrd/blob/master/src/claimtrie.cpp#L1677 could calculate the wrong expiration time for a claim that was created before the hard fork an expires after the hard fork. The way we extend the claim is fairly straight forward. When we encounter the hard fork block, we set the new expiration time, and we look at all the entries in the expiration queue either in the dirty queue (where entries that are not saved to disk resides) or the disk database. The entries are adjusted to have their expiration time extended by the difference between the new expiration time and the old expiration time. Effectively, this makes it look like all the claims share the same new expiration time so the issue I described is solved. The above work on extending the expiraiton of existing claims is on b3aa62c For the unit tests, I added a series of tests to see if supports behaved properly, and also added tests to see if the claimtrie behaved properly on the hard fork if I simulated a restart (write claimtrie to disk, clear it in memory, and than read it from disk). https://github.com/lbryio/lbrycrd/pull/137/commits/6621f50b985d49a5b5c4c09b32d871c58fa54121 The other commits should be straight forward.
lbrynaut (Migrated from github.com) reviewed 2018-05-15 19:34:44 +02:00
lbrynaut (Migrated from github.com) commented 2018-05-15 19:34:44 +02:00

Remove FIXME comment

Remove FIXME comment
lbrynaut (Migrated from github.com) reviewed 2018-05-15 19:34:54 +02:00
lbrynaut (Migrated from github.com) commented 2018-05-15 19:34:54 +02:00

Remove FIXME comment

Remove FIXME comment
lbrynaut (Migrated from github.com) reviewed 2018-05-15 19:37:16 +02:00
lbrynaut (Migrated from github.com) commented 2018-05-15 19:37:15 +02:00

expiration is spelled incorrectly in several places, maybe do a quick search for them?

expiration is spelled incorrectly in several places, maybe do a quick search for them?
lbrynaut (Migrated from github.com) reviewed 2018-05-15 19:39:51 +02:00
lbrynaut (Migrated from github.com) commented 2018-05-15 19:39:51 +02:00

I realize I initially used the view height, but we could replace with pindex->nHeight (in all places it's used in debug)

I realize I initially used the view height, but we could replace with pindex->nHeight (in all places it's used in debug)
lbrynaut (Migrated from github.com) reviewed 2018-05-15 19:41:02 +02:00
lbrynaut (Migrated from github.com) commented 2018-05-15 19:41:02 +02:00

What is v13 fork? Why not call it the claim expiration fork or something more intuitive?

What is v13 fork? Why not call it the claim expiration fork or something more intuitive?
lbrynaut (Migrated from github.com) reviewed 2018-05-15 19:41:28 +02:00
lbrynaut (Migrated from github.com) commented 2018-05-15 19:41:28 +02:00

?

?
lbrynaut (Migrated from github.com) reviewed 2018-05-15 19:41:55 +02:00
@ -164,7 +163,16 @@ struct ClaimTrieChainFixture{
unsigned int num_txs;
lbrynaut (Migrated from github.com) commented 2018-05-15 19:41:55 +02:00

Seems 1 line is enough?

Seems 1 line is enough?
lbrynaut (Migrated from github.com) reviewed 2018-05-15 19:42:34 +02:00
@ -300,6 +308,17 @@ struct ClaimTrieChainFixture{
num_txs_for_next_block = 0;
}
lbrynaut (Migrated from github.com) commented 2018-05-15 19:42:34 +02:00

s/reading it/reading/

s/reading it/reading/
lbrynaut (Migrated from github.com) reviewed 2018-05-15 19:43:26 +02:00
lbrynaut (Migrated from github.com) commented 2018-05-15 19:43:25 +02:00

This also doesn't do exactly what's in the comment since the Cache isn't modified/updated/rebuilt.

This also doesn't do exactly what's in the comment since the Cache isn't modified/updated/rebuilt.
lbrynaut (Migrated from github.com) approved these changes 2018-05-15 19:44:41 +02:00
kaykurokawa commented 2018-05-16 18:02:38 +02:00 (Migrated from github.com)

It was discovered that the testnet blocks haven't been progressing (mining was turned off) so I'll need to set a new fork height for the testnet.

It was discovered that the testnet blocks haven't been progressing (mining was turned off) so I'll need to set a new fork height for the testnet.
kaykurokawa (Migrated from github.com) reviewed 2018-05-16 21:27:09 +02:00
kaykurokawa (Migrated from github.com) commented 2018-05-16 21:27:09 +02:00

What do you mean here exactly ? You may have misssed where WriteToDisk clears out the cache entries https://github.com/lbryio/lbrycrd/blob/master/src/claimtrie.cpp#L1047 here

What do you mean here exactly ? You may have misssed where WriteToDisk clears out the cache entries https://github.com/lbryio/lbrycrd/blob/master/src/claimtrie.cpp#L1047 here
kaykurokawa commented 2018-05-16 21:28:31 +02:00 (Migrated from github.com)

made fixes as reviewed by lbrynaut

made fixes as reviewed by lbrynaut
lbrynaut (Migrated from github.com) reviewed 2018-05-16 21:45:14 +02:00
lbrynaut (Migrated from github.com) commented 2018-05-16 21:45:14 +02:00

I was referring to the state of the TrieCache.

I was referring to the state of the TrieCache.
lbrynaut (Migrated from github.com) approved these changes 2018-05-16 22:28:02 +02:00
shyba (Migrated from github.com) approved these changes 2018-05-17 19:29:40 +02:00
@ -2174,1 +2174,4 @@
std::string name(vvchParams[0].begin(), vvchParams[0].end());
std::string value(vvchParams[1].begin(), vvchParams[1].end());
claimId = ClaimIdHash(hash, i);
LogPrintf("--- %s[%lu]: OP_CLAIM_NAME \"%s\" = \"%s\" with claimId %s and tx prevout %s at index %d\n",
shyba (Migrated from github.com) commented 2018-05-17 19:16:20 +02:00

maybe log this only if in debug mode? otherwise getnameproof can become verbose as it currently disconnects and reconnects blocks for generating previous block proofs.

maybe log this only if in debug mode? otherwise `getnameproof` can become verbose as it currently disconnects and reconnects blocks for generating previous block proofs.
shyba (Migrated from github.com) commented 2018-05-17 19:25:06 +02:00

s/expiraiton/expiration/

s/expiraiton/expiration/
@ -847,0 +898,4 @@
fixture.DecrementBlocks(1);
BOOST_CHECK_EQUAL(pclaimTrie->nExpirationTime, fixture.originalExpiration);
fixture.IncrementBlocks(1);
shyba (Migrated from github.com) commented 2018-05-17 19:25:21 +02:00

s/expiraiton/expiration/

s/expiraiton/expiration/
shyba (Migrated from github.com) reviewed 2018-05-17 19:30:51 +02:00
shyba (Migrated from github.com) commented 2018-05-17 19:30:51 +02:00

oh, I see @lbrynaut already found that, sorry for the flood.

oh, I see @lbrynaut already found that, sorry for the flood.
kaykurokawa (Migrated from github.com) reviewed 2018-05-22 03:42:55 +02:00
@ -2174,1 +2174,4 @@
std::string name(vvchParams[0].begin(), vvchParams[0].end());
std::string value(vvchParams[1].begin(), vvchParams[1].end());
claimId = ClaimIdHash(hash, i);
LogPrintf("--- %s[%lu]: OP_CLAIM_NAME \"%s\" = \"%s\" with claimId %s and tx prevout %s at index %d\n",
kaykurokawa (Migrated from github.com) commented 2018-05-22 03:42:55 +02:00

is there a debugging log?

is there a debugging log?
kaykurokawa (Migrated from github.com) reviewed 2018-05-22 03:43:03 +02:00
@ -847,0 +898,4 @@
fixture.DecrementBlocks(1);
BOOST_CHECK_EQUAL(pclaimTrie->nExpirationTime, fixture.originalExpiration);
fixture.IncrementBlocks(1);
kaykurokawa (Migrated from github.com) commented 2018-05-22 03:43:02 +02:00

fixed

fixed
kaykurokawa commented 2018-05-22 03:46:01 +02:00 (Migrated from github.com)

Made fix as suggested by syba,
Adjusted fork height on testnet to 278160 (in about an hour from now) , and I will run this on testnet.
Maybe for debug logging comment by shyba, we can do another PR to perhaps improve/clean up different log messages?

Made fix as suggested by syba, Adjusted fork height on testnet to 278160 (in about an hour from now) , and I will run this on testnet. Maybe for debug logging comment by shyba, we can do another PR to perhaps improve/clean up different log messages?
shyba commented 2018-05-23 05:54:26 +02:00 (Migrated from github.com)

@kaykurokawa yes, I agree. Created an issue for logging here.

@kaykurokawa yes, I agree. Created an [issue for logging here](https://github.com/lbryio/lbrycrd/issues/144).
kaykurokawa commented 2018-05-23 21:07:46 +02:00 (Migrated from github.com)

Rebased to two commits, rebased to master

Rebased to two commits, rebased to master
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: LBRYCommunity/lbrycrd#137
No description provided.