Skip to content

Commit

Permalink
Added implementation of asset locks
Browse files Browse the repository at this point in the history
  • Loading branch information
knst committed Sep 23, 2022
1 parent 9010b81 commit 9deaabf
Show file tree
Hide file tree
Showing 33 changed files with 1,444 additions and 26 deletions.
4 changes: 4 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ BITCOIN_CORE_H = \
cuckoocache.h \
ctpl_stl.h \
cxxtimer.hpp \
evo/assetlocktx.h \
evo/cbtx.h \
evo/creditpool.h \
evo/deterministicmns.h \
evo/dmnstate.h \
evo/evodb.h \
Expand Down Expand Up @@ -371,7 +373,9 @@ libbitcoin_server_a_SOURCES = \
consensus/tx_verify.cpp \
dbwrapper.cpp \
dsnotificationinterface.cpp \
evo/assetlocktx.cpp \
evo/cbtx.cpp \
evo/creditpool.cpp \
evo/deterministicmns.cpp \
evo/dmnstate.cpp \
evo/evodb.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ BITCOIN_TESTS =\
test/dip0020opcodes_tests.cpp \
test/descriptor_tests.cpp \
test/dynamic_activation_thresholds_tests.cpp \
test/evo_assetlocks_tests.cpp \
test/evo_deterministicmns_tests.cpp \
test/evo_instantsend_tests.cpp \
test/evo_simplifiedmns_tests.cpp \
Expand Down
4 changes: 4 additions & 0 deletions src/bloom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ bool CBloomFilter::CheckSpecialTransactionMatchesAndUpdate(const CTransaction &t
case(TRANSACTION_MNHF_SIGNAL):
// No additional checks for this transaction types
return false;
case(TRANSACTION_ASSET_LOCK):
case(TRANSACTION_ASSET_UNLOCK):
// TODO asset lock/unlock bloom?
return false;
}

LogPrintf("Unknown special transaction type in Bloom filter check.\n");
Expand Down
40 changes: 40 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ class CMainParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_DIP0024].nThresholdMin = 2420; // 60% of 4032
consensus.vDeployments[Consensus::DEPLOYMENT_DIP0024].nFalloffCoeff = 5; // this corresponds to 10 periods

consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].bit = 8;
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nStartTime = 999999999999ULL; // TODO ENABLE BEFORE FINAL RELEASE
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nTimeout = 999999999999ULL; // TODO ENABLE BEFORE FINAL RELEASE
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nWindowSize = 4032;
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nThresholdStart = 3226; // 80% of 4032
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nThresholdMin = 2420; // 60% of 4032
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nFalloffCoeff = 5; // this corresponds to 10 periods

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

Expand Down Expand Up @@ -309,6 +317,8 @@ class CMainParams : public CChainParams {
consensus.llmqTypeDIP0024InstantSend = Consensus::LLMQType::LLMQ_60_75;
consensus.llmqTypePlatform = Consensus::LLMQType::LLMQ_100_67;
consensus.llmqTypeMnhf = Consensus::LLMQType::LLMQ_400_85;
// TODO or which one?
consensus.llmqTypeDIPCreditLocks = Consensus::LLMQType::LLMQ_400_85;

fDefaultConsistencyChecks = false;
fRequireStandard = true;
Expand Down Expand Up @@ -475,6 +485,14 @@ class CTestNetParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_DIP0024].nThresholdMin = 60; // 60% of 100
consensus.vDeployments[Consensus::DEPLOYMENT_DIP0024].nFalloffCoeff = 5; // this corresponds to 10 periods

consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].bit = 8;
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nStartTime = 999999999999ULL; // TODO ENABLE BEFORE INITIAL RC
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nTimeout = 999999999999ULL;
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nWindowSize = 100;
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nThresholdStart = 80; // 80% of 100
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nThresholdMin = 60; // 60% of 60
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nFalloffCoeff = 5; // this corresponds to 10 periods

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

