Skip to content

Commit 8bdf0b6

Browse files
authored
sync code from 3.15.3 (FISCO-BCOS#4900)
2 parents 1a16cd2 + 33bcf34 commit 8bdf0b6

File tree

26 files changed

+249
-310
lines changed

26 files changed

+249
-310
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ endif()
66

77
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
88

9-
set(VERSION "3.15.2")
9+
set(VERSION "3.15.3")
1010
set(VERSION_SUFFIX "")
1111
include(Options)
1212
configure_project()

bcos-crypto/bcos-crypto/merkle/Merkle.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class Merkle
134134

135135
setNumberToHash(count, out.emplace_back());
136136
for (auto it = ::ranges::begin(originHashes) + index;
137-
it < ::ranges::begin(originHashes) + index + count; ++it)
137+
it < ::ranges::begin(originHashes) + index + count; ++it)
138138
{
139139
bcos::concepts::bytebuffer::assignTo(*it, out.emplace_back());
140140
}
@@ -162,9 +162,9 @@ class Merkle
162162
}
163163
}
164164

165-
void generateMerkle(HashRange auto const& originHashes, MerkleRange auto& out) const
165+
void generateMerkle(HashRange auto&& originHashes, MerkleRange auto& out) const
166166
{
167-
if (::ranges::empty(originHashes)) [[unlikely]]
167+
if (::ranges::empty(originHashes))
168168
{
169169
BOOST_THROW_EXCEPTION(std::invalid_argument{"Empty input"});
170170
}

bcos-framework/bcos-framework/protocol/Protocol.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ enum ProtocolVersion : uint32_t
115115

116116
enum class BlockVersion : uint32_t
117117
{
118+
V3_15_3_VERSION = 0x030f0300, // 3.15.3
118119
V3_15_2_VERSION = 0x030f0200, // 3.15.2
119120
V3_15_1_VERSION = 0x030f0100, // 3.15.1
120121
V3_15_0_VERSION = 0x030f0000, // 3.15.0
@@ -152,7 +153,7 @@ enum class BlockVersion : uint32_t
152153
V3_0_VERSION = 0x03000000,
153154
RC4_VERSION = 4,
154155
MIN_VERSION = RC4_VERSION,
155-
MAX_VERSION = V3_15_2_VERSION, // 3.15.2
156+
MAX_VERSION = V3_15_3_VERSION, // 3.15.3
156157
};
157158

158159
enum class TransactionVersion : uint32_t
@@ -167,7 +168,7 @@ const std::string RC4_VERSION_STR = "3.0.0-rc4";
167168
const std::string RC_VERSION_PREFIX = "3.0.0-rc";
168169
const std::string V3_9_VERSION_STR = "3.9.0";
169170

170-
constexpr BlockVersion DEFAULT_VERSION = bcos::protocol::BlockVersion::V3_15_2_VERSION; // 3.15.2
171+
constexpr BlockVersion DEFAULT_VERSION = bcos::protocol::BlockVersion::V3_15_3_VERSION; // 3.15.3
171172
const std::string DEFAULT_VERSION_STR = V3_9_VERSION_STR;
172173
constexpr uint8_t MAX_MAJOR_VERSION = std::numeric_limits<uint8_t>::max();
173174
constexpr uint8_t MIN_MAJOR_VERSION = 3;

bcos-framework/bcos-framework/storage2/MemoryStorage.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,14 @@ class MemoryStorage
310310
return {};
311311
}
312312

313-
task::AwaitableValue<void> removeSome(::ranges::input_range auto keys, bool direct)
313+
task::AwaitableValue<void> removeSome(
314+
::ranges::input_range auto keys, bool ignoreLogicalDeletion)
314315
{
315316
for (auto&& key : keys)
316317
{
317318
auto& bucket = getBucket(key);
318319
Lock lock(bucket.mutex, true);
319-
writeOne(bucket, std::forward<decltype(key)>(key), deleteItem, direct);
320+
writeOne(bucket, std::forward<decltype(key)>(key), deleteItem, ignoreLogicalDeletion);
320321
}
321322

322323
return {};
@@ -434,10 +435,13 @@ class MemoryStorage
434435
return task::AwaitableValue(std::move(iterator));
435436
}
436437

