Skip to content

Commit c17a103

Browse files
Copilotmaxtropetsachamayou
authored
Introduce a concrete exception type for identity-history-not-fetched cases (#7708)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: maxtropets <16566519+maxtropets@users.noreply.github.com> Co-authored-by: Max <maxtropets@microsoft.com> Co-authored-by: Max Tropets <maxtropets@gmail.com> Co-authored-by: Amaury Chamayou <amchamay@microsoft.com>
1 parent 5c9a673 commit c17a103

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111

1212
### Added
1313

14+
- Added `ccf::IdentityHistoryNotFetched` exception type to distinguish identity-history-fetching errors from other logic errors in the network identity subsystem (#7708).
1415
- Added `ccf::describe_cose_receipt_v1(receipt)` to obtain COSE receipts with Merkle proof in unprotected header for non-signature TXs, and empty unprotected header for signature TXs (#7700).
1516
- `NetworkIdentitySubsystemInterface` now exposes `get_trusted_keys()`, returning all trusted network identity keys as a `TrustedKeys` map (#7690).
1617

include/ccf/network_identity_interface.h

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "ccf/crypto/ec_public_key.h"
66
#include "ccf/node_subsystem_interface.h"
77

8+
#include <exception>
89
#include <map>
910
#include <optional>
1011
#include <string>
@@ -31,6 +32,20 @@ namespace ccf
3132
/// network identity keys over the history of the service.
3233
using TrustedKeys = std::map<ccf::SeqNo, ccf::crypto::ECPublicKeyPtr>;
3334

35+
/// Exception thrown when identity data is requested before the
36+
/// asynchronous identity-history-fetching process has completed.
37+
struct IdentityHistoryNotFetched : public std::exception
38+
{
39+
std::string msg;
40+
41+
IdentityHistoryNotFetched(std::string msg) : msg(std::move(msg)) {}
42+
43+
[[nodiscard]] const char* what() const noexcept override
44+
{
45+
return msg.c_str();
46+
}
47+
};
48+
3449
/// Interface for accessing the network identity subsystem, which manages
3550
/// the service's cryptographic identity and its historical trusted keys.
3651
class NetworkIdentitySubsystemInterface : public ccf::AbstractNodeSubSystem
@@ -53,25 +68,27 @@ namespace ccf
5368
/// or std::nullopt if the chain is not available for the given sequence
5469
/// number.
5570
///
56-
/// @throws std::logic_error if endorsement fetching has not completed.
71+
/// @throws IdentityHistoryNotFetched if identity history fetching has not
72+
/// completed.
5773
[[nodiscard]] virtual std::optional<CoseEndorsementsChain>
5874
get_cose_endorsements_chain(ccf::SeqNo seqno) const = 0;
5975

6076
/// Returns the trusted EC public key that was active at the given
6177
/// sequence number, or nullptr if the sequence number precedes the
6278
/// earliest known trusted key.
6379
///
64-
/// @throws std::logic_error if endorsement fetching has not completed
65-
/// (i.e. endorsements_fetching_status() != FetchStatus::Done), or if
66-
/// no trusted keys have been fetched.
80+
/// @throws IdentityHistoryNotFetched if identity history fetching has not
81+
/// completed.
82+
/// @throws std::logic_error if no trusted keys have been fetched, or if
83+
/// internal key resolution is inconsistent.
6784
[[nodiscard]] virtual ccf::crypto::ECPublicKeyPtr get_trusted_identity_for(
6885
ccf::SeqNo seqno) const = 0;
6986

7087
/// Returns all trusted network identity keys as a map from sequence
7188
/// number to EC public key.
7289
///
73-
/// @throws std::logic_error if endorsement fetching has not completed
74-
/// (i.e. endorsements_fetching_status() != FetchStatus::Done).
90+
/// @throws IdentityHistoryNotFetched if identity history fetching has not
91+
/// completed.
7592
[[nodiscard]] virtual TrustedKeys get_trusted_keys() const = 0;
7693
};
7794
}

src/node/rpc/network_identity_subsystem.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ namespace ccf
144144
{
145145
if (fetch_status.load() != FetchStatus::Done)
146146
{
147-
throw std::logic_error(fmt::format(
148-
"COSE endorsements chain requested for seqno {} but endorsement "
149-
"fetching has not been completed yet",
147+
throw IdentityHistoryNotFetched(fmt::format(
148+
"COSE endorsements chain requested for seqno {} but identity "
149+
"history fetching has not been completed yet",
150150
seqno));
151151
}
152152

@@ -186,9 +186,9 @@ namespace ccf
186186
{
187187
if (fetch_status.load() != FetchStatus::Done)
188188
{
189-
throw std::logic_error(fmt::format(
190-
"Trusted key requested for seqno {} but the fetching has "
191-
"not been completed yet",
189+
throw IdentityHistoryNotFetched(fmt::format(
190+
"Trusted key requested for seqno {} but identity history "
191+
"fetching has not been completed yet",
192192
seqno));
193193
}
194194
if (trusted_keys.empty())
@@ -217,8 +217,8 @@ namespace ccf
217217
{
218218
if (fetch_status.load() != FetchStatus::Done)
219219
{
220-
throw std::logic_error(
221-
"Trusted keys requested but endorsements/key fetching has not "
220+
throw IdentityHistoryNotFetched(
221+
"Trusted keys requested but identity history fetching has not "
222222
"completed yet");
223223
}
224224
return trusted_keys;

0 commit comments

Comments
 (0)