Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ class CMainParams : public CChainParams {
// Dash BIP32 prvkeys start with 'xprv' (Bitcoin defaults)
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x88, 0xAD, 0xE4};

// DIP-18 Dash Platform address HRP (bech32m)
bech32_platform_hrp = "dash";

// Dash BIP44 coin type is '5'
nExtCoinType = 5;

Expand Down Expand Up @@ -452,6 +455,9 @@ class CTestNetParams : public CChainParams {
// Testnet Dash BIP32 prvkeys start with 'tprv' (Bitcoin defaults)
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};

// DIP-18 Dash Platform address HRP (bech32m)
bech32_platform_hrp = "tdash";

// Testnet Dash BIP44 coin type is '1' (All coin's testnet default)
nExtCoinType = 1;

Expand Down Expand Up @@ -625,6 +631,9 @@ class CDevNetParams : public CChainParams {
// Testnet Dash BIP32 prvkeys start with 'tprv' (Bitcoin defaults)
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};

// DIP-18 Dash Platform address HRP (bech32m)
bech32_platform_hrp = "tdash";

// Testnet Dash BIP44 coin type is '1' (All coin's testnet default)
nExtCoinType = 1;

Expand Down Expand Up @@ -900,6 +909,9 @@ class CRegTestParams : public CChainParams {
// Regtest Dash BIP32 prvkeys start with 'tprv' (Bitcoin defaults)
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};

// DIP-18 Dash Platform address HRP (bech32m)
bech32_platform_hrp = "tdash";

// Regtest Dash BIP44 coin type is '1' (All coin's testnet default)
nExtCoinType = 1;

Expand Down
3 changes: 3 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ class CChainParams
/** Return the list of hostnames to look up for DNS seeds */
const std::vector<std::string>& DNSSeeds() const { return vSeeds; }
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
/** DIP-18 Platform address bech32m HRP: "dash" on mainnet, "tdash" on test chains */
const std::string& Bech32PlatformHRP() const { return bech32_platform_hrp; }
int ExtCoinType() const { return nExtCoinType; }
const std::vector<uint8_t>& FixedSeeds() const { return vFixedSeeds; }
const CCheckpointData& Checkpoints() const { return checkpointData; }
Expand Down Expand Up @@ -164,6 +166,7 @@ class CChainParams
uint64_t m_assumed_chain_state_size;
std::vector<std::string> vSeeds;
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
std::string bech32_platform_hrp;
int nExtCoinType;
std::string strNetworkID;
CBlock genesis;
Expand Down
30 changes: 12 additions & 18 deletions src/evo/assetlocktx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,10 @@
using node::BlockManager;


/**
* Common code for Asset Lock and Asset Unlock
*/
bool CheckAssetLockUnlockTx(const BlockManager& blockman, const llmq::CQuorumManager& qman, const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, const std::optional<CRangesSet>& indexes, TxValidationState& state)
{
switch (tx.nType) {
case TRANSACTION_ASSET_LOCK:
return CheckAssetLockTx(tx, state);
case TRANSACTION_ASSET_UNLOCK:
return CheckAssetUnlockTx(blockman, qman, tx, pindexPrev, indexes, state);
default:
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-not-asset-locks-at-all");
}
}

/**
* Asset Lock Transaction
*/
bool CheckAssetLockTx(const CTransaction& tx, TxValidationState& state)
bool CheckAssetLockTx(const CTransaction& tx, TxValidationState& state, bool is_v24_active)
{
if (tx.nType != TRANSACTION_ASSET_LOCK) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-assetlocktx-type");
Expand Down Expand Up @@ -71,6 +56,9 @@ bool CheckAssetLockTx(const CTransaction& tx, TxValidationState& state)
if (opt_assetLockTx->getVersion() == 0 || opt_assetLockTx->getVersion() > CAssetLockPayload::CURRENT_VERSION) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-assetlocktx-version");
}
if (!is_v24_active && opt_assetLockTx->getVersion() == CAssetLockPayload::CURRENT_VERSION) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-assetlocktx-version-2");
}

if (opt_assetLockTx->getCreditOutputs().empty()) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-assetlocktx-emptycreditoutputs");
Expand All @@ -83,8 +71,14 @@ bool CheckAssetLockTx(const CTransaction& tx, TxValidationState& state)
}

