Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #4025 - bitcartel:shorter_block_target_interval_zip208,…
… r=<try> Implement ZIP 208: Shorter Block Target Spacing Closes #3690.
- Loading branch information
Showing
41 changed files
with
813 additions
and
429 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env python | ||
# Copyright (c) 2019 The Zcash developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or https://www.opensource.org/licenses/mit-license.php . | ||
|
||
import sys; assert sys.version_info < (3,), ur"This script does not run under Python 3. Please use Python 2.7.x." | ||
|
||
from decimal import Decimal | ||
from test_framework.test_framework import BitcoinTestFramework | ||
from test_framework.util import ( | ||
assert_equal, | ||
get_coinbase_address, | ||
initialize_chain_clean, | ||
start_nodes, | ||
wait_and_assert_operationid_status, | ||
) | ||
|
||
|
||
class ShorterBlockTimes(BitcoinTestFramework): | ||
def setup_nodes(self): | ||
return start_nodes(4, self.options.tmpdir, [[ | ||
'-nuparams=5ba81b19:0', # Overwinter | ||
'-nuparams=76b809bb:0', # Sapling | ||
'-nuparams=2bb40e60:106', # Blossom | ||
]] * 4) | ||
|
||
def setup_chain(self): | ||
print("Initializing test directory " + self.options.tmpdir) | ||
initialize_chain_clean(self.options.tmpdir, 4) | ||
|
||
def run_test(self): | ||
print "Mining blocks..." | ||
self.nodes[0].generate(101) | ||
self.sync_all() | ||
|
||
# Sanity-check the block height | ||
assert_equal(self.nodes[0].getblockcount(), 101) | ||
|
||
node0_taddr = get_coinbase_address(self.nodes[0]) | ||
node0_zaddr = self.nodes[0].z_getnewaddress('sapling') | ||
recipients = [{'address': node0_zaddr, 'amount': Decimal('10')}] | ||
myopid = self.nodes[0].z_sendmany(node0_taddr, recipients, 1, Decimal('0')) | ||
txid = wait_and_assert_operationid_status(self.nodes[0], myopid) | ||
assert_equal(105, self.nodes[0].getrawtransaction(txid, 1)['expiryheight']) # Blossom activation - 1 | ||
self.sync_all() | ||
self.nodes[0].generate(1) | ||
self.sync_all() | ||
assert_equal(10, Decimal(self.nodes[0].z_gettotalbalance()['private'])) | ||
|
||
self.nodes[0].generate(2) | ||
self.sync_all() | ||
print "Mining last pre-Blossom blocks" | ||
# Activate blossom | ||
self.nodes[1].generate(1) | ||
self.sync_all() | ||
# Check that we received a pre-Blossom mining reward | ||
assert_equal(10, Decimal(self.nodes[1].getwalletinfo()['immature_balance'])) | ||
|
||
# After blossom activation the block reward will be halved | ||
print "Mining first Blossom block" | ||
self.nodes[1].generate(1) | ||
self.sync_all() | ||
# Check that we received an additional Blossom mining reward | ||
assert_equal(15, self.nodes[1].getwalletinfo()['immature_balance']) | ||
|
||
# Send and mine a transaction after activation | ||
myopid = self.nodes[0].z_sendmany(node0_taddr, recipients, 1, Decimal('0')) | ||
txid = wait_and_assert_operationid_status(self.nodes[0], myopid) | ||
assert_equal(147, self.nodes[0].getrawtransaction(txid, 1)['expiryheight']) # height + 1 + 40 | ||
self.nodes[1].generate(1) | ||
self.sync_all() | ||
assert_equal(20, Decimal(self.nodes[0].z_gettotalbalance()['private'])) | ||
|
||
|
||
if __name__ == '__main__': | ||
ShorterBlockTimes().main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) 2019 The Zcash developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or https://www.opensource.org/licenses/mit-license.php . | ||
|
||
#include "params.h" | ||
|
||
#include "upgrades.h" | ||
|
||
namespace Consensus { | ||
bool Params::NetworkUpgradeActive(int nHeight, Consensus::UpgradeIndex idx) const { | ||
return NetworkUpgradeState(nHeight, *this, idx) == UPGRADE_ACTIVE; | ||
} | ||
|
||
int Params::Halving(int nHeight) const { | ||
// zip208 | ||
// Halving(height) := | ||
// floor((height - SlowStartShift) / PreBlossomHalvingInterval), if not IsBlossomActivated(height) | ||
// floor((BlossomActivationHeight - SlowStartShift) / PreBlossomHalvingInterval + (height - BlossomActivationHeight) / PostBlossomHalvingInterval), otherwise | ||
if (NetworkUpgradeActive(nHeight, Consensus::UPGRADE_BLOSSOM)) { | ||
int64_t blossomActivationHeight = vUpgrades[Consensus::UPGRADE_BLOSSOM].nActivationHeight; | ||
// Ideally we would say: | ||
// halvings = (blossomActivationHeight - consensusParams.SubsidySlowStartShift()) / consensusParams.nPreBlossomSubsidyHalvingInterval | ||
// + (nHeight - blossomActivationHeight) / consensusParams.nPostBlossomSubsidyHalvingInterval; | ||
// But, (blossomActivationHeight - consensusParams.SubsidySlowStartShift()) / consensusParams.nPreBlossomSubsidyHalvingInterval | ||
// would need to be treated as a rational number in order for this to work. | ||
// Define scaledHalvings := halvings * consensusParams.nPostBlossomSubsidyHalvingInterval; | ||
int64_t scaledHalvings = ((blossomActivationHeight - SubsidySlowStartShift()) * Consensus::BLOSSOM_POW_TARGET_SPACING_RATIO) | ||
+ (nHeight - blossomActivationHeight); | ||
return (int) (scaledHalvings / nPostBlossomSubsidyHalvingInterval); | ||
} else { | ||
return (nHeight - SubsidySlowStartShift()) / nPreBlossomSubsidyHalvingInterval; | ||
} | ||
} | ||
|
||
int Params::GetLastFoundersRewardBlockHeight(int nHeight) const { | ||
// zip208 | ||
// FoundersRewardLastBlockHeight := max({ height ⦂ N | Halving(height) < 1 }) | ||
// Halving(h) is defined as floor(f(h)) where f is a strictly increasing rational | ||
// function, so it's sufficient to solve for f(height) = 1 in the rationals and | ||
// then take ceiling(height - 1). | ||
// H := blossom activation height; SS := SubsidySlowStartShift(); R := BLOSSOM_POW_TARGET_SPACING_RATIO | ||
// preBlossom: | ||
// 1 = (height - SS) / preInterval | ||
// height = preInterval + SS | ||
// postBlossom: | ||
// 1 = (H - SS) / preInterval + (height - H) / postInterval | ||
// height = H + postInterval - (H - SS) * (postInterval / preInterval) | ||
// height = H + postInterval - (H - SS) * R | ||
// Note: This depends on R being an integer | ||
bool blossomActive = NetworkUpgradeActive(nHeight, Consensus::UPGRADE_BLOSSOM); | ||
if (blossomActive) { | ||
int blossomActivationHeight = vUpgrades[Consensus::UPGRADE_BLOSSOM].nActivationHeight; | ||
// The following calculation depends on BLOSSOM_POW_TARGET_SPACING_RATIO being an integer. | ||
return blossomActivationHeight + nPostBlossomSubsidyHalvingInterval | ||
- (blossomActivationHeight - SubsidySlowStartShift()) * BLOSSOM_POW_TARGET_SPACING_RATIO - 1; | ||
} else { | ||
return nPreBlossomSubsidyHalvingInterval + SubsidySlowStartShift() - 1; | ||
} | ||
} | ||
|
||
int64_t Params::PoWTargetSpacing(int nHeight) const { | ||
// zip208 | ||
// PoWTargetSpacing(height) := | ||
// PreBlossomPoWTargetSpacing, if not IsBlossomActivated(height) | ||
// PostBlossomPoWTargetSpacing, otherwise. | ||
bool blossomActive = NetworkUpgradeActive(nHeight, Consensus::UPGRADE_BLOSSOM); | ||
return blossomActive ? nPostBlossomPowTargetSpacing : nPreBlossomPowTargetSpacing; | ||
} | ||
|
||
int64_t Params::AveragingWindowTimespan(int nHeight) const { | ||
return nPowAveragingWindow * PoWTargetSpacing(nHeight); | ||
} | ||
|
||
int64_t Params::MinActualTimespan(int nHeight) const { | ||
return (AveragingWindowTimespan(nHeight) * (100 - nPowMaxAdjustUp)) / 100; | ||
} | ||
|
||
int64_t Params::MaxActualTimespan(int nHeight) const { | ||
return (AveragingWindowTimespan(nHeight) * (100 + nPowMaxAdjustDown)) / 100; | ||
} | ||
} |
Oops, something went wrong.