Expand Down Expand Up @@ -527,6 +545,8 @@ class CTestNetParams : public CChainParams {
consensus.llmqTypeDIP0024InstantSend = Consensus::LLMQType::LLMQ_60_75;
consensus.llmqTypePlatform = Consensus::LLMQType::LLMQ_100_67;
consensus.llmqTypeMnhf = Consensus::LLMQType::LLMQ_50_60;
// TODO or which one?
consensus.llmqTypeDIPCreditLocks = Consensus::LLMQType::LLMQ_50_60;

fDefaultConsistencyChecks = false;
fRequireStandard = false;
Expand Down Expand Up @@ -671,6 +691,14 @@ class CDevNetParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_DIP0024].nThresholdMin = 60; // 60% of 100
consensus.vDeployments[Consensus::DEPLOYMENT_DIP0024].nFalloffCoeff = 5; // this corresponds to 10 periods

consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].bit = 8;
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nStartTime = 999999999999ULL; // TODO ENABLE
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nTimeout = 999999999999ULL;
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nWindowSize = 100;
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nThresholdStart = 80; // 80% of 100
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nThresholdMin = 60; // 60% of 60
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nFalloffCoeff = 5; // this corresponds to 10 periods

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

Expand Down Expand Up @@ -726,6 +754,8 @@ class CDevNetParams : public CChainParams {
consensus.llmqTypeDIP0024InstantSend = Consensus::LLMQType::LLMQ_60_75;
consensus.llmqTypePlatform = Consensus::LLMQType::LLMQ_100_67;
consensus.llmqTypeMnhf = Consensus::LLMQType::LLMQ_50_60;
// TODO or which one?
consensus.llmqTypeDIPCreditLocks = Consensus::LLMQType::LLMQ_50_60;

UpdateDevnetLLMQChainLocksFromArgs(args);
UpdateDevnetLLMQInstantSendFromArgs(args);
Expand Down Expand Up @@ -912,6 +942,14 @@ class CRegTestParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_DIP0024].nThresholdMin = 180; // 60% of 300
consensus.vDeployments[Consensus::DEPLOYMENT_DIP0024].nFalloffCoeff = 5; // this corresponds to 10 periods

consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].bit = 8;
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nStartTime = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nTimeout = 999999999999ULL;
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nWindowSize = 100;
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nThresholdStart = 80; // 80% of 100
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nThresholdMin = 60; // 60% of 100
consensus.vDeployments[Consensus::DEPLOYMENT_DIPCREDITLOCKS].nFalloffCoeff = 5; // this corresponds to 10 periods

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

Expand Down Expand Up @@ -995,6 +1033,8 @@ class CRegTestParams : public CChainParams {
consensus.llmqTypeDIP0024InstantSend = Consensus::LLMQType::LLMQ_TEST_DIP0024;
consensus.llmqTypePlatform = Consensus::LLMQType::LLMQ_TEST;
consensus.llmqTypeMnhf = Consensus::LLMQType::LLMQ_TEST;
// TODO or which one?
consensus.llmqTypeDIPCreditLocks = Consensus::LLMQType::LLMQ_TEST;

UpdateLLMQTestParametersFromArgs(args, Consensus::LLMQType::LLMQ_TEST);
UpdateLLMQTestParametersFromArgs(args, Consensus::LLMQType::LLMQ_TEST_INSTANTSEND);
Expand Down
2 changes: 2 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum DeploymentPos {
DEPLOYMENT_REALLOC, // Deployment of Block Reward Reallocation
DEPLOYMENT_DIP0020, // Deployment of DIP0020, DIP0021 and LMQ_100_67 quorums
DEPLOYMENT_DIP0024, // Deployment of DIP0024 (Quorum Rotation) and decreased governance proposal fee
DEPLOYMENT_DIPCREDITLOCKS, // Deployment of DIP00XX (Asset Locks)
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in versionbits.cpp
MAX_VERSION_BITS_DEPLOYMENTS
};
Expand Down Expand Up @@ -123,6 +124,7 @@ struct Params {
LLMQType llmqTypeDIP0024InstantSend{LLMQType::LLMQ_NONE};
LLMQType llmqTypePlatform{LLMQType::LLMQ_NONE};
LLMQType llmqTypeMnhf{LLMQType::LLMQ_NONE};
LLMQType llmqTypeDIPCreditLocks{LLMQType::LLMQ_NONE};
};
} // namespace Consensus

