14#include <nlohmann/json.hpp>
20 std::vector<uint8_t>
raw;
26 std::shared_ptr<ccf::kv::Store>
store =
nullptr;
29 const std::shared_ptr<ccf::kv::Store>& store_,
30 std::vector<uint8_t>&& raw_,
38 static void deserialise_snapshot(
39 const std::shared_ptr<ccf::kv::Store>& store,
40 const std::vector<uint8_t>& snapshot,
42 std::vector<ccf::kv::Version>* view_history =
nullptr,
43 bool public_only =
false,
44 std::optional<std::vector<uint8_t>> prev_service_identity = std::nullopt)
46 const auto* data = snapshot.data();
47 auto size = snapshot.size();
49 auto tx_hdr = serialized::peek<ccf::kv::SerialisedEntryHeader>(data, size);
50 auto store_snapshot_size =
53 auto receipt_data = data + store_snapshot_size;
54 auto receipt_size = size - store_snapshot_size;
56 if (receipt_size == 0)
58 throw std::logic_error(
"No receipt included in snapshot");
61 auto j = nlohmann::json::parse(receipt_data, receipt_data + receipt_size);
63 auto receipt = std::dynamic_pointer_cast<ccf::ProofReceipt>(receipt_p);
64 if (receipt ==
nullptr)
66 throw std::logic_error(
67 fmt::format(
"Unexpected receipt type: missing expanded claims"));
70 auto snapshot_digest =
72 auto snapshot_digest_claim = receipt->leaf_components.claims_digest.value();
73 if (snapshot_digest != snapshot_digest_claim)
75 throw std::logic_error(fmt::format(
76 "Snapshot digest ({}) does not match receipt claim ({})",
78 snapshot_digest_claim));
81 auto root = receipt->calculate_root();
82 auto raw_sig = receipt->signature;
88 receipt->signature.data(),
89 receipt->signature.size(),
92 throw std::logic_error(
93 "Signature verification failed for snapshot receipt");
96 if (prev_service_identity)
99 if (!v->verify_certificate(
104 throw std::logic_error(
105 "Previous service identity does not endorse the node identity that "
106 "signed the snapshot");
108 LOG_DEBUG_FMT(
"Previous service identity endorses snapshot signer");
112 "Deserialising snapshot (size: {}, public only: {})",
116 auto rc = store->deserialise_snapshot(
117 snapshot.data(), store_snapshot_size, hooks, view_history, public_only);
120 throw std::logic_error(fmt::format(
"Failed to apply snapshot: {}", rc));
124 "Snapshot successfully deserialised at seqno {}",
125 store->current_version());
128 static std::unique_ptr<StartupSnapshotInfo> initialise_from_snapshot(
129 const std::shared_ptr<ccf::kv::Store>& store,
130 std::vector<uint8_t>&& snapshot,
132 std::vector<ccf::kv::Version>* view_history =
nullptr,
133 bool public_only =
false,
134 std::optional<std::vector<uint8_t>> previous_service_identity =
137 deserialise_snapshot(
143 previous_service_identity);
144 return std::make_unique<StartupSnapshotInfo>(
145 store, std::move(snapshot), store->current_version());
148 static std::vector<uint8_t> build_and_serialise_receipt(
149 const std::vector<uint8_t>& sig,
150 const std::vector<uint8_t>& tree,
155 const std::string& commit_evidence,
159 auto proof = history.get_proof(
seqno);
161 cd.
set(std::move(claims_digest));
174 const auto receipt_str = receipt.dump();
175 return std::vector<uint8_t>(receipt_str.begin(), receipt_str.end());
Definition claims_digest.h:10
void set(Digest &&digest_)
Definition claims_digest.h:21
Definition sha256_hash.h:16
#define LOG_INFO_FMT
Definition logger.h:362
#define LOG_DEBUG_FMT
Definition logger.h:357
VerifierUniquePtr make_unique_verifier(const std::vector< uint8_t > &cert)
Definition verifier.cpp:13
uint64_t Version
Definition version.h:8
@ PASS
Definition kv_types.h:342
std::vector< ConsensusHookPtr > ConsensusHookPtrs
Definition hooks.h:22
Definition app_interface.h:14
EntityId< NodeIdFormatter > NodeId
Definition entity_id.h:155
nlohmann::json describe_receipt_v1(const TxReceiptImpl &receipt)
Definition historical_queries_adapter.cpp:68
std::shared_ptr< Receipt > ReceiptPtr
Definition receipt.h:131
seqno
Definition signatures.h:54
Definition snapshot_serdes.h:19
std::shared_ptr< ccf::kv::Store > store
Definition snapshot_serdes.h:26
StartupSnapshotInfo(const std::shared_ptr< ccf::kv::Store > &store_, std::vector< uint8_t > &&raw_, ccf::kv::Version seqno_)
Definition snapshot_serdes.h:28
std::vector< uint8_t > raw
Definition snapshot_serdes.h:20
ccf::kv::Version seqno
Definition snapshot_serdes.h:21
Definition tx_receipt_impl.h:13