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 =
55 throw std::logic_error(
"Snapshot transaction size should not be zero");
58 const auto* receipt_data = data + store_snapshot_size;
59 auto receipt_size = size - store_snapshot_size;
61 if (receipt_size == 0)
63 throw std::logic_error(
"No receipt included in snapshot");
66 LOG_INFO_FMT(
"Deserialising snapshot receipt (size: {}).", receipt_size);
67 constexpr size_t max_printed_size = 1024;
68 if (receipt_size > max_printed_size)
71 "Receipt size ({}) exceeds max printed size ({}), only printing "
77 auto printed_size = std::min<size_t>(receipt_size, max_printed_size);
78 LOG_INFO_FMT(
"{}", ds::to_hex(receipt_data, receipt_data + printed_size));
80 auto j = nlohmann::json::parse(receipt_data, receipt_data + receipt_size);
82 auto receipt = std::dynamic_pointer_cast<ccf::ProofReceipt>(receipt_p);
83 if (receipt ==
nullptr)
85 throw std::logic_error(
86 fmt::format(
"Unexpected receipt type: missing expanded claims"));
89 auto snapshot_digest =
91 auto snapshot_digest_claim = receipt->leaf_components.claims_digest.value();
92 if (snapshot_digest != snapshot_digest_claim)
94 throw std::logic_error(fmt::format(
95 "Snapshot digest ({}) does not match receipt claim ({})",
97 snapshot_digest_claim));
100 auto root = receipt->calculate_root();
101 auto raw_sig = receipt->signature;
107 receipt->signature.data(),
108 receipt->signature.size(),
111 throw std::logic_error(
112 "Signature verification failed for snapshot receipt");
115 if (prev_service_identity)
118 if (!v->verify_certificate(
123 throw std::logic_error(
124 "Previous service identity does not endorse the node identity that "
125 "signed the snapshot");
127 LOG_DEBUG_FMT(
"Previous service identity endorses snapshot signer");
131 "Deserialising snapshot (size: {}, public only: {})",
135 auto rc = store->deserialise_snapshot(
136 snapshot.data(), store_snapshot_size, hooks, view_history, public_only);
139 throw std::logic_error(fmt::format(
"Failed to apply snapshot: {}", rc));
143 "Snapshot successfully deserialised at seqno {}",
144 store->current_version());
147 static std::unique_ptr<StartupSnapshotInfo> initialise_from_snapshot(
148 const std::shared_ptr<ccf::kv::Store>& store,
149 std::vector<uint8_t>&& snapshot,
151 std::vector<ccf::kv::Version>* view_history =
nullptr,
152 bool public_only =
false,
153 std::optional<std::vector<uint8_t>> previous_service_identity =
156 deserialise_snapshot(
162 previous_service_identity);
163 return std::make_unique<StartupSnapshotInfo>(
164 store, std::move(snapshot), store->current_version());
167 static std::vector<uint8_t> build_and_serialise_receipt(
168 const std::vector<uint8_t>& sig,
169 const std::vector<uint8_t>& tree,
174 const std::string& commit_evidence,
178 auto proof = history.get_proof(
seqno);
181 cd.
set(std::move(claims_digest));
194 const auto receipt_str = receipt.dump();
195 return {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 internal_logger.h:15
#define LOG_DEBUG_FMT
Definition internal_logger.h:14
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:303
std::vector< ConsensusHookPtr > ConsensusHookPtrs
Definition hooks.h:22
Definition app_interface.h:14
EntityId< NodeIdFormatter > NodeId
Definition entity_id.h:164
nlohmann::json describe_receipt_v1(const TxReceiptImpl &receipt)
Definition historical_queries_adapter.cpp:68
std::shared_ptr< Receipt > ReceiptPtr
Definition receipt.h:128
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:14