creditOutputsAmount += out.nValue;
if (!out.scriptPubKey.IsPayToPublicKeyHash()) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-assetlocktx-pubKeyHash");
if (opt_assetLockTx->getVersion() >= 2) {
if (!out.scriptPubKey.IsPayToPublicKeyHash() && !out.scriptPubKey.IsPayToScriptHash()) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-assetlocktx-script-pubkey");
}
} else {
if (!out.scriptPubKey.IsPayToPublicKeyHash()) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-assetlocktx-pubKeyHash");
}
}
}
if (creditOutputsAmount != returnAmount) {
Expand Down
10 changes: 5 additions & 5 deletions src/evo/assetlocktx.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ class BlockManager;
class CAssetLockPayload
{
public:
static constexpr uint8_t CURRENT_VERSION = 1;
static constexpr uint8_t INITIAL_VERSION = 1;
static constexpr uint8_t CURRENT_VERSION = 2;
static constexpr auto SPECIALTX_TYPE = TRANSACTION_ASSET_LOCK;

private:
uint8_t nVersion{CURRENT_VERSION};
std::vector<CTxOut> creditOutputs;

public:
explicit CAssetLockPayload(const std::vector<CTxOut>& creditOutputs) :
creditOutputs(creditOutputs)
explicit CAssetLockPayload(const std::vector<CTxOut>& creditOutputs, uint8_t nVersion = CURRENT_VERSION) :
nVersion(nVersion), creditOutputs(creditOutputs)
{}

CAssetLockPayload() = default;
Expand Down Expand Up @@ -154,9 +155,8 @@ class CAssetUnlockPayload
}
};

bool CheckAssetLockTx(const CTransaction& tx, TxValidationState& state);
bool CheckAssetLockTx(const CTransaction& tx, TxValidationState& state, bool is_v24_active = false);
bool CheckAssetUnlockTx(const node::BlockManager& blockman, const llmq::CQuorumManager& qman, const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, const std::optional<CRangesSet>& indexes, TxValidationState& state);
bool CheckAssetLockUnlockTx(const node::BlockManager& blockman, const llmq::CQuorumManager& qman, const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, const std::optional<CRangesSet>& indexes, TxValidationState& state);
bool GetAssetUnlockFee(const CTransaction& tx, CAmount& txfee, TxValidationState& state);

#endif // BITCOIN_EVO_ASSETLOCKTX_H
16 changes: 15 additions & 1 deletion src/evo/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#include <util/std23.h>

#include <core_io.h>
#include <key_io.h>
#include <rpc/util.h>
#include <script/standard.h>
#include <util/check.h>

#include <univalue.h>
Expand Down Expand Up @@ -98,7 +100,9 @@ RPCResult CAssetLockPayload::GetJsonHelp(const std::string& key, bool optional)
{RPCResult::Type::STR, "asm", "The asm"},
{RPCResult::Type::STR_HEX, "hex", "The hex"},
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
}}}}}}
}},
{RPCResult::Type::STR, "address", /*optional=*/true, "DIP-18 Platform address (version >= 2 only)"},
}}}}
}};
}

Expand All @@ -112,6 +116,16 @@ UniValue CAssetLockPayload::ToJson() const
UniValue spk(UniValue::VOBJ);
ScriptToUniv(credit_output.scriptPubKey, spk, /*include_hex=*/true, /*include_address=*/false);
out.pushKV("scriptPubKey", spk);
if (nVersion >= 2) {
CTxDestination dest;
if (ExtractDestination(credit_output.scriptPubKey, dest)) {
if (const auto* pkh = std::get_if<PKHash>(&dest)) {
out.pushKV("address", EncodePlatformDestination(PlatformP2PKHDestination(uint160(*pkh))));
} else if (const auto* sh = std::get_if<ScriptHash>(&dest)) {
out.pushKV("address", EncodePlatformDestination(PlatformP2SHDestination(uint160(*sh))));
}
}
}
outputs.push_back(out);
}

Expand Down
16 changes: 4 additions & 12 deletions src/evo/creditpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <memory>
#include <stack>

using node::BlockManager;
using node::ReadBlockFromDisk;

// Forward declaration to prevent a new circular dependencies through masternode/payments.h
Expand Down Expand Up @@ -248,8 +247,7 @@ CCreditPoolManager::~CCreditPoolManager() = default;

CCreditPoolDiff::CCreditPoolDiff(CCreditPool starter, const CBlockIndex* pindexPrev,
const Consensus::Params& consensusParams, const CAmount blockSubsidy) :
pool(std::move(starter)),
pindexPrev(pindexPrev)
pool(std::move(starter))
{
assert(pindexPrev);

Expand Down Expand Up @@ -297,15 +295,9 @@ bool CCreditPoolDiff::Unlock(const CTransaction& tx, TxValidationState& state)
return true;
}

