Skip to content

Commit

Permalink
Merge pull request #11 from a7853z/master
Browse files Browse the repository at this point in the history
Compensation coins merge
  • Loading branch information
bitcoincandyofficial authored Feb 28, 2019
2 parents 2b2c162 + dbcb431 commit d278335
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class CBlockIndex {

//! Check whether this block index entry is valid up to the passed validity
//! level.
bool IsValid(enum BlockValidity nUpTo = BlockValidity::TRANSACTIONS) const {
bool IsValid(enum BlockValidity nUpTo = BlockValidity::TRANSACTIONS) const {
return nStatus.isValid(nUpTo);
}

Expand Down
17 changes: 12 additions & 5 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,14 @@ class CMainParams : public CChainParams {
consensus.cdyHeight = 512666;

// hard fork
consensus.CDYZawyLWMAHeight = 573123;
consensus.nNewRuleHeight = 592447;
consensus.CDYEquihashForkHeight = 656960; // Around 09/01/2018

consensus.CDYZawyLWMAHeight = 573123;


/** Height to publish compensing coins*/
consensus.nCompenseHeight = 758000;
consensus.sCompenseAddress = "CVbtt8dqZKG4xzG7C1oGzEd1G66eoDn2ee";

consensus.BitcoinPostforkBlock = uint256S("0000000000000000007b746068bd08ba4089f97636690e9dc758774e7db21f17"); // 512666 block hash
consensus.BitcoinPostforkTime = 1515799972;

Expand Down Expand Up @@ -375,11 +378,13 @@ class CTestNetParams : public CChainParams {

// hard fork-----add by hmc
consensus.cdyHeight = 201601;

consensus.CDYZawyLWMAHeight = 201641;
consensus.nNewRuleHeight = 201651;
consensus.CDYEquihashForkHeight = 201671;

consensus.nCompenseHeight = 202136;
consensus.sCompenseAddress = "mhZBATdK8nghjJ6S8F7DSEvDc1pz47bgzP";

consensus.CDYZawyLWMAHeight = 201641;
consensus.BitcoinPostforkBlock = uint256S("00000000d16d6c2aecc7436eea0c54a53741fee9abf265606aa465d6fd3f3d8a"); // block 201601
consensus.BitcoinPostforkTime = 1393815074;

Expand Down Expand Up @@ -530,6 +535,8 @@ class CRegTestParams : public CChainParams {
consensus.nNewRuleHeight = 201836;
consensus.CDYEquihashForkHeight = 201876;

consensus.nCompenseHeight = 202000;
consensus.sCompenseAddress = "CSZnk6KoMoEwHmveF3KcyRfEWsZfZ3dgEU";
// Nov, 13 hard fork is always on on regtest.
consensus.daaHeight = 2250;

Expand Down
5 changes: 5 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ struct Params {
int CDYZawyLWMAHeight;
/** Block height at which Equihash<144,5> becomes active */
int CDYEquihashForkHeight;
/** Height to publish compensing coins*/
uint32_t nCompenseHeight;

std::string sCompenseAddress;

/** Limit BITCOIN_MAX_FUTURE_BLOCK_TIME **/
int64_t CDYMaxFutureBlockTime;

Expand Down
2 changes: 1 addition & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn) {
LOCK2(cs_main, mempool.cs);
CBlockIndex *pindexPrev = chainActive.Tip();
nHeight = pindexPrev->nHeight + 1;

pblock->nVersion =
ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());
// -regtest only: allow overriding block.nVersion with
Expand Down
89 changes: 89 additions & 0 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,94 @@ static UniValue decoderawtransaction(const Config &config,
return result;
}


static UniValue replayblock(const Config &config,
const JSONRPCRequest &request) {
if (request.fHelp || request.params.size() != 1) {
throw std::runtime_error(
"replayblock \"hexstring\"\n"
"\nReturn replay tx result.\n"
"\nArguments:\n"
"1. \"hexstring\" (string, required) The block hex "
"string\n"

"\nResult:\n"
"{\n"
"}\n"
"\nExamples:\n" +
HelpExampleCli("decoderawtransaction", "\"blockhexstring\"") +
HelpExampleRpc("decoderawtransaction", "\"blockhexstring\""));
}

LOCK(cs_main);
RPCTypeCheck(request.params, {UniValue::VSTR});

std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>();
CBlock &block = *blockptr;
bool legacy_format = false;
if (!DecodeHexBlk(block, request.params[0].get_str(), legacy_format)) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
}

if (block.vtx.empty() || !block.vtx[0]->IsCoinBase()) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR,
"Block does not start with a coinbase");
}

bool fLimitFree = false;
Amount nMaxRawTxFee = maxTxFee;
uint32_t nMissingInput = 0;
uint32_t nAlreadyInChain = 0;
uint32_t nOtherError = 0;

//skip coinbase transaction
for (unsigned int i = 1; i < block.vtx.size(); i++) {
CTransactionRef tx = block.vtx[i];
const uint256 &txid = tx->GetId();
CCoinsViewCache &view = *pcoinsTip;
bool fHaveChain = false;
for (size_t o = 0; !fHaveChain && o < tx->vout.size(); o++) {
const Coin &existingCoin = view.AccessCoin(COutPoint(txid, o));
fHaveChain = !existingCoin.IsSpent();
}
bool fHaveMempool = mempool.exists(txid);
if (!fHaveMempool && !fHaveChain) {
// Push to local node and sync with wallets.
CValidationState state;
bool fMissingInputs;
if (!AcceptToMemoryPool(config, mempool, state, std::move(tx),
fLimitFree, &fMissingInputs, false,
nMaxRawTxFee)) {
if (state.IsInvalid()) {
nOtherError++;
} else {
if (fMissingInputs) {
nMissingInput++;
} else
nOtherError++;
}
}
} else if (fHaveChain) {
nAlreadyInChain++;
}

if (!g_connman) {
throw JSONRPCError(
RPC_CLIENT_P2P_DISABLED,
"Error: Peer-to-peer functionality missing or disabled");
}

CInv inv(MSG_TX, txid);
g_connman->ForEachNode([&inv](CNode *pnode) { pnode->PushInventory(inv); });
}
char result[200];
sprintf(result, "Replay block done, %d tx in total, %d missing inputs, %d already in chain, %d other error",
block.vtx.size()-1, nMissingInput, nAlreadyInChain, nOtherError);
return result;

}


static UniValue decodescript(const Config &config,
const JSONRPCRequest &request) {
if (request.fHelp || request.params.size() != 1) {
Expand Down Expand Up @@ -1278,6 +1366,7 @@ static const CRPCCommand commands[] = {
{ "rawtransactions", "sendrawtransaction", sendrawtransaction, false, {"hexstring","allowhighfees"} },
{ "rawtransactions", "combinerawtransaction", combinerawtransaction, false, {"txs"} },
{ "rawtransactions", "signrawtransaction", signrawtransaction, false, {"hexstring","prevtxs","privkeys","sighashtype"} }, /* uses wallet if enabled */
{ "rawtransactions", "replayblock", replayblock, true, {"hexstring"}},

{ "blockchain", "gettxoutproof", gettxoutproof, true, {"txids", "blockhash"} },
{ "blockchain", "verifytxoutproof", verifytxoutproof, true, {"proof"} },
Expand Down
19 changes: 18 additions & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "validationinterface.h"
#include "versionbits.h"
#include "warnings.h"
#include "dstencode.h"

#include <atomic>
#include <sstream>
Expand Down Expand Up @@ -1227,9 +1228,13 @@ Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams) {
else halvings = nHeight / consensusParams.nSubsidyHalvingInterval;


if (nHeight == consensusParams.cdyHeight)
if (nHeight == consensusParams.cdyHeight) {
return 210000 * COIN;// * COIN_SCALE;
}

if (nHeight == consensusParams.nCompenseHeight) {
return 1000000 * COIN;
}
// Force block reward to zero when right shift is undefined.
if (halvings >= 61) return Amount(0); //change it from 64 to 61

Expand Down Expand Up @@ -2210,6 +2215,18 @@ static bool ConnectBlock(const Config &config, const CBlock &block,
REJECT_INVALID, "bad-cb-amount");
}

if (block.nHeight == chainparams.GetConsensus().nCompenseHeight) {
CScript scriptPubKeyCompense;
const std::string sCompenseAddress = chainparams.GetConsensus().sCompenseAddress;
CTxDestination destination = DecodeDestination(sCompenseAddress);
scriptPubKeyCompense = GetScriptForDestination(destination);
if (block.vtx[0]->vout.size()!= 1 ||
block.vtx[0]->vout[0].scriptPubKey != scriptPubKeyCompense) {
return state.DoS(100, false, REJECT_INVALID, "blk-bad-scriptPubKey", false,
"not the expected scriptPubKey at compense height");
}
}

if (!control.Wait()) {
return state.DoS(100, false, REJECT_INVALID, "blk-bad-inputs", false,
"parallel script check failed");
Expand Down

0 comments on commit d278335

Please sign in to comment.