25 #include "validation.h"
28 #include <boost/test/unit_test.hpp>
35 static SimpleUTXOMap BuildSimpleUtxoMap(
const std::vector<CTransaction>& txs)
38 for (
size_t i = 0; i < txs.size(); i++) {
40 for (
size_t j = 0; j < tx.
vout.size(); j++) {
41 utxos.emplace(std::piecewise_construct,
42 std::forward_as_tuple(tx.
GetHash(), j),
43 std::forward_as_tuple((
int)i + 1, tx.
vout[j].nValue));
54 std::vector<COutPoint> selectedUtxos;
57 while (!utxos.empty()) {
59 for (
auto it = utxos.begin(); it != utxos.end(); ++it) {
60 if (chainHeight - it->second.first < 100) {
65 selectedAmount += it->second.second;
66 selectedUtxos.emplace_back(it->first);
71 if (selectedAmount >= amount) {
72 changeRet = selectedAmount - amount;
83 auto inputs = SelectUTXOs(utxos, amount, change);
84 for (
size_t i = 0; i < inputs.size(); i++) {
85 tx.
vin.emplace_back(inputs[i]);
87 tx.
vout.emplace_back(
CTxOut(amount, scriptPayout));
89 tx.
vout.emplace_back(change, scriptChange);
98 for (
size_t i = 0; i < tx.
vin.size(); i++) {
112 const CScript& s = (scriptDest != nullopt ? *scriptDest
114 FundTransaction(mtx, utxos, s, s, amount);
115 SignTransaction(mtx, coinbaseKey);
117 for (
size_t i = 0; i < mtx.
vout.size() && idx < 0; i++) {
118 if (mtx.
vout[i].nValue == amount) idx = i;
124 static CKey GetRandomKey()
146 bool fInvalidCollateral =
false)
159 tx.
nType = CTransaction::TxType::PROREG;
160 FundTransaction(tx, utxos, scriptPayout,
162 (optCollateralOut ? 0 :
Params().GetConsensus().nMNCollateralAmt - (fInvalidCollateral ? 1 : 0)));
166 SignTransaction(tx, coinbaseKey);
174 auto inputs = SelectUTXOs(utxos, 1 * COIN, change);
183 tx.
nType = CTransaction::TxType::PROUPSERV;
185 FundTransaction(tx, utxos, s, s, 1 * COIN);
190 SignTransaction(tx, coinbaseKey);
198 auto inputs = SelectUTXOs(utxos, 1 * COIN, change);
208 tx.
nType = CTransaction::TxType::PROUPREG;
210 FundTransaction(tx, utxos, s, s, 1 * COIN);
214 SignTransaction(tx, coinbaseKey);
222 auto inputs = SelectUTXOs(utxos, 1 * COIN, change);
230 tx.
nType = CTransaction::TxType::PROUPREV;
232 FundTransaction(tx, utxos, s, s, 1 * COIN);
237 SignTransaction(tx, coinbaseKey);
242 static CScript GenerateRandomAddress()
249 template<
typename ProPL>
254 pl.scriptPayout = GenerateRandomAddress();
277 BOOST_ASSERT(pl.
nReason != ProUpRevPL::RevocationReason::REASON_CHANGE_OF_KEYS);
278 pl.
nReason = ProUpRevPL::RevocationReason::REASON_CHANGE_OF_KEYS;
286 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
287 const auto& txin = tx.
vin[i];
290 BOOST_ASSERT(
GetTransaction(txin.prevout.hash, txFrom, hashBlock));
292 CAmount amount = txFrom->vout[txin.prevout.n].nValue;
300 static bool IsMNPayeeInBlock(
const CBlock& block,
const CScript& expected)
302 for (
const auto& txout : block.
vtx[0]->vout) {
303 if (txout.scriptPubKey == expected)
return true;
308 static void CheckPayments(
const std::map<uint256, int>& mp,
size_t mapSize,
int minCount)
311 for (
const auto& it : mp) {
312 BOOST_CHECK_MESSAGE(it.second >= minCount,
313 strprintf(
"MN %s didn't receive expected num of payments (%d<%d)",it.first.ToString(), it.second, minCount)
322 auto utxos = BuildSimpleUtxoMap(coinbaseTxns);
327 int nHeight = chainTip->
nHeight;
333 CreateAndProcessBlock({}, coinbaseKey);
339 int64_t nTime =
GetTime() - 10;
346 std::vector<uint256> dmnHashes;
347 std::map<uint256, CKey> ownerKeys;
348 std::map<uint256, CBLSSecretKey> operatorKeys;
351 for (
size_t i = 0; i < 6; i++) {
354 auto tx = CreateProRegTx(nullopt, utxos, port++, GenerateRandomAddress(), coinbaseKey,
ownerKey,
operatorKey.GetPublicKey());
356 dmnHashes.emplace_back(txid);
368 auto tx2 = MalleateProTxPayout<ProRegPL>(tx);
374 CreateAndProcessBlock({tx}, coinbaseKey);
380 if (tx.
vout.size() > 1) {
393 std::map<uint256, int> mapPayments;
394 for (
size_t i = 0; i < 20; i++) {
400 auto dmnExpectedPayee = mnList.GetMNPayee();
401 CBlock block = CreateAndProcessBlock({}, coinbaseKey);
403 BOOST_ASSERT(!block.
vtx.empty());
404 BOOST_CHECK(IsMNPayeeInBlock(block, dmnExpectedPayee->pdmnState->scriptPayout));
405 mapPayments[dmnExpectedPayee->proTxHash]++;
409 CheckPayments(mapPayments, 6, 3);
415 auto tx = CreateProRegTx(o, utxos, port, GenerateRandomAddress(), coinbaseKey, GetRandomKey(), GetRandomBLSKey().GetPublicKey());
424 const COutPoint& coll_out = CreateNewUTXO(utxos, mtx, coinbaseKey,
Params().GetConsensus().nMNCollateralAmt-1);
425 CreateAndProcessBlock({mtx}, coinbaseKey);
433 auto tx = CreateProRegTx(
Optional<COutPoint>(coll_out), utxos, port, GenerateRandomAddress(), coinbaseKey, GetRandomKey(), GetRandomBLSKey().GetPublicKey());
439 utxos.emplace(coll_out, std::make_pair(coll_coin.
nHeight, coll_coin.
out.
nValue));
445 const COutPoint& coll_out = CreateNewUTXO(utxos, mtx, coinbaseKey,
Params().GetConsensus().nMNCollateralAmt);
446 CreateAndProcessBlock({mtx}, coinbaseKey);
455 spendTx.
vin.emplace_back(coll_out);
456 spendTx.
vout.emplace_back(
Params().GetConsensus().nMNCollateralAmt - 1000,
458 SignTransaction(spendTx, coinbaseKey);
459 CreateAndProcessBlock({spendTx}, coinbaseKey);
465 auto tx = CreateProRegTx(
Optional<COutPoint>(coll_out), utxos, port, GenerateRandomAddress(), coinbaseKey, GetRandomKey(), GetRandomBLSKey().GetPublicKey());
472 auto tx = CreateProRegTx(nullopt, utxos, port, GenerateRandomAddress(), coinbaseKey, GetRandomKey(), GetRandomBLSKey().GetPublicKey(), 0,
true);
479 const CKey& coll_key = GetRandomKey();
482 const COutPoint& coll_out = CreateNewUTXO(utxos, mtx, coinbaseKey,
Params().GetConsensus().nMNCollateralAmt,
484 CreateAndProcessBlock({mtx}, coinbaseKey);
492 auto tx = CreateProRegTx(
Optional<COutPoint>(coll_out), utxos, port, GenerateRandomAddress(), coinbaseKey, coll_key, GetRandomBLSKey().GetPublicKey());
499 const CKey&
ownerKey = ownerKeys.at(dmnHashes[InsecureRandRange(dmnHashes.size())]);
500 auto tx = CreateProRegTx(nullopt, utxos, port, GenerateRandomAddress(), coinbaseKey,
ownerKey, GetRandomBLSKey().GetPublicKey());
508 auto tx = CreateProRegTx(nullopt, utxos, port, GenerateRandomAddress(), coinbaseKey, GetRandomKey(),
operatorKey.GetPublicKey());
515 auto tx = CreateProRegTx(nullopt, utxos, 1 + InsecureRandRange(port-1), GenerateRandomAddress(), coinbaseKey, GetRandomKey(), GetRandomBLSKey().GetPublicKey());
525 auto tx1 = CreateProRegTx(nullopt, utxos, port, GenerateRandomAddress(), coinbaseKey,
ownerKey, operatorKey1.
GetPublicKey());
526 auto tx2 = CreateProRegTx(nullopt, utxos, (port+1), GenerateRandomAddress(), coinbaseKey,
ownerKey, operatorKey2.
GetPublicKey());
527 CBlock block = CreateBlock({tx1, tx2}, coinbaseKey);
529 indexFake.nHeight = nHeight;
530 indexFake.pprev = chainTip;
539 const CKey& ownerKey1 = GetRandomKey();
540 const CKey& ownerKey2 = GetRandomKey();
542 auto tx1 = CreateProRegTx(nullopt, utxos, port, GenerateRandomAddress(), coinbaseKey, ownerKey1,
operatorKey.GetPublicKey());
543 auto tx2 = CreateProRegTx(nullopt, utxos, (port+1), GenerateRandomAddress(), coinbaseKey, ownerKey2,
operatorKey.GetPublicKey());
544 CBlock block = CreateBlock({tx1, tx2}, coinbaseKey);
546 indexFake.nHeight = nHeight;
547 indexFake.pprev = chainTip;
556 auto tx1 = CreateProRegTx(nullopt, utxos, port, GenerateRandomAddress(), coinbaseKey, GetRandomKey(), GetRandomBLSKey().GetPublicKey());
557 auto tx2 = CreateProRegTx(nullopt, utxos, port, GenerateRandomAddress(), coinbaseKey, GetRandomKey(), GetRandomBLSKey().GetPublicKey());
558 CBlock block = CreateBlock({tx1, tx2}, coinbaseKey);
560 indexFake.nHeight = nHeight;
561 indexFake.pprev = chainTip;
570 for (
size_t i = 0; i < 3; i++) {
571 std::vector<CMutableTransaction> txns;
572 for (
size_t j = 0; j < 3; j++) {
575 auto tx = CreateProRegTx(nullopt, utxos, port++, GenerateRandomAddress(), coinbaseKey,
ownerKey,
operatorKey.GetPublicKey());
577 dmnHashes.emplace_back(txid);
584 txns.emplace_back(tx);
586 CreateAndProcessBlock(txns, coinbaseKey);
590 for (
size_t j = 0; j < 3; j++) {
599 for (
size_t i = 0; i < 30; i++) {
601 auto dmnExpectedPayee = mnList.GetMNPayee();
602 CBlock block = CreateAndProcessBlock({}, coinbaseKey);
604 BOOST_ASSERT(!block.
vtx.empty());
605 BOOST_CHECK(IsMNPayeeInBlock(block, dmnExpectedPayee->pdmnState->scriptPayout));
606 mapPayments[dmnExpectedPayee->proTxHash]++;
611 CheckPayments(mapPayments, 15, 2);
614 std::vector<CTxOut> vecMnOutsPrev;
616 std::vector<CTxOut> vecMnOutsNow;
621 CBlock invalidBlock = CreateBlock({}, coinbaseKey);
622 std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>(invalidBlock);
624 invalidCoinbaseTx.
vout.clear();
625 for (
const CTxOut& mnOut: vecMnOutsPrev) {
626 invalidCoinbaseTx.
vout.emplace_back(mnOut);
628 invalidCoinbaseTx.
vout.emplace_back(
631 pblock->vtx[0] = MakeTransactionRef(invalidCoinbaseTx);
641 const uint256& proTx = dmnHashes[InsecureRandRange(dmnHashes.size())];
642 auto tx = CreateProUpServTx(utxos, proTx, operatorKeys.at(proTx), 1000,
CScript(), coinbaseKey);
648 auto tx2 = MalleateProUpServTx(tx);
652 CreateAndProcessBlock({tx}, coinbaseKey);
657 BOOST_ASSERT(dmn !=
nullptr);
665 int randomIdx = InsecureRandRange(dmnHashes.size());
667 do { randomIdx2 = InsecureRandRange(dmnHashes.size()); }
while (randomIdx2 == randomIdx);
668 const uint256& proTx = dmnHashes[randomIdx];
669 int new_port =
deterministicMNManager->GetListAtChainTip().GetMN(dmnHashes[randomIdx2])->pdmnState->addr.GetPort();
671 auto tx = CreateProUpServTx(utxos, proTx, operatorKeys.at(proTx), new_port,
CScript(), coinbaseKey);
693 auto tx = CreateProRegTx(nullopt, utxos, port++, GenerateRandomAddress(), coinbaseKey,
ownerKey,
operatorKey.GetPublicKey(), 500);
695 CreateAndProcessBlock({tx}, coinbaseKey);
700 auto dmn = mnList.GetMN(txid);
701 BOOST_CHECK(dmn->pdmnState->scriptOperatorPayout.empty());
705 const CScript& operatorPayee = GenerateRandomAddress();
706 auto tx2 = CreateProUpServTx(utxos, txid,
operatorKey, (port-1), operatorPayee, coinbaseKey);
707 CreateAndProcessBlock({tx2}, coinbaseKey);
711 BOOST_ASSERT(dmn !=
nullptr);
712 BOOST_CHECK(dmn->pdmnState->scriptOperatorPayout == operatorPayee);
717 const CScript& operatorPayee = GenerateRandomAddress();
718 auto tx = CreateProUpServTx(utxos, dmnHashes[0], operatorKeys.at(dmnHashes[0]), 1, operatorPayee, coinbaseKey);
728 auto tx1 = CreateProRegTx(nullopt, utxos, port++, GenerateRandomAddress(), coinbaseKey, GetRandomKey(), GetRandomBLSKey().GetPublicKey());
729 const uint256& proTx = dmnHashes[InsecureRandRange(dmnHashes.size())];
730 auto tx2 = CreateProUpServTx(utxos, proTx, operatorKeys.at(proTx), (port-1),
CScript(), coinbaseKey);
731 CBlock block = CreateBlock({tx1, tx2}, coinbaseKey);
733 indexFake.nHeight = nHeight;
734 indexFake.pprev = chainTip;
744 const uint256& proTx = dmnHashes[InsecureRandRange(dmnHashes.size())];
746 const CKey& new_votingKey = GetRandomKey();
747 const CScript& new_payee = GenerateRandomAddress();
750 auto tx = CreateProUpRegTx(utxos, proTx, GetRandomKey(), new_operatorKey.
GetPublicKey(), new_votingKey, new_payee, coinbaseKey);
755 tx = CreateProUpRegTx(utxos, proTx, ownerKeys.at(proTx), new_operatorKey.
GetPublicKey(), new_votingKey, new_payee, coinbaseKey);
757 BOOST_CHECK_MESSAGE(CheckTransactionSignature(tx),
"ProUpReg signature verification failed");
759 auto tx2 = MalleateProTxPayout<ProUpRegPL>(tx);
763 CreateAndProcessBlock({tx}, coinbaseKey);
768 BOOST_ASSERT(dmn !=
nullptr);
769 BOOST_CHECK_MESSAGE(dmn->pdmnState->pubKeyOperator.Get() == new_operatorKey.
GetPublicKey(),
"mn operator key not changed");
770 BOOST_CHECK_MESSAGE(dmn->pdmnState->keyIDVoting == new_votingKey.
GetPubKey().
GetID(),
"mn voting key not changed");
771 BOOST_CHECK_MESSAGE(dmn->pdmnState->scriptPayout == new_payee,
"mn script payout not changed");
773 operatorKeys[proTx] = std::move(new_operatorKey);
776 BOOST_CHECK_MESSAGE(dmn->pdmnState->addr ==
CService(),
"IP address not cleared after changing operator");
777 BOOST_CHECK_MESSAGE(dmn->pdmnState->scriptOperatorPayout.empty(),
"operator payee not empty after changing operator");
782 auto tx3 = CreateProUpServTx(utxos, proTx, operatorKeys.at(proTx), 2000,
CScript(), coinbaseKey);
783 CreateAndProcessBlock({tx3}, coinbaseKey);
796 for (
size_t i = 0; i < 32; i++) {
798 CBlock block = CreateAndProcessBlock({}, coinbaseKey);
801 BOOST_ASSERT(!block.
vtx.empty());
802 BOOST_CHECK(IsMNPayeeInBlock(block, dmnExpectedPayee->pdmnState->scriptPayout));
803 mapPayments[dmnExpectedPayee->proTxHash]++;
806 CheckPayments(mapPayments, 16, 2);
811 const CKey& votingKey = GetRandomKey();
813 auto tx = CreateProUpRegTx(utxos,
GetRandHash(), GetRandomKey(),
operatorKey.GetPublicKey(), votingKey, GenerateRandomAddress(), coinbaseKey);
822 int randomIdx = InsecureRandRange(dmnHashes.size());
824 do { randomIdx2 = InsecureRandRange(dmnHashes.size()); }
while (randomIdx2 == randomIdx);
825 const uint256& proTx = dmnHashes[randomIdx];
826 const CBLSSecretKey& new_operatorKey = operatorKeys.at(dmnHashes[randomIdx2]);
828 auto tx = CreateProUpRegTx(utxos, proTx, ownerKeys.at(proTx), new_operatorKey.
GetPublicKey(), GetRandomKey(), GenerateRandomAddress(), coinbaseKey);
837 int randomIdx1 = InsecureRandRange(dmnHashes.size());
839 do { randomIdx2 = InsecureRandRange(dmnHashes.size()); }
while (randomIdx2 == randomIdx1);
840 const uint256& proTx1 = dmnHashes[randomIdx1];
841 const uint256& proTx2 = dmnHashes[randomIdx2];
842 BOOST_ASSERT(proTx1 != proTx2);
844 const CKey& new_votingKey = GetRandomKey();
845 const CScript& new_payee = GenerateRandomAddress();
846 auto tx1 = CreateProUpRegTx(utxos, proTx1, ownerKeys.at(proTx1), new_operatorKey.
GetPublicKey(), new_votingKey, new_payee, coinbaseKey);
847 auto tx2 = CreateProUpRegTx(utxos, proTx2, ownerKeys.at(proTx2), new_operatorKey.
GetPublicKey(), new_votingKey, new_payee, coinbaseKey);
848 CBlock block = CreateBlock({tx1, tx2}, coinbaseKey);
850 indexFake.nHeight = nHeight;
851 indexFake.pprev = chainTip;
854 "Accepted block with duplicate operator key in ProUpReg txes");
865 auto tx1 = CreateProRegTx(nullopt, utxos, port++, GenerateRandomAddress(), coinbaseKey, GetRandomKey(), new_operatorKey.
GetPublicKey());
866 const uint256& proTx = dmnHashes[InsecureRandRange(dmnHashes.size())];
867 auto tx2 = CreateProUpRegTx(utxos, proTx, ownerKeys.at(proTx), new_operatorKey.
GetPublicKey(), GetRandomKey(), GenerateRandomAddress(), coinbaseKey);
868 CBlock block = CreateBlock({tx1, tx2}, coinbaseKey);
870 indexFake.nHeight = nHeight;
871 indexFake.pprev = chainTip;
874 "Accepted block with duplicate operator key in ProReg+ProUpReg txes");
882 const uint256& proTx = dmnHashes[InsecureRandRange(dmnHashes.size())];
886 auto tx = CreateProUpRevTx(utxos, proTx, reason, GetRandomBLSKey(), coinbaseKey);
891 tx = CreateProUpRevTx(utxos, proTx, reason, operatorKeys.at(proTx), coinbaseKey);
893 BOOST_CHECK_MESSAGE(CheckTransactionSignature(tx),
"ProUpReg signature verification failed");
895 auto tx2 = MalleateProUpRevTx(tx);
899 CreateAndProcessBlock({tx}, coinbaseKey);
904 BOOST_ASSERT(dmn !=
nullptr);
905 BOOST_CHECK_MESSAGE(!dmn->pdmnState->pubKeyOperator.Get().IsValid(),
"mn operator key not removed");
906 BOOST_CHECK_MESSAGE(dmn->pdmnState->addr ==
CService(),
"mn IP address not removed");
907 BOOST_CHECK_MESSAGE(dmn->pdmnState->scriptOperatorPayout.empty(),
"mn operator payout not removed");
919 std::vector<CBLSSecretKey>& skeys,
922 size_t m = skeys.size();
923 BOOST_ASSERT(pkeys.size() == m);
928 BOOST_ASSERT(m <= (
size_t) params.size);
931 qfl.
signers.resize(params.size);
933 for (
size_t i = 0; i < (size_t) params.size; i++) {
948 std::vector<CBLSSignature> sigs;
949 for (
size_t i = 0; i < m; i++) {
950 sigs.emplace_back(skeys[i].Sign(commitmentHash));
965 tx.
nType = CTransaction::TxType::LLMQCOMM;
996 auto utxos = BuildSimpleUtxoMap(coinbaseTxns);
999 int nHeight = chainTip->
nHeight;
1003 CreateAndProcessBlock({}, coinbaseKey);
1009 int64_t nTime =
GetTime() - 10;
1016 std::vector<uint256> dmnHashes;
1017 std::map<uint256, CKey> ownerKeys;
1018 std::map<uint256, CBLSSecretKey> operatorKeys;
1021 for (
size_t i = 0; i < 6; i++) {
1024 auto tx = CreateProRegTx(nullopt, utxos, port++, GenerateRandomAddress(), coinbaseKey,
ownerKey,
operatorKey.GetPublicKey());
1026 dmnHashes.emplace_back(txid);
1029 CreateAndProcessBlock({tx}, coinbaseKey);
1041 for (
size_t i = 0; i < 20; i++) {
1042 CreateAndProcessBlock({}, coinbaseKey);
1050 uint256 quorumHash =
chainActive[nHeight - (nHeight % params.dkgInterval)]->GetBlockHash();
1055 std::vector<CBLSPublicKey> pkeys;
1056 std::vector<CBLSSecretKey> skeys;
1057 for (
size_t i = 0; i < members.size()-1; i++) {
1058 pkeys.emplace_back(members[i]->pdmnState->pubKeyOperator.Get());
1059 skeys.emplace_back(operatorKeys.at(members[i]->proTxHash));
1061 const uint256& invalidmn_proTx = members.back()->proTxHash;
1073 std::vector<CBLSPublicKey> allkeys(pkeys);
1074 allkeys.emplace_back(members.back()->pdmnState->pubKeyOperator.Get());
1085 CreateAndProcessBlock({}, coinbaseKey);
1107 auto pblock_invalid = std::make_shared<CBlock>(CreateBlock({nullQfcTx}, coinsbaseScript,
true,
false,
false));
1112 pblock_invalid = std::make_shared<CBlock>(
1113 CreateBlock({nullQfcTx}, coinsbaseScript,
true,
false,
false));
1117 CreateAndProcessBlock({}, coinbaseKey);
1123 pblock_invalid = std::make_shared<CBlock>(
1124 CreateBlock({nullQfcTx}, coinsbaseScript,
true,
false,
true));
1128 pblock_invalid = std::make_shared<CBlock>(CreateBlock({}, coinsbaseScript,
true,
false,
false));
1132 for (
int i = 0; i < 2; i++) {
1133 const auto& block = CreateBlock({nullQfcTx}, coinsbaseScript,
true,
false,
false);
1150 pblock_invalid = std::make_shared<CBlock>(CreateBlock({nullQfcTx}, coinsbaseScript,
true,
false,
false));
1155 pblock_invalid = std::make_shared<CBlock>(CreateBlock({nullQfcTx}, coinsbaseScript,
true,
false,
false));
1161 auto pblock_forked = std::make_shared<CBlock>(CreateBlock({}, coinsbaseScript,
true,
false,
false, pblock_419));
1163 pblock_forked->nNonce++;
1168 const auto it =
mapBlockIndex.find(pblock_forked->GetHash());
1175 pblock_invalid = std::make_shared<CBlock>(CreateBlock({nullQfcTx}, coinsbaseScript,
true,
false,
false));
1179 int old_quorum_hash_height = nHeight - (nHeight % params.dkgInterval) - params.cacheDkgInterval - params.dkgInterval;
1182 pblock_invalid = std::make_shared<CBlock>(CreateBlock({nullQfcTx}, coinsbaseScript,
true,
false,
false));
1186 auto old_qfc = CreateFinalCommitment(pkeys, skeys, old_quorum_hash);
1190 CreateAndProcessBlock({}, coinbaseKey);
1196 pblock_invalid = std::make_shared<CBlock>(CreateBlock({nullQfcTx}, coinsbaseScript,
true,
false,
false));
1214 CreateAndProcessBlock({}, coinbaseKey);
1221 for (
size_t i = 0; i < 8; i++) {
1222 CreateAndProcessBlock({}, coinbaseKey);
1227 quorumHash =
chainActive[nHeight - (nHeight % params.dkgInterval)]->GetBlockHash();
1232 for (
size_t i = 0; i < members.size(); i++) {
1233 pkeys.emplace_back(members[i]->pdmnState->pubKeyOperator.Get());
1234 skeys.emplace_back(operatorKeys.at(members[i]->proTxHash));
1236 std::vector<CBLSPublicKey> pkeys2(pkeys.begin(), pkeys.end()-1);
1237 std::vector<CBLSSecretKey> skeys2(skeys.begin(), skeys.end()-1);
1250 qfc = CreateFinalCommitment(pkeys, skeys, quorumHash);
1268 pblock_invalid = std::make_shared<CBlock>(CreateBlock({qtx}, coinsbaseScript,
true,
false,
false));
1272 for (
size_t i = 0; i < 8; i++) {
1273 CreateAndProcessBlock({}, coinbaseKey);
1278 auto pblock = std::make_shared<CBlock>(CreateBlock({nullQfcTx}, coinsbaseScript,
true,
false,
false));
1283 for (
size_t i = 0; i < 19; i++) {
1284 CreateAndProcessBlock({}, coinbaseKey);
1293 quorumHash =
chainActive[nHeight - (nHeight % params.dkgInterval)]->GetBlockHash();
1299 for (
size_t i = 0; i < members.size(); i++) {
1300 pkeys.emplace_back(members[i]->pdmnState->pubKeyOperator.Get());
1301 skeys.emplace_back(operatorKeys.at(members[i]->proTxHash));
1323 CreateAndProcessBlock({}, coinbaseKey);
int64_t CAmount
Amount in PIV (Can be negative)
CMutableTransaction CreateCoinbaseTx(const CScript &scriptPubKeyIn, CBlockIndex *pindexPrev)
bool SolveBlock(std::shared_ptr< CBlock > &pblock, int nHeight)
Modify the nonce/extranonce in a block.
void ProcessBlockAndCheckRejectionReason(std::shared_ptr< CBlock > &pblock, const std::string &blockRejectionReason, int expectedChainHeight)
void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivationHeight)
Allows modifying the network upgrade regtest parameters.
const CChainParams & Params()
Return the currently selected parameters.
A CService with information about it as peer.
void AggregateInsecure(const CBLSPublicKey &o)
CBLSPublicKey GetPublicKey() const
void AggregateInsecure(const CBLSSecretKey &o)
static CBLSSignature AggregateSecure(const std::vector< CBLSSignature > &sigs, const std::vector< CBLSPublicKey > &pks, const uint256 &hash)
Basic key store, that keeps keys in an address->secret map.
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
Add a key to the store.
std::vector< CTransactionRef > vtx
The block chain is a tree shaped structure starting with the genesis block at the root,...
CBlockIndex * pprev
pointer to the index of the predecessor of this block
uint256 GetBlockHash() const
int nHeight
height of the entry in the chain. The genesis block has height 0
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or nullptr if none.
int Height() const
Return the maximal height in the chain.
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
const Consensus::Params & GetConsensus() const
CCoinsView that adds a memory cache for transactions to another CCoinsView.
bool GetUTXOCoin(const COutPoint &outpoint, Coin &coin) const
Get the coin and check if it's spent.
static bool SignHash(const uint256 &hash, const CKey &key, std::vector< unsigned char > &vchSigRet)
Sign the hash, returns true if successful.
An encapsulated private key.
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
CPubKey GetPubKey() const
Compute the public key from a private key.
bool GetMasternodeTxOuts(const CBlockIndex *pindexPrev, std::vector< CTxOut > &voutMasternodePaymentsRet) const
Information about a peer.
An outpoint - a combination of a transaction hash and an index n into its vout.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Serialized script, used inside transaction inputs and outputs.
A combination of a network address (CNetAddr) and a (TCP) port.
bool IsSporkActive(SporkId nSporkID)
void AddOrUpdateSporkMessage(const CSporkMessage &spork, bool flush=false)
An output of a transaction.
Capture information about block/transaction validation.
std::string GetRejectReason() const
CTxOut out
unspent transaction output
uint32_t nHeight
at which height the containing transaction was included in the active block chain
COutPoint collateralOutpoint
CBLSPublicKey pubKeyOperator
std::vector< unsigned char > vchSig
CBLSPublicKey pubKeyOperator
CScript scriptOperatorPayout
void SetCurrentSyncPhase(int sync_phase)
bool Verify(const std::vector< CBLSPublicKey > &allkeys, const Consensus::LLMQParams ¶ms) const
CBLSPublicKey quorumPublicKey
std::vector< bool > validMembers
std::vector< bool > signers
void ProcessMessage(CNode *pfrom, CDataStream &vRecv, int &retMisbehavingScore)
CFinalCommitment commitment
BOOST_AUTO_TEST_SUITE(cuckoocache_tests)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
std::unique_ptr< CDeterministicMNManager > deterministicMNManager
BOOST_FIXTURE_TEST_CASE(dip3_protx, TestChain400Setup)
CMutableTransaction CreateNullQfcTx(const uint256 &quorumHash, int nHeight)
std::map< COutPoint, std::pair< int, CAmount > > SimpleUTXOMap
CMutableTransaction CreateQfcTx(const uint256 &quorumHash, int nHeight, Optional< llmq::CFinalCommitment > opt_qfc)
uint256 SerializeHash(const T &obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
Compute the 256-bit hash of an object's serialization.
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, unsigned int flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptError *serror)
CMasternodePayments masternodePayments
Object for who's going to get paid on which blocks.
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
UniValue spork(const JSONRPCRequest &request)
uint256 BuildCommitmentHash(Consensus::LLMQType llmqType, const uint256 &blockHash, const std::vector< bool > &validMembers, const CBLSPublicKey &pubKey, const uint256 &vvecHash)
std::unique_ptr< CQuorumBlockProcessor > quorumBlockProcessor
RecursiveMutex cs_main
Global state.
CService LookupNumeric(const std::string &name, int portDefault)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
boost::optional< T > Optional
Substitute for C++17 std::optional.
uint256 GetRandHash() noexcept
bool SignSignature(const CKeyStore &keystore, const CScript &fromPubKey, CMutableTransaction &txTo, unsigned int nIn, const CAmount &amount, int nHashType, bool fColdStake)
Produce a script signature for a transaction.
bool VerifyLLMQCommitment(const llmq::CFinalCommitment &qfc, const CBlockIndex *pindexPrev, CValidationState &state)
bool CheckSpecialTx(const CTransaction &tx, const CBlockIndex *pindexPrev, const CCoinsViewCache *view, CValidationState &state)
Payload validity checks (including duplicate unique properties against list at pindexPrev)
uint256 CalcTxInputsHash(const CTransaction &tx)
bool ProcessSpecialTxsInBlock(const CBlock &block, const CBlockIndex *pindex, const CCoinsViewCache *view, CValidationState &state, bool fJustCheck)
CSporkManager sporkManager
@ SPORK_22_LLMQ_DKG_MAINTENANCE
@ SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT
@ SPORK_21_LEGACY_MNS_MAX_HEIGHT
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a PIVX scriptPubKey for the given CTxDestination.
A mutable version of CTransaction.
uint256 GetHash() const
Compute the hash of this CMutableTransaction.
SigVersion GetRequiredSigVersion() const
std::vector< CTxOut > vout
static constexpr int NO_ACTIVATION_HEIGHT
Special value for nActivationHeight indicating that the upgrade will never activate.
std::map< LLMQType, LLMQParams > llmqs
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
TierTwoSyncState g_tiertwo_sync_state
#define MASTERNODE_SYNC_FINISHED
void SetTxPayload(CMutableTransaction &tx, const T &payload)
bool GetTxPayload(const std::vector< unsigned char > &payload, T &obj)
std::shared_ptr< const CTransaction > CTransactionRef
const uint256 UINT256_ZERO
constant uint256 instances
const uint256 UINT256_ONE
int64_t GetTime()
DEPRECATED Use either GetSystemTimeInSeconds (not mockable) or GetTime<T> (mockable)
bool GetTransaction(const uint256 &hash, CTransactionRef &txOut, uint256 &hashBlock, bool fAllowSlow, CBlockIndex *blockIndex)
Return transaction in tx, and if it was found inside a block, its hash is placed in hashBlock.
CTxMemPool mempool(::minRelayTxFee)
bool ProcessNewBlock(const std::shared_ptr< const CBlock > &pblock, const FlatFilePos *dbp)
Process an incoming block.
std::unique_ptr< CCoinsViewCache > pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
int64_t GetMasternodePayment(int nHeight)
CAmount GetBlockValue(int nHeight)
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree, bool *pfMissingInputs, bool fOverrideMempoolLimit, bool fRejectInsaneFee, bool ignoreFees)
(try to) add transaction to memory pool
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).