Skip to content

Commit

Permalink
Add enforce value
Browse files Browse the repository at this point in the history
  • Loading branch information
blondfrogs committed Jul 6, 2020
1 parent bf95ab4 commit 62c30f9
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ class CMainParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE].nTimeout = 1620324000; // UTC: Thu May 06 2021 18:00:00
consensus.vDeployments[Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE].nOverrideRuleChangeActivationThreshold = 1714; // Approx 85% of 2016
consensus.vDeployments[Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE].nOverrideMinerConfirmationWindow = 2016;
consensus.vDeployments[Consensus::DEPLOYMENT_ENFORCE_VALUE].bit = 9;
consensus.vDeployments[Consensus::DEPLOYMENT_ENFORCE_VALUE].nStartTime = 1593453600; // UTC: Mon Jun 29 2020 18:00:00
consensus.vDeployments[Consensus::DEPLOYMENT_ENFORCE_VALUE].nTimeout = 1624989600; // UTC: Mon Jun 29 2020 18:00:00
consensus.vDeployments[Consensus::DEPLOYMENT_ENFORCE_VALUE].nOverrideRuleChangeActivationThreshold = 1209; // Approx 60% of 2016
consensus.vDeployments[Consensus::DEPLOYMENT_ENFORCE_VALUE].nOverrideMinerConfirmationWindow = 2016;

// The best chain should have at least this much work
consensus.nMinimumChainWork = uint256S("000000000000000000000000000000000000000000000020d4ac871fb7009b63"); // Block 1186833
Expand Down
1 change: 1 addition & 0 deletions src/consensus/consensus.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static const size_t MIN_SERIALIZABLE_TRANSACTION_WEIGHT = WITNESS_SCALE_FACTOR *
UNUSED_VAR static bool fAssetsIsActive = false;
UNUSED_VAR static bool fRip5IsActive = false;
UNUSED_VAR static bool fTransferScriptIsActive = false;
UNUSED_VAR static bool fEnforcedValuesIsActive = false;

unsigned int GetMaxBlockWeight();
unsigned int GetMaxBlockSerializedSize();
Expand Down
1 change: 1 addition & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum DeploymentPos
DEPLOYMENT_ASSETS, // Deployment of RIP2
DEPLOYMENT_MSG_REST_ASSETS, // Delpoyment of RIP5 and Restricted assets
DEPLOYMENT_TRANSFER_SCRIPT_SIZE,
DEPLOYMENT_ENFORCE_VALUE,
// DEPLOYMENT_CSV, // Deployment of BIP68, BIP112, and BIP113.
// DEPLOYMENT_SEGWIT, // Deployment of BIP141, BIP143, and BIP147.
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in versionbits.cpp
Expand Down
22 changes: 21 additions & 1 deletion src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& i
return nSigOps;
}

bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fCheckDuplicateInputs)
bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fCheckDuplicateInputs, bool fMempoolCheck, bool fBlockCheck)
{
// Basic checks that don't depend on any context
if (tx.vin.empty())
Expand Down Expand Up @@ -308,7 +308,27 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe
// Specific check and error message to go with to make sure the amount is 0
if (txout.nValue != 0)
return state.DoS(100, false, REJECT_INVALID, "bad-txns-asset-issued-amount-isn't-zero");
} else if (nType == TX_REISSUE_ASSET) {
// Specific check and error message to go with to make sure the amount is 0
if (AreEnforcedValuesDeployed()) {
// We only want to not accept these txes when checking them from CheckBlock.
// We don't want to change the behavior when reading transactions from the database
// when AreEnforcedValuesDeployed return true
if (fBlockCheck) {
if (txout.nValue != 0) {
return state.DoS(100, false, REJECT_INVALID, "bad-txns-asset-reissued-amount-isn't-zero");
}
}
}

if (fMempoolCheck) {
// Don't accept to the mempool no matter what on these types of transactions
if (txout.nValue != 0) {
return state.DoS(100, false, REJECT_INVALID, "bad-txns-asset-reissued-amount-isn't-zero");
}
}
}

}
}

Expand Down
2 changes: 1 addition & 1 deletion src/consensus/tx_verify.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CNullAssetTxData;
/** Transaction validation functions */

/** Context-independent validity checks */
bool CheckTransaction(const CTransaction& tx, CValidationState& state, bool fCheckDuplicateInputs=true);
bool CheckTransaction(const CTransaction& tx, CValidationState& state, bool fCheckDuplicateInputs=true, bool fMempoolCheck = false, bool fBlockCheck = false);

namespace Consensus {
/**
Expand Down
1 change: 1 addition & 0 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
BIP9SoftForkDescPushBack(bip9_softforks, "assets", consensusParams, Consensus::DEPLOYMENT_ASSETS);
BIP9SoftForkDescPushBack(bip9_softforks, "messaging_restricted", consensusParams, Consensus::DEPLOYMENT_MSG_REST_ASSETS);
BIP9SoftForkDescPushBack(bip9_softforks, "transfer_script", consensusParams, Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE);
BIP9SoftForkDescPushBack(bip9_softforks, "enforce", consensusParams, Consensus::DEPLOYMENT_ENFORCE_VALUE);
obj.push_back(Pair("softforks", softforks));
obj.push_back(Pair("bip9_softforks", bip9_softforks));

Expand Down
19 changes: 16 additions & 3 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
AssertLockHeld(cs_main);
if (pfMissingInputs)
*pfMissingInputs = false;
if (!CheckTransaction(tx, state))
if (!CheckTransaction(tx, state, true, true))
return false; // state filled in by CheckTransaction

// Coinbase is only valid in a block, not as a loose transaction
Expand Down Expand Up @@ -3997,7 +3997,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P

// Check transactions
for (const auto& tx : block.vtx)
if (!CheckTransaction(*tx, state))
if (!CheckTransaction(*tx, state, true, false, true))
return state.Invalid(false, state.GetRejectCode(), state.GetRejectReason(),
strprintf("Transaction check failed (tx hash %s) %s %s", tx->GetHash().ToString(), state.GetDebugMessage(), state.GetRejectReason()));

Expand Down Expand Up @@ -5703,7 +5703,20 @@ double GuessVerificationProgress(const ChainTxData& data, CBlockIndex *pindex) {
}

/** RVN START */
bool AreAssetsDeployed() {
bool AreEnforcedValuesDeployed()
{
if (fEnforcedValuesIsActive)
return true;

const ThresholdState thresholdState = VersionBitsTipState(GetParams().GetConsensus(), Consensus::DEPLOYMENT_ENFORCE_VALUE);
if (thresholdState == THRESHOLD_ACTIVE)
fEnforcedValuesIsActive = true;

return fEnforcedValuesIsActive;
}

bool AreAssetsDeployed()
{

if (fAssetsIsActive)
return true;
Expand Down
2 changes: 2 additions & 0 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,8 @@ bool AreMessagesDeployed();

bool AreRestrictedAssetsDeployed();

bool AreEnforcedValuesDeployed();

bool IsRip5Active();


Expand Down
4 changes: 4 additions & 0 deletions src/versionbits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_B
{
/*.name =*/ "transfer_script",
/*.gbt_force =*/ true,
},
{
/*.name =*/ "enforce_value",
/*.gbt_force =*/ true,
}
};

Expand Down

0 comments on commit 62c30f9

Please sign in to comment.