Skip to content

Commit

Permalink
Merge branch 'master' into test/polkadot-functional-zombietests
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsa authored May 20, 2024
2 parents 3649f23 + 63a8a04 commit ebfe405
Show file tree
Hide file tree
Showing 49 changed files with 208 additions and 532 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
name: "${{ matrix.options.name }}"
runs-on: ubuntu-latest
timeout-minutes: 120
container: qdrvm/kagome-dev:8-minideb
container: qdrvm/kagome-dev:9-minideb
steps:
- uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6
- uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
name: "${{ matrix.options.name }}"
runs-on: [ actions-runner-controller ]
timeout-minutes: 120
container: qdrvm/kagome-dev:8-minideb
container: qdrvm/kagome-dev:9-minideb
steps:
- uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6
- uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
Expand All @@ -114,7 +114,7 @@ jobs:
name: "Linux: clang-tidy"
runs-on: ubuntu-latest
timeout-minutes: 120
container: qdrvm/kagome-dev:8-minideb
container: qdrvm/kagome-dev:9-minideb
steps:
- uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6
with:
Expand All @@ -138,7 +138,7 @@ jobs:
name: "Self-hosted: Linux: gcc-12 coverage/sonar"
runs-on: [ actions-runner-controller ]
timeout-minutes: 120
container: qdrvm/kagome-dev:8-minideb
container: qdrvm/kagome-dev:9-minideb
steps:
- uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6
- uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
Expand Down Expand Up @@ -178,7 +178,7 @@ jobs:
name: "${{ matrix.options.name }}"
runs-on: ubuntu-latest
timeout-minutes: 120
container: qdrvm/kagome-dev:8-minideb
container: qdrvm/kagome-dev:9-minideb
steps:
- uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6
- uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
Expand All @@ -203,7 +203,7 @@ jobs:
name: "${{ matrix.options.name }}"
runs-on: [ actions-runner-controller ]
timeout-minutes: 120
container: qdrvm/kagome-dev:8-minideb
container: qdrvm/kagome-dev:9-minideb
steps:
- uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6
- uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
Expand All @@ -230,7 +230,7 @@ jobs:
build-type: "RelWithDebInfo"
runs-on: [ actions-runner-controller ]
timeout-minutes: 120
container: qdrvm/kagome-dev:8-minideb
container: qdrvm/kagome-dev:9-minideb
steps:
- uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6
- uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
Expand Down Expand Up @@ -268,7 +268,7 @@ jobs:
build-type: "RelWithDebInfo"
runs-on: [ actions-runner-controller ]
timeout-minutes: 120
container: qdrvm/kagome-dev:8-minideb
container: qdrvm/kagome-dev:9-minideb
steps:
- uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6
with:
Expand Down
2 changes: 1 addition & 1 deletion core/api/jrpc/decode_args.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace kagome::api::details {
if (r) {
return std::move(r.value());
}
throw jsonrpc::InvalidParametersFault{r.error().message()};
throw jsonrpc::InvalidParametersFault{fmt::to_string(r.error())};
}

