Skip to content

Commit bd7c9df

Browse files
Add deadpool feature
1 parent d02b33f commit bd7c9df

59 files changed

Lines changed: 4514 additions & 155 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Makefile.am

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ BITCOIN_CORE_H = \
145145
core_memusage.h \
146146
cuckoocache.h \
147147
dbwrapper.h \
148+
deadpool/announcedb.h \
149+
deadpool/deadpool.h \
150+
deadpool/index.h \
148151
deploymentinfo.h \
149152
deploymentstatus.h \
150153
external_signer.h \
@@ -156,6 +159,7 @@ BITCOIN_CORE_H = \
156159
index/base.h \
157160
index/blockfilterindex.h \
158161
index/coinstatsindex.h \
162+
index/deadpoolindex.h \
159163
index/disktxpos.h \
160164
index/txindex.h \
161165
indirectmap.h \
@@ -329,6 +333,7 @@ libbitcoin_server_a_SOURCES = \
329333
blockfilter.cpp \
330334
chain.cpp \
331335
consensus/tx_verify.cpp \
336+
deadpool/announcedb.cpp \
332337
dbwrapper.cpp \
333338
deploymentstatus.cpp \
334339
flatfile.cpp \
@@ -338,6 +343,7 @@ libbitcoin_server_a_SOURCES = \
338343
index/base.cpp \
339344
index/blockfilterindex.cpp \
340345
index/coinstatsindex.cpp \
346+
index/deadpoolindex.cpp \
341347
index/txindex.cpp \
342348
init.cpp \
343349
mapport.cpp \
@@ -360,6 +366,7 @@ libbitcoin_server_a_SOURCES = \
360366
pow.cpp \
361367
rest.cpp \
362368
rpc/blockchain.cpp \
369+
rpc/deadpool.cpp \
363370
rpc/mining.cpp \
364371
rpc/misc.cpp \
365372
rpc/net.cpp \
@@ -506,6 +513,8 @@ libbitcoin_consensus_a_SOURCES = \
506513
consensus/params.h \
507514
consensus/tx_check.cpp \
508515
consensus/validation.h \
516+
deadpool/deadpool.cpp \
517+
deadpool/deadpool.h \
509518
hash.cpp \
510519
hash.h \
511520
prevector.h \
@@ -515,6 +524,7 @@ libbitcoin_consensus_a_SOURCES = \
515524
primitives/transaction.h \
516525
pubkey.cpp \
517526
pubkey.h \
527+
script/bignum.h \
518528
script/bitcoinconsensus.cpp \
519529
script/interpreter.cpp \
520530
script/interpreter.h \

src/Makefile.test.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ BITCOIN_TESTS =\
8686
test/compress_tests.cpp \
8787
test/crypto_tests.cpp \
8888
test/cuckoocache_tests.cpp \
89+
test/deadpool_tests.cpp \
8990
test/denialofservice_tests.cpp \
9091
test/descriptor_tests.cpp \
9192
test/flatfile_tests.cpp \

src/bench/mempool_eviction.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ static void AddTx(const CTransactionRef& tx, const CAmount& nFee, CTxMemPool& po
1515
bool spendsCoinbase = false;
1616
unsigned int sigOpCost = 4;
1717
LockPoints lp;
18+
CAmount nBurnAmount = 0;
1819
pool.addUnchecked(CTxMemPoolEntry(
19-
tx, nFee, nTime, nHeight,
20+
tx, nFee, nBurnAmount, nTime, nHeight,
2021
spendsCoinbase, sigOpCost, lp));
2122
}
2223

src/bench/mempool_stress.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static void AddTx(const CTransactionRef& tx, CTxMemPool& pool) EXCLUSIVE_LOCKS_R
1616
bool spendsCoinbase = false;
1717
unsigned int sigOpCost = 4;
1818
LockPoints lp;
19-
pool.addUnchecked(CTxMemPoolEntry(tx, 1000, nTime, nHeight, spendsCoinbase, sigOpCost, lp));
19+
pool.addUnchecked(CTxMemPoolEntry(tx, 1000, 0, nTime, nHeight, spendsCoinbase, sigOpCost, lp));
2020
}
2121

