Skip to content

Commit 77c0c34

Browse files
committed
cummulative update from PR #5026: feat: add implementation of DIP 0027 Credit Asset Locks
This commit includes: - Asset Lock transaction - Asset Unlock transaction (withdrawal) - Credit Pool in coinbase - Unit tests for Asset Lock/Unlock tx - New functional test `feature_asset_locks.py` - RPC for Credit Pool (currently locked amount) - Asset unlock limits are equals to: min(max(100, min(.10 * assetlockpool, 1000)), assetlockpool) - Removing expired asset-unlock transaction from mempool - Asset unlock transaction are restricted to be accepted during only 48 blocks feat: improve improved funtional test feature_asset_locks.py to test more - rollback of block with tx Asset Lock - rollback of block with tx Asset Unlock - duplicate 'asset unlock' tx for new block - asset unlock rollback and reconsider - reconsider/invalide blocks - manually created block with invalid transaction feat: proper implementation of CCreditPoolManager with credits and index validation This commit implements: - an index validation for asset-unlock txes - refactoring of CCreditPoolManager - serializing CreditPoolCb to evo db when needed - unlock transactions are validated twice: when accepting to block chain and in miner - indexes also validated before beeing added to txmempool - functional test with duplicated indexes in Asset Unlock txes feat: add unittests for SkipSet structure fix: check validity of asset-locked amount in coin base tx for new block
1 parent eade838 commit 77c0c34

35 files changed

+2102
-48
lines changed

src/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,10 @@ BITCOIN_CORE_H = \
169169
cuckoocache.h \
170170
ctpl_stl.h \
171171
cxxtimer.hpp \
172+
evo/assetlocktx.h \
172173
evo/dmn_types.h \
173174
evo/cbtx.h \
175+
evo/creditpool.h \
174176
evo/deterministicmns.h \
175177
evo/dmnstate.h \
176178
evo/evodb.h \
@@ -384,7 +386,9 @@ libbitcoin_server_a_SOURCES = \
384386
consensus/tx_verify.cpp \
385387
dbwrapper.cpp \
386388
dsnotificationinterface.cpp \
389+
evo/assetlocktx.cpp \
387390
evo/cbtx.cpp \
391+
evo/creditpool.cpp \
388392
evo/deterministicmns.cpp \
389393
evo/dmnstate.cpp \
390394
evo/evodb.cpp \

src/Makefile.test.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ BITCOIN_TESTS =\
9595
test/dip0020opcodes_tests.cpp \
9696
test/descriptor_tests.cpp \
9797
test/dynamic_activation_thresholds_tests.cpp \
98+
test/evo_assetlocks_tests.cpp \
9899
test/evo_deterministicmns_tests.cpp \
99100
test/evo_instantsend_tests.cpp \
100101
test/evo_simplifiedmns_tests.cpp \

src/bloom.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ bool CBloomFilter::CheckSpecialTransactionMatchesAndUpdate(const CTransaction &t
194194
case(TRANSACTION_MNHF_SIGNAL):
195195
// No additional checks for this transaction types
196196
return false;
197+
case(TRANSACTION_ASSET_LOCK):
198+
case(TRANSACTION_ASSET_UNLOCK):
199+
// TODO asset lock/unlock bloom?
200+
return false;
197201
}
198202

199203
LogPrintf("Unknown special transaction type in Bloom filter check.\n");

