Skip to content

Commit

Permalink
Add new arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenroose committed Mar 20, 2019
1 parent fde9fe1 commit 484d83c
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <chainparamsseeds.h>
#include <consensus/merkle.h>
#include <issuance.h>
#include <primitives/transaction.h>
#include <tinyformat.h>
#include <util.h>
Expand Down Expand Up @@ -144,11 +145,14 @@ class CMainParams : public CChainParams {

consensus.genesis_subsidy = 50*COIN;
consensus.connect_genesis_outputs = false;
consensus.subsidy_asset = CAsset();
anyonecanspend_aremine = false;
enforce_pak = false;
multi_data_permitted = false;
consensus.has_parent_chain = false;
g_signed_blocks = false;
g_con_elementswitness = false;
g_con_blockheightinheader = false;

/**
* The message start string is designed to be unlikely to occur in normal data.
Expand Down Expand Up @@ -267,10 +271,14 @@ class CTestNetParams : public CChainParams {

consensus.genesis_subsidy = 50*COIN;
consensus.connect_genesis_outputs = false;
consensus.subsidy_asset = CAsset();
anyonecanspend_aremine = false;
enforce_pak = false;
multi_data_permitted = false;
consensus.has_parent_chain = false;
g_signed_blocks = false;
g_con_elementswitness = false;
g_con_blockheightinheader = false;

pchMessageStart[0] = 0x0b;
pchMessageStart[1] = 0x11;
Expand Down Expand Up @@ -364,10 +372,14 @@ class CRegTestParams : public CChainParams {

consensus.genesis_subsidy = 50*COIN;
consensus.connect_genesis_outputs = false;
consensus.subsidy_asset = CAsset();
anyonecanspend_aremine = false;
enforce_pak = false;
multi_data_permitted = false;
consensus.has_parent_chain = false;
g_signed_blocks = false;
g_con_elementswitness = false;
g_con_blockheightinheader = false;

pchMessageStart[0] = 0xfa;
pchMessageStart[1] = 0xbf;
Expand Down Expand Up @@ -573,6 +585,27 @@ class CCustomParams : public CRegTestParams {

base58Prefixes[BLINDED_ADDRESS] = std::vector<unsigned char>(1, args.GetArg("-blindedprefix", 4));

// Calculate pegged Bitcoin asset
std::vector<unsigned char> commit = CommitToArguments(consensus, strNetworkID);
uint256 entropy;
GenerateAssetEntropy(entropy, COutPoint(uint256(commit), 0), parentGenesisBlockHash);

// Elements serialization uses derivation, bitcoin serialization uses 0x00
if (g_con_elementswitness) {
CalculateAsset(consensus.pegged_asset, entropy);
} else {
assert(consensus.pegged_asset == CAsset());
}

consensus.parent_pegged_asset.SetHex(args.GetArg("-con_parent_pegged_asset", "0x00"));
initial_reissuance_tokens = args.GetArg("-initialreissuancetokens", 0);

// Subsidy asset, like policyAsset, defaults to the pegged_asset
consensus.subsidy_asset = consensus.pegged_asset;
if (gArgs.IsArgSet("-subsidyasset")) {
consensus.subsidy_asset = CAsset(uint256S(gArgs.GetArg("-subsidyasset", "0x00")));
}

// END ELEMENTS fields

// CSV always active by default, unlike regtest
Expand Down
1 change: 1 addition & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class CChainParams
std::string strNetworkID;
CBlock genesis;
CAmount initialFreeCoins;
CAmount initial_reissuance_tokens;
std::vector<SeedSpec6> vFixedSeeds;
bool fDefaultConsistencyChecks;
bool fRequireStandard;
Expand Down
4 changes: 4 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#ifndef BITCOIN_CONSENSUS_PARAMS_H
#define BITCOIN_CONSENSUS_PARAMS_H

#include <asset.h>
#include <uint256.h>
#include <limits>
#include <map>
Expand Down Expand Up @@ -83,13 +84,16 @@ struct Params {
// ELEMENTS CHAIN PARAMS
CScript mandatory_coinbase_destination;
CAmount genesis_subsidy;
CAsset subsidy_asset;
bool connect_genesis_outputs;
bool has_parent_chain;
uint256 parentChainPowLimit;
uint32_t pegin_min_depth;
CScript parent_chain_signblockscript;
bool ParentChainHasPow() const { return parent_chain_signblockscript == CScript();}
CScript fedpegScript;
CAsset pegged_asset;
CAsset parent_pegged_asset;
// g_con_blockheightinheader global hack instead of proper arg due to circular dep
std::string genesis_style;
CScript signblockscript;
Expand Down
27 changes: 26 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@

#include <primitives/pak.h> // CPAKList
#include <assetsdir.h> // InitGlobalAssetDir
#include <pegins.h>

#if ENABLE_ZMQ
#include <zmq/zmqnotificationinterface.h>
Expand Down Expand Up @@ -512,6 +513,7 @@ void SetupServerArgs()
gArgs.AddArg("-blech32_hrp", strprintf("The human-readable part of the chain's blech32 encoding. Used in confidential addresses.(default: %s)", defaultChainParams->Blech32HRP()), false, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-assetdir", "Entries of pet names of assets, in this format:asset=<hex>:<label>. There can be any number of entries.", false, OptionsCategory::ELEMENTS);
gArgs.AddArg("-defaultpeggedassetname", "Default name of the pegged asset. (default: bitcoin)", false, OptionsCategory::ELEMENTS);
gArgs.AddArg("-blindedaddresses", "Give blind addresses by default via getnewaddress and getrawchangeaddress. (default: -con_elementswitness value)", false, OptionsCategory::ELEMENTS);

#if HAVE_DECL_DAEMON
gArgs.AddArg("-daemon", "Run in the background as a daemon and accept commands", false, OptionsCategory::OPTIONS);
Expand Down Expand Up @@ -539,6 +541,12 @@ void SetupServerArgs()
gArgs.AddArg("-parentscriptprefix", strprintf("The byte prefix, in decimal, of the parent chain's base58 script address. (default: %d)", 196), false, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-parent_bech32_hrp", strprintf("The human-readable part of the parent chain's bech32 encoding. (default: %s)", "bc"), false, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-parent_blech32_hrp", strprintf("The human-readable part of the parent chain's blech32 encoding. (default: %s)", "bc"), false, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-con_parent_pegged_asset=<hex>", "Asset ID (hex) for pegged asset for when parent chain has CA. (default: 0x00)", false, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-feeasset=<hex>", strprintf("Asset ID (hex) for mempool/relay fees (default: %s)", defaultChainParams->GetConsensus().pegged_asset.GetHex()), false, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-subsidyasset=<hex>", strprintf("Asset ID (hex) for the block subsidy (default: %s)", defaultChainParams->GetConsensus().pegged_asset.GetHex()), false, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-initialreissuancetokens=<n>", "The amount of reissuance tokens created in the genesis block. (default: 0)", false, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-ct_bits", strprintf("The default number of hiding bits in a rangeproof. Will be exceeded to cover amounts exceeding the maximum hiding value. (default: %d)", 36), false, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-ct_exponent", strprintf("The hiding exponent. (default: %s)", 0), false, OptionsCategory::CHAINPARAMS);

// Add the hidden options
gArgs.AddHiddenArgs(hidden_args);
Expand Down Expand Up @@ -1294,6 +1302,9 @@ bool AppInitMain()
RegisterZMQRPCCommands(tableRPC);
#endif

// ELEMENTS:
policyAsset = CAsset(uint256S(gArgs.GetArg("-feeasset", chainparams.GetConsensus().pegged_asset.GetHex())));

/* Start the RPC server already. It will be started in "warmup" mode
* and not really process calls already (but it will signify connections
* that the server is there and will be ready later). Warmup mode will
Expand Down Expand Up @@ -1832,7 +1843,21 @@ bool AppInitMain()
}
}

// ********************************************************* Step 14: finished
// ********************************************************* Step 14: Check fedpeg
// ELEMENTS:
if (chainparams.GetConsensus().has_parent_chain) {
// Will assert if not properly formatted
const CScript& fedpeg_script = chainparams.GetConsensus().fedpegScript;
unsigned int dummy_required;
std::vector<std::vector<unsigned char>> dummy_keys;
if (!MatchLiquidWatchman(fedpeg_script) &&
fedpeg_script != CScript() << OP_TRUE &&
!MatchMultisig(fedpeg_script, dummy_required, dummy_keys)) {
return InitError(_("ERROR: Fedpegscript is not one of the accepted templates: OP_TRUE, CHECKMULTISIG, and Liquidv1"));
}
}

// ********************************************************* Step 15: finished

SetRPCWarmupFinished();

Expand Down
2 changes: 2 additions & 0 deletions src/policy/policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <utilstrencodings.h>
#include <chainparams.h> // Peg-out enforcement

// ELEMENTS:
CAsset policyAsset;

CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)
{
Expand Down
3 changes: 3 additions & 0 deletions src/policy/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
class CCoinsViewCache;
class CTxOut;

// ELEMENTS:
extern CAsset policyAsset;

/** Default for -blockmaxweight, which controls the range of block weights the mining code will create **/
static const unsigned int DEFAULT_BLOCK_MAX_WEIGHT = MAX_BLOCK_WEIGHT - 4000;
/** Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by mining code **/
Expand Down

0 comments on commit 484d83c

Please sign in to comment.