CCF
Loading...
Searching...
No Matches
snapshot.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include "kv/kv_types.h"
6
7namespace ccf::kv
8{
10 {
11 private:
12 Version version;
13
14 std::vector<std::unique_ptr<ccf::kv::AbstractMap::Snapshot>> snapshots;
15 std::optional<std::vector<uint8_t>> hash_at_snapshot = std::nullopt;
16 std::optional<std::vector<Version>> view_history = std::nullopt;
17
18 public:
19 StoreSnapshot(Version version_) : version(version_) {}
20
22 std::unique_ptr<ccf::kv::AbstractMap::Snapshot> snapshot)
23 {
24 snapshots.push_back(std::move(snapshot));
25 }
26
27 void add_hash_at_snapshot(std::vector<uint8_t>&& hash_at_snapshot_)
28 {
29 hash_at_snapshot = std::move(hash_at_snapshot_);
30 }
31
32 void add_view_history(std::vector<Version>&& view_history_)
33 {
34 view_history = std::move(view_history_);
35 }
36
37 Version get_version() const override
38 {
39 return version;
40 }
41
42 std::vector<uint8_t> serialise(
43 const std::shared_ptr<AbstractTxEncryptor>& encryptor) override
44 {
45 // Set the execution dependency for the snapshot to be the version
46 // previous to said snapshot to ensure that the correct snapshot is
47 // serialized.
48 // Notes:
49 // - Snapshots are always taken at compacted state so version only is
50 // unique enough to prevent IV reuse
51 // - Because snapshot generation and ledger rekey can be interleaved,
52 // consider historical ledger secrets when encrypting snapshot (see
53 // https://github.com/microsoft/CCF/issues/3796).
54 KvStoreSerialiser serialiser(
55 encryptor,
56 {0, version},
58 0,
59 {},
60 ccf::no_claims(),
61 true /* historical_hint */);
62
63 if (hash_at_snapshot.has_value())
64 {
65 serialiser.serialise_raw(hash_at_snapshot.value());
66 }
67
68 if (view_history.has_value())
69 {
70 serialiser.serialise_view_history(view_history.value());
71 }
72
74 {
75 for (const auto& it : snapshots)
76 {
77 if (it->get_security_domain() == domain)
78 {
79 it->serialise(serialiser);
80 }
81 }
82 }
83
84 return serialiser.get_raw_data();
85 }
86 };
87}
Definition generic_serialise_wrapper.h:20
void serialise_raw(const std::vector< uint8_t > &raw)
Definition generic_serialise_wrapper.h:108
Definition snapshot.h:10
Version get_version() const override
Definition snapshot.h:37
StoreSnapshot(Version version_)
Definition snapshot.h:19
std::vector< uint8_t > serialise(const std::shared_ptr< AbstractTxEncryptor > &encryptor) override
Definition snapshot.h:42
void add_hash_at_snapshot(std::vector< uint8_t > &&hash_at_snapshot_)
Definition snapshot.h:27
void add_map_snapshot(std::unique_ptr< ccf::kv::AbstractMap::Snapshot > snapshot)
Definition snapshot.h:21
void add_view_history(std::vector< Version > &&view_history_)
Definition snapshot.h:32
Definition app_interface.h:19
@ PRIVATE
Definition kv_types.h:257
@ PUBLIC
Definition kv_types.h:256
uint64_t Version
Definition version.h:8
Definition fetch.h:35