diff --git a/src/bench/readwriteblock.cpp b/src/bench/readwriteblock.cpp index 10434b15d20..1550ca4362e 100644 --- a/src/bench/readwriteblock.cpp +++ b/src/bench/readwriteblock.cpp @@ -55,7 +55,7 @@ static void ReadRawBlockBench(benchmark::Bench& bench) const auto testing_setup{MakeNoLogFileContext(ChainType::MAIN)}; auto& blockman{testing_setup->m_node.chainman->m_blockman}; const auto pos{blockman.WriteBlock(CreateTestBlock(), 413'567)}; - std::vector block_data; + std::vector block_data; blockman.ReadRawBlock(block_data, pos); // warmup bench.run([&] { const auto success{blockman.ReadRawBlock(block_data, pos)}; diff --git a/src/init.cpp b/src/init.cpp index d7a2a347e50..1f72c22ec2f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1677,7 +1677,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) #ifdef ENABLE_ZMQ g_zmq_notification_interface = CZMQNotificationInterface::Create( - [&chainman = node.chainman](std::vector& block, const CBlockIndex& index) { + [&chainman = node.chainman](std::vector& block, const CBlockIndex& index) { assert(chainman); return chainman->m_blockman.ReadRawBlock(block, WITH_LOCK(cs_main, return index.GetBlockPos())); }); diff --git a/src/net_processing.cpp b/src/net_processing.cpp index ead69f086df..c4fe412fb8a 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2303,7 +2303,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv& } else if (inv.IsMsgWitnessBlk()) { // Fast-path: in this case it is possible to serve the block directly from disk, // as the network format matches the format on disk - std::vector block_data; + std::vector block_data; if (!m_chainman.m_blockman.ReadRawBlock(block_data, block_pos)) { if (WITH_LOCK(m_chainman.GetMutex(), return m_chainman.m_blockman.IsBlockPruned(*pindex))) { LogDebug(BCLog::NET, "Block was pruned before it could be read, %s\n", pfrom.DisconnectMsg(fLogIPs)); diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index 04936ec99da..5816baa20e7 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -995,7 +995,7 @@ bool BlockManager::ReadBlock(CBlock& block, const FlatFilePos& pos, const std::o block.SetNull(); // Open history file to read - std::vector block_data; + std::vector block_data; if (!ReadRawBlock(block_data, pos)) { return false; } @@ -1037,7 +1037,7 @@ bool BlockManager::ReadBlock(CBlock& block, const CBlockIndex& index) const return ReadBlock(block, block_pos, index.GetBlockHash()); } -bool BlockManager::ReadRawBlock(std::vector& block, const FlatFilePos& pos) const +bool BlockManager::ReadRawBlock(std::vector& block, const FlatFilePos& pos) const { if (pos.nPos < STORAGE_HEADER_BYTES) { // If nPos is less than STORAGE_HEADER_BYTES, we can't read the header that precedes the block data @@ -1071,7 +1071,7 @@ bool BlockManager::ReadRawBlock(std::vector& block, const FlatFilePos& } block.resize(blk_size); // Zeroing of memory is intentional here - filein.read(MakeWritableByteSpan(block)); + filein.read(block); } catch (const std::exception& e) { LogError("Read from block file failed: %s for %s while reading raw block", e.what(), pos.ToString()); return false; diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h index 9405f68c6cf..b12915d3c05 100644 --- a/src/node/blockstorage.h +++ b/src/node/blockstorage.h @@ -413,7 +413,7 @@ public: /** Functions for disk access for blocks */ bool ReadBlock(CBlock& block, const FlatFilePos& pos, const std::optional& expected_hash = {}) const; bool ReadBlock(CBlock& block, const CBlockIndex& index) const; - bool ReadRawBlock(std::vector& block, const FlatFilePos& pos) const; + bool ReadRawBlock(std::vector& block, const FlatFilePos& pos) const; bool ReadBlockUndo(CBlockUndo& blockundo, const CBlockIndex& index) const; diff --git a/src/rest.cpp b/src/rest.cpp index 464880224c8..b05546e2d6b 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -318,7 +318,7 @@ static bool rest_block(const std::any& context, pos = pblockindex->GetBlockPos(); } - std::vector block_data{}; + std::vector block_data{}; if (!chainman.m_blockman.ReadRawBlock(block_data, pos)) { return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found"); } @@ -326,7 +326,7 @@ static bool rest_block(const std::any& context, switch (rf) { case RESTResponseFormat::BINARY: { req->WriteHeader("Content-Type", "application/octet-stream"); - req->WriteReply(HTTP_OK, std::as_bytes(std::span{block_data})); + req->WriteReply(HTTP_OK, block_data); return true; } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index dd70c499fd7..24b45a816df 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -660,9 +660,9 @@ static CBlock GetBlockChecked(BlockManager& blockman, const CBlockIndex& blockin return block; } -static std::vector GetRawBlockChecked(BlockManager& blockman, const CBlockIndex& blockindex) +static std::vector GetRawBlockChecked(BlockManager& blockman, const CBlockIndex& blockindex) { - std::vector data{}; + std::vector data{}; FlatFilePos pos{}; { LOCK(cs_main); @@ -812,7 +812,7 @@ static RPCHelpMan getblock() } } - const std::vector block_data{GetRawBlockChecked(chainman.m_blockman, *pblockindex)}; + const std::vector block_data{GetRawBlockChecked(chainman.m_blockman, *pblockindex)}; if (verbosity <= 0) { return HexStr(block_data); diff --git a/src/streams.h b/src/streams.h index 5a596047121..ebef958f544 100644 --- a/src/streams.h +++ b/src/streams.h @@ -100,13 +100,14 @@ private: class SpanReader { private: - std::span m_data; + std::span m_data; public: /** * @param[in] data Referenced byte vector to overwrite/append */ - explicit SpanReader(std::span data) : m_data{data} {} + explicit SpanReader(std::span data) : m_data{std::as_bytes(data)} {} + explicit SpanReader(std::span data) : m_data{data} {} template SpanReader& operator>>(T&& obj) diff --git a/src/zmq/zmqnotificationinterface.cpp b/src/zmq/zmqnotificationinterface.cpp index 4f01e8fd330..e5b5f9d8054 100644 --- a/src/zmq/zmqnotificationinterface.cpp +++ b/src/zmq/zmqnotificationinterface.cpp @@ -40,7 +40,7 @@ std::list CZMQNotificationInterface::GetActiveNotif return result; } -std::unique_ptr CZMQNotificationInterface::Create(std::function&, const CBlockIndex&)> get_block_by_index) +std::unique_ptr CZMQNotificationInterface::Create(std::function&, const CBlockIndex&)> get_block_by_index) { std::map factories; factories["pubhashblock"] = CZMQAbstractNotifier::Create; diff --git a/src/zmq/zmqnotificationinterface.h b/src/zmq/zmqnotificationinterface.h index ad445bbd393..5dacf3b32e7 100644 --- a/src/zmq/zmqnotificationinterface.h +++ b/src/zmq/zmqnotificationinterface.h @@ -26,7 +26,7 @@ public: std::list GetActiveNotifiers() const; - static std::unique_ptr Create(std::function&, const CBlockIndex&)> get_block_by_index); + static std::unique_ptr Create(std::function&, const CBlockIndex&)> get_block_by_index); protected: bool Initialize(); diff --git a/src/zmq/zmqpublishnotifier.cpp b/src/zmq/zmqpublishnotifier.cpp index c0a04d28a61..1e7aa11ce9b 100644 --- a/src/zmq/zmqpublishnotifier.cpp +++ b/src/zmq/zmqpublishnotifier.cpp @@ -243,7 +243,7 @@ bool CZMQPublishRawBlockNotifier::NotifyBlock(const CBlockIndex *pindex) { LogDebug(BCLog::ZMQ, "Publish rawblock %s to %s\n", pindex->GetBlockHash().GetHex(), this->address); - std::vector block{}; + std::vector block{}; if (!m_get_block_by_index(block, *pindex)) { zmqError("Can't read block from disk"); return false; diff --git a/src/zmq/zmqpublishnotifier.h b/src/zmq/zmqpublishnotifier.h index cc941a899c5..ed81dc0a238 100644 --- a/src/zmq/zmqpublishnotifier.h +++ b/src/zmq/zmqpublishnotifier.h @@ -49,10 +49,10 @@ public: class CZMQPublishRawBlockNotifier : public CZMQAbstractPublishNotifier { private: - const std::function&, const CBlockIndex&)> m_get_block_by_index; + const std::function&, const CBlockIndex&)> m_get_block_by_index; public: - CZMQPublishRawBlockNotifier(std::function&, const CBlockIndex&)> get_block_by_index) + CZMQPublishRawBlockNotifier(std::function&, const CBlockIndex&)> get_block_by_index) : m_get_block_by_index{std::move(get_block_by_index)} {} bool NotifyBlock(const CBlockIndex *pindex) override; };