static auto &mapAt(const jsonrpc::Value &j, const std::string &k) {
Expand Down
4 changes: 2 additions & 2 deletions core/api/jrpc/jrpc_method.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ namespace kagome::api {

// Init request
if (auto &&init_result = request.init(params); not init_result) {
throw jsonrpc::Fault(init_result.error().message());
throw jsonrpc::Fault(fmt::to_string(init_result.error()));
}

// Execute request
auto &&result = request.execute();

// Handle of failure
if (not result) {
throw jsonrpc::Fault(result.error().message());
throw jsonrpc::Fault(fmt::to_string(result.error()));
}

if constexpr (std::is_same_v<decltype(result.value()), void>) {
Expand Down
2 changes: 1 addition & 1 deletion core/api/service/jrpc_fn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace kagome::api {
}
return {};
}
throw jsonrpc::Fault(result.error().message());
throw jsonrpc::Fault(fmt::to_string(result.error()));
} else {
call();
return {};
Expand Down
52 changes: 17 additions & 35 deletions core/benchmark/block_execution_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,23 @@ OUTCOME_CPP_DEFINE_CATEGORY(kagome::benchmark,
return "Unknown BlockExecutionBenchmark error";
}

#define STR_SIMPLE(a) #a
#define STR(a) STR_SIMPLE(a)
#define CONCAT_SIMPLE(a, b) a##b
#define CONCAT(a, b) CONCAT_SIMPLE(a, b)

static_assert(STR(CONCAT(2, 3)) == std::string_view("23"));

// mind if you want to move it to global scope, __LINE__ is not very reliable,
// may use __COUNTER__ instead
#define OUTCOME_TRY_MSG(var, expr, msg, ...) \
auto CONCAT(_res_, __LINE__) = (expr); \
do { \
if (CONCAT(_res_, __LINE__).has_error()) { \
SL_ERROR(logger_, \
"Failure on {}: {} ({})", \
#expr, \
CONCAT(_res_, __LINE__).error().message(), \
fmt::format(msg, __VA_ARGS__)); \
return CONCAT(_res_, __LINE__).as_failure(); \
} \
} while (false); \
auto var = std::move(CONCAT(_res_, __LINE__).value());

#define OUTCOME_TRY_MSG_VOID(expr, msg, ...) \
do { \
auto CONCAT(_res_, __LINE__) = (expr); \
if (CONCAT(_res_, __LINE__).has_error()) { \
SL_ERROR(logger_, \
"Failure on {}: {} ({})", \
#expr, \
CONCAT(_res_, __LINE__).error().message(), \
fmt::format(msg, __VA_ARGS__)); \
return CONCAT(_res_, __LINE__).as_failure(); \
} \
} while (false);
#define _OUTCOME_TRY_MSG_VOID(tmp, expr, ...) \
auto &&tmp = expr; \
if (tmp.has_error()) { \
SL_ERROR(logger_, \
"Failure on {}: {} ({})", \
#expr, \
tmp.error(), \
fmt::format(__VA_ARGS__)); \
return std::move(tmp).error(); \
}
#define _OUTCOME_TRY_MSG_OUT(tmp, out, expr, ...) \
_OUTCOME_TRY_MSG_VOID(tmp, expr, __VA_ARGS__); \
auto out = std::move(tmp).value();
#define OUTCOME_TRY_MSG(out, expr, ...) \
_OUTCOME_TRY_MSG_OUT(BOOST_OUTCOME_TRY_UNIQUE_NAME, out, expr, __VA_ARGS__)
#define OUTCOME_TRY_MSG_VOID(expr, ...) \
_OUTCOME_TRY_MSG_VOID(BOOST_OUTCOME_TRY_UNIQUE_NAME, expr, __VA_ARGS__)

namespace {

Expand Down
6 changes: 2 additions & 4 deletions core/common/tagged.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ namespace kagome {
public:
typedef Tag tag;

template <typename... Args>
explicit Tagged(Args &&...args) : Base(std::forward<Args>(args)...) {}
Tagged() : Base() {}

Tagged(T &&value) noexcept(not std::is_lvalue_reference_v<decltype(value)>)
: Base(std::forward<T>(value)) {}
Tagged(T value) : Base(std::move(value)) {}

Tagged &operator=(T &&value) noexcept(
not std::is_lvalue_reference_v<decltype(value)>) {
Expand Down
2 changes: 1 addition & 1 deletion core/host_api/impl/child_storage_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ namespace kagome::host_api {
} else {
SL_ERROR(
logger_, "Error in ext_storage_read_version_1: {}", value.error());
throw std::runtime_error{value.error().message()};
value.value();
}

return memory.storeBuffer(scale::encode(res).value());
Expand Down
24 changes: 5 additions & 19 deletions core/host_api/impl/crypto_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,23 +455,11 @@ namespace kagome::host_api {
}

namespace {
template <typename T>
using failure_type =
decltype(outcome::result<std::decay_t<T>>(T{}).as_failure());

/**
* @brief converts outcome::failure_type to Secp256k1VerifyError error code
* @param failure outcome::result containing error
* @return error code
*/
template <class T>
Secp256k1VerifyError convertFailureToError(const failure_type<T> &failure) {
const outcome::result<void> res = failure;
if (res == outcome::failure(Secp256k1ProviderError::INVALID_V_VALUE)) {
Secp256k1VerifyError convertFailureToError(const std::error_code &error) {
if (error == Secp256k1ProviderError::INVALID_V_VALUE) {
return secp256k1::secp256k1_verify_error::kInvalidV;
}
if (res
== outcome::failure(Secp256k1ProviderError::INVALID_R_OR_S_VALUE)) {
if (error == Secp256k1ProviderError::INVALID_R_OR_S_VALUE) {
return secp256k1::secp256k1_verify_error::kInvalidRS;
}

Expand Down Expand Up @@ -500,8 +488,7 @@ namespace kagome::host_api {
logger_->error("failed to recover uncompressed secp256k1 public key: {}",
public_key.error());

auto error_code =
convertFailureToError<UncompressedPublicKey>(public_key.as_failure());
auto error_code = convertFailureToError(public_key.error());
auto error_result =
scale::encode(static_cast<ResultType>(error_code)).value();

Expand Down Expand Up @@ -552,8 +539,7 @@ namespace kagome::host_api {
logger_->error("failed to recover uncompressed secp256k1 public key: {}",
public_key.error());

auto error_code =
convertFailureToError<CompressedPublicKey>(public_key.as_failure());
auto error_code = convertFailureToError(public_key.error());
auto error_result =
scale::encode(static_cast<ResultType>(error_code)).value();
return getMemory().storeBuffer(error_result);
Expand Down
8 changes: 3 additions & 5 deletions core/host_api/impl/storage_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ namespace kagome::host_api {
SL_TRACE_VOID_FUNC_CALL(logger_);
if (res.has_error()) {
logger_->error("Storage transaction start has failed: {}", res.error());
throw std::runtime_error(res.error().message());
res.value();
}
++transactions_;
}
Expand All @@ -287,7 +287,7 @@ namespace kagome::host_api {
if (res.has_error()) {
logger_->error("Storage transaction rollback has failed: {}",
res.error());
throw std::runtime_error(res.error().message());
res.value();
}
--transactions_;
}
Expand All @@ -298,7 +298,7 @@ namespace kagome::host_api {
if (res.has_error()) {
logger_->error("Storage transaction rollback has failed: {}",
res.error());
throw std::runtime_error(res.error().message());
res.value();
}
--transactions_;
}
Expand All @@ -324,7 +324,6 @@ namespace kagome::host_api {
const auto &pairs = scale::decode<KeyValueCollection>(buffer);
if (!pairs) {
logger_->error("failed to decode pairs: {}", pairs.error());
throw std::runtime_error(pairs.error().message());
}

auto &&pv = pairs.value();
Expand Down Expand Up @@ -352,7 +351,6 @@ namespace kagome::host_api {
codec.encodeNode(*trie->getRoot(), storage::trie::StateVersion::V0, {});
if (!enc) {
logger_->error("failed to encode trie root: {}", enc.error());
throw std::runtime_error(enc.error().message());
}
const auto &hash = codec.hash256(enc.value());

Expand Down
4 changes: 0 additions & 4 deletions core/injector/application_injector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,6 @@ namespace {
std::move(storage),
std::move(substitutes),
std::move(block_storage));
if (res.has_error()) {
throw std::runtime_error("Error creating RuntimeUpgradeTrackerImpl: "
+ res.error().message());
}
return std::shared_ptr<runtime::RuntimeUpgradeTrackerImpl>(
std::move(res.value()));
}
Expand Down
4 changes: 2 additions & 2 deletions core/network/adapters/protobuf_block_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace kagome::network {
std::vector<uint8_t>::iterator loaded) {
::api::v1::BlockRequest msg;

msg.set_fields(htobe32(t.fields));
msg.set_fields(htobe32(static_cast<uint8_t>(t.fields)));

kagome::visit_in_place(
t.from,
Expand Down Expand Up @@ -65,7 +65,7 @@ namespace kagome::network {
return AdaptersError::PARSE_FAILED;
}

out.fields.load(be32toh(msg.fields()));
out.fields = toBlockAttribute(be32toh(msg.fields()));
out.direction = static_cast<decltype(out.direction)>(msg.direction());

switch (msg.from_block_case()) {
Expand Down
2 changes: 1 addition & 1 deletion core/network/impl/peer_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ namespace kagome::network {
"Unable to create stream {} with {}: {}",
validation_protocol->protocolName(),
peer_id,
stream_result.error().message());
stream_result.error());
return;
}

Expand Down
2 changes: 1 addition & 1 deletion core/network/impl/protocols/fetch_attested_candidate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace kagome::network {
if (res.has_error()) {
base().logger()->error(
"Fetching attested candidate response failed.(error={})",
res.error().message());
res.error());
} else {
base().logger()->trace("Fetching attested candidate response.");
}
Expand Down
2 changes: 1 addition & 1 deletion core/network/impl/protocols/protocol_fetch_chunk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace kagome::network {
auto res = pp_->OnFetchChunkRequest(std::move(request));
if (res.has_error()) {
base().logger()->error("Fetching chunk response failed.(error={})",
res.error().message());
res.error());
} else {
visit_in_place(
res.value(),
Expand Down
2 changes: 1 addition & 1 deletion core/network/impl/protocols/protocol_req_pov.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace kagome::network {
base().logger()->warn(
"Our PoV response has error.(candidate hash={}, error={})",
request,
response.error().message());
response.error());
} else {
base().logger()->info("Our PoV response {} data.(candidate hash={})",
boost::get<ParachainBlock>(&response.value())
Expand Down
20 changes: 10 additions & 10 deletions core/network/impl/protocols/sync_protocol_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,19 @@ namespace kagome::network {
stream->remotePeerId().value());

logmsg += ", fields=";
if (block_request.fields & BlockAttribute::HEADER) {
if (has(block_request.fields, BlockAttribute::HEADER)) {
logmsg += 'H';
}
if (block_request.fields & BlockAttribute::BODY) {
if (has(block_request.fields, BlockAttribute::BODY)) {
logmsg += 'B';
}
if (block_request.fields & BlockAttribute::RECEIPT) {
if (has(block_request.fields, BlockAttribute::RECEIPT)) {
logmsg += 'R';
}
if (block_request.fields & BlockAttribute::MESSAGE_QUEUE) {
if (has(block_request.fields, BlockAttribute::MESSAGE_QUEUE)) {
logmsg += 'M';
}
if (block_request.fields & BlockAttribute::JUSTIFICATION) {
if (has(block_request.fields, BlockAttribute::JUSTIFICATION)) {
logmsg += 'J';
}

Expand Down Expand Up @@ -438,19 +438,19 @@ namespace kagome::network {
if (base_.logger()->level() >= log::Level::DEBUG) {
std::string logmsg = "Requesting blocks: fields=";

if (block_request.fields & BlockAttribute::HEADER) {
if (has(block_request.fields, BlockAttribute::HEADER)) {
logmsg += 'H';
}
if (block_request.fields & BlockAttribute::BODY) {
if (has(block_request.fields, BlockAttribute::BODY)) {
logmsg += "B";
}
if (block_request.fields & BlockAttribute::RECEIPT) {
if (has(block_request.fields, BlockAttribute::RECEIPT)) {
logmsg += "R";
}
if (block_request.fields & BlockAttribute::MESSAGE_QUEUE) {
if (has(block_request.fields, BlockAttribute::MESSAGE_QUEUE)) {
logmsg += "M";
}
if (block_request.fields & BlockAttribute::JUSTIFICATION) {
if (has(block_request.fields, BlockAttribute::JUSTIFICATION)) {
logmsg += "J";
}

Expand Down
Loading

0 comments on commit ebfe405

Please sign in to comment.