Skip to content

Commit

Permalink
Merge pull request #296 from h4x3rotab/genesis
Browse files Browse the repository at this point in the history
Zawy's LWMA & testnet reset
  • Loading branch information
h4x3rotab committed Mar 13, 2018
2 parents 5cc156c + e803c16 commit 530ed7c
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 76 deletions.
6 changes: 3 additions & 3 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
* Maximum amount of time that a block timestamp is allowed to exceed the
* current network-adjusted time before the block will be accepted.
*/
static const int64_t MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60;
static const int64_t BITCOIN_MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60;

/**
* Timestamp window used as a grace period by code that compares external
* timestamps (such as timestamps passed to RPCs, or wallet key creation times)
* to block timestamps. This should be set at least as high as
* MAX_FUTURE_BLOCK_TIME.
* BITCOIN_MAX_FUTURE_BLOCK_TIME.
*/
static const int64_t TIMESTAMP_WINDOW = MAX_FUTURE_BLOCK_TIME;
static const int64_t TIMESTAMP_WINDOW = BITCOIN_MAX_FUTURE_BLOCK_TIME;

class CBlockFileInfo
{
Expand Down
93 changes: 53 additions & 40 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "base58.h"
#include <assert.h>
#include <boost/assign/list_of.hpp>
#include <limits>

#include "chainparamsseeds.h"

Expand All @@ -46,6 +47,7 @@ static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesi
genesis.hashPrevBlock.SetNull();
genesis.nHeight = 0;
genesis.hashMerkleRoot = BlockMerkleRoot(genesis);

return genesis;
}

