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
6 changes: 5 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,11 @@ void SetupServerArgs(ArgsManager& argsman)
argsman.AddArg("-incrementalrelayfee=<amt>", strprintf("Fee rate (in %s/kB) used to define cost of relay, used for mempool limiting. (default: %s)", CURRENCY_UNIT, FormatMoney(DEFAULT_INCREMENTAL_RELAY_FEE)), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::NODE_RELAY);
argsman.AddArg("-bytespersigop", strprintf("Equivalent bytes per sigop in transactions for relay and mining (default: %u)", DEFAULT_BYTES_PER_SIGOP), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
argsman.AddArg("-datacarrier", strprintf("Relay and mine data carrier transactions (default: %u)", DEFAULT_ACCEPT_DATACARRIER), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
argsman.AddArg("-datacarriersize", strprintf("Maximum size of data in data carrier transactions we relay and mine (default: %u)", MAX_OP_RETURN_RELAY), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
argsman.AddArg("-datacarriersize",
strprintf("Relay and mine transactions whose data-carrying raw scriptPubKey "
"is of this size or less (default: %u)",
MAX_OP_RETURN_RELAY),
ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
argsman.AddArg("-permitbaremultisig", strprintf("Relay non-P2SH multisig (default: %u)", DEFAULT_PERMIT_BAREMULTISIG), ArgsManager::ALLOW_ANY,
OptionsCategory::NODE_RELAY);
argsman.AddArg("-minrelaytxfee=<amt>", strprintf("Fees (in %s/kB) smaller than this are considered zero fee for relaying, mining and transaction creation (default: %s)",
Expand Down
12 changes: 6 additions & 6 deletions src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ CBlockFileInfo* BlockManager::GetBlockFileInfo(size_t n)
return &m_blockfile_info.at(n);
}

static bool UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const uint256& hashBlock, const CMessageHeader::MessageStartChars& messageStart)
static bool UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const uint256& hashBlock)
{
// Open history file to append
CAutoFile fileout(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION);
Expand All @@ -494,7 +494,7 @@ static bool UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const

// Write index header
unsigned int nSize = GetSerializeSize(blockundo, fileout.GetVersion());
fileout << messageStart << nSize;
fileout << GetParams().MessageStart() << nSize;

// Write undo data
long fileOutPos = ftell(fileout.Get());
Expand Down Expand Up @@ -692,7 +692,7 @@ bool BlockManager::FindUndoPos(BlockValidationState& state, int nFile, FlatFileP
return true;
}

static bool WriteBlockToDisk(const CBlock& block, FlatFilePos& pos, const CMessageHeader::MessageStartChars& messageStart)
static bool WriteBlockToDisk(const CBlock& block, FlatFilePos& pos)
{
// Open history file to append
CAutoFile fileout(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
Expand All @@ -702,7 +702,7 @@ static bool WriteBlockToDisk(const CBlock& block, FlatFilePos& pos, const CMessa

// Write index header
unsigned int nSize = GetSerializeSize(block, fileout.GetVersion());
fileout << messageStart << nSize;
fileout << GetParams().MessageStart() << nSize;

// Write block
long fileOutPos = ftell(fileout.Get());
Expand All @@ -724,7 +724,7 @@ bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValid
if (!FindUndoPos(state, pindex->nFile, _pos, ::GetSerializeSize(blockundo, CLIENT_VERSION) + 40)) {
return error("ConnectBlock(): FindUndoPos failed");
}
if (!UndoWriteToDisk(blockundo, _pos, pindex->pprev->GetBlockHash(), chainparams.MessageStart())) {
if (!UndoWriteToDisk(blockundo, _pos, pindex->pprev->GetBlockHash())) {
return AbortNode(state, "Failed to write undo data");
}
// rev files are written in block height order, whereas blk files are written as blocks come in (often out of order)
Expand Down Expand Up @@ -802,7 +802,7 @@ FlatFilePos BlockManager::SaveBlockToDisk(const CBlock& block, int nHeight, CCha
return FlatFilePos();
}
if (!position_known) {
if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) {
if (!WriteBlockToDisk(block, blockPos)) {
AbortNode("Failed to write block");
return FlatFilePos();
}
Expand Down
10 changes: 4 additions & 6 deletions src/rpc/mempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,15 @@ UniValue MempoolToJSON(const CTxMemPool& pool, const llmq::CInstantSendManager*
}
return o;
} else {
UniValue a(UniValue::VARR);
uint64_t mempool_sequence;
std::vector<uint256> vtxid;
{
LOCK(pool.cs);
pool.queryHashes(vtxid);
for (const CTxMemPoolEntry& e : pool.entryAll()) {
a.push_back(e.GetTx().GetHash().ToString());
}
mempool_sequence = pool.GetSequence();
}
UniValue a(UniValue::VARR);
for (const uint256& hash : vtxid)
a.push_back(hash.ToString());

if (!include_mempool_sequence) {
return a;
} else {
Expand Down
4 changes: 1 addition & 3 deletions src/test/fuzz/tx_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ void Finish(FuzzedDataProvider& fuzzed_data_provider, MockedTxPool& tx_pool, con
if (!info_all.empty()) {
const auto& tx_to_remove = *PickValue(fuzzed_data_provider, info_all).tx;
WITH_LOCK(tx_pool.cs, tx_pool.removeRecursive(tx_to_remove, MemPoolRemovalReason::BLOCK /* dummy */));
std::vector<uint256> all_txids;
tx_pool.queryHashes(all_txids);
assert(all_txids.size() < info_all.size());
assert(tx_pool.size() < info_all.size());
WITH_LOCK(::cs_main, tx_pool.check(chainstate.CoinsTip(), chainstate.m_chain.Height() + 1));
}
SyncWithValidationInterfaceQueue();
Expand Down
13 changes: 0 additions & 13 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,19 +1283,6 @@ std::vector<CTxMemPool::indexed_transaction_set::const_iterator> CTxMemPool::Get
return iters;
}

void CTxMemPool::queryHashes(std::vector<uint256>& vtxid) const
{
LOCK(cs);
auto iters = GetSortedDepthAndScore();

vtxid.clear();
vtxid.reserve(mapTx.size());

for (auto it : iters) {
vtxid.push_back(it->GetTx().GetHash());
}
}

static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it) {
return TxMempoolInfo{it->GetSharedTx(), it->GetTime(), it->GetFee(), it->GetTxSize(), it->GetModifiedFee() - it->GetFee()};
}
Expand Down
1 change: 0 additions & 1 deletion src/txmempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,6 @@ class CTxMemPool
void clear();
void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs); //lock free
bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb);
void queryHashes(std::vector<uint256>& vtxid) const;
bool isSpent(const COutPoint& outpoint) const;
unsigned int GetTransactionsUpdated() const;
void AddTransactionsUpdated(unsigned int n);
Expand Down
30 changes: 26 additions & 4 deletions test/functional/mempool_datacarrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@

class DataCarrierTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 3
self.num_nodes = 4
self.extra_args = [
[],
["-datacarrier=0"],
["-datacarrier=1", f"-datacarriersize={MAX_OP_RETURN_RELAY - 1}"]
["-datacarrier=1", f"-datacarriersize={MAX_OP_RETURN_RELAY - 1}"],
["-datacarrier=1", f"-datacarriersize=2"],
]

def test_null_data_transaction(self, node: TestNode, data: bytes, success: bool) -> None:
def test_null_data_transaction(self, node: TestNode, data, success: bool) -> None:
tx = self.wallet.create_self_transfer(fee_rate=0)["tx"]
tx.vout.append(CTxOut(nValue=0, scriptPubKey=CScript([OP_RETURN, data])))
data = [] if data is None else [data]
tx.vout.append(CTxOut(nValue=0, scriptPubKey=CScript([OP_RETURN] + data)))
tx.vout[0].nValue -= tx.get_vsize() # simply pay 1sat/vbyte fee

tx_hex = tx.serialize().hex()
Expand All @@ -50,6 +52,8 @@ def run_test(self):
default_size_data = random_bytes(MAX_OP_RETURN_RELAY - 3)
too_long_data = random_bytes(MAX_OP_RETURN_RELAY - 2)
small_data = random_bytes(MAX_OP_RETURN_RELAY - 4)
one_byte = random_bytes(1)
zero_bytes = random_bytes(0)

self.log.info("Testing null data transaction with default -datacarrier and -datacarriersize values.")
self.test_null_data_transaction(node=self.nodes[0], data=default_size_data, success=True)
Expand All @@ -66,6 +70,24 @@ def run_test(self):
self.log.info("Testing a null data transaction with a size smaller than accepted by -datacarriersize.")
self.test_null_data_transaction(node=self.nodes[2], data=small_data, success=True)

self.log.info("Testing a null data transaction with no data.")
self.test_null_data_transaction(node=self.nodes[0], data=None, success=True)
self.test_null_data_transaction(node=self.nodes[1], data=None, success=False)
self.test_null_data_transaction(node=self.nodes[2], data=None, success=True)
self.test_null_data_transaction(node=self.nodes[3], data=None, success=True)

self.log.info("Testing a null data transaction with zero bytes of data.")
self.test_null_data_transaction(node=self.nodes[0], data=zero_bytes, success=True)
self.test_null_data_transaction(node=self.nodes[1], data=zero_bytes, success=False)
self.test_null_data_transaction(node=self.nodes[2], data=zero_bytes, success=True)
self.test_null_data_transaction(node=self.nodes[3], data=zero_bytes, success=True)

self.log.info("Testing a null data transaction with one byte of data.")
self.test_null_data_transaction(node=self.nodes[0], data=one_byte, success=True)
self.test_null_data_transaction(node=self.nodes[1], data=one_byte, success=False)
self.test_null_data_transaction(node=self.nodes[2], data=one_byte, success=True)
self.test_null_data_transaction(node=self.nodes[3], data=one_byte, success=False)


if __name__ == '__main__':
DataCarrierTest().main()
Loading