src/chainparams.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ class CMainParams : public CChainParams {
315315
consensus.llmqTypeDIP0024InstantSend = Consensus::LLMQType::LLMQ_60_75;
316316
consensus.llmqTypePlatform = Consensus::LLMQType::LLMQ_100_67;
317317
consensus.llmqTypeMnhf = Consensus::LLMQType::LLMQ_400_85;
318+
consensus.llmqTypeAssetLocks = Consensus::LLMQType::LLMQ_400_85;
318319

319320
fDefaultConsistencyChecks = false;
320321
fRequireStandard = true;
@@ -556,6 +557,7 @@ class CTestNetParams : public CChainParams {
556557
consensus.llmqTypeDIP0024InstantSend = Consensus::LLMQType::LLMQ_60_75;
557558
consensus.llmqTypePlatform = Consensus::LLMQType::LLMQ_25_67;
558559
consensus.llmqTypeMnhf = Consensus::LLMQType::LLMQ_50_60;
560+
consensus.llmqTypeAssetLocks = Consensus::LLMQType::LLMQ_50_60;
559561

560562
fDefaultConsistencyChecks = false;
561563
fRequireStandard = false;
@@ -779,6 +781,7 @@ class CDevNetParams : public CChainParams {
779781
consensus.llmqTypeDIP0024InstantSend = Consensus::LLMQType::LLMQ_60_75;
780782
consensus.llmqTypePlatform = Consensus::LLMQType::LLMQ_100_67;
781783
consensus.llmqTypeMnhf = Consensus::LLMQType::LLMQ_50_60;
784+
consensus.llmqTypeAssetLocks = Consensus::LLMQType::LLMQ_50_60;
782785

783786
UpdateDevnetLLMQChainLocksFromArgs(args);
784787
UpdateDevnetLLMQInstantSendFromArgs(args);
@@ -1078,6 +1081,7 @@ class CRegTestParams : public CChainParams {
10781081
consensus.llmqTypeDIP0024InstantSend = Consensus::LLMQType::LLMQ_TEST_DIP0024;
10791082
consensus.llmqTypePlatform = Consensus::LLMQType::LLMQ_TEST_PLATFORM;
10801083
consensus.llmqTypeMnhf = Consensus::LLMQType::LLMQ_TEST;
1084+
consensus.llmqTypeAssetLocks = Consensus::LLMQType::LLMQ_TEST;
10811085

10821086
UpdateLLMQTestParametersFromArgs(args, Consensus::LLMQType::LLMQ_TEST);
10831087
UpdateLLMQTestParametersFromArgs(args, Consensus::LLMQType::LLMQ_TEST_INSTANTSEND);

src/consensus/params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ struct Params {
125125
LLMQType llmqTypeDIP0024InstantSend{LLMQType::LLMQ_NONE};
126126
LLMQType llmqTypePlatform{LLMQType::LLMQ_NONE};
127127
LLMQType llmqTypeMnhf{LLMQType::LLMQ_NONE};
128+
LLMQType llmqTypeAssetLocks{LLMQType::LLMQ_NONE};
128129
};
129130
} // namespace Consensus
130131

src/consensus/tx_check.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@
1212

1313
bool CheckTransaction(const CTransaction& tx, TxValidationState& state)
1414
{
15-
bool allowEmptyTxInOut = false;
15+
bool allowEmptyTxIn = false;
16+
bool allowEmptyTxOut = false;
1617
if (tx.nType == TRANSACTION_QUORUM_COMMITMENT) {
17-
allowEmptyTxInOut = true;
18+
allowEmptyTxIn = true;
19+
allowEmptyTxOut = true;
20+
}
21+
if (tx.nType == TRANSACTION_ASSET_UNLOCK) {
22+
allowEmptyTxIn = true;
1823
}
1924

2025
// Basic checks that don't depend on any context
21-
if (!allowEmptyTxInOut && tx.vin.empty())
26+
if (!allowEmptyTxIn && tx.vin.empty())
2227
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-vin-empty");
23-
if (!allowEmptyTxInOut && tx.vout.empty())
28+
if (!allowEmptyTxOut && tx.vout.empty())
2429
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-vout-empty");
2530
// Size limits
2631
if (::GetSerializeSize(tx, PROTOCOL_VERSION) > MAX_LEGACY_BLOCK_SIZE)

src/consensus/tx_verify.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <primitives/transaction.h>
99
#include <script/interpreter.h>
1010
#include <consensus/validation.h>
11+
#include <evo/assetlocktx.h>
1112

1213
// TODO remove the following dependencies
1314
#include <chain.h>
@@ -160,6 +161,20 @@ unsigned int GetTransactionSigOpCount(const CTransaction& tx, const CCoinsViewCa
160161

161162
bool Consensus::CheckTxInputs(const CTransaction& tx, TxValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, CAmount& txfee)
162163
{
164+
165+
if (bool isAssetUnlockTx = (tx.nVersion == 3 && tx.nType == TRANSACTION_ASSET_UNLOCK); isAssetUnlockTx) {
166+
CAssetUnlockPayload assetUnlockTx;
167+
if (!GetTxPayload(tx, assetUnlockTx)) {
168+
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-assetunlocktx-payload");
169+
}
170+
CAmount txfee_aux = assetUnlockTx.getFee();
171+
if (!MoneyRange(txfee_aux)) {
172+
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-assetunlock-fee-outofrange");
173+
}
174+
txfee = txfee_aux;
175+
return true;
176+
}
177+
163178
// are the actual inputs available?
164179
if (!inputs.HaveInputs(tx)) {
165180
return state.Invalid(TxValidationResult::TX_MISSING_INPUTS, "bad-txns-inputs-missingorspent",

src/core_write.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <spentindex.h>
1818

19+
#include <evo/assetlocktx.h>
1920
#include <evo/cbtx.h>
2021
#include <evo/mnhftx.h>
2122
#include <evo/providertx.h>
@@ -310,6 +311,20 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
310311
mnhfTx.ToJson(obj);
311312
entry.pushKV("mnhfTx", obj);
312313
}
314+
} else if (tx.nType == TRANSACTION_ASSET_LOCK) {
315+
CAssetLockPayload assetLockTx;
316+
if (!GetTxPayload(tx, assetLockTx)) {
317+
UniValue obj;
318+
assetLockTx.ToJson(obj);
319+
entry.pushKV("assetLockTx", obj);
320+
}
321+
} else if (tx.nType == TRANSACTION_ASSET_UNLOCK) {
322+
CAssetUnlockPayload assetUnlockTx;
323+
if (!GetTxPayload(tx, assetUnlockTx)) {
324+
UniValue obj;
325+
assetUnlockTx.ToJson(obj);
326+
entry.pushKV("assetUnlockTx", obj);
327+
}
313328
}
314329

315330
if (!hashBlock.IsNull())

0 commit comments

Comments
 (0)