437-
template <class FromStorage>
438-
requires withConcurrent && (!FromStorage::withConcurrent)
439-
friend task::Task<void> tag_invoke(
440-
storage2::tag_t<merge> /*unused*/, MemoryStorage& toStorage, FromStorage& fromStorage)
438+
void merge(MemoryStorage& toStorage)
439+
requires withConcurrent
440+
{}
441+
template <class FromStorage, class... FromStorages>
442+
void merge(MemoryStorage& toStorage, FromStorage& fromStorage, FromStorages&... fromStorages)
443+
requires(withConcurrent && !FromStorage::withConcurrent &&
444+
(... && (!FromStorages::withConcurrent)))
441445
{
442446
auto& bucket = fromStorage.m_buckets[0];
443447
auto& index = bucket.container.template get<0>();
@@ -473,6 +477,15 @@ class MemoryStorage
473477
}
474478
}
475479
});
480+
merge(toStorage, fromStorages...);
481+
}
482+
483+
template <class... FromStorages>
484+
requires(withConcurrent && (... && (!FromStorages::withConcurrent)))
485+
friend task::Task<void> tag_invoke(storage2::tag_t<storage2::merge> /*unused*/,
486+
MemoryStorage& toStorage, FromStorages&... fromStorage)
487+
{
488+
toStorage.merge(toStorage, fromStorage...);
476489
co_return;
477490
}
478491
};

bcos-framework/test/unittests/storage2/TestMemoryStorage.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
#include <bcos-framework/storage2/MemoryStorage.h>
55
#include <bcos-task/Wait.h>
66
#include <fmt/format.h>
7+
#include <boost/test/tools/old/interface.hpp>
78
#include <boost/test/unit_test.hpp>
89
#include <functional>
10+
#include <ostream>
11+
#include <range/v3/view/transform.hpp>
912
#include <string>
1013
#include <variant>
1114

@@ -311,6 +314,23 @@ BOOST_AUTO_TEST_CASE(merge)
311314
++i;
312315
}
313316
BOOST_CHECK_EQUAL(i, 19);
317+
318+
MemoryStorage<int, int, ORDERED> storage3;
319+
MemoryStorage<int, int, ORDERED> storage4;
320+
MemoryStorage<int, int, ORDERED | CONCURRENT> storage5;
321+
322+
co_await storage2::writeSome(storage3,
323+
::ranges::views::zip(::ranges::views::iota(0, 10), ::ranges::repeat_view<int>(100)));
324+
co_await storage2::writeSome(storage4,
325+
::ranges::views::zip(::ranges::views::iota(10, 20), ::ranges::repeat_view<int>(100)));
326+
co_await storage2::merge(storage5, storage3, storage4);
327+
328+
auto values2 = co_await storage2::readSome(storage5, ::ranges::views::iota(0, 20));
329+
BOOST_CHECK_EQUAL(values2.size(), 20);
330+
auto expectValues2 = ::ranges::views::iota(0, 20) | ::ranges::views::transform([](int i) {
331+
return std::make_optional(100);
332+
}) | ::ranges::to<std::vector>();
333+
BOOST_CHECK(values2 == expectValues2);
314334
}());
315335
}
316336

bcos-front/bcos-front/FrontService.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <range/v3/view/concat.hpp>
3232
#include <range/v3/view/single.hpp>
3333
#include <thread>
34+
#include <utility>
3435

