Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gruve-p committed Nov 28, 2023
2 parents cea6080 + fe4e83f commit 1d0f460
Show file tree
Hide file tree
Showing 78 changed files with 522 additions and 469 deletions.
2 changes: 1 addition & 1 deletion ci/test/00_setup_env_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export SDK_URL=${SDK_URL:-https://bitcoincore.org/depends-sources/sdks}
export CONTAINER_NAME=ci_macos_cross
export CI_IMAGE_NAME_TAG="docker.io/ubuntu:22.04"
export HOST=x86_64-apple-darwin
export PACKAGES="cmake libz-dev python3-setuptools zip"
export PACKAGES="cmake libz-dev zip"
export XCODE_VERSION=12.2
export XCODE_BUILD_ID=12B45b
export RUN_UNIT_TESTS=false
Expand Down
2 changes: 1 addition & 1 deletion depends/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The paths are automatically configured and no other options are needed unless ta

#### For macOS cross compilation

sudo apt-get install curl bsdmainutils cmake libz-dev python3-setuptools zip
sudo apt-get install curl bsdmainutils cmake libz-dev zip

Note: You must obtain the macOS SDK before proceeding with a cross-compile.
Under the depends directory, create a subdirectory named `SDKs`.
Expand Down
2 changes: 1 addition & 1 deletion src/bench/disconnected_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct ReorgTxns {
static BlockTxns CreateRandomTransactions(size_t num_txns)
{
// Ensure every transaction has a different txid by having each one spend the previous one.
static uint256 prevout_hash{uint256::ZERO};
static Txid prevout_hash{};

BlockTxns txns;
txns.reserve(num_txns);
Expand Down
2 changes: 1 addition & 1 deletion src/bench/duplicate_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static void DuplicateInputs(benchmark::Bench& bench)

uint64_t n_inputs = (((MAX_BLOCK_SERIALIZED_SIZE / WITNESS_SCALE_FACTOR) - (CTransaction(coinbaseTx).GetTotalSize() + CTransaction(naughtyTx).GetTotalSize())) / 41) - 100;
for (uint64_t x = 0; x < (n_inputs - 1); ++x) {
naughtyTx.vin.emplace_back(GetRandHash(), 0, CScript(), 0);
naughtyTx.vin.emplace_back(Txid::FromUint256(GetRandHash()), 0, CScript(), 0);
}
naughtyTx.vin.emplace_back(naughtyTx.vin.back());

Expand Down
2 changes: 1 addition & 1 deletion src/bench/mempool_stress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static std::vector<CTransactionRef> CreateOrderedCoins(FastRandomContext& det_ra
for (size_t ancestor = 0; ancestor < n_ancestors && !available_coins.empty(); ++ancestor){
size_t idx = det_rand.randrange(available_coins.size());
Available coin = available_coins[idx];
uint256 hash = coin.ref->GetHash();
Txid hash = coin.ref->GetHash();
// biased towards taking min_ancestors parents, but maybe more
size_t n_to_take = det_rand.randrange(2) == 0 ?
min_ancestors :
Expand Down
15 changes: 6 additions & 9 deletions src/blockfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
#include <util/golombrice.h>
#include <util/string.h>

/// Protocol version used to serialize parameters in GCS filter encoding.
static constexpr int GCS_SER_VERSION = 0;

static const std::map<BlockFilterType, std::string> g_filter_types = {
{BlockFilterType::BASIC, "basic"},
};
Expand Down Expand Up @@ -49,7 +46,7 @@ GCSFilter::GCSFilter(const Params& params)
GCSFilter::GCSFilter(const Params& params, std::vector<unsigned char> encoded_filter, bool skip_decode_check)
: m_params(params), m_encoded(std::move(encoded_filter))
{
SpanReader stream{GCS_SER_VERSION, m_encoded};
SpanReader stream{m_encoded};

uint64_t N = ReadCompactSize(stream);
m_N = static_cast<uint32_t>(N);
Expand All @@ -62,7 +59,7 @@ GCSFilter::GCSFilter(const Params& params, std::vector<unsigned char> encoded_fi

// Verify that the encoded filter contains exactly N elements. If it has too much or too little
// data, a std::ios_base::failure exception will be raised.
BitStreamReader<SpanReader> bitreader{stream};
BitStreamReader bitreader{stream};
for (uint64_t i = 0; i < m_N; ++i) {
GolombRiceDecode(bitreader, m_params.m_P);
}
Expand All @@ -81,15 +78,15 @@ GCSFilter::GCSFilter(const Params& params, const ElementSet& elements)
}
m_F = static_cast<uint64_t>(m_N) * static_cast<uint64_t>(m_params.m_M);

CVectorWriter stream(GCS_SER_VERSION, m_encoded, 0);
VectorWriter stream{m_encoded, 0};

WriteCompactSize(stream, m_N);

if (elements.empty()) {
return;
}

BitStreamWriter<CVectorWriter> bitwriter(stream);
BitStreamWriter bitwriter{stream};

uint64_t last_value = 0;
for (uint64_t value : BuildHashedSet(elements)) {
Expand All @@ -103,13 +100,13 @@ GCSFilter::GCSFilter(const Params& params, const ElementSet& elements)

bool GCSFilter::MatchInternal(const uint64_t* element_hashes, size_t size) const
{
SpanReader stream{GCS_SER_VERSION, m_encoded};
SpanReader stream{m_encoded};

// Seek forward by size of N
uint64_t N = ReadCompactSize(stream);
assert(N == m_N);

BitStreamReader<SpanReader> bitreader{stream};
BitStreamReader bitreader{stream};

uint64_t value = 0;
size_t hashes_index = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/coins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void CCoinsViewCache::EmplaceCoinInternalDANGER(COutPoint&& outpoint, Coin&& coi

void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool check_for_overwrite) {
bool fCoinbase = tx.IsCoinBase();
const uint256& txid = tx.GetHash();
const Txid& txid = tx.GetHash();
for (size_t i = 0; i < tx.vout.size(); ++i) {
bool overwrite = check_for_overwrite ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase;
// Coinbase transactions can always be overwritten, in order to correctly
Expand Down Expand Up @@ -341,7 +341,7 @@ void CCoinsViewCache::SanityCheck() const
static const size_t MIN_TRANSACTION_OUTPUT_WEIGHT = WITNESS_SCALE_FACTOR * ::GetSerializeSize(CTxOut());
static const size_t MAX_OUTPUTS_PER_BLOCK = MAX_BLOCK_WEIGHT / MIN_TRANSACTION_OUTPUT_WEIGHT;

const Coin& AccessByTxid(const CCoinsViewCache& view, const uint256& txid)
const Coin& AccessByTxid(const CCoinsViewCache& view, const Txid& txid)
{
COutPoint iter(txid, 0);
while (iter.n < MAX_OUTPUTS_PER_BLOCK) {
Expand Down
2 changes: 1 addition & 1 deletion src/coins.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ void AddCoins(CCoinsViewCache& cache, const CTransaction& tx, int nHeight, bool
//! This function can be quite expensive because in the event of a transaction
//! which is not found in the cache, it can cause up to MAX_OUTPUTS_PER_BLOCK
//! lookups to database, so it should be used with care.
const Coin& AccessByTxid(const CCoinsViewCache& cache, const uint256& txid);
const Coin& AccessByTxid(const CCoinsViewCache& cache, const Txid& txid);

/**
* This is a minimally invasive approach to shutdown on LevelDB read errors from the
Expand Down
4 changes: 2 additions & 2 deletions src/common/bloom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ bool CBloomFilter::IsRelevantAndUpdate(const CTransaction& tx)
// for finding tx when they appear in a block
if (vData.empty()) // zero-size = "match-all" filter
return true;
const uint256& hash = tx.GetHash();
if (contains(hash))
const Txid& hash = tx.GetHash();
if (contains(hash.ToUint256()))
fFound = true;

for (unsigned int i = 0; i < tx.vout.size(); i++)
Expand Down
2 changes: 1 addition & 1 deletion src/external_signer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ UniValue ExternalSigner::GetDescriptors(const int account)
bool ExternalSigner::SignTransaction(PartiallySignedTransaction& psbtx, std::string& error)
{
// Serialize the PSBT
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
DataStream ssTx{};
ssTx << psbtx;
// parse ExternalSigner master fingerprint
std::vector<unsigned char> parsed_m_fingerprint = ParseHex(m_fingerprint);
Expand Down
4 changes: 2 additions & 2 deletions src/groestlcoin-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInpu
}

// append to transaction input list
CTxIn txin(txid, vout, CScript(), nSequenceIn);
CTxIn txin(Txid::FromUint256(txid), vout, CScript(), nSequenceIn);
tx.vin.push_back(txin);
}

Expand Down Expand Up @@ -634,7 +634,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
if (nOut < 0)
throw std::runtime_error("vout cannot be negative");

COutPoint out(txid, nOut);
COutPoint out(Txid::FromUint256(txid), nOut);
std::vector<unsigned char> pkData(ParseHexUV(prevOut["scriptPubKey"], "scriptPubKey"));
CScript scriptPubKey(pkData.begin(), pkData.end());

Expand Down
4 changes: 2 additions & 2 deletions src/kernel/coinstats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static void ApplyCoinHash(std::nullptr_t, const COutPoint& outpoint, const Coin&
//! construction could cause a previously invalid (and potentially malicious)
//! UTXO snapshot to be considered valid.
template <typename T>
static void ApplyHash(T& hash_obj, const uint256& hash, const std::map<uint32_t, Coin>& outputs)
static void ApplyHash(T& hash_obj, const Txid& hash, const std::map<uint32_t, Coin>& outputs)
{
for (auto it = outputs.begin(); it != outputs.end(); ++it) {
COutPoint outpoint = COutPoint(hash, it->first);
Expand Down Expand Up @@ -118,7 +118,7 @@ static bool ComputeUTXOStats(CCoinsView* view, CCoinsStats& stats, T hash_obj, c
std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor());
assert(pcursor);

uint256 prevkey;
Txid prevkey;
std::map<uint32_t, Coin> outputs;
while (pcursor->Valid()) {
if (interruption_point) interruption_point();
Expand Down
31 changes: 15 additions & 16 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,8 @@ bool CNode::ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete)
return true;
}

V1Transport::V1Transport(const NodeId node_id, int nTypeIn, int nVersionIn) noexcept :
m_magic_bytes{Params().MessageStart()}, m_node_id(node_id), hdrbuf(nTypeIn, nVersionIn), vRecv(nTypeIn, nVersionIn)
V1Transport::V1Transport(const NodeId node_id) noexcept
: m_magic_bytes{Params().MessageStart()}, m_node_id{node_id}
{
LOCK(m_recv_mutex);
Reset();
Expand Down Expand Up @@ -819,7 +819,7 @@ bool V1Transport::SetMessageToSend(CSerializedNetMsg& msg) noexcept

// serialize header
m_header_to_send.clear();
CVectorWriter{INIT_PROTO_VERSION, m_header_to_send, 0, hdr};
VectorWriter{m_header_to_send, 0, hdr};

// update state
m_message_to_send = std::move(msg);
Expand Down Expand Up @@ -969,12 +969,12 @@ void V2Transport::StartSendingHandshake() noexcept
// We cannot wipe m_send_garbage as it will still be used as AAD later in the handshake.
}

V2Transport::V2Transport(NodeId nodeid, bool initiating, int type_in, int version_in, const CKey& key, Span<const std::byte> ent32, std::vector<uint8_t> garbage) noexcept :
m_cipher{key, ent32}, m_initiating{initiating}, m_nodeid{nodeid},
m_v1_fallback{nodeid, type_in, version_in}, m_recv_type{type_in}, m_recv_version{version_in},
m_recv_state{initiating ? RecvState::KEY : RecvState::KEY_MAYBE_V1},
m_send_garbage{std::move(garbage)},
m_send_state{initiating ? SendState::AWAITING_KEY : SendState::MAYBE_V1}
V2Transport::V2Transport(NodeId nodeid, bool initiating, const CKey& key, Span<const std::byte> ent32, std::vector<uint8_t> garbage) noexcept
: m_cipher{key, ent32}, m_initiating{initiating}, m_nodeid{nodeid},
m_v1_fallback{nodeid},
m_recv_state{initiating ? RecvState::KEY : RecvState::KEY_MAYBE_V1},
m_send_garbage{std::move(garbage)},
m_send_state{initiating ? SendState::AWAITING_KEY : SendState::MAYBE_V1}
{
Assume(m_send_garbage.size() <= MAX_GARBAGE_LEN);
// Start sending immediately if we're the initiator of the connection.
Expand All @@ -984,9 +984,9 @@ V2Transport::V2Transport(NodeId nodeid, bool initiating, int type_in, int versio
}
}

V2Transport::V2Transport(NodeId nodeid, bool initiating, int type_in, int version_in) noexcept :
V2Transport{nodeid, initiating, type_in, version_in, GenerateRandomKey(),
MakeByteSpan(GetRandHash()), GenerateRandomGarbage()} { }
V2Transport::V2Transport(NodeId nodeid, bool initiating) noexcept
: V2Transport{nodeid, initiating, GenerateRandomKey(),
MakeByteSpan(GetRandHash()), GenerateRandomGarbage()} {}

void V2Transport::SetReceiveState(RecvState recv_state) noexcept
{
Expand Down Expand Up @@ -1430,8 +1430,7 @@ CNetMessage V2Transport::GetReceivedMessage(std::chrono::microseconds time, bool
Assume(m_recv_state == RecvState::APP_READY);
Span<const uint8_t> contents{m_recv_decode_buffer};
auto msg_type = GetMessageType(contents);
CDataStream ret(m_recv_type, m_recv_version);
CNetMessage msg{std::move(ret)};
CNetMessage msg{DataStream{}};
// Note that BIP324Cipher::EXPANSION also includes the length descriptor size.
msg.m_raw_message_size = m_recv_decode_buffer.size() + BIP324Cipher::EXPANSION;
if (msg_type) {
Expand Down Expand Up @@ -3661,9 +3660,9 @@ ServiceFlags CConnman::GetLocalServices() const
static std::unique_ptr<Transport> MakeTransport(NodeId id, bool use_v2transport, bool inbound) noexcept
{
if (use_v2transport) {
return std::make_unique<V2Transport>(id, /*initiating=*/!inbound, SER_NETWORK, INIT_PROTO_VERSION);
return std::make_unique<V2Transport>(id, /*initiating=*/!inbound);
} else {
return std::make_unique<V1Transport>(id, SER_NETWORK, INIT_PROTO_VERSION);
return std::make_unique<V1Transport>(id);
}
}

Expand Down
28 changes: 9 additions & 19 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,16 @@ class CNodeStats
* Ideally it should only contain receive time, payload,
* type and size.
*/
class CNetMessage {
class CNetMessage
{
public:
CDataStream m_recv; //!< received message data
DataStream m_recv; //!< received message data
std::chrono::microseconds m_time{0}; //!< time of message receipt
uint32_t m_message_size{0}; //!< size of the payload
uint32_t m_raw_message_size{0}; //!< used wire size of the message (including header/checksum)
std::string m_type;

CNetMessage(CDataStream&& recv_in) : m_recv(std::move(recv_in)) {}
explicit CNetMessage(DataStream&& recv_in) : m_recv(std::move(recv_in)) {}
// Only one CNetMessage object will exist for the same message on either
// the receive or processing queue. For performance reasons we therefore
// delete the copy constructor and assignment operator to avoid the
Expand All @@ -249,11 +250,6 @@ class CNetMessage {
CNetMessage(const CNetMessage&) = delete;
CNetMessage& operator=(CNetMessage&&) = default;
CNetMessage& operator=(const CNetMessage&) = delete;

void SetVersion(int nVersionIn)
{
m_recv.SetVersion(nVersionIn);
}
};

/** The Transport converts one connection's sent messages to wire bytes, and received bytes back. */
Expand Down Expand Up @@ -379,9 +375,9 @@ class V1Transport final : public Transport
mutable XCoin::GroestlHasher hasher GUARDED_BY(m_recv_mutex); // GRS
mutable uint256 data_hash GUARDED_BY(m_recv_mutex);
bool in_data GUARDED_BY(m_recv_mutex); // parsing header (false) or data (true)
CDataStream hdrbuf GUARDED_BY(m_recv_mutex); // partially received header
DataStream hdrbuf GUARDED_BY(m_recv_mutex){}; // partially received header
CMessageHeader hdr GUARDED_BY(m_recv_mutex); // complete header
CDataStream vRecv GUARDED_BY(m_recv_mutex); // received message data
DataStream vRecv GUARDED_BY(m_recv_mutex){}; // received message data
unsigned int nHdrPos GUARDED_BY(m_recv_mutex);
unsigned int nDataPos GUARDED_BY(m_recv_mutex);

Expand Down Expand Up @@ -421,7 +417,7 @@ class V1Transport final : public Transport
size_t m_bytes_sent GUARDED_BY(m_send_mutex) {0};

public:
V1Transport(const NodeId node_id, int nTypeIn, int nVersionIn) noexcept;
explicit V1Transport(const NodeId node_id) noexcept;

bool ReceivedMessageComplete() const override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex)
{
Expand Down Expand Up @@ -599,10 +595,6 @@ class V2Transport final : public Transport
std::vector<uint8_t> m_recv_aad GUARDED_BY(m_recv_mutex);
/** Buffer to put decrypted contents in, for converting to CNetMessage. */
std::vector<uint8_t> m_recv_decode_buffer GUARDED_BY(m_recv_mutex);
/** Deserialization type. */
const int m_recv_type;
/** Deserialization version number. */
const int m_recv_version;
/** Current receiver state. */
RecvState m_recv_state GUARDED_BY(m_recv_mutex);

Expand Down Expand Up @@ -648,13 +640,11 @@ class V2Transport final : public Transport
*
* @param[in] nodeid the node's NodeId (only for debug log output).
* @param[in] initiating whether we are the initiator side.
* @param[in] type_in the serialization type of returned CNetMessages.
* @param[in] version_in the serialization version of returned CNetMessages.
*/
V2Transport(NodeId nodeid, bool initiating, int type_in, int version_in) noexcept;
V2Transport(NodeId nodeid, bool initiating) noexcept;

/** Construct a V2 transport with specified keys and garbage (test use only). */
V2Transport(NodeId nodeid, bool initiating, int type_in, int version_in, const CKey& key, Span<const std::byte> ent32, std::vector<uint8_t> garbage) noexcept;
V2Transport(NodeId nodeid, bool initiating, const CKey& key, Span<const std::byte> ent32, std::vector<uint8_t> garbage) noexcept;

// Receive side functions.
bool ReceivedMessageComplete() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex);
Expand Down
Loading

0 comments on commit 1d0f460

Please sign in to comment.