Skip to content

Commit 0e188d0

Browse files
committed
Merge commit '556eca47bd5a4a318a39bf03a1fd8ac9c0c926d8' into validation_helpers
2 parents f848260 + 556eca4 commit 0e188d0

Some content is hidden

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

44 files changed

+1003
-359
lines changed

libbitcoinkernel-sys/bitcoin/.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ jobs:
468468
file-env: './ci/test/00_setup_env_arm.sh'
469469
provider: 'gha'
470470

471-
- name: 'ASan + LSan + UBSan + integer'
471+
- name: 'ASan + LSan + UBSan + integer, no depends, USDT'
472472
cirrus-runner: 'ghcr.io/cirruslabs/ubuntu-runner-amd64:24.04-md' # has to match container in ci/test/00_setup_env_native_asan.sh for tracing tools
473473
fallback-runner: 'ubuntu-24.04'
474474
timeout-minutes: 120

libbitcoinkernel-sys/bitcoin/ci/test/00_setup_env_native_asan.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export NO_DEPENDS=1
2626
export GOAL="install"
2727
export CI_LIMIT_STACK_SIZE=1
2828
export BITCOIN_CONFIG="\
29-
--preset=dev-mode \
29+
-DWITH_USDT=ON -DWITH_ZMQ=ON -DBUILD_GUI=ON \
3030
-DSANITIZERS=address,float-divide-by-zero,integer,undefined \
3131
-DCMAKE_C_COMPILER=clang \
3232
-DCMAKE_CXX_COMPILER=clang++ \

libbitcoinkernel-sys/bitcoin/doc/i2p.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,3 @@ In most cases, the default router settings should work fine.
166166

167167
Please see the "General Guidance for Developers" section in https://geti2p.net/en/docs/api/samv3
168168
if you are developing a downstream application that may be bundling I2P with Bitcoin.
169-
170-
## Privacy recommendations
171-
172-
- Operating a node that listens on multiple networks (e.g. IPv4 and I2P) can help
173-
strengthen the Bitcoin network, as nodes in this configuration (i.e. bridge nodes) increase
174-
the cost and complexity of launching eclipse and partition attacks. However, under certain
175-
conditions, an adversary that can connect to your node on multiple networks may be
176-
able to correlate those identities by observing shared runtime characteristics. It
177-
is not recommended to expose your node over multiple networks if you require
178-
unlinkability across those identities.

libbitcoinkernel-sys/bitcoin/doc/tor.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,3 @@ for normal IPv4/IPv6 communication, use:
238238
Otherwise it is trivial to link them, which may reduce privacy. Onion
239239
services created automatically (as in section 2) always have only one port
240240
open.
241-
- Operating a node that listens on multiple networks (e.g. IPv4 and Tor) can help
242-
strengthen the Bitcoin network, as nodes in this configuration (i.e. bridge nodes) increase
243-
the cost and complexity of launching eclipse and partition attacks. However, under certain
244-
conditions, an adversary that can connect to your node on multiple networks may be
245-
able to correlate those identities by observing shared runtime characteristics. It
246-
is not recommended to expose your node over multiple networks if you require
247-
unlinkability across those identities.

libbitcoinkernel-sys/bitcoin/src/bench/connectblock.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <script/interpreter.h>
1010
#include <sync.h>
1111
#include <test/util/setup_common.h>
12+
#include <undo.h>
1213
#include <validation.h>
1314

1415
#include <cassert>
@@ -100,7 +101,9 @@ void BenchmarkConnectBlock(benchmark::Bench& bench, std::vector<CKey>& keys, std
100101
auto* pindex{chainman->m_blockman.AddToBlockIndex(test_block, chainman->m_best_header)}; // Doing this here doesn't impact the benchmark
101102
CCoinsViewCache viewNew{&chainstate.CoinsTip()};
102103

103-
assert(chainstate.ConnectBlock(test_block, test_block_state, pindex, viewNew));
104+
CBlockUndo blockundo;
105+
assert(chainstate.SpendBlock(test_block, pindex, viewNew, test_block_state, blockundo));
106+
assert(chainstate.ConnectBlock(test_block, blockundo, test_block_state, pindex));
104107
});
105108
}
106109

libbitcoinkernel-sys/bitcoin/src/bitcoin-chainstate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class TestValidationInterface : public ValidationInterface
4444

4545
std::optional<std::string> m_expected_valid_block = std::nullopt;
4646

