Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: adapt for updated qtils and scale #2379

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
32cb454
refactor: force apply clang-format
xDimon Jan 20, 2025
b43dcda
update: qtils, scale
xDimon Feb 3, 2025
500a40e
refactor: explicit using of Tagged
xDimon Feb 6, 2025
c5bcdf2
feature: adapt to support aggregate coding
xDimon Jan 28, 2025
2570db6
refactor: adapt for updated outcome-macros for GTest
xDimon Feb 3, 2025
49c9254
factor: compact and fixed integers at scale
xDimon Feb 5, 2025
0e507ee
refactor: adapt to support new wersion of SCALE
xDimon Feb 13, 2025
06dcfb4
update: qtils
xDimon Feb 16, 2025
e79233e
test: qtils patch
xDimon Feb 16, 2025
12948eb
fix: missed return
xDimon Feb 16, 2025
d044e0a
fix: wavm build
xDimon Feb 16, 2025
c4fb935
update: scale
xDimon Feb 16, 2025
1d0b9f5
fix: clang-tidy issues
xDimon Feb 16, 2025
9c8a1a6
fix: clang-tidy issues
xDimon Feb 16, 2025
54b76de
fix: clang-tidy issues
xDimon Feb 17, 2025
d22d934
fix: clang-tidy issues
xDimon Feb 17, 2025
cae874c
refactor: Roles
xDimon Feb 17, 2025
baf72bc
fix: clang-tidy issues
xDimon Feb 17, 2025
24c0f6e
fix: scale-coding of grandpa things
xDimon Feb 17, 2025
aa00a60
fix: self-review issues
xDimon Feb 18, 2025
234abfb
refactor: force applying clang-format for all files
xDimon Feb 18, 2025
6df2c6e
draft
xDimon Feb 18, 2025
715abf9
update: scale with auto-detection abnormal aggregates
xDimon Feb 18, 2025
26561a9
fix: make CandidateReceipt custom decomposable
xDimon Feb 20, 2025
912d19c
refactor: use refactored BitVector
xDimon Feb 22, 2025
341227d
update: scale
xDimon Feb 22, 2025
f72a249
fix: UBSAN and clang-tidy issues
xDimon Feb 23, 2025
e497965
update: dependencies
xDimon Feb 24, 2025
b586e5a
update: dependencies
xDimon Feb 26, 2025
adcd5db
git: Merge branch 'master' into refactor/adopt_for_updated_qtils_and_…
xDimon Feb 26, 2025
dc3b84f
fix: clang-tidy issue
xDimon Feb 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
23 changes: 23 additions & 0 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ hunter_config(
KEEP_PACKAGE_SOURCES
)

hunter_config(
libp2p
URL https://github.com/libp2p/cpp-libp2p/archive/5d0013db9850a1c23dfe9ef6673077959b2d784f.tar.gz
SHA1 bf1b740a60e621cd156fb8754b423750fc7070ed
KEEP_PACKAGE_SOURCES
)