Expand Down Expand Up @@ -98,18 +100,22 @@ class CMainParams : public CChainParams {
consensus.BIP66Height = 363725; // 00000000000000000379eaa19dce8c9b722d46ae6a57c2f1a988119488b50931
consensus.BTGHeight = 491407; // Around 10/25/2017 12:00 UTC
consensus.BTGPremineWindow = 8000;
consensus.BTGZawyLWMAHeight = std::numeric_limits<int>::max(); // Not activated on mainnet
consensus.BTGPremineEnforceWhitelist = true;
consensus.powLimit = uint256S("0007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.powLimitStart = uint256S("0000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.powLimitLegacy = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");

consensus.nDigishieldAveragingWindow = 30;
assert(maxUint/UintToArith256(consensus.powLimit) >= consensus.nDigishieldAveragingWindow);
consensus.nDigishieldMaxAdjustDown = 32;
consensus.nDigishieldMaxAdjustUp = 16;

consensus.nZawyLwmaAveragingWindow = 45;
consensus.nZawyLwmaAjustedWeight = 13632;
consensus.BTGMaxFutureBlockTime = 12 * 10 * 60; // 120 mins

//based on https://github.com/BTCGPU/BTCGPU/issues/78
consensus.nPowAveragingWindow = 30;
assert(maxUint/UintToArith256(consensus.powLimit) >= consensus.nPowAveragingWindow);
consensus.nPowMaxAdjustDown = 32;
consensus.nPowMaxAdjustUp = 16;

consensus.nPowTargetTimespanLegacy = 14 * 24 * 60 * 60;; // 10 minutes
consensus.nPowTargetTimespanLegacy = 14 * 24 * 60 * 60; // 10 minutes
consensus.nPowTargetSpacing = 10 * 60;
consensus.fPowAllowMinDifficultyBlocks = false;
consensus.fPowNoRetargeting = false;
Expand Down Expand Up @@ -219,22 +225,26 @@ class CTestNetParams : public CChainParams {
CTestNetParams() {
strNetworkID = "test";
consensus.nSubsidyHalvingInterval = 210000;
consensus.BIP34Height = 21111;
consensus.BIP34Hash = uint256S("0x0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8");
consensus.BIP65Height = 581885; // 00000000007f6655f22f98e72ed80d8b06dc761d5da09df0fa1dc4be4f861eb6
consensus.BIP66Height = 330776; // 000000002104c8c45e99a8853285a3b592602a3ccde2b832481da85e9e4ba182
consensus.BTGHeight = 1210320;
consensus.BIP34Height = -1;
consensus.BIP34Hash = uint256();
consensus.BIP65Height = -1;
consensus.BIP66Height = -1;
consensus.BTGHeight = 1;
consensus.BTGZawyLWMAHeight = -1; // Activated on testnet
consensus.BTGPremineWindow = 50;
consensus.BTGPremineEnforceWhitelist = false;
consensus.powLimit = uint256S("0007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.powLimitStart = uint256S("0000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.powLimitStart = uint256S("0007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.powLimitLegacy = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");

//based on https://github.com/BTCGPU/BTCGPU/issues/78
consensus.nPowAveragingWindow = 30;
assert(maxUint/UintToArith256(consensus.powLimit) >= consensus.nPowAveragingWindow);
consensus.nPowMaxAdjustDown = 32;
consensus.nPowMaxAdjustUp = 16;
consensus.nDigishieldAveragingWindow = 30;
assert(maxUint/UintToArith256(consensus.powLimit) >= consensus.nDigishieldAveragingWindow);
consensus.nDigishieldMaxAdjustDown = 32;
consensus.nDigishieldMaxAdjustUp = 16;

consensus.nZawyLwmaAveragingWindow = 45;
consensus.nZawyLwmaAjustedWeight = 13632;
consensus.BTGMaxFutureBlockTime = 7 * 10 * 60; // 70 mins

consensus.nPowTargetTimespanLegacy = 14 * 24 * 60 * 60; // two weeks
consensus.nPowTargetSpacing = 10 * 60;
Expand All @@ -248,44 +258,42 @@ class CTestNetParams : public CChainParams {

// Deployment of BIP68, BIP112, and BIP113.
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 1456790400; // March 1st, 2016
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = 1493596800; // May 1st, 2017
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 1514764800; // January 1st, 2018
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = 1546300800; // January 1st, 2019

// Deployment of SegWit (BIP141, BIP143, and BIP147)
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1462060800; // May 1st 2016
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1493596800; // May 1st 2017
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1514764800; // January 1st 2018
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1546300800; // January 1st 2019

// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000002830dab7f76dbb7d63");
consensus.nMinimumChainWork = uint256S("0x00");

// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0x0000000002e9e7b00e1f6dc5123a04aad68dd0f0968d8c7aa45f6640795c37b1"); //1135275
consensus.defaultAssumeValid = uint256S("0x00");

pchMessageStart[0] = 0xe1;
pchMessageStart[0] = 0xe2;
pchMessageStart[1] = 0x48;
pchMessageStart[2] = 0x6e;
pchMessageStart[3] = 0x45;
nDefaultPort = 18338;
nPruneAfterHeight = 1000;
const size_t N = 200, K = 9; // Same as mainchain.
const size_t N = 200, K = 9; // Same as mainnet.
BOOST_STATIC_ASSERT(equihash_parameters_acceptable(N, K));
nEquihashN = N;
nEquihashK = K;

genesis = CreateGenesisBlock(1296688602, 414098458, 0x1d00ffff, 1, 50 * COIN);
genesis = CreateGenesisBlock(1516123516, 0x56bd5142, 0x1d00ffff, 1, 50 * COIN);
consensus.hashGenesisBlock = genesis.GetHash(consensus);
assert(consensus.hashGenesisBlock == uint256S("0x000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"));
assert(consensus.hashGenesisBlock == uint256S("0x00000000e0781ebe24b91eedc293adfea2f557b53ec379e78959de3853e6f9f6"));
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));

vFixedSeeds.clear();
vSeeds.clear();
// nodes with support for servicebits filtering should be at the top

vSeeds.emplace_back("eu-test-dnsseed.bitcoingold-official.org", true);
vSeeds.emplace_back("test-dnsseed.bitcoingold.org", true);
vSeeds.emplace_back("test-dnsseed.btcgpu.org", true);
vSeeds.emplace_back("btg.dnsseed.minertopia.org", true);

base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
Expand All @@ -302,15 +310,14 @@ class CTestNetParams : public CChainParams {

checkpointData = (CCheckpointData) {
{
{546, uint256S("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70")},
{0, uint256S("0x00000000e0781ebe24b91eedc293adfea2f557b53ec379e78959de3853e6f9f6")},
}
};

chainTxData = ChainTxData{
// Data as of block 00000000000001c200b9790dc637d3bb141fe77d155b966ed775b17e109f7c6c (height 1156179)
1501802953,
14706531,
0.15
0,
0,
0
};
}
};
Expand All @@ -327,16 +334,22 @@ class CRegTestParams : public CChainParams {
consensus.BIP34Hash = uint256();
consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in rpc activation tests)
consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in rpc activation tests)
consensus.BTGHeight = 3000;
consensus.BTGHeight = 2000;
consensus.BTGZawyLWMAHeight = -1; // Activated on regtest
consensus.BTGPremineWindow = 10;
consensus.BTGPremineEnforceWhitelist = false;
consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.powLimitStart = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.powLimitLegacy = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
//based on https://github.com/BTCGPU/BTCGPU/issues/78
consensus.nPowAveragingWindow = 30;
consensus.nPowMaxAdjustDown = 16;
consensus.nPowMaxAdjustUp = 32;

consensus.nDigishieldAveragingWindow = 30;
consensus.nDigishieldMaxAdjustDown = 32;
consensus.nDigishieldMaxAdjustUp = 16;

consensus.nZawyLwmaAveragingWindow = 45;
consensus.nZawyLwmaAjustedWeight = 13632;
consensus.BTGMaxFutureBlockTime = 7 * 10 * 60; // 70 mins

consensus.nPowTargetTimespanLegacy = 14 * 24 * 60 * 60; // two weeks
consensus.nPowTargetSpacing = 10 * 60;
consensus.fPowAllowMinDifficultyBlocks = true;
Expand Down
28 changes: 20 additions & 8 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ struct Params {
int BIP66Height;
/** Block height at which Bitcoin GPU hard fork becomes active */
int BTGHeight;
/** Block height at which Zawy's LWMA difficulty algorithm becomes active */
int BTGZawyLWMAHeight;
/** Limit BITCOIN_MAX_FUTURE_BLOCK_TIME **/
int64_t BTGMaxFutureBlockTime;
/** Premining blocks for Bitcoin GPU hard fork **/
int BTGPremineWindow;
bool BTGPremineEnforceWhitelist;
Expand All @@ -73,14 +77,22 @@ struct Params {
uint256 nMinimumChainWork;
uint256 defaultAssumeValid;

//Zcash logic for diff adjustment
int64_t nPowAveragingWindow;
int64_t nPowMaxAdjustDown;
int64_t nPowMaxAdjustUp;
int64_t AveragingWindowTimespan() const { return nPowAveragingWindow * nPowTargetSpacing; }
int64_t MinActualTimespan() const { return (AveragingWindowTimespan() * (100 - nPowMaxAdjustUp )) / 100; }
int64_t MaxActualTimespan() const { return (AveragingWindowTimespan() * (100 + nPowMaxAdjustDown)) / 100; }

// Params for Digishield difficulty adjustment algorithm. (Used by mainnet currently.)
int64_t nDigishieldAveragingWindow;
int64_t nDigishieldMaxAdjustDown;
int64_t nDigishieldMaxAdjustUp;
int64_t DigishieldAveragingWindowTimespan() const { return nDigishieldAveragingWindow * nPowTargetSpacing; }
int64_t DigishieldMinActualTimespan() const {
return (DigishieldAveragingWindowTimespan() * (100 - nDigishieldMaxAdjustUp)) / 100;
}
int64_t DigishieldMaxActualTimespan() const {
return (DigishieldAveragingWindowTimespan() * (100 + nDigishieldMaxAdjustDown)) / 100;
}

// Params for Zawy's LWMA difficulty adjustment algorithm. (Used by testnet and regtest)
int64_t nZawyLwmaAveragingWindow; // N
int64_t nZawyLwmaAjustedWeight; // k = (N+1)/2 * 0.9989^(500/N) * T


};
} // namespace Consensus
Expand Down
Loading

0 comments on commit 530ed7c

Please sign in to comment.