47-
void BlockChecked(const Block block, const BlockValidationState state) override
47+
void BlockChecked(const Block block, const BlockValidationStateView state) override
4848
{
4949
auto mode{state.GetValidationMode()};
5050
switch (mode) {

libbitcoinkernel-sys/bitcoin/src/chain.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
#include <chain.h>
77
#include <tinyformat.h>
88
#include <util/check.h>
9+
#include <util/time.h>
10+
11+
std::string CBlockFileInfo::ToString() const
12+
{
13+
return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, FormatISO8601Date(nTimeFirst), FormatISO8601Date(nTimeLast));
14+
}
915

1016
std::string CBlockIndex::ToString() const
1117
{

libbitcoinkernel-sys/bitcoin/src/chain.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,47 @@ static constexpr int32_t SEQ_ID_INIT_FROM_DISK = 1;
4747
*/
4848
static constexpr int64_t MAX_BLOCK_TIME_GAP = 90 * 60;
4949

50+
class CBlockFileInfo
51+
{
52+
public:
53+
unsigned int nBlocks{}; //!< number of blocks stored in file
54+
unsigned int nSize{}; //!< number of used bytes of block file
55+
unsigned int nUndoSize{}; //!< number of used bytes in the undo file
56+
unsigned int nHeightFirst{}; //!< lowest height of block in file
57+
unsigned int nHeightLast{}; //!< highest height of block in file
58+
uint64_t nTimeFirst{}; //!< earliest time of block in file
59+
uint64_t nTimeLast{}; //!< latest time of block in file
60+
61+
SERIALIZE_METHODS(CBlockFileInfo, obj)
62+
{
63+
READWRITE(VARINT(obj.nBlocks));
64+
READWRITE(VARINT(obj.nSize));
65+
READWRITE(VARINT(obj.nUndoSize));
66+
READWRITE(VARINT(obj.nHeightFirst));
67+
READWRITE(VARINT(obj.nHeightLast));
68+
READWRITE(VARINT(obj.nTimeFirst));
69+
READWRITE(VARINT(obj.nTimeLast));
70+
}
71+
72+
CBlockFileInfo() = default;
73+
74+
std::string ToString() const;
75+
76+
/** update statistics (does not update nSize) */
77+
void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn)
78+
{
79+
if (nBlocks == 0 || nHeightFirst > nHeightIn)
80+
nHeightFirst = nHeightIn;
81+
if (nBlocks == 0 || nTimeFirst > nTimeIn)
82+
nTimeFirst = nTimeIn;
83+
nBlocks++;
84+
if (nHeightIn > nHeightLast)
85+
nHeightLast = nHeightIn;
86+
if (nTimeIn > nTimeLast)
87+
nTimeLast = nTimeIn;
88+
}
89+
};
90+
5091
enum BlockStatus : uint32_t {
5192
//! Unused.
5293
BLOCK_VALID_UNKNOWN = 0,

libbitcoinkernel-sys/bitcoin/src/coins.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,29 @@ const Coin& CCoinsViewCache::AccessCoin(const COutPoint &outpoint) const {
163163
}
164164
}
165165

166+
std::vector<std::reference_wrapper<const Coin>> CCoinsViewCache::AccessCoins(const CTransaction& tx) const
167+
{
168+
std::vector<std::reference_wrapper<const Coin>> coins;
169+
coins.reserve(tx.vin.size());
170+
for (const CTxIn& input : tx.vin) {
171+
coins.emplace_back(AccessCoin(input.prevout));
172+
}
173+
return coins;
174+
}
175+
176+
std::vector<CTxOut> CCoinsViewCache::GetUnspentOutputs(const CTransaction& tx) const
177+
{
178+
std::vector<CTxOut> spent_outputs;
179+
spent_outputs.reserve(tx.vin.size());
180+
for (const auto& txin : tx.vin) {
181+
const COutPoint& prevout = txin.prevout;
182+
const Coin& coin = AccessCoin(prevout);
183+
assert(!coin.IsSpent());
184+
spent_outputs.emplace_back(coin.out);
185+
}
186+
return spent_outputs;
187+
}
188+
166189
bool CCoinsViewCache::HaveCoin(const COutPoint &outpoint) const {
167190
CCoinsMap::const_iterator it = FetchCoin(outpoint);
168191
return (it != cacheCoins.end() && !it->second.coin.IsSpent());
@@ -349,8 +372,8 @@ void CCoinsViewCache::SanityCheck() const
349372
assert(recomputed_usage == cachedCoinsUsage);
350373
}
351374

352-
static const uint64_t MIN_TRANSACTION_OUTPUT_WEIGHT{WITNESS_SCALE_FACTOR * ::GetSerializeSize(CTxOut())};
353-
static const uint64_t MAX_OUTPUTS_PER_BLOCK{MAX_BLOCK_WEIGHT / MIN_TRANSACTION_OUTPUT_WEIGHT};
375+
static const size_t MIN_TRANSACTION_OUTPUT_WEIGHT = WITNESS_SCALE_FACTOR * ::GetSerializeSize(CTxOut());
376+
static const size_t MAX_OUTPUTS_PER_BLOCK = MAX_BLOCK_WEIGHT / MIN_TRANSACTION_OUTPUT_WEIGHT;
354377

355378
const Coin& AccessByTxid(const CCoinsViewCache& view, const Txid& txid)
356379
{

libbitcoinkernel-sys/bitcoin/src/coins.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,22 @@ class CCoinsViewCache : public CCoinsViewBacked
413413
*/
414414
const Coin& AccessCoin(const COutPoint &output) const;
415415

416+
/**
417+
* Return a vector of references to Coins in the cache, or coinEmpty if
418+
* the Coin is not found.
419+
*
420+
* Generally, this should only be held for a short scope. The coins should
421+
* generally not be held through any other calls to this cache.
422+
*/
423+
std::vector<std::reference_wrapper<const Coin>> AccessCoins(const CTransaction& tx) const;
424+
425+
/**
426+
* Return a vector of unspent outputs of coins in the cache that are spent
427+
* by the provided transaction. The coins they belong to must be unspent in
428+
* the cache.
429+
*/
430+
std::vector<CTxOut> GetUnspentOutputs(const CTransaction& tx) const;
431+
416432
/**
417433
* Add a coin. Set possible_overwrite to true if an unspent version may
418434
* already exist in the cache.

0 commit comments

Comments
 (0)