hunter_config(
soralog
VERSION 0.2.4
Expand All @@ -118,3 +125,19 @@ hunter_config(
KEEP_PACKAGE_SOURCES
)

hunter_config(
scale
# VERSION 2.0.0
URL https://github.com/qdrvm/scale-codec-cpp/archive/refs/tags/v2.0.0.tar.gz
SHA1 a83f0a034693809b948451ff774aeb58462a0f96
KEEP_PACKAGE_SOURCES
)

hunter_config(
qtils
URL https://github.com/qdrvm/qtils/archive/6d02006f7c0fe44958acbfe53016fa81f1ac0bf5.tar.gz
SHA1 b37b32a882788eb8f2c796098b5bf3a19cf00fe3
CMAKE_ARGS
FORMAT_ERROR_WITH_FULLTYPE=ON
KEEP_PACKAGE_SOURCES
)
10 changes: 5 additions & 5 deletions core/api/jrpc/value_converter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "primitives/rpc_methods.hpp"
#include "primitives/runtime_dispatch_info.hpp"
#include "primitives/version.hpp"
#include "scale/scale.hpp"
#include "scale/kagome_scale.hpp"

namespace kagome::api {

Expand Down Expand Up @@ -98,19 +98,19 @@ namespace kagome::api {
}

inline jsonrpc::Value makeValue(const primitives::Balance &val) {
jsonrpc::Value ret((*val).str());
jsonrpc::Value ret(val.str());
return ret;
}

inline jsonrpc::Value makeValue(const primitives::Weight &val) {
jStruct data;
data["ref_time"] = static_cast<int64_t>(*val.ref_time);
data["proof_size"] = static_cast<int64_t>(*val.proof_size);
data["ref_time"] = static_cast<int64_t>(val.ref_time);
data["proof_size"] = static_cast<int64_t>(val.proof_size);
return data;
}

inline jsonrpc::Value makeValue(const primitives::OldWeight &val) {
jsonrpc::Value ret(static_cast<int64_t>(*val));
jsonrpc::Value ret(static_cast<int64_t>(val));
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion core/api/service/author/impl/author_api_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "crypto/sr25519_types.hpp"
#include "primitives/transaction.hpp"
#include "runtime/runtime_api/session_keys_api.hpp"
#include "scale/scale_decoder_stream.hpp"
#include "scale/kagome_scale.hpp"
#include "subscription/subscriber.hpp"
#include "transaction_pool/transaction_pool.hpp"

Expand Down
2 changes: 1 addition & 1 deletion core/api/service/child_state/requests/get_keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "api/service/child_state/requests/get_keys.hpp"

#include "scale/scale.hpp"
#include "scale/kagome_scale.hpp"

namespace kagome::api::child_state::request {

Expand Down
2 changes: 1 addition & 1 deletion core/api/service/child_state/requests/get_keys_paged.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "api/service/child_state/requests/get_keys_paged.hpp"

#include "scale/scale.hpp"
#include "scale/kagome_scale.hpp"

namespace kagome::api::child_state::request {

Expand Down
2 changes: 1 addition & 1 deletion core/api/service/state/requests/call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "api/service/state/requests/call.hpp"

#include "scale/scale.hpp"
#include "scale/kagome_scale.hpp"

namespace kagome::api::state::request {

Expand Down
2 changes: 1 addition & 1 deletion core/api/service/state/requests/get_keys_paged.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "api/service/state/requests/get_keys_paged.hpp"

#include "scale/scale.hpp"
#include "scale/kagome_scale.hpp"

namespace kagome::api::state::request {

Expand Down
2 changes: 1 addition & 1 deletion core/api/service/state/requests/get_storage_size.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace kagome::api::state::request {
GetStorageSize &operator=(GetStorageSize &&) = default;

explicit GetStorageSize(std::shared_ptr<StateApi> api)
: api_(std::move(api)) {};
: api_(std::move(api)){};
~GetStorageSize() = default;

outcome::result<void> init(const jsonrpc::Request::Parameters &params);
Expand Down
2 changes: 1 addition & 1 deletion core/api/service/system/impl/system_api_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "blockchain/block_tree.hpp"
#include "primitives/ss58_codec.hpp"
#include "scale/scale.hpp"
#include "scale/kagome_scale.hpp"
#include "transaction_pool/transaction_pool.hpp"

namespace kagome::api {
Expand Down
9 changes: 5 additions & 4 deletions core/api/service/system/requests/peers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "api/service/base_request.hpp"

#include "account_next_index.hpp"
#include "api/jrpc/value_converter.hpp"
#include "api/service/system/system_api.hpp"
#include "chain.hpp"
#include "chain_type.hpp"
Expand Down Expand Up @@ -40,10 +41,10 @@ namespace kagome::api::system::request {
jsonrpc::Value::Struct peer;
peer.emplace("PeerId", peer_id.toBase58());
peer.emplace("roles",
status.get().roles.flags.authority ? "AUTHORITY"
: status.get().roles.flags.full ? "FULL"
: status.get().roles.flags.light ? "LIGHT"
: "NONE");
status.get().roles.isAuthority() ? "AUTHORITY"
: status.get().roles.isFull() ? "FULL"
: status.get().roles.isLight() ? "LIGHT"
: "NONE");
peer.emplace("bestHash", makeValue(status.get().best_block.hash));
peer.emplace("bestNumber", makeValue(status.get().best_block.number));

Expand Down
34 changes: 9 additions & 25 deletions core/application/impl/app_configuration_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,7 @@ namespace {
const uint32_t def_ws_max_connections = 500;
const uint16_t def_p2p_port = 30363;
const bool def_dev_mode = false;
const kagome::network::Roles def_roles = [] {
kagome::network::Roles roles;
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
roles.flags.full = 1;
return roles;
}();
const kagome::network::Roles def_roles{kagome::network::Roles::Full};
const auto def_sync_method = kagome::application::SyncMethod::Full;
const auto def_runtime_exec_method =
kagome::application::AppConfiguration::RuntimeExecutionMethod::Compile;
Expand Down Expand Up @@ -178,11 +173,12 @@ namespace {

static constexpr std::array<std::string_view,
1 + KAGOME_WASM_COMPILER_WASM_EDGE>
interpreters{
interpreters {
#if KAGOME_WASM_COMPILER_WASM_EDGE == 1
"WasmEdge",
"WasmEdge",
#endif
"Binaryen"};
"Binaryen"
};

static const std::string interpreters_str =
fmt::format("[{}]", fmt::join(interpreters, ", "));
Expand Down Expand Up @@ -444,10 +440,7 @@ namespace kagome::application {
bool validator_mode = false;
load_bool(val, "validator", validator_mode);
if (validator_mode) {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
roles_.flags.full = 0;
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
roles_.flags.authority = 1;
roles_ = kagome::network::Roles::Authority;
}

load_ms(val, "log", logger_tuning_config_);
Expand Down Expand Up @@ -1000,10 +993,7 @@ namespace kagome::application {
}
}

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
roles_.flags.full = 0;
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
roles_.flags.authority = 1;
roles_ = network::Roles::Authority;
p2p_port_ = def_p2p_port;
rpc_host_ = def_rpc_host;
openmetrics_http_host_ = def_openmetrics_http_host;
Expand All @@ -1024,10 +1014,7 @@ namespace kagome::application {
node_name_ = name;
dev_mnemonic_phrase_ = dev;
// if dev account is passed node is considered as validator
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
roles_.flags.full = 0;
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
roles_.flags.authority = 1;
roles_ = network::Roles::Authority;
}
}

Expand Down Expand Up @@ -1055,10 +1042,7 @@ namespace kagome::application {
});

if (vm.end() != vm.find("validator")) {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
roles_.flags.full = 0;
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
roles_.flags.authority = 1;
roles_ = network::Roles::Authority;
}

find_argument<std::string>(
Expand Down
3 changes: 1 addition & 2 deletions core/application/impl/kagome_application_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ namespace kagome::application {
"The roles the node is running as");
auto metric_node_roles =
metrics_registry->registerGaugeMetric(nodeRolesMetricName);
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
metric_node_roles->set(app_config_->roles().value);
metric_node_roles->set(app_config_->roles().value());

constexpr auto buildInfoMetricName = "kagome_build_info";
metrics_registry->registerGaugeFamily(
Expand Down
3 changes: 2 additions & 1 deletion core/application/modes/precompile_wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ namespace kagome::application::mode {
auto code_hash = hasher_->blake2b_256(bytes);
OUTCOME_TRY(config,
parachain::sessionParams(*parachain_api_, block.hash));
OUTCOME_TRY(module_factory_->precompile(code_hash, bytes, config.context_params));
OUTCOME_TRY(
module_factory_->precompile(code_hash, bytes, config.context_params));
}
return outcome::success();
}
Expand Down
2 changes: 1 addition & 1 deletion core/authority_discovery/publisher/address_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ namespace kagome::authority_discovery {
PB_SPAN_ADD(record, addresses, address.getBytesAddress());
}
if (now) {
TimestampScale time{now->count()};
Timestamp time{now->count()};
OUTCOME_TRY(encoded_time, scale::encode(time));
PB_SPAN_SET(*record.mutable_creation_time(), timestamp, encoded_time);
}
Expand Down
12 changes: 7 additions & 5 deletions core/authority_discovery/query/audi_store_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
namespace kagome::authority_discovery {

AudiStoreImpl::AudiStoreImpl(std::shared_ptr<storage::SpacedStorage> storage)
: space_{storage->getSpace(storage::Space::kAudiPeers)} {
: log_(
log::createLogger("AuthorityDiscoveryStore", "authority_discovery")),
space_{storage->getSpace(storage::Space::kAudiPeers)} {
BOOST_ASSERT(space_ != nullptr);
}

void AudiStoreImpl::store(const primitives::AuthorityDiscoveryId &authority,
const AuthorityPeerInfo &data) {
auto encoded = scale::encode(data);

if (not encoded) {
SL_ERROR(log_, "Failed to encode PeerInfo");
if (encoded.has_error()) {
SL_ERROR(log_, "Failed to encode AuthorityPeerInfo: {}", encoded.error());
return;
}

Expand Down Expand Up @@ -51,8 +53,8 @@ namespace kagome::authority_discovery {

auto decoded = scale::decode<AuthorityPeerInfo>(res.value().value());

if (not decoded) {
SL_ERROR(log_, "Failed to decode PeerInfo");
if (decoded.has_error()) {
SL_ERROR(log_, "Failed to decode AuthorityPeerInfo: {}", decoded.error());
return std::nullopt;
}

Expand Down
2 changes: 1 addition & 1 deletion core/authority_discovery/query/audi_store_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ namespace kagome::authority_discovery {
const AuthorityPeerInfo &)> f) override;

private:
std::shared_ptr<storage::BufferStorage> space_;
log::Logger log_;
std::shared_ptr<storage::BufferStorage> space_;
};

} // namespace kagome::authority_discovery
7 changes: 2 additions & 5 deletions core/authority_discovery/query/authority_peer_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
#include "authority_discovery/timestamp.hpp"
#include "common/buffer.hpp"
#include "scale/libp2p_types.hpp"
#include "scale/tie.hpp"

namespace kagome::authority_discovery {
struct AuthorityPeerInfo {
SCALE_TIE(3);

common::Buffer raw{};
std::optional<TimestampScale> time{};
::scale::PeerInfoSerializable peer{};
std::optional<Timestamp> time{};
scale::PeerInfoSerializable peer{};
};

} // namespace kagome::authority_discovery
20 changes: 9 additions & 11 deletions core/authority_discovery/query/query_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,10 @@ namespace kagome::authority_discovery {
std::optional<Timestamp> time{};
if (record.has_creation_time()) {
OUTCOME_TRY(tmp,
scale::decode<TimestampScale>(
scale::decode<Timestamp>(
qtils::str2byte(record.creation_time().timestamp())));
time = *tmp;
if (it and it->time and time <= it->time->number) {
time = tmp;
if (it and it->time and time <= it->time) {
SL_TRACE(log_, "lookup: outdated record for authority {}", authority);
return outcome::success();
}
Expand Down Expand Up @@ -365,14 +365,12 @@ namespace kagome::authority_discovery {
if (not audi_store_->contains(authority)) {
metric_known_authorities_count->inc();
}
audi_store_->store(
authority,
AuthorityPeerInfo{
.raw = std::move(signed_record_pb),
.time = time.has_value() ? std::make_optional(TimestampScale{*time})
: std::nullopt,
.peer = peer,
});
audi_store_->store(authority,
AuthorityPeerInfo{
.raw = std::move(signed_record_pb),
.time = time,
.peer = peer,
});

validation_protocol_.get()->reserve(peer.id, true);

Expand Down
5 changes: 2 additions & 3 deletions core/authority_discovery/timestamp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

#pragma once

#include "scale/big_fixed_integers.hpp"
#include <scale/kagome_scale.hpp>

namespace kagome::authority_discovery {
using Timestamp = ::scale::uint128_t;
using TimestampScale = ::scale::Fixed<Timestamp>;
using Timestamp = scale::uint128_t;
} // namespace kagome::authority_discovery
17 changes: 5 additions & 12 deletions core/authorship/impl/block_builder_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,13 @@ namespace kagome::authorship {
}

size_t BlockBuilderImpl::estimateBlockSize() const {
scale::ScaleEncoderStream s(true);
for (const auto &xt : extrinsics_) {
s << xt;
}
return estimatedBlockHeaderSize() + s.size();
auto size = scale::encoded_size(extrinsics_).value();
return estimatedBlockHeaderSize() + size;
}

size_t BlockBuilderImpl::estimatedBlockHeaderSize() const {
static std::optional<size_t> size = std::nullopt;
if (not size) {
scale::ScaleEncoderStream s(true);
s << block_header_;
size = s.size();
}
return size.value();
static const size_t size =
scale::encoded_size(primitives::BlockHeader{}).value();
return size;
}
} // namespace kagome::authorship
Loading
Loading