bool CCreditPoolDiff::ProcessLockUnlockTransaction(const BlockManager& blockman, const llmq::CQuorumManager& qman, const CTransaction& tx, TxValidationState& state)
bool CCreditPoolDiff::ProcessLockUnlockTransaction(const CTransaction& tx, TxValidationState& state)
{
if (!tx.IsSpecialTxVersion()) return true;
if (tx.nType != TRANSACTION_ASSET_LOCK && tx.nType != TRANSACTION_ASSET_UNLOCK) return true;

if (!CheckAssetLockUnlockTx(blockman, qman, tx, pindexPrev, pool.indexes, state)) {
// pass the state returned by the function above
return false;
}

try {
switch (tx.nType) {
Expand All @@ -322,7 +314,7 @@ bool CCreditPoolDiff::ProcessLockUnlockTransaction(const BlockManager& blockman,
}
}

std::optional<CCreditPoolDiff> GetCreditPoolDiffForBlock(CCreditPoolManager& cpoolman, const BlockManager& blockman, const llmq::CQuorumManager& qman,
std::optional<CCreditPoolDiff> GetCreditPoolDiffForBlock(CCreditPoolManager& cpoolman,
const CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams,
const CAmount blockSubsidy, BlockValidationState& state)
{
Expand All @@ -333,7 +325,7 @@ std::optional<CCreditPoolDiff> GetCreditPoolDiffForBlock(CCreditPoolManager& cpo
for (size_t i = 1; i < block.vtx.size(); ++i) {
const auto& tx = *block.vtx[i];
TxValidationState tx_state;
if (!creditPoolDiff.ProcessLockUnlockTransaction(blockman, qman, tx, tx_state)) {
if (!creditPoolDiff.ProcessLockUnlockTransaction(tx, tx_state)) {
assert(tx_state.GetResult() == TxValidationResult::TX_CONSENSUS);
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, tx_state.GetRejectReason(),
strprintf("Process Lock/Unlock Transaction failed at Credit Pool (tx hash %s) %s", tx.GetHash().ToString(), tx_state.GetDebugMessage()));
Expand Down
12 changes: 4 additions & 8 deletions src/evo/creditpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ struct Params;
namespace llmq {
class CQuorumManager;
} // namespace llmq
namespace node {
class BlockManager;
} // namespace node

struct CCreditPool {
CAmount locked{0};
Expand Down Expand Up @@ -70,16 +67,15 @@ struct CCreditPool {
* limits should stay same and depends only on the previous block.
*/
class CCreditPoolDiff {
private:
public:
const CCreditPool pool;
private:
std::unordered_set<uint64_t> newIndexes;

CAmount sessionLocked{0};
CAmount sessionUnlocked{0};
CAmount platformReward{0};

const CBlockIndex *pindexPrev{nullptr};

public:
explicit CCreditPoolDiff(CCreditPool starter, const CBlockIndex *pindexPrev,
const Consensus::Params& consensusParams,
Expand All @@ -90,7 +86,7 @@ class CCreditPoolDiff {
* to change amount of credit pool
* @return true if transaction can be included in this block
*/
bool ProcessLockUnlockTransaction(const node::BlockManager& blockman, const llmq::CQuorumManager& qman, const CTransaction& tx, TxValidationState& state);
bool ProcessLockUnlockTransaction(const CTransaction& tx, TxValidationState& state);

/**
* this function returns total amount of credits for the next block
Expand Down Expand Up @@ -147,7 +143,7 @@ class CCreditPoolManager
EXCLUSIVE_LOCKS_REQUIRED(!cache_mutex);
};

std::optional<CCreditPoolDiff> GetCreditPoolDiffForBlock(CCreditPoolManager& cpoolman, const node::BlockManager& blockman, const llmq::CQuorumManager& qman,
std::optional<CCreditPoolDiff> GetCreditPoolDiffForBlock(CCreditPoolManager& cpoolman,
const CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams,
const CAmount blockSubsidy, BlockValidationState& state);

Expand Down
4 changes: 2 additions & 2 deletions src/evo/specialtxman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static bool CheckSpecialTxInner(CDeterministicMNManager& dmnman, llmq::CQuorumSn
case TRANSACTION_MNHF_SIGNAL:
return CheckMNHFTx(chainman, qman, tx, pindexPrev, state);
case TRANSACTION_ASSET_LOCK:
return CheckAssetLockTx(tx, state);
return CheckAssetLockTx(tx, state, DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_V24));
case TRANSACTION_ASSET_UNLOCK:
return CheckAssetUnlockTx(chainman.m_blockman, qman, tx, pindexPrev, indexes, state);
}
Expand Down Expand Up @@ -743,7 +743,7 @@ bool CSpecialTxProcessor::CheckCreditPoolDiffForBlock(const CBlock& block, const

try {
const CAmount blockSubsidy = GetBlockSubsidy(pindex, m_consensus_params);
const auto creditPoolDiff = GetCreditPoolDiffForBlock(m_cpoolman, m_chainman.m_blockman, m_qman, block,
const auto creditPoolDiff = GetCreditPoolDiffForBlock(m_cpoolman, block,
pindex->pprev, m_consensus_params, blockSubsidy, state);
if (!creditPoolDiff.has_value()) return false;

Expand Down
Loading
Loading