3536
using namespace bcos;
3637
using namespace front;
@@ -102,7 +103,7 @@ void FrontService::start()
102103
// try to getNodeIDs from gateway
103104
auto self = std::weak_ptr<FrontService>(shared_from_this());
104105
m_gatewayInterface->asyncGetGroupNodeInfo(
105-
m_groupID, [self](Error::Ptr _error, bcos::gateway::GroupNodeInfo::Ptr _groupNodeInfo) {
106+
m_groupID, [self](const Error::Ptr& _error, const bcos::gateway::GroupNodeInfo::Ptr& _groupNodeInfo) {
106107
if (_error)
107108
{
108109
FRONT_LOG(ERROR) << LOG_BADGE("start") << LOG_DESC("asyncGetGroupNodeInfo failed")
@@ -121,7 +122,7 @@ void FrontService::start()
121122
}
122123
});
123124

124-
m_frontServiceThread = std::make_shared<std::thread>([=, this]() {
125+
m_frontServiceThread = std::make_shared<std::thread>([this]() {
125126
while (m_run)
126127
{
127128
try
@@ -278,7 +279,7 @@ void FrontService::asyncSendMessageByNodeID(int _moduleID, bcos::crypto::NodeIDP
278279

279280
auto self = weak_from_this();
280281
sendMessage(_moduleID, _nodeID, uuid, _data, false,
281-
[self, _moduleID, _nodeID, uuid](Error::Ptr _error) {
282+
[self, _moduleID, _nodeID, uuid](const Error::Ptr& _error) {
282283
auto front = self.lock();
283284
if (!front)
284285
{
@@ -437,13 +438,13 @@ void FrontService::protocolNegotiate(bcos::gateway::GroupNodeInfo::Ptr _groupNod
437438
}
438439

439440
void FrontService::notifyGroupNodeInfo(
440-
const std::string& _groupID, bcos::gateway::GroupNodeInfo::Ptr _groupNodeInfo)
441+
const std::string& _groupID, const bcos::gateway::GroupNodeInfo::Ptr& _groupNodeInfo)
441442
{
442443
Guard l(x_notifierLock);
443444
for (const auto& entry : m_module2GroupNodeInfoNotifier)
444445
{
445446
auto moduleID = entry.first;
446-
entry.second(_groupNodeInfo, [_groupID, moduleID](Error::Ptr _error) {
447+
entry.second(_groupNodeInfo, [_groupID, moduleID](const Error::Ptr& _error) {
447448
if (_error)
448449
{
449450
FRONT_LOG(ERROR) << LOG_DESC("onReceiveGroupNodeInfo dispather failed")
@@ -468,7 +469,7 @@ void FrontService::handleCallback(bcos::Error::Ptr _error, bytesConstRef _payLoa
468469
if (frontService)
469470
{
470471
frontService->sendMessage(
471-
_moduleID, _nodeID, _uuid, _data, true, [_uuid](Error::Ptr _error) {
472+
_moduleID, _nodeID, _uuid, _data, true, [_uuid](const Error::Ptr& _error) {
472473
if (_error && (_error->errorCode() != CommonError::SUCCESS))
473474
{
474475
FRONT_LOG(ERROR)
@@ -599,7 +600,7 @@ void FrontService::onReceiveBroadcastMessage(const std::string& _groupID,
599600
*/
600601
void FrontService::sendMessage(int _moduleID, bcos::crypto::NodeIDPtr _nodeID,
601602
const std::string& _uuid, bytesConstRef _data, bool isResponse,
602-
ReceiveMsgFunc _receiveMsgCallback)
603+
const ReceiveMsgFunc& _receiveMsgCallback)
603604
{
604605
auto message = messageFactory()->buildMessage();
605606
message->setModuleID(_moduleID);
@@ -614,11 +615,11 @@ void FrontService::sendMessage(int _moduleID, bcos::crypto::NodeIDPtr _nodeID,
614615
message->encode(*buffer);
615616

616617
// call gateway interface to send the message
617-
m_gatewayInterface->asyncSendMessageByNodeID(m_groupID, _moduleID, m_nodeID, _nodeID,
618+
m_gatewayInterface->asyncSendMessageByNodeID(m_groupID, _moduleID, m_nodeID, std::move(_nodeID),
618619
bytesConstRef(buffer->data(), buffer->size()), [_receiveMsgCallback](Error::Ptr _error) {
619620
if (_receiveMsgCallback)
620621
{
621-
_receiveMsgCallback(_error);
622+
_receiveMsgCallback(std::move(_error));
622623
}
623624
});
624625
}

bcos-front/bcos-front/FrontService.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class FrontService : public FrontServiceInterface, public std::enable_shared_fro
146146
* @return void
147147
*/
148148
void sendMessage(int _moduleID, bcos::crypto::NodeIDPtr _nodeID, const std::string& _uuid,
149-
bytesConstRef _data, bool isResponse, ReceiveMsgFunc _receiveMsgCallback);
149+
bytesConstRef _data, bool isResponse, const ReceiveMsgFunc& _receiveMsgCallback);
150150

151151
/**
152152
* @brief: handle message timeout
@@ -267,7 +267,7 @@ class FrontService : public FrontServiceInterface, public std::enable_shared_fro
267267
virtual void handleCallback(bcos::Error::Ptr _error, bytesConstRef _payLoad,
268268
std::string const& _uuid, int _moduleID, bcos::crypto::NodeIDPtr _nodeID);
269269
void notifyGroupNodeInfo(
270-
const std::string& _groupID, bcos::gateway::GroupNodeInfo::Ptr _groupNodeInfo);
270+
const std::string& _groupID, const bcos::gateway::GroupNodeInfo::Ptr& _groupNodeInfo);
271271

272272
virtual void protocolNegotiate(bcos::gateway::GroupNodeInfo::Ptr _groupNodeInfo);
273273

bcos-rpc/bcos-rpc/web3jsonrpc/endpoints/EthEndpoint.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ task::Task<void> EthEndpoint::getTransactionCount(const Json::Value& request, Js
255255
{
256256
WEB3_LOG(TRACE) << "eth_getTransactionCount pending tx from txpool"
257257
<< LOG_KV("address", address) << LOG_KV("blockTag", blockTag)
258-
<< LOG_KV("nonce", nonce.value() + 1);
259-
Json::Value result = toQuantity(nonce.value() + 1);
258+
<< LOG_KV("nonce", nonce.value());
259+
Json::Value result = toQuantity(nonce.value());
260260
buildJsonContent(result, response);
261261
co_return;
262262
}

0 commit comments

Comments
 (0)