Skip to content

Commit

Permalink
Remove ccf::historical::adapter_v2 (#5873)
Browse files Browse the repository at this point in the history
  • Loading branch information
achamayou authored Dec 19, 2023
1 parent 3c5168d commit 2ea3867
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 108 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Removed

- `ccf::historical::adapter_v2` is removed, replaced by `ccf::historical::adapter_v3` first introduced in 2.0.0.
- `ccf::EnclaveAttestationProvider` has been removed. It is replaced by `ccf::AttestationProvider`

## [5.0.0-dev10]
Expand Down
17 changes: 0 additions & 17 deletions include/ccf/historical_queries_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,4 @@ namespace ccf::historical
ccfapp::AbstractNodeContext& node_context,
const CheckHistoricalTxStatus& available,
const TxIDExtractor& extractor = txid_from_header);

/// @cond
// Doxygen cannot parse these declarations; some combination of a macro,
// attribute syntax, and namespaced types results in the following warning
// (treated as error):
// Found ';' while parsing initializer list! (doxygen could be confused by a
// macro call without semicolon)
// Use label-less cond to unconditionally exclude this block from parsing
// until the declarations are removed are removed.
CCF_DEPRECATED(
"Will be removed in 3.0, switch to ccf::historical::adapter_v3")
ccf::endpoints::EndpointFunction adapter_v2(
const HandleHistoricalQuery& f,
ccfapp::AbstractNodeContext& node_context,
const CheckHistoricalTxStatus& available,
const TxIDExtractor& extractor = txid_from_header);
/// @endcond
}
91 changes: 0 additions & 91 deletions src/node/historical_queries_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,95 +374,4 @@ namespace ccf::historical
ccf::endpoints::EndpointFunction,
ccf::endpoints::EndpointContext>(f, node_context, available, extractor);
}

ccf::endpoints::EndpointFunction adapter_v2(
const HandleHistoricalQuery& f,
AbstractStateCache& state_cache,
const CheckHistoricalTxStatus& available,
const TxIDExtractor& extractor)
{
return [f, &state_cache, available, extractor](
endpoints::EndpointContext& args) {
// Extract the requested transaction ID
ccf::TxID target_tx_id;
{
const auto tx_id_opt = extractor(args);
if (tx_id_opt.has_value())
{
target_tx_id = tx_id_opt.value();
}
else
{
return;
}
}

// Check that the requested transaction ID is available
{
auto error_reason = fmt::format(
"Transaction {} is not available.", target_tx_id.to_str());
auto is_available =
available(target_tx_id.view, target_tx_id.seqno, error_reason);
switch (is_available)
{
case HistoricalTxStatus::Error:
{
args.rpc_ctx->set_error(
HTTP_STATUS_INTERNAL_SERVER_ERROR,
ccf::errors::TransactionPendingOrUnknown,
std::move(error_reason));
return;
}
case HistoricalTxStatus::PendingOrUnknown:
{
// Set header No-Cache
args.rpc_ctx->set_response_header(
http::headers::CACHE_CONTROL, "no-cache");
args.rpc_ctx->set_error(
HTTP_STATUS_NOT_FOUND,
ccf::errors::TransactionPendingOrUnknown,
std::move(error_reason));
return;
}
case HistoricalTxStatus::Invalid:
{
args.rpc_ctx->set_error(
HTTP_STATUS_NOT_FOUND,
ccf::errors::TransactionInvalid,
std::move(error_reason));
return;
}
case HistoricalTxStatus::Valid:
{
}
}
}

// We need a handle to determine whether this request is the 'same' as a
// previous one. For simplicity we use target_tx_id.seqno. This means we
// keep a lot of state around for old requests! It should be cleaned up
// manually
const auto historic_request_handle = target_tx_id.seqno;

// Get a state at the target version from the cache, if it is present
auto historical_state =
state_cache.get_state_at(historic_request_handle, target_tx_id.seqno);
if (historical_state == nullptr)
{
args.rpc_ctx->set_response_status(HTTP_STATUS_ACCEPTED);
constexpr size_t retry_after_seconds = 3;
args.rpc_ctx->set_response_header(
http::headers::RETRY_AFTER, retry_after_seconds);
args.rpc_ctx->set_response_header(
http::headers::CONTENT_TYPE, http::headervalues::contenttype::TEXT);
args.rpc_ctx->set_response_body(fmt::format(
"Historical transaction {} is not currently available.",
target_tx_id.to_str()));
return;
}

// Call the provided handler
f(args, historical_state);
};
}
}

0 comments on commit 2ea3867

Please sign in to comment.