Skip to content

Commit

Permalink
Merge branch 'main' of github.com:microsoft/CCF into fuzz_test_logging
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyashton committed Jul 3, 2024
2 parents 9b32ae0 + 75e397b commit ccc134a
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 87 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- The `programmability` sample app now demonstrates how applications can define their own extensions, creating bindings between C++ and JS state, and allowing JS endpoints to call functions implemented in C++.
- Introduce `DynamicJSEndpointRegistry::record_action_for_audit_v1` and `DynamicJSEndpointRegistry::check_action_not_replayed_v1` to allow an application making use of the programmability feature to easily implement auditability, and protect users allowed to update the application against replay attacks (#6285).
- Endpoints now support a `ToBackup` redirection strategy, for requests which should never be executed on a primary. These must also be read-only. These are configured similar to `ToPrimary` endpoints, with a `to_backup` object (specifying by-role or statically-addressed targets) in each node's configuration.
- Introduced `ccf::historical::read_only_adapter_v4` and `ccf::historical::read_write_adapter_v4`. Users are now capable of passing a custom error handler to the adapter to customise RPC responses for internal historical queries errors, which are listed in `ccf::historical::HistoricalQueryErrorCode` enum.

## Changed
### Changed

- Updated Open Enclave to [0.19.7](https://github.com/openenclave/openenclave/releases/tag/v0.19.7).

### Deprecated

- `ccf::historical::adapter_v3` becomes deprecated in favour of `_v4` version.

### Removed

- Removed the existing metrics endpoint and API (`GET /api/metrics`, `get_metrics_v1`). Stats for request execution can instead be gathered by overriding the `EndpointRegistry::handle_event_request_completed()` method.
Expand Down
7 changes: 0 additions & 7 deletions include/ccf/ds/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,6 @@ namespace ccf::logger
logger->write(line);
}

#ifndef INSIDE_ENCLAVE
if (line.log_level == LoggerLevel::FATAL)
{
throw std::logic_error("Fatal: " + format_to_text(line));
}
#endif

return true;
}
};
Expand Down
41 changes: 41 additions & 0 deletions include/ccf/historical_queries_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ namespace ccf::historical
std::optional<ccf::TxID> txid_from_header(
endpoints::CommandEndpointContext& args);

enum class HistoricalQueryErrorCode
{
InternalError,
TransactionPending,
TransactionInvalid,
TransactionIdMissing,
TransactionPartiallyReady,
};

using ErrorHandler = std::function<void(
HistoricalQueryErrorCode err,
std::string reason,
endpoints::EndpointContext& args)>;

using ReadOnlyErrorHandler = std::function<void(
HistoricalQueryErrorCode err,
std::string reason,
endpoints::ReadOnlyEndpointContext& args)>;

void default_error_handler(
HistoricalQueryErrorCode err,
std::string reason,
endpoints::CommandEndpointContext& args);

enum class HistoricalTxStatus
{
Error,
Expand All @@ -56,21 +80,38 @@ namespace ccf::historical
ccf::SeqNo seqno,
std::string& error_reason);

CCF_DEPRECATED("Replaced by _v4")
ccf::endpoints::EndpointFunction adapter_v3(
const HandleHistoricalQuery& f,
ccf::AbstractNodeContext& node_context,
const CheckHistoricalTxStatus& available,
const TxIDExtractor& extractor = txid_from_header);

CCF_DEPRECATED("Replaced by _v4")
ccf::endpoints::ReadOnlyEndpointFunction read_only_adapter_v3(
const HandleReadOnlyHistoricalQuery& f,
ccf::AbstractNodeContext& node_context,
const CheckHistoricalTxStatus& available,
const ReadOnlyTxIDExtractor& extractor = txid_from_header);

CCF_DEPRECATED("Replaced by _v4")
ccf::endpoints::EndpointFunction read_write_adapter_v3(
const HandleReadWriteHistoricalQuery& f,
ccf::AbstractNodeContext& node_context,
const CheckHistoricalTxStatus& available,
const TxIDExtractor& extractor = txid_from_header);

ccf::endpoints::ReadOnlyEndpointFunction read_only_adapter_v4(
const HandleReadOnlyHistoricalQuery& f,
ccf::AbstractNodeContext& node_context,
const CheckHistoricalTxStatus& available,
const ReadOnlyTxIDExtractor& extractor = txid_from_header,
const ReadOnlyErrorHandler& ehandler = default_error_handler);

ccf::endpoints::EndpointFunction read_write_adapter_v4(
const HandleReadWriteHistoricalQuery& f,
ccf::AbstractNodeContext& node_context,
const CheckHistoricalTxStatus& available,
const TxIDExtractor& extractor = txid_from_header,
const ErrorHandler& ehandler = default_error_handler);
}
6 changes: 3 additions & 3 deletions samples/apps/logging/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ namespace loggingapp
make_read_only_endpoint(
"/log/private/historical",
HTTP_GET,
ccf::historical::read_only_adapter_v3(
ccf::historical::read_only_adapter_v4(
get_historical, context, is_tx_committed),
auth_policies)
.set_auto_schema<void, LoggingGetHistorical::Out>()
Expand Down Expand Up @@ -1335,7 +1335,7 @@ namespace loggingapp
make_read_only_endpoint(
"/log/private/historical_receipt",
HTTP_GET,
ccf::historical::read_only_adapter_v3(
ccf::historical::read_only_adapter_v4(
get_historical_with_receipt, context, is_tx_committed),
auth_policies)
.set_auto_schema<void, LoggingGetReceipt::Out>()
Expand Down Expand Up @@ -1391,7 +1391,7 @@ namespace loggingapp
make_read_only_endpoint(
"/log/public/historical_receipt",
HTTP_GET,
ccf::historical::read_only_adapter_v3(
ccf::historical::read_only_adapter_v4(
get_historical_with_receipt_and_claims, context, is_tx_committed),
auth_policies)
.set_auto_schema<void, LoggingGetReceipt::Out>()
Expand Down
2 changes: 1 addition & 1 deletion src/apps/js_generic/js_generic_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace ccf
consensus, view, seqno, error_reason);
};

ccf::historical::adapter_v3(
ccf::historical::read_write_adapter_v4(
[this, endpoint](
ccf::endpoints::EndpointContext& endpoint_ctx,
ccf::historical::StatePtr state) {
Expand Down
2 changes: 2 additions & 0 deletions src/clients/perf/perf_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace client
if (core_id > threads || core_id < 0)
{
LOG_FATAL_FMT("Invalid core id: {}", core_id);
abort();
return false;
}

Expand All @@ -43,6 +44,7 @@ namespace client
if (sched_setaffinity(0, sizeof(cpu_set_t), &set) < 0)
{
LOG_FATAL_FMT("Unable to set affinity");
abort();
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/ds/test/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ TEST_CASE("Framework logging macros")

{
REQUIRE(logs.empty());
REQUIRE_THROWS(LOG_FATAL_FMT("Hello C"));
LOG_FATAL_FMT("Hello C");
REQUIRE(logs.size() == 1);

const auto& log = logs[0];
Expand Down Expand Up @@ -109,7 +109,7 @@ TEST_CASE("Application logging macros")

{
REQUIRE(logs.empty());
REQUIRE_THROWS(CCF_APP_FATAL("Hello C"));
CCF_APP_FATAL("Hello C");
REQUIRE(logs.size() == 1);

const auto& log = logs[0];
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/common_endpoint_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ namespace ccf
make_read_only_endpoint(
"/receipt",
HTTP_GET,
ccf::historical::read_only_adapter_v3(
ccf::historical::read_only_adapter_v4(
get_receipt, context, is_tx_committed, txid_from_query_string),
no_auth_required)
.set_auto_schema<void, nlohmann::json>()
Expand Down
4 changes: 3 additions & 1 deletion src/endpoints/endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ namespace ccf::endpoints
{
if (installer == nullptr)
{
LOG_FATAL_FMT(
auto msg = fmt::format(
"Can't install this endpoint ({}) - it is not associated with an "
"installer",
full_uri_path);
LOG_FATAL_FMT("{}", msg);
throw std::logic_error(msg);
}
else
{
Expand Down
14 changes: 1 addition & 13 deletions src/host/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,6 @@ void print_version(size_t)
exit(0);
}

std::string read_required_environment_variable(
const std::string& envvar, const std::string& name)
{
auto ev = std::getenv(envvar.c_str());
if (ev == nullptr)
{
LOG_FATAL_FMT(
"Environment variable \"{}\" for {} is not set", envvar, name);
}
LOG_INFO_FMT("Reading {} from environment {}", name, envvar);
return ev;
}

int main(int argc, char** argv)
{
// ignore SIGPIPE
Expand Down Expand Up @@ -680,6 +667,7 @@ int main(int argc, char** argv)
else
{
LOG_FATAL_FMT("Start command should be start|join|recover. Exiting.");
return static_cast<int>(CLI::ExitCodes::ValidationError);
}

std::vector<uint8_t> startup_snapshot = {};
Expand Down
2 changes: 2 additions & 0 deletions src/host/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ namespace asynchost
virtual void on_resolve_failed()
{
LOG_FATAL_FMT("{} {} resolve failed", conn_name, name);
abort();
}
virtual void on_listen_failed()
{
LOG_FATAL_FMT("{} {} listen failed", conn_name, name);
abort();
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/js/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ namespace ccf::js
consensus, view, seqno, error_reason);
};

ccf::historical::adapter_v3(
ccf::historical::read_write_adapter_v4(
[this, endpoint](
ccf::endpoints::EndpointContext& endpoint_ctx,
ccf::historical::StatePtr state) {
Expand Down
5 changes: 2 additions & 3 deletions src/node/acme_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ namespace ACME
}
catch (const std::exception& ex)
{
LOG_FATAL_FMT("ACME: request callback failed: {}", ex.what());
LOG_FAIL_FMT("ACME: request callback failed: {}", ex.what());
return false;
}
});
Expand Down Expand Up @@ -807,8 +807,7 @@ namespace ACME
}
else
{
LOG_FATAL_FMT(
"ACME: unknown order status '{}', aborting", status);
LOG_FAIL_FMT("ACME: unknown order status '{}', aborting", status);
guard.unlock();
remove_order(*order_url_opt);
}
Expand Down
Loading

0 comments on commit ccc134a

Please sign in to comment.