2222
struct Available {

src/bench/rpc_mempool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
static void AddTx(const CTransactionRef& tx, const CAmount& fee, CTxMemPool& pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, pool.cs)
1313
{
1414
LockPoints lp;
15-
pool.addUnchecked(CTxMemPoolEntry(tx, fee, /* time */ 0, /* height */ 1, /* spendsCoinbase */ false, /* sigOpCost */ 4, lp));
15+
pool.addUnchecked(CTxMemPoolEntry(tx, fee, /* burned */ 0, /* time */ 0, /* height */ 1, /* spendsCoinbase */ false, /* sigOpCost */ 4, lp));
1616
}
1717

1818
static void RpcMempool(benchmark::Bench& bench)

src/chainparams.cpp

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class CMainParams : public CChainParams {
100100
consensus.nPowTargetSpacing = 30 * 60; // 30 Minutes * 60 Seconds |-> Seconds in 30 minutes
101101
consensus.fPowAllowMinDifficultyBlocks = false;
102102
consensus.fPowNoRetargeting = false;
103-
consensus.nRuleChangeActivationThreshold = 100;
103+
consensus.nRuleChangeActivationThreshold = 639; // 95% of 672 (rounded up from 638.4)
104104
consensus.nMinerConfirmationWindow = 672; // nPowTargetTimespan / nPowTargetSpacing
105105

106106
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
@@ -118,6 +118,17 @@ class CMainParams : public CChainParams {
118118
//Number of rounds for gHash to generate random Ws around which to search for semiprimes.
119119
consensus.hashRounds = 1;
120120

121+
// Deadpool softfork
122+
consensus.vDeployments[Consensus::DEPLOYMENT_DEADPOOL].bit = 27;
123+
consensus.vDeployments[Consensus::DEPLOYMENT_DEADPOOL].nStartTime = 1735689600LL; // 2025-01-01
124+
consensus.vDeployments[Consensus::DEPLOYMENT_DEADPOOL].nTimeout = 1748736000LL; // 2025-06-01
125+
consensus.vDeployments[Consensus::DEPLOYMENT_DEADPOOL].min_activation_height = 155000; // no delay
126+
127+
// Deadpool parametrization
128+
consensus.nDeadpoolAnnounceMaturity = 100;
129+
consensus.nDeadpoolAnnounceValidity = 672;
130+
consensus.nDeadpoolAnnounceMinBurn = 1000000; // 0.01 COIN
131+
121132
/**
122133
* The message start string is designed to be unlikely to occur in normal data.
123134
* The characters are rarely used upper ASCII, not valid as UTF-8, and produce
@@ -210,6 +221,17 @@ class CTestNetParams : public CChainParams {
210221
//Number of Miller-Rabin rounds, determines primality with false positive rate of 4^(-rounds).
211222
consensus.MillerRabinRounds = 50 ;
212223

224+
// Deadpool softfork
225+
consensus.vDeployments[Consensus::DEPLOYMENT_DEADPOOL].bit = 27;
226+
consensus.vDeployments[Consensus::DEPLOYMENT_DEADPOOL].nStartTime = 1735689600LL; // Jan 1st, 2025
227+
consensus.vDeployments[Consensus::DEPLOYMENT_DEADPOOL].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
228+
consensus.vDeployments[Consensus::DEPLOYMENT_DEADPOOL].min_activation_height = 0; // No activation delay
229+
230+
// Deadpool parametrization
231+
consensus.nDeadpoolAnnounceMaturity = 5;
232+
consensus.nDeadpoolAnnounceValidity = 100;
233+
consensus.nDeadpoolAnnounceMinBurn = 1000000; // 0.01 COIN
234+
213235
//Number of rounds for gHash to generate random Ws around which to search for semiprimes.
214236
consensus.hashRounds = 1;
215237

@@ -356,6 +378,17 @@ class SigNetParams : public CChainParams {
356378
//Number of rounds for gHash to generate random Ws around which to search for semiprimes.
357379
consensus.hashRounds = 1;
358380

381+
// Deadpool softfork
382+
consensus.vDeployments[Consensus::DEPLOYMENT_DEADPOOL].bit = 27;
383+
consensus.vDeployments[Consensus::DEPLOYMENT_DEADPOOL].nStartTime = 0;
384+
consensus.vDeployments[Consensus::DEPLOYMENT_DEADPOOL].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
385+
consensus.vDeployments[Consensus::DEPLOYMENT_DEADPOOL].min_activation_height = (4 * consensus.nMinerConfirmationWindow); // Add one more epoch than required
386+
387+
// Deadpool parametrization
388+
consensus.nDeadpoolAnnounceMaturity = 5;
389+
consensus.nDeadpoolAnnounceValidity = 100;
390+
consensus.nDeadpoolAnnounceMinBurn = 1000000; // 0.01 COIN
391+
359392
vFixedSeeds.clear();
360393
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
361394
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
@@ -397,8 +430,8 @@ class CRegTestParams : public CChainParams {
397430
consensus.nPowTargetSpacing = 30 * 60;
398431
consensus.fPowAllowMinDifficultyBlocks = true;
399432
consensus.fPowNoRetargeting = true;
400-
consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains
401-
consensus.nMinerConfirmationWindow = 144; // Faster than normal for regtest (144 instead of 2016)
433+
consensus.nRuleChangeActivationThreshold = 24; // 75% for testchains
434+
consensus.nMinerConfirmationWindow = 32; // Faster than normal for regtest (32 instead of 2016)
402435

403436
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
404437
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 0;
@@ -423,6 +456,17 @@ class CRegTestParams : public CChainParams {
423456
//Number of rounds for gHash to generate random Ws around which to search for semiprimes.
424457
consensus.hashRounds = 1;
425458

459+
// Deadpool softfork
460+
consensus.vDeployments[Consensus::DEPLOYMENT_DEADPOOL].bit = 27;
461+
consensus.vDeployments[Consensus::DEPLOYMENT_DEADPOOL].nStartTime = 0;
462+
consensus.vDeployments[Consensus::DEPLOYMENT_DEADPOOL].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
463+
consensus.vDeployments[Consensus::DEPLOYMENT_DEADPOOL].min_activation_height = (4 * consensus.nMinerConfirmationWindow); // Add one more epoch than required
464+
465+
// Deadpool parametrization
466+
consensus.nDeadpoolAnnounceMaturity = 5;
467+
consensus.nDeadpoolAnnounceValidity = 100;
468+
consensus.nDeadpoolAnnounceMinBurn = 1000000; // 0.01 COIN
469+
426470
UpdateActivationParametersFromArgs(args);
427471

428472
vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds.

src/consensus/params.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ constexpr bool ValidDeployment(BuriedDeployment dep) { return dep <= DEPLOYMENT_
2828

2929
enum DeploymentPos : uint16_t {
3030
DEPLOYMENT_TESTDUMMY,
31+
DEPLOYMENT_DEADPOOL,
3132
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in deploymentinfo.cpp
3233
MAX_VERSION_BITS_DEPLOYMENTS
3334
};
@@ -116,6 +117,17 @@ struct Params {
116117
//Number of rounds for gHash to generate random Ws around which to search for semiprimes.
117118
uint32_t hashRounds;
118119

120+
//// deadpool parameters ////
121+
122+
//! The number of blocks a deadpool announcement needs to mature
123+
uint16_t nDeadpoolAnnounceMaturity;
124+
//! The number of blocks a deadpool announcement is valid for
125+
uint16_t nDeadpoolAnnounceValidity;
126+
//! The minimum amount to burn on an announcement
127+
int64_t nDeadpoolAnnounceMinBurn;
128+
129+
int64_t DeadpoolAnnounceMaxAge() const { return nDeadpoolAnnounceMaturity + nDeadpoolAnnounceValidity; }
130+
119131
/**
120132
* If true, witness commitments contain a payload equal to a Bitcoin Script solution
121133
* to the signet challenge. See BIP325.

src/consensus/validation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ enum class TxValidationResult {
5353
*/
5454
TX_CONFLICT,
5555
TX_MEMPOOL_POLICY, //!< violated mempool's fee/size/descendant/RBF/etc limits
56+
TX_DEADPOOL_NO_ANNOUNCE, //!< No valid announcement could be found for a deadpool claim
5657
};
5758

5859
/** A "reason" why a block was invalid, suitable for determining whether the

src/deadpool/announcedb.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright (c) 2024 AUTHOR
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <deadpool/announcedb.h>
6+
7+
#include <deadpool/deadpool.h>
8+
#include <deadpool/index_common.h>
9+
#include <node/ui_interface.h>
10+
#include <uint256.h>
11+
#include <util/system.h>
12+
13+
#include <vector>
14+
#include <stdint.h>
15+
16+
static constexpr uint8_t DB_DEADPOOL_ANN{'a'};
17+
18+
CAnnounceDB::CAnnounceDB(size_t nCacheSize, bool fMemory, bool fWipe) : CDBWrapper(gArgs.GetDataDirNet() / "announcedb", nCacheSize, fMemory, fWipe) {}
19+
20+
bool CAnnounceDB::AddAnnouncements(const std::vector<CLocdAnnouncement> &list) {
21+
CDBBatch batch(*this);
22+
size_t count;
23+
24+
for (std::vector<CLocdAnnouncement>::const_iterator it=list.begin(); it != list.end(); it++) {
25+
const uint256 entry = it->announcement.NHash();
26+
LogPrint(BCLog::COINDB, "Added announcement (%s:%u) at height %d for entry %s to db.\n", it->locator.hash.GetHex(), it->locator.n, it->announcement.nHeight, entry.GetHex());
27+
const DeadpoolIndexKey key({DB_DEADPOOL_ANN, entry, it->locator});
28+
const CClaimValue value({it->announcement.nHeight, it->announcement.ClaimHash()});
29+
batch.Write(key, value);
30+
count++;
31+
}
32+
33+
bool ret = WriteBatch(batch);
34+
LogPrint(BCLog::COINDB, "Committed %u announcements to db.\n", count);
35+
return ret;
36+
}
37+
38+
bool CAnnounceDB::RemoveAnnouncements(const std::vector<CLocdAnnouncement> &list) {
39+
CDBBatch batch(*this);
40+
size_t count;
41+
42+
for (std::vector<CLocdAnnouncement>::const_iterator it=list.begin(); it != list.end(); it++) {
43+
const uint256 entry = it->announcement.NHash();
44+
LogPrint(BCLog::COINDB, "Removed announcement (%s:%u) for entry %s from db.\n", it->locator.hash.GetHex(), it->locator.n, entry.GetHex());
45+
const DeadpoolIndexKey key({DB_DEADPOOL_ANN, entry, it->locator});
46+
batch.Erase(key);
47+
count++;
48+
}
49+
50+
bool ret = WriteBatch(batch);
51+
LogPrint(BCLog::COINDB, "Removed %u announcements from db.\n", count);
52+
return ret;
53+
}
54+
55+
bool CAnnounceDB::ClaimExists(const uint256 &hash, const uint256 &claim, const int32_t minHeight, const int32_t maxHeight) const
56+
{
57+
std::unique_ptr<CDBIterator> pcursor(const_cast<CAnnounceDB&>(*this).NewIterator());
58+
59+
const DeadpoolIndexSearchKey searchKey({DB_DEADPOOL_ANN, hash});
60+
pcursor->Seek(searchKey);
61+
62+
while (pcursor->Valid()) {
63+
DeadpoolIndexKey key = {};
64+
CClaimValue value = {};
65+
66+
if (pcursor->GetKey(key) && key.type == DB_DEADPOOL_ANN && key.deadpoolId == hash) {
67+
if (pcursor->GetValue(value)) {
68+
if (value.height <= maxHeight && value.height >= minHeight && value.claimHash == claim) {
69+
LogPrint(BCLog::COINDB, "Found claim %s for entry %s: %s:%u.\n", claim.GetHex(), hash.GetHex(), key.locator.hash.GetHex(), key.locator.n);
70+
return true;
71+
}
72+
}
73+
pcursor->Next();
74+
} else {
75+
break;
76+
}
77+
}
78+
79+
return false;
80+
}

src/deadpool/announcedb.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) 2024 AUTHOR
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef FACTORN_ANNOUNCEDB_H
6+
#define FACTORN_ANNOUNCEDB_H
7+
8+
#include <deadpool/deadpool.h>
9+
#include <deadpool/index_common.h>
10+
#include <primitives/transaction.h> // for COutPoint
11+
#include <dbwrapper.h>
12+
#include <uint256.h>
13+
14+
#include <cstdint>
15+
#include <memory>
16+
#include <string>
17+
#include <utility>
18+
#include <vector>
19+
20+
//! maximum cache for announcedb in MiB
21+
static const int64_t nMaxAnnounceDbCache = 16;
22+
23+
class CClaimValue {
24+
public:
25+
int32_t height;
26+
uint256 claimHash;
27+
28+
SERIALIZE_METHODS(CClaimValue, obj) {
29+
READWRITE(obj.height);
30+
READWRITE(obj.claimHash);
31+
}
32+
};
33+
34+
class CAnnounceDB : public CDBWrapper
35+
{
36+
public:
37+
explicit CAnnounceDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
38+
39+
bool AddAnnouncements(const std::vector<CLocdAnnouncement> &list);
40+
bool RemoveAnnouncements(const std::vector<CLocdAnnouncement> &list);
41+
bool ClaimExists(const uint256 &hash, const uint256 &claim, const int32_t minHeight, const int32_t maxHeight) const;
42+
};
43+
44+
#endif // FACTORN_ANNOUNCEDB_H

0 commit comments

Comments
 (0)