Expand Down
13 changes: 9 additions & 4 deletions src/consensus/tx_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@

bool CheckTransaction(const CTransaction& tx, CValidationState& state)
{
bool allowEmptyTxInOut = false;
bool allowEmptyTxIn = false;
bool allowEmptyTxOut = false;
if (tx.nType == TRANSACTION_QUORUM_COMMITMENT) {
allowEmptyTxInOut = true;
allowEmptyTxIn = true;
allowEmptyTxOut = true;
}
if (tx.nType == TRANSACTION_ASSET_UNLOCK) {
allowEmptyTxIn = true;
}

// Basic checks that don't depend on any context
if (!allowEmptyTxInOut && tx.vin.empty())
if (!allowEmptyTxIn && tx.vin.empty())
return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-txns-vin-empty");
if (!allowEmptyTxInOut && tx.vout.empty())
if (!allowEmptyTxOut && tx.vout.empty())
return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-txns-vout-empty");
// Size limits
if (::GetSerializeSize(tx, PROTOCOL_VERSION) > MAX_LEGACY_BLOCK_SIZE)
Expand Down
16 changes: 16 additions & 0 deletions src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <primitives/transaction.h>
#include <script/interpreter.h>
#include <consensus/validation.h>
#include <evo/assetlocktx.h>

// TODO remove the following dependencies
#include <chain.h>
Expand Down Expand Up @@ -160,6 +161,21 @@ unsigned int GetTransactionSigOpCount(const CTransaction& tx, const CCoinsViewCa

bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, CAmount& txfee)
{

bool isAssetUnlockTx = (tx.nVersion == 3 && tx.nType == TRANSACTION_ASSET_UNLOCK);
if (isAssetUnlockTx) {
CAssetUnlockPayload assetUnlockTx;
if (!GetTxPayload(tx, assetUnlockTx)) {
return state.Invalid(ValidationInvalidReason::TX_BAD_SPECIAL, false, REJECT_INVALID, "bad-assetunlocktx-payload");
}
CAmount txfee_aux = assetUnlockTx.getFee();
if (!MoneyRange(txfee_aux)) {
return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-txns-assetunlock-fee-outofrange");
}
txfee = txfee_aux;
return true;
}

// are the actual inputs available?
if (!inputs.HaveInputs(tx)) {
return state.Invalid(ValidationInvalidReason::TX_MISSING_INPUTS, false, REJECT_INVALID, "bad-txns-inputs-missingorspent", strprintf("%s: inputs missing/spent", __func__));
Expand Down
15 changes: 15 additions & 0 deletions src/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <spentindex.h>

#include <evo/assetlocktx.h>
#include <evo/cbtx.h>
#include <evo/mnhftx.h>
#include <evo/providertx.h>
Expand Down Expand Up @@ -310,6 +311,20 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
mnhfTx.ToJson(obj);
entry.pushKV("mnhfTx", obj);
}
} else if (tx.nType == TRANSACTION_ASSET_LOCK) {
CAssetLockPayload assetLockTx;
if (!GetTxPayload(tx, assetLockTx)) {
UniValue obj;
assetLockTx.ToJson(obj);
entry.pushKV("assetLockTx", obj);
}
} else if (tx.nType == TRANSACTION_ASSET_UNLOCK) {
CAssetUnlockPayload assetUnlockTx;
if (!GetTxPayload(tx, assetUnlockTx)) {
UniValue obj;
assetUnlockTx.ToJson(obj);
entry.pushKV("assetUnlockTx", obj);
}
}

if (!hashBlock.IsNull())
Expand Down
Loading

0 comments on commit 9deaabf

Please sign in to comment.