From 45328bf20013319821ab35a8043ee9d1ac82ae4b Mon Sep 17 00:00:00 2001 From: Eddy Ashton Date: Fri, 28 Jun 2024 15:42:49 +0100 Subject: [PATCH] Re-namespace `::kv` to `ccf::kv` (#6312) --- .daily_canary | 2 +- CHANGELOG.md | 1 + doc/architecture/ledger.rst | 14 +- doc/build_apps/example_cpp.rst | 4 +- doc/build_apps/kv/api.rst | 42 +- doc/build_apps/kv/kv_how_to.rst | 58 +- doc/build_apps/kv/kv_serialisation.rst | 8 +- doc/overview/glossary.rst | 2 +- include/ccf/app_interface.h | 2 +- include/ccf/base_endpoint_registry.h | 16 +- include/ccf/crypto/sha256_hash.h | 2 +- include/ccf/endpoint.h | 2 +- include/ccf/endpoint_context.h | 8 +- include/ccf/endpoint_registry.h | 16 +- .../endpoints/authentication/all_of_auth.h | 2 +- .../authentication/authentication_types.h | 2 +- .../ccf/endpoints/authentication/cert_auth.h | 6 +- .../ccf/endpoints/authentication/cose_auth.h | 10 +- .../ccf/endpoints/authentication/empty_auth.h | 2 +- .../ccf/endpoints/authentication/jwt_auth.h | 2 +- include/ccf/entity_id.h | 2 +- include/ccf/historical_queries_adapter.h | 4 +- include/ccf/historical_queries_interface.h | 16 +- include/ccf/historical_queries_utils.h | 2 +- .../strategies/visit_each_entry_in_map.h | 2 +- include/ccf/indexing/strategy.h | 2 +- include/ccf/js/common_context.h | 2 +- include/ccf/js/extensions/ccf/gov_effects.h | 4 +- include/ccf/js/extensions/ccf/kv.h | 4 +- include/ccf/js/registry.h | 22 +- include/ccf/kv/abstract_handle.h | 2 +- include/ccf/kv/get_name.h | 2 +- include/ccf/kv/hooks.h | 2 +- include/ccf/kv/map.h | 26 +- include/ccf/kv/map_diff.h | 41 +- include/ccf/kv/map_handle.h | 38 +- include/ccf/kv/read_only_store.h | 8 +- include/ccf/kv/serialisers/blit_serialiser.h | 2 +- include/ccf/kv/serialisers/json_serialiser.h | 2 +- include/ccf/kv/serialisers/serialised_entry.h | 2 +- include/ccf/kv/set.h | 35 +- include/ccf/kv/set_handle.h | 38 +- include/ccf/kv/unit.h | 20 +- include/ccf/kv/untyped.h | 10 +- include/ccf/kv/untyped_map_diff.h | 12 +- include/ccf/kv/untyped_map_handle.h | 12 +- include/ccf/kv/value.h | 33 +- include/ccf/kv/value_handle.h | 28 +- include/ccf/kv/version.h | 2 +- include/ccf/node/quote.h | 2 +- include/ccf/pal/measurement.h | 2 +- .../ccf/research/create_tx_claims_digest.h | 2 +- .../custom_protocol_subsystem_interface.h | 2 +- include/ccf/service/blit_serialiser_pem.h | 2 +- include/ccf/service/map.h | 20 +- include/ccf/service/node_info.h | 2 +- include/ccf/service/tables/gov.h | 2 +- include/ccf/service/tables/jwt.h | 5 +- include/ccf/service/tables/members.h | 4 +- include/ccf/service/tables/modules.h | 6 +- include/ccf/service/tables/nodes.h | 2 +- include/ccf/service/tables/service.h | 3 +- include/ccf/service/tables/users.h | 2 +- include/ccf/tx.h | 4 +- samples/apps/basic/basic.cpp | 2 +- .../apps/logging/create_tx_claims_digest.cpp | 2 +- samples/apps/logging/logging.cpp | 8 +- .../apps/programmability/programmability.cpp | 14 +- src/apps/js_generic/js_generic_base.cpp | 8 +- src/apps/tpcc/app/tpcc_tables.h | 16 +- src/consensus/aft/impl/state.h | 41 +- src/consensus/aft/raft.h | 143 ++--- src/consensus/aft/raft_types.h | 16 +- src/consensus/aft/test/committable_suffix.cpp | 36 +- src/consensus/aft/test/driver.h | 29 +- src/consensus/aft/test/enclave.cpp | 4 +- src/consensus/aft/test/logging_stub.h | 82 +-- src/consensus/aft/test/main.cpp | 94 +-- src/consensus/aft/test/test_common.h | 2 +- src/consensus/aft/test/view_history.cpp | 63 +- src/consensus/ledger_enclave.h | 16 +- src/ds/test/map_test.cpp | 4 +- src/enclave/rpc_handler.h | 2 +- src/endpoints/authentication/all_of_auth.cpp | 2 +- src/endpoints/authentication/cert_auth.cpp | 6 +- src/endpoints/authentication/cose_auth.cpp | 10 +- src/endpoints/authentication/empty_auth.cpp | 2 +- src/endpoints/authentication/jwt_auth.cpp | 2 +- src/endpoints/base_endpoint_registry.cpp | 18 +- src/endpoints/endpoint_registry.cpp | 11 +- src/endpoints/grpc/grpc.h | 4 +- src/host/ledger.h | 18 +- src/host/test/ledger.cpp | 24 +- src/indexing/historical_transaction_fetcher.h | 8 +- .../strategies/seqnos_by_key_bucketed.cpp | 4 +- .../strategies/visit_each_entry_in_map.cpp | 4 +- src/indexing/test/common.h | 37 +- src/indexing/test/indexing.cpp | 55 +- src/indexing/test/lfs.cpp | 26 +- src/indexing/transaction_fetcher_interface.h | 4 +- src/js/extensions/ccf/historical.cpp | 6 +- src/js/extensions/ccf/kv.cpp | 12 +- src/js/extensions/ccf/kv_helpers.h | 2 +- src/js/extensions/ccf/network.h | 4 +- src/js/extensions/ccf/node.h | 4 +- src/js/permissions_checks.h | 18 +- src/js/registry.cpp | 26 +- src/kv/apply_changes.h | 8 +- src/kv/committable_tx.h | 19 +- src/kv/compacted_version_conflict.h | 2 +- src/kv/deserialise.h | 26 +- src/kv/encryptor.h | 2 +- src/kv/generic_serialise_wrapper.h | 8 +- src/kv/kv_types.h | 42 +- src/kv/raw_serialise.h | 12 +- src/kv/serialised_entry_format.h | 2 +- src/kv/serialiser_declare.h | 2 +- src/kv/snapshot.h | 9 +- src/kv/store.h | 66 +-- src/kv/test/kv_bench.cpp | 55 +- src/kv/test/kv_contention.cpp | 32 +- src/kv/test/kv_dynamic_tables.cpp | 112 ++-- src/kv/test/kv_serialisation.cpp | 162 +++--- src/kv/test/kv_snapshot.cpp | 109 ++-- src/kv/test/kv_test.cpp | 539 +++++++++--------- src/kv/test/null_encryptor.h | 2 +- src/kv/test/stub_consensus.h | 2 +- src/kv/tx.cpp | 8 +- src/kv/tx_pimpl.h | 2 +- src/kv/untyped_change_set.h | 53 +- src/kv/untyped_map.h | 34 +- src/kv/untyped_map_diff.cpp | 5 +- src/kv/untyped_map_handle.cpp | 4 +- src/kv/version_v.h | 2 +- src/node/ccf_acme_client.h | 6 +- src/node/encryptor.h | 2 +- src/node/endpoint_context_impl.h | 4 +- src/node/gov/handlers/proposals.h | 8 +- src/node/historical_queries.h | 63 +- src/node/historical_queries_adapter.cpp | 2 +- src/node/historical_queries_utils.cpp | 4 +- src/node/history.h | 110 ++-- src/node/hooks.h | 8 +- src/node/jwt_key_auto_refresh.h | 4 +- src/node/ledger_secret.h | 5 +- src/node/ledger_secrets.h | 27 +- src/node/node_signature_verify.h | 4 +- src/node/node_state.h | 149 ++--- src/node/quote.cpp | 8 +- src/node/rpc/custom_protocol_subsystem.h | 2 +- src/node/rpc/frontend.h | 36 +- src/node/rpc/gov_effects.h | 12 +- src/node/rpc/gov_effects_interface.h | 12 +- src/node/rpc/jwt_management.h | 7 +- src/node/rpc/member_frontend.h | 20 +- src/node/rpc/no_create_tx_claims_digest.cpp | 2 +- src/node/rpc/node_call_types.h | 14 +- src/node/rpc/node_frontend.h | 17 +- src/node/rpc/node_interface.h | 23 +- src/node/rpc/node_operation.h | 8 +- src/node/rpc/node_operation_interface.h | 12 +- src/node/rpc/test/frontend_test.cpp | 94 +-- src/node/rpc/test/frontend_test_infra.h | 6 +- src/node/rpc/test/node_frontend_test.cpp | 14 +- src/node/rpc/test/node_stub.h | 36 +- src/node/secret_broadcast.h | 6 +- src/node/share_manager.h | 28 +- src/node/snapshot_serdes.h | 29 +- src/node/snapshotter.h | 20 +- src/node/test/encryptor.cpp | 64 +-- src/node/test/historical_queries.cpp | 67 +-- src/node/test/history.cpp | 150 ++--- src/node/test/history_bench.cpp | 22 +- src/node/test/snapshot.cpp | 44 +- src/node/test/snapshotter.cpp | 39 +- src/service/internal_tables_access.h | 53 +- src/service/network_tables.h | 6 +- src/service/tables/secrets.h | 5 +- src/service/tables/shares.h | 14 +- src/service/tables/signatures.h | 3 +- src/service/tables/snapshot_evidence.h | 2 +- 181 files changed, 2131 insertions(+), 1984 deletions(-) diff --git a/.daily_canary b/.daily_canary index a02a115d02e2..899c44f0baf3 100644 --- a/.daily_canary +++ b/.daily_canary @@ -3,4 +3,4 @@ ( V ) / . \ | +---=---' /--x-m- /--n-n---xXx--/--yY------>>>----<<<>>]]{{}}---||-/\---.. 2024__ -!..! \ No newline at end of file +!..!! \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 8aa500cce9bc..6b6f76a8b38f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - `::http` is now `ccf::http` - `::nonstd` is now `ccf::nonstd` - `::crypto` is now `ccf::crypto` + - `::kv` is now `ccf::kv` - `::logger` is now `ccf::logger` - The `programmability` sample app now demonstrates how applications can define their own extensions, creating bindings between C++ and JS state, and allowing JS endpoints to call functions implemented in C++. - Introduce `DynamicJSEndpointRegistry::record_action_for_audit_v1` and `DynamicJSEndpointRegistry::check_action_not_replayed_v1` to allow an application making use of the programmability feature to easily implement auditability, and protect users allowed to update the application against replay attacks (#6285). diff --git a/doc/architecture/ledger.rst b/doc/architecture/ledger.rst index 4abc7d3179ee..9bb636892be5 100644 --- a/doc/architecture/ledger.rst +++ b/doc/architecture/ledger.rst @@ -35,21 +35,21 @@ The following table describes the structure of a serialised transaction as it is + +------------------------------------------+-------------------------------------------------------------------------+ | | uint64_t | Length of serialised public domain | +----------+------------------------------------------+-------------------------------------------------------------------------+ -| | :cpp:type:`kv::EntryType` | Snapshot, or a WriteSet variant | +| | :cpp:type:`ccf::kv::EntryType` | Snapshot, or a WriteSet variant | + +------------------------------------------+-------------------------------------------------------------------------+ -| | :cpp:type:`kv::Version` | Transaction version | +| | :cpp:type:`ccf::kv::Version` | Transaction version | + +------------------------------------------+-------------------------------------------------------------------------+ -| | :cpp:type:`ccf::crypto::Sha256Hash` | User-defined claims digest, when entry type is WriteSetWith.*Claims | +| | :cpp:type:`ccf::crypto::Sha256Hash` | User-defined claims digest, when entry type is WriteSetWith.*Claims | + +------------------------------------------+-------------------------------------------------------------------------+ -| | :cpp:type:`ccf::crypto::Sha256Hash` | Commit evidence digest, when entry type is WriteSetWithCommitEvidence.* | +| | :cpp:type:`ccf::crypto::Sha256Hash` | Commit evidence digest, when entry type is WriteSetWithCommitEvidence.* | + +------------------------------------------+-------------------------------------------------------------------------+ -| | :cpp:type:`kv::Version` | Unused, reserved for compatibility | +| | :cpp:type:`ccf::kv::Version` | Unused, reserved for compatibility | + +------------------------------------------+-------------------------------------------------------------------------+ | | **Repeating [0..n]** | With ``n`` the number of maps in the transaction | + +-----+------------------------------------+-------------------------------------------------------------------------+ -| | | std::string | Name of the serialised :cpp:type:`kv::Map` | +| | | std::string | Name of the serialised :cpp:type:`ccf::kv::Map` | | +-----+------------------------------------+-------------------------------------------------------------------------+ -| | | :cpp:type:`kv::Version` | Read version | +| | | :cpp:type:`ccf::kv::Version` | Read version | | +-----+------------------------------------+-------------------------------------------------------------------------+ | | | uint64_t | Read count | | | +------------------------------------+-------------------------------------------------------------------------+ diff --git a/doc/build_apps/example_cpp.rst b/doc/build_apps/example_cpp.rst index 9cc5f748bde2..9dbb3b70e8c7 100644 --- a/doc/build_apps/example_cpp.rst +++ b/doc/build_apps/example_cpp.rst @@ -19,7 +19,7 @@ The Logging example application simply has: .. note:: - :cpp:type:`kv::Map` tables are the only interface between CCF and the replicated application, and the sole mechanism for it to have distributed state. + :cpp:type:`ccf::kv::Map` tables are the only interface between CCF and the replicated application, and the sole mechanism for it to have distributed state. The Logging application keeps its state in a pair of tables, one containing private encrypted logs and the other containing public unencrypted logs. Their type is defined as: @@ -54,7 +54,7 @@ The implementation of :cpp:func:`ccfapp::make_user_endpoints()` should return a :lines: 1 :dedent: -The logging app defines :cpp:class:`ccfapp::LoggerHandlers`, which creates and installs handler functions or lambdas for several different HTTP endpoints. Each of these functions takes as input the details of the current request (such as the URI which was called, the query string, the request body), interacts with the KV tables using the given :cpp:class:`kv::Tx` object, and returns a result: +The logging app defines :cpp:class:`ccfapp::LoggerHandlers`, which creates and installs handler functions or lambdas for several different HTTP endpoints. Each of these functions takes as input the details of the current request (such as the URI which was called, the query string, the request body), interacts with the KV tables using the given :cpp:class:`ccf::kv::Tx` object, and returns a result: .. literalinclude:: ../../samples/apps/logging/logging.cpp :language: cpp diff --git a/doc/build_apps/kv/api.rst b/doc/build_apps/kv/api.rst index e498bcb6d4fc..7bcfba652fbb 100644 --- a/doc/build_apps/kv/api.rst +++ b/doc/build_apps/kv/api.rst @@ -3,84 +3,84 @@ Key-Value Store API This page presents the API that a CCF application must use to access and mutate the replicated key-value store. -A CCF application should store its data in one or more :cpp:type:`kv::Map`. The name, type, and serialisation of these maps is under the application's control. Each invocation of an :cpp:class:`ccf::EndpointRegistry::Endpoint` is given a :cpp:class:`kv::Tx` transaction object, through which it can read and write to its :cpp:type:`kv::Map`. +A CCF application should store its data in one or more :cpp:type:`ccf::kv::Map`. The name, type, and serialisation of these maps is under the application's control. Each invocation of an :cpp:class:`ccf::EndpointRegistry::Endpoint` is given a :cpp:class:`ccf::kv::Tx` transaction object, through which it can read and write to its :cpp:type:`ccf::kv::Map`. Map --- -.. doxygentypedef:: kv::Version +.. doxygentypedef:: ccf::kv::Version :project: CCF -.. doxygenvariable:: kv::NoVersion +.. doxygenvariable:: ccf::kv::NoVersion :project: CCF -.. doxygenclass:: kv::TypedMap +.. doxygenclass:: ccf::kv::TypedMap :project: CCF -.. doxygentypedef:: kv::Map +.. doxygentypedef:: ccf::kv::Map :project: CCF -.. doxygenclass:: kv::TypedValue +.. doxygenclass:: ccf::kv::TypedValue :project: CCF -.. doxygentypedef:: kv::Value +.. doxygentypedef:: ccf::kv::Value :project: CCF -.. doxygenclass:: kv::TypedSet +.. doxygenclass:: ccf::kv::TypedSet :project: CCF -.. doxygentypedef:: kv::Set +.. doxygentypedef:: ccf::kv::Set :project: CCF Transaction ----------- -.. doxygenclass:: kv::ReadOnlyTx +.. doxygenclass:: ccf::kv::ReadOnlyTx :project: CCF :members: ro -.. doxygenclass:: kv::Tx +.. doxygenclass:: ccf::kv::Tx :project: CCF :members: rw, wo Handles ------- -.. doxygenclass:: kv::ReadableMapHandle +.. doxygenclass:: ccf::kv::ReadableMapHandle :project: CCF :members: -.. doxygenclass:: kv::WriteableMapHandle +.. doxygenclass:: ccf::kv::WriteableMapHandle :project: CCF :members: -.. doxygenclass:: kv::MapHandle +.. doxygenclass:: ccf::kv::MapHandle :project: CCF -.. doxygenclass:: kv::ReadableValueHandle +.. doxygenclass:: ccf::kv::ReadableValueHandle :project: CCF :members: -.. doxygenclass:: kv::WriteableValueHandle +.. doxygenclass:: ccf::kv::WriteableValueHandle :project: CCF :members: -.. doxygenclass:: kv::ValueHandle +.. doxygenclass:: ccf::kv::ValueHandle :project: CCF -.. doxygenclass:: kv::ReadableSetHandle +.. doxygenclass:: ccf::kv::ReadableSetHandle :project: CCF :members: -.. doxygenclass:: kv::WriteableSetHandle +.. doxygenclass:: ccf::kv::WriteableSetHandle :project: CCF :members: -.. doxygenclass:: kv::SetHandle +.. doxygenclass:: ccf::kv::SetHandle :project: CCF Serialisation ------------- -.. doxygenenum:: kv::EntryType +.. doxygenenum:: ccf::kv::EntryType :project: CCF \ No newline at end of file diff --git a/doc/build_apps/kv/kv_how_to.rst b/doc/build_apps/kv/kv_how_to.rst index f97570189602..1667454fac06 100644 --- a/doc/build_apps/kv/kv_how_to.rst +++ b/doc/build_apps/kv/kv_how_to.rst @@ -1,70 +1,70 @@ Key-Value Store How-To ====================== -The `Key-Value Store` (KV) consists of a set of :cpp:type:`kv::Map` objects that are available to the endpoints of an application. Endpoint handlers create handles which allow them to read and write from these :cpp:type:`kv::Map` objects. The framework handles conflicts between concurrent execution of multiple transactions, and produces a consistent order of transactions which is replicated between nodes, allowing the entries to be read from multiple nodes. This page outlines the core concepts and C++ APIs used to interact with the KV. +The `Key-Value Store` (KV) consists of a set of :cpp:type:`ccf::kv::Map` objects that are available to the endpoints of an application. Endpoint handlers create handles which allow them to read and write from these :cpp:type:`ccf::kv::Map` objects. The framework handles conflicts between concurrent execution of multiple transactions, and produces a consistent order of transactions which is replicated between nodes, allowing the entries to be read from multiple nodes. This page outlines the core concepts and C++ APIs used to interact with the KV. Map Naming ---------- -A :cpp:type:`kv::Map` (often referred to as a `Table`) is a collection of key-value pairs of a given type. The :cpp:type:`kv::Map` itself is identified by its name, which is used to lookup the map :cpp:type:`kv::Map` from the local store during a transaction. +A :cpp:type:`ccf::kv::Map` (often referred to as a `Table`) is a collection of key-value pairs of a given type. The :cpp:type:`ccf::kv::Map` itself is identified by its name, which is used to lookup the map :cpp:type:`ccf::kv::Map` from the local store during a transaction. -If a :cpp:type:`kv::Map` with the given name did not previously exist, it will be created in this transaction. +If a :cpp:type:`ccf::kv::Map` with the given name did not previously exist, it will be created in this transaction. -A :cpp:type:`kv::Map` can either be created as private (default) or public. Public map's names begin with a ``public:`` prefix, any any other name indicates a private map. For instance the name ``public:foo`` to a public map, while ``foo`` refers to a private map. Transactions on private maps are written to the ledger in encrypted form and can only be decrypted in the enclave of nodes that have joined the network. Transactions on public maps are written to the ledger as plaintext and can be read from outside the enclave; only their integrity is protected. The security domain of a map (public or private) cannot be changed after its creation, since this is encoded in the map's name. Public and private maps with similar names in different domains are distinct; writes to ``public:foo`` have no impact on ``foo``, and vice versa. +A :cpp:type:`ccf::kv::Map` can either be created as private (default) or public. Public map's names begin with a ``public:`` prefix, any any other name indicates a private map. For instance the name ``public:foo`` to a public map, while ``foo`` refers to a private map. Transactions on private maps are written to the ledger in encrypted form and can only be decrypted in the enclave of nodes that have joined the network. Transactions on public maps are written to the ledger as plaintext and can be read from outside the enclave; only their integrity is protected. The security domain of a map (public or private) cannot be changed after its creation, since this is encoded in the map's name. Public and private maps with similar names in different domains are distinct; writes to ``public:foo`` have no impact on ``foo``, and vice versa. Some table names are reserved for governance of a CCF service and cannot be modified by application code. For more information, see :doc:`/audit/read_write_restrictions`. Transaction Semantics --------------------- -A transaction (:cpp:class:`kv::Tx`) encapsulates an individual endpoint invocation's atomic interaction with the KV. Transactions may read from and write to multiple :cpp:type:`kv::Map`, and each is automatically ordered, applied, serialised, and committed by the framework. +A transaction (:cpp:class:`ccf::kv::Tx`) encapsulates an individual endpoint invocation's atomic interaction with the KV. Transactions may read from and write to multiple :cpp:type:`ccf::kv::Map`, and each is automatically ordered, applied, serialised, and committed by the framework. -A reference to a new :cpp:class:`kv::Tx` is passed to each endpoint handler, and used to interact with the KV. +A reference to a new :cpp:class:`ccf::kv::Tx` is passed to each endpoint handler, and used to interact with the KV. -Each :cpp:class:`kv::Tx` gets a consistent, opaque view of the KV, including the values which have been left by previous writes. Any writes produced by this transaction will be visible to all future transactions. +Each :cpp:class:`ccf::kv::Tx` gets a consistent, opaque view of the KV, including the values which have been left by previous writes. Any writes produced by this transaction will be visible to all future transactions. -When the endpoint handler indicates that its :cpp:class:`kv::Tx` should be applied (see :ref:`this section ` for details), the executing node attempts to apply the changes to its local KV. If this produces conflicts with concurrently executing transactions, it will be automatically re-executed. Once the transaction is applied successfully, it is automatically replicated to other nodes and will, if the network is healthy, eventually be committed. +When the endpoint handler indicates that its :cpp:class:`ccf::kv::Tx` should be applied (see :ref:`this section ` for details), the executing node attempts to apply the changes to its local KV. If this produces conflicts with concurrently executing transactions, it will be automatically re-executed. Once the transaction is applied successfully, it is automatically replicated to other nodes and will, if the network is healthy, eventually be committed. -For each :cpp:type:`kv::Map` that a transaction wants to write to or read from, a :cpp:class:`kv::MapHandle` must first be acquired. These are acquired from the :cpp:func:`kv::Tx::rw` (`read-write`) method. These may be acquired either by name (in which case the desired type must be explicitly specified as a template parameter), or by using a :cpp:type:`kv::Map` instance which defines both the map's name and key-value types. +For each :cpp:type:`ccf::kv::Map` that a transaction wants to write to or read from, a :cpp:class:`ccf::kv::MapHandle` must first be acquired. These are acquired from the :cpp:func:`ccf::kv::Tx::rw` (`read-write`) method. These may be acquired either by name (in which case the desired type must be explicitly specified as a template parameter), or by using a :cpp:type:`ccf::kv::Map` instance which defines both the map's name and key-value types. By name: .. code-block:: cpp // Handle for map1 - auto map1_handle = tx.rw>("map1"); + auto map1_handle = tx.rw>("map1"); // Handles for 2 other maps, one public and one private, with different types - auto map2_handle = tx.rw>("public:map2"); - auto map3_handle = tx.rw>("map3"); + auto map2_handle = tx.rw>("public:map2"); + auto map3_handle = tx.rw>("map3"); -By :cpp:type:`kv::Map`: +By :cpp:type:`ccf::kv::Map`: .. code-block:: cpp - kv::Map map_priv("map1"); + ccf::kv::Map map_priv("map1"); auto map1_handle = tx.rw(map_priv); - kv::Map map_pub("public:map2"); + ccf::kv::Map map_pub("public:map2"); auto map2_handle = tx.rw(map_pub); - kv::Map map_priv_int("map3"); + ccf::kv::Map map_priv_int("map3"); auto map3_handle = tx.rw(map_priv_int); The latter approach introduces a named binding between the map's name and the types of its keys and values, reducing the chance for errors where code attempts to read a map with the wrong type. -.. note:: As mentioned above, there is no need to explicitly declare a :cpp:type:`kv::Map` before it is used. The first write to a :cpp:type:`kv::Map` implicitly creates it in the underlying KV. Within a transaction, a newly created :cpp:type:`kv::Map` behaves exactly the same as an existing :cpp:type:`kv::Map` with no keys - the framework views these as semantically identical, and offers no way for the application logic to tell them apart. Any writes to a newly created :cpp:type:`kv::Map` will be persisted when the transaction commits, and future transactions will be able to access this :cpp:type:`kv::Map` by name to read those writes. +.. note:: As mentioned above, there is no need to explicitly declare a :cpp:type:`ccf::kv::Map` before it is used. The first write to a :cpp:type:`ccf::kv::Map` implicitly creates it in the underlying KV. Within a transaction, a newly created :cpp:type:`ccf::kv::Map` behaves exactly the same as an existing :cpp:type:`ccf::kv::Map` with no keys - the framework views these as semantically identical, and offers no way for the application logic to tell them apart. Any writes to a newly created :cpp:type:`ccf::kv::Map` will be persisted when the transaction commits, and future transactions will be able to access this :cpp:type:`ccf::kv::Map` by name to read those writes. Accessing Map content via a Handle ---------------------------------- -Once a :cpp:class:`kv::MapHandle` on a specific :cpp:type:`kv::Map` has been obtained, it is possible to: +Once a :cpp:class:`ccf::kv::MapHandle` on a specific :cpp:type:`ccf::kv::Map` has been obtained, it is possible to: -- test (:cpp:func:`kv::ReadableMapHandle::has`) whether a key has any associated value; -- read (:cpp:func:`kv::ReadableMapHandle::get`) the value associated with a key; -- write (:cpp:func:`kv::WriteableMapHandle::put`) a new value for a key; -- delete (:cpp:func:`kv::WriteableMapHandle::remove`) a key and its current value; -- iterate (:cpp:func:`kv::ReadableMapHandle::foreach`) through all key-value pairs. +- test (:cpp:func:`ccf::kv::ReadableMapHandle::has`) whether a key has any associated value; +- read (:cpp:func:`ccf::kv::ReadableMapHandle::get`) the value associated with a key; +- write (:cpp:func:`ccf::kv::WriteableMapHandle::put`) a new value for a key; +- delete (:cpp:func:`ccf::kv::WriteableMapHandle::remove`) a key and its current value; +- iterate (:cpp:func:`ccf::kv::ReadableMapHandle::foreach`) through all key-value pairs. .. code-block:: cpp @@ -91,7 +91,7 @@ Once a :cpp:class:`kv::MapHandle` on a specific :cpp:type:`kv::Map` has been obt Read/Write safety ----------------- -If you are only reading from or only writing to a given :cpp:type:`kv::Map` you can retrieve a `read-only` or `write-only` handle for it. This will turn unexpected reads/writes (which would introduce unintended dependencies between transactions) into compile-time errors. Instead of calling :cpp:func:`kv::Tx::rw` to get a handle which can both read and write, you can call :cpp:func:`kv::ReadOnlyTx::ro` to acquire a `read-only` handle or :cpp:func:`kv::Tx::wo` to acquire a `write-only` handle. +If you are only reading from or only writing to a given :cpp:type:`ccf::kv::Map` you can retrieve a `read-only` or `write-only` handle for it. This will turn unexpected reads/writes (which would introduce unintended dependencies between transactions) into compile-time errors. Instead of calling :cpp:func:`ccf::kv::Tx::rw` to get a handle which can both read and write, you can call :cpp:func:`ccf::kv::ReadOnlyTx::ro` to acquire a `read-only` handle or :cpp:func:`ccf::kv::Tx::wo` to acquire a `write-only` handle. .. code-block:: cpp @@ -122,7 +122,7 @@ Note that, as in the sample above, it is possible to acquire different kinds of Removing a key -------------- -If a Key-Value pair was written to a :cpp:type:`kv::Map` by a previous :cpp:class:`kv::Tx`, it is possible to delete this key. Because of the append-only nature of the KV, this Key-Value pair is not actually removed from the :cpp:type:`kv::Map` but instead explicitly marked as deleted in the version that the deleting :cpp:class:`kv::Tx` is applied at. +If a Key-Value pair was written to a :cpp:type:`ccf::kv::Map` by a previous :cpp:class:`ccf::kv::Tx`, it is possible to delete this key. Because of the append-only nature of the KV, this Key-Value pair is not actually removed from the :cpp:type:`ccf::kv::Map` but instead explicitly marked as deleted in the version that the deleting :cpp:class:`ccf::kv::Tx` is applied at. .. code-block:: cpp @@ -141,7 +141,7 @@ Global commit A transaction is automatically (globally) committed once the consensus protocol has established that a majority of nodes in the CCF network have successfully received and acknowledged that transaction. To operate on durable state, an application may want to query the globally committed state rather than the *current* state of the KV. -The :cpp:func:`kv::MapHandle::get_globally_committed` member function returns the value of a key that we know has been globally committed. +The :cpp:func:`ccf::kv::MapHandle::get_globally_committed` member function returns the value of a key that we know has been globally committed. .. code-block:: cpp @@ -166,9 +166,9 @@ Miscellaneous ``foreach()`` ~~~~~~~~~~~~~ -Values can only be retrieved directly (:cpp:func:`kv::MapHandle::get`) for a given target key. However, it is sometimes necessary to access unknown keys, or to iterate through all Key-Value pairs. +Values can only be retrieved directly (:cpp:func:`ccf::kv::MapHandle::get`) for a given target key. However, it is sometimes necessary to access unknown keys, or to iterate through all Key-Value pairs. -CCF offers a member function :cpp:func:`kv::MapHandle::foreach` to iterate over all the elements written to that :cpp:type:`kv::Map` so far, and run a lambda function for each Key-Value pair. Note that a :cpp:class:`kv::MapHandle::foreach` loop can be ended early by returning ``false`` from this lambda, while ``true`` should be returned to continue iteration. +CCF offers a member function :cpp:func:`ccf::kv::MapHandle::foreach` to iterate over all the elements written to that :cpp:type:`ccf::kv::Map` so far, and run a lambda function for each Key-Value pair. Note that a :cpp:class:`ccf::kv::MapHandle::foreach` loop can be ended early by returning ``false`` from this lambda, while ``true`` should be returned to continue iteration. .. code-block:: cpp @@ -192,7 +192,7 @@ CCF offers a member function :cpp:func:`kv::MapHandle::foreach` to iterate over Applying and reverting writes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Changes to the KV are made by atomic transactions. For a given :cpp:class:`kv::Tx`, either all of its writes are applied, or none are. Only applied writes are replicated and may be globally committed. Transactions may be abandoned without applying their writes - their changes will never be seen by other transactions. +Changes to the KV are made by atomic transactions. For a given :cpp:class:`ccf::kv::Tx`, either all of its writes are applied, or none are. Only applied writes are replicated and may be globally committed. Transactions may be abandoned without applying their writes - their changes will never be seen by other transactions. By default CCF decides which transactions are successful (so should be applied to the persistent store) by looking at the status code contained in the response: all transactions producing ``2xx`` status codes will be applied, while any other status code will be treated as an error and will `not` be applied to the persistent store. If this behaviour is not desired, for instance when an app wants to log incoming requests even though they produce an error, then it can be dynamically overridden by explicitly telling CCF whether it should apply a given transaction: diff --git a/doc/build_apps/kv/kv_serialisation.rst b/doc/build_apps/kv/kv_serialisation.rst index ace926c4d064..9f2c0aa69cd8 100644 --- a/doc/build_apps/kv/kv_serialisation.rst +++ b/doc/build_apps/kv/kv_serialisation.rst @@ -1,14 +1,14 @@ Key-Value Serialisation ======================= -Every transaction executed by the primary on its Key-Value store is serialised before being replicated to all backups of the CCF network and written to the ledger. The serialisation format is defined per :cpp:type:`kv::Map` and distinctly for the key and value types. +Every transaction executed by the primary on its Key-Value store is serialised before being replicated to all backups of the CCF network and written to the ledger. The serialisation format is defined per :cpp:type:`ccf::kv::Map` and distinctly for the key and value types. -.. tip:: Selecting the right serialision format for a KV map depends on the application logic but is generally a trade-off between performance and auditability of the ledger. For example, the default serialisation format for :cpp:type:`kv::Map` is JSON and allows for easy parsing of transactions in the `public` ledger. For more performance sensitive use cases, apps may define or use their own serialisers. +.. tip:: Selecting the right serialision format for a KV map depends on the application logic but is generally a trade-off between performance and auditability of the ledger. For example, the default serialisation format for :cpp:type:`ccf::kv::Map` is JSON and allows for easy parsing of transactions in the `public` ledger. For more performance sensitive use cases, apps may define or use their own serialisers. Custom key and value types -------------------------- -User-defined types can be used for both the key and value types of a :cpp:type:`kv::Map`. It must be possible to use the key type as the key of an ``std::map`` (so it must be copyable, assignable, and less-comparable), and both types must be serialisable. By default, when using a :cpp:type:`kv::Map`, serialisation converts to JSON. To add support to your custom types, it should usually be possible to use the ``DECLARE_JSON_...`` macros: +User-defined types can be used for both the key and value types of a :cpp:type:`ccf::kv::Map`. It must be possible to use the key type as the key of an ``std::map`` (so it must be copyable, assignable, and less-comparable), and both types must be serialisable. By default, when using a :cpp:type:`ccf::kv::Map`, serialisation converts to JSON. To add support to your custom types, it should usually be possible to use the ``DECLARE_JSON_...`` macros: .. literalinclude:: ../../../src/kv/test/kv_serialisation.cpp :language: cpp @@ -22,7 +22,7 @@ Custom serialisers can also be defined. The serialiser itself must be a type imp :start-after: SNIPPET_START: CustomSerialiser definition :end-before: SNIPPET_END: CustomSerialiser definition -To use these serialised for a specific map declare the map as a :cpp:class:`kv::TypedMap`, adding the appropriate serialiser types for the key and value types: +To use these serialised for a specific map declare the map as a :cpp:class:`ccf::kv::TypedMap`, adding the appropriate serialiser types for the key and value types: .. literalinclude:: ../../../src/kv/test/kv_serialisation.cpp :language: cpp diff --git a/doc/overview/glossary.rst b/doc/overview/glossary.rst index ebdc7e015329..72016a58b34a 100644 --- a/doc/overview/glossary.rst +++ b/doc/overview/glossary.rst @@ -79,7 +79,7 @@ Glossary `Transport Layer Security `_ is an IETF cryptographic protocol standard designed to secure communications between a client and a server over a computer network. Transaction ID - Unique transaction identifier in CCF, composed of a View and a Sequence Number separated by a period. Sequence Numbers start from 1, and are contiguous. Views are monotonic. E.g. The transaction ID ``2.15`` indicates the View is ``2`` and the Sequence Number is ``15``. Sequence Numbers are also referred to as a :cpp:type:`kv::Version` in the context of the Key-Value store. + Unique transaction identifier in CCF, composed of a View and a Sequence Number separated by a period. Sequence Numbers start from 1, and are contiguous. Views are monotonic. E.g. The transaction ID ``2.15`` indicates the View is ``2`` and the Sequence Number is ``15``. Sequence Numbers are also referred to as a :cpp:type:`ccf::kv::Version` in the context of the Key-Value store. Users Directly interact with the application running in CCF. Their public identity should be voted in by members before they are allowed to issue requests. diff --git a/include/ccf/app_interface.h b/include/ccf/app_interface.h index f5c9ed702f9e..71cdd72bf99e 100644 --- a/include/ccf/app_interface.h +++ b/include/ccf/app_interface.h @@ -17,7 +17,7 @@ namespace ccf class RpcFrontend; } -namespace kv +namespace ccf::kv { class Store; } diff --git a/include/ccf/base_endpoint_registry.h b/include/ccf/base_endpoint_registry.h index 1f3efe04242b..7697dc66f77e 100644 --- a/include/ccf/base_endpoint_registry.h +++ b/include/ccf/base_endpoint_registry.h @@ -188,7 +188,7 @@ namespace ccf * does not affect the OpenAPI version of the format of the document. */ ApiResult generate_openapi_document_v1( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::string& title, const std::string& description, const std::string& document_version, @@ -197,7 +197,7 @@ namespace ccf /** Get a quote attesting to the hardware this node is running on. */ ApiResult get_quote_for_this_node_v1( - kv::ReadOnlyTx& tx, QuoteInfo& quote_info); + ccf::kv::ReadOnlyTx& tx, QuoteInfo& quote_info); /** Get the id of the currently executing node. */ @@ -207,7 +207,7 @@ namespace ccf * running on. */ ApiResult get_quotes_for_all_trusted_nodes_v1( - kv::ReadOnlyTx& tx, std::map& quotes); + ccf::kv::ReadOnlyTx& tx, std::map& quotes); /** Get the view associated with a given seqno, to construct a valid TxID. */ @@ -216,26 +216,28 @@ namespace ccf /** Get the user data associated with a given user id. */ ApiResult get_user_data_v1( - kv::ReadOnlyTx& tx, const UserId& user_id, nlohmann::json& user_data); + ccf::kv::ReadOnlyTx& tx, + const UserId& user_id, + nlohmann::json& user_data); /** Get the member data associated with a given member id. */ ApiResult get_member_data_v1( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const MemberId& member_id, nlohmann::json& member_data); /** Get the certificate (PEM) of a given user id. */ ApiResult get_user_cert_v1( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const UserId& user_id, ccf::crypto::Pem& user_cert_pem); /** Get the certificate (PEM) of a given member id. */ ApiResult get_member_cert_v1( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const MemberId& member_id, ccf::crypto::Pem& member_cert_pem); diff --git a/include/ccf/crypto/sha256_hash.h b/include/ccf/crypto/sha256_hash.h index 6c3adfab1cf1..cf4cde1a0f15 100644 --- a/include/ccf/crypto/sha256_hash.h +++ b/include/ccf/crypto/sha256_hash.h @@ -76,7 +76,7 @@ struct formatter }; FMT_END_NAMESPACE -namespace kv::serialisers +namespace ccf::kv::serialisers { template <> struct BlitSerialiser diff --git a/include/ccf/endpoint.h b/include/ccf/endpoint.h index f9a66ad9ab3c..610f0a073902 100644 --- a/include/ccf/endpoint.h +++ b/include/ccf/endpoint.h @@ -30,7 +30,7 @@ namespace ccf::endpoints }; } -namespace kv::serialisers +namespace ccf::kv::serialisers { template <> struct BlitSerialiser diff --git a/include/ccf/endpoint_context.h b/include/ccf/endpoint_context.h index 0f55e53cef35..eca44c2299cb 100644 --- a/include/ccf/endpoint_context.h +++ b/include/ccf/endpoint_context.h @@ -53,12 +53,12 @@ namespace ccf::endpoints struct EndpointContext : public CommandEndpointContext { - EndpointContext(const std::shared_ptr& r, kv::Tx& t) : + EndpointContext(const std::shared_ptr& r, ccf::kv::Tx& t) : CommandEndpointContext(r), tx(t) {} - kv::Tx& tx; + ccf::kv::Tx& tx; }; using EndpointFunction = std::function; @@ -69,12 +69,12 @@ namespace ccf::endpoints struct ReadOnlyEndpointContext : public CommandEndpointContext { ReadOnlyEndpointContext( - const std::shared_ptr& r, kv::ReadOnlyTx& t) : + const std::shared_ptr& r, ccf::kv::ReadOnlyTx& t) : CommandEndpointContext(r), tx(t) {} - kv::ReadOnlyTx& tx; + ccf::kv::ReadOnlyTx& tx; }; using ReadOnlyEndpointFunction = std::function; diff --git a/include/ccf/endpoint_registry.h b/include/ccf/endpoint_registry.h index 3177fe3967f5..ab991ee0785b 100644 --- a/include/ccf/endpoint_registry.h +++ b/include/ccf/endpoint_registry.h @@ -15,7 +15,7 @@ #include #include -namespace kv +namespace ccf::kv { class Consensus; class TxHistory; @@ -161,8 +161,8 @@ namespace ccf::endpoints std::map>> templated_endpoints; - kv::Consensus* consensus = nullptr; - kv::TxHistory* history = nullptr; + ccf::kv::Consensus* consensus = nullptr; + ccf::kv::TxHistory* history = nullptr; public: EndpointRegistry(const std::string& method_prefix_) : @@ -254,12 +254,12 @@ namespace ccf::endpoints * internally, so must be able to populate the document * with the supported endpoints however it defines them. */ - virtual void build_api(nlohmann::json& document, kv::ReadOnlyTx&); + virtual void build_api(nlohmann::json& document, ccf::kv::ReadOnlyTx&); virtual void init_handlers(); virtual EndpointDefinitionPtr find_endpoint( - kv::Tx&, ccf::RpcContext& rpc_ctx); + ccf::kv::Tx&, ccf::RpcContext& rpc_ctx); virtual void execute_endpoint( EndpointDefinitionPtr e, EndpointContext& args); @@ -268,7 +268,7 @@ namespace ccf::endpoints EndpointDefinitionPtr e, CommandEndpointContext& args, const TxID& tx_id); virtual std::set get_allowed_verbs( - kv::Tx&, const ccf::RpcContext& rpc_ctx); + ccf::kv::Tx&, const ccf::RpcContext& rpc_ctx); virtual bool request_needs_root(const ccf::RpcContext& rpc_ctx); @@ -278,9 +278,9 @@ namespace ccf::endpoints virtual void tick(std::chrono::milliseconds); - void set_consensus(kv::Consensus* c); + void set_consensus(ccf::kv::Consensus* c); - void set_history(kv::TxHistory* h); + void set_history(ccf::kv::TxHistory* h); // Override these methods to log or report request metrics. virtual void handle_event_request_completed( diff --git a/include/ccf/endpoints/authentication/all_of_auth.h b/include/ccf/endpoints/authentication/all_of_auth.h index f6bef98c8ede..f278bd882e40 100644 --- a/include/ccf/endpoints/authentication/all_of_auth.h +++ b/include/ccf/endpoints/authentication/all_of_auth.h @@ -37,7 +37,7 @@ namespace ccf const std::vector>& _policies); std::unique_ptr authenticate( - kv::ReadOnlyTx&, + ccf::kv::ReadOnlyTx&, const std::shared_ptr&, std::string&) override; diff --git a/include/ccf/endpoints/authentication/authentication_types.h b/include/ccf/endpoints/authentication/authentication_types.h index 81f63d6e0180..d22d2535344f 100644 --- a/include/ccf/endpoints/authentication/authentication_types.h +++ b/include/ccf/endpoints/authentication/authentication_types.h @@ -30,7 +30,7 @@ namespace ccf virtual ~AuthnPolicy() = default; virtual std::unique_ptr authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) = 0; diff --git a/include/ccf/endpoints/authentication/cert_auth.h b/include/ccf/endpoints/authentication/cert_auth.h index 3a84091820dc..6624cc01c059 100644 --- a/include/ccf/endpoints/authentication/cert_auth.h +++ b/include/ccf/endpoints/authentication/cert_auth.h @@ -38,7 +38,7 @@ namespace ccf virtual ~UserCertAuthnPolicy(); std::unique_ptr authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) override; @@ -72,7 +72,7 @@ namespace ccf virtual ~MemberCertAuthnPolicy(); std::unique_ptr authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) override; @@ -99,7 +99,7 @@ namespace ccf static constexpr auto SECURITY_SCHEME_NAME = "node_cert"; std::unique_ptr authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) override; diff --git a/include/ccf/endpoints/authentication/cose_auth.h b/include/ccf/endpoints/authentication/cose_auth.h index 368e2eb5beb7..03a59bb0fe6e 100644 --- a/include/ccf/endpoints/authentication/cose_auth.h +++ b/include/ccf/endpoints/authentication/cose_auth.h @@ -125,7 +125,7 @@ namespace ccf ~MemberCOSESign1AuthnPolicy(); std::unique_ptr authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) override; @@ -158,7 +158,7 @@ namespace ccf using MemberCOSESign1AuthnPolicy::MemberCOSESign1AuthnPolicy; std::unique_ptr authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) override; @@ -182,7 +182,7 @@ namespace ccf static const OpenAPISecuritySchema security_schema; virtual std::unique_ptr _authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason); @@ -198,7 +198,7 @@ namespace ccf ~UserCOSESign1AuthnPolicy(); std::unique_ptr authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) override; @@ -240,7 +240,7 @@ namespace ccf {} std::unique_ptr authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) override; diff --git a/include/ccf/endpoints/authentication/empty_auth.h b/include/ccf/endpoints/authentication/empty_auth.h index 11d1e44d8562..f5ec3870e575 100644 --- a/include/ccf/endpoints/authentication/empty_auth.h +++ b/include/ccf/endpoints/authentication/empty_auth.h @@ -17,7 +17,7 @@ namespace ccf static constexpr auto SECURITY_SCHEME_NAME = "no_auth"; std::unique_ptr authenticate( - kv::ReadOnlyTx&, + ccf::kv::ReadOnlyTx&, const std::shared_ptr&, std::string&) override; diff --git a/include/ccf/endpoints/authentication/jwt_auth.h b/include/ccf/endpoints/authentication/jwt_auth.h index 3413dff4b8b8..3a44ee55a73a 100644 --- a/include/ccf/endpoints/authentication/jwt_auth.h +++ b/include/ccf/endpoints/authentication/jwt_auth.h @@ -37,7 +37,7 @@ namespace ccf virtual ~JwtAuthnPolicy(); std::unique_ptr authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) override; diff --git a/include/ccf/entity_id.h b/include/ccf/entity_id.h index 3b26668d7042..0c0f961df367 100644 --- a/include/ccf/entity_id.h +++ b/include/ccf/entity_id.h @@ -202,7 +202,7 @@ struct formatter> }; FMT_END_NAMESPACE -namespace kv::serialisers +namespace ccf::kv::serialisers { template struct BlitSerialiser> diff --git a/include/ccf/historical_queries_adapter.h b/include/ccf/historical_queries_adapter.h index 837c9d3eed1f..397ba87d7d13 100644 --- a/include/ccf/historical_queries_adapter.h +++ b/include/ccf/historical_queries_adapter.h @@ -9,7 +9,7 @@ #include "ccf/tx_id.h" #include "ccf/tx_status.h" -namespace kv +namespace ccf::kv { class Consensus; } @@ -51,7 +51,7 @@ namespace ccf::historical ccf::View view, ccf::SeqNo seqno, std::string& error_reason)>; HistoricalTxStatus is_tx_committed_v2( - kv::Consensus* consensus, + ccf::kv::Consensus* consensus, ccf::View view, ccf::SeqNo seqno, std::string& error_reason); diff --git a/include/ccf/historical_queries_interface.h b/include/ccf/historical_queries_interface.h index 32a2a4e8d91e..f94516d81aa8 100644 --- a/include/ccf/historical_queries_interface.h +++ b/include/ccf/historical_queries_interface.h @@ -16,14 +16,14 @@ namespace ccf::historical struct State { /// Read-only historical store at transaction_id - kv::ReadOnlyStorePtr store = nullptr; + ccf::kv::ReadOnlyStorePtr store = nullptr; /// Receipt for ledger entry at transaction_id TxReceiptImplPtr receipt = nullptr; /// View and Sequence Number for the State ccf::TxID transaction_id; State( - const kv::ReadOnlyStorePtr& store_, + const ccf::kv::ReadOnlyStorePtr& store_, const TxReceiptImplPtr& receipt_, const ccf::TxID& transaction_id_) : store(store_), @@ -93,7 +93,7 @@ namespace ccf::historical * is equivalent to get_store_at(handle, seqno, seqno), but returns nullptr * if the state is currently unavailable. */ - virtual kv::ReadOnlyStorePtr get_store_at( + virtual ccf::kv::ReadOnlyStorePtr get_store_at( RequestHandle handle, ccf::SeqNo seqno, ExpiryDuration seconds_until_expiry) = 0; @@ -101,7 +101,7 @@ namespace ccf::historical /** Same as @c get_store_at but uses default expiry value. * @see get_store_at */ - virtual kv::ReadOnlyStorePtr get_store_at( + virtual ccf::kv::ReadOnlyStorePtr get_store_at( RequestHandle handle, ccf::SeqNo seqno) = 0; /** Retrieve a full state at a given seqno, including the Store, the TxID @@ -135,7 +135,7 @@ namespace ccf::historical * vector will be of length (end_seqno - start_seqno + 1) and will contain * no nullptrs. */ - virtual std::vector get_store_range( + virtual std::vector get_store_range( RequestHandle handle, ccf::SeqNo start_seqno, ccf::SeqNo end_seqno, @@ -144,7 +144,7 @@ namespace ccf::historical /** Same as @c get_store_range but uses default expiry value. * @see get_store_range */ - virtual std::vector get_store_range( + virtual std::vector get_store_range( RequestHandle handle, ccf::SeqNo start_seqno, ccf::SeqNo end_seqno) = 0; /** Retrieve a range of states at the given indices, including the Store, @@ -165,11 +165,11 @@ namespace ccf::historical /** Retrieve stores for a set of given indices. */ - virtual std::vector get_stores_for( + virtual std::vector get_stores_for( RequestHandle handle, const SeqNoCollection& seqnos, ExpiryDuration seconds_until_expiry) = 0; - virtual std::vector get_stores_for( + virtual std::vector get_stores_for( RequestHandle handle, const SeqNoCollection& seqnos) = 0; /** Retrieve states for a set of given indices. diff --git a/include/ccf/historical_queries_utils.h b/include/ccf/historical_queries_utils.h index 9d1f375ad4d5..133dcd10b996 100644 --- a/include/ccf/historical_queries_utils.h +++ b/include/ccf/historical_queries_utils.h @@ -19,7 +19,7 @@ namespace ccf::historical // additional entries have been requested, in which case the caller should // retry later. bool populate_service_endorsements( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, ccf::historical::StatePtr& state, AbstractStateCache& state_cache, std::shared_ptr diff --git a/include/ccf/indexing/strategies/visit_each_entry_in_map.h b/include/ccf/indexing/strategies/visit_each_entry_in_map.h index 7d0edabccc28..fb6b9613e058 100644 --- a/include/ccf/indexing/strategies/visit_each_entry_in_map.h +++ b/include/ccf/indexing/strategies/visit_each_entry_in_map.h @@ -34,7 +34,7 @@ namespace ccf::indexing::strategies virtual ~VisitEachEntryInMap() = default; void handle_committed_transaction( - const ccf::TxID& tx_id, const kv::ReadOnlyStorePtr& store) override; + const ccf::TxID& tx_id, const ccf::kv::ReadOnlyStorePtr& store) override; std::optional next_requested() override; nlohmann::json describe() override; diff --git a/include/ccf/indexing/strategy.h b/include/ccf/indexing/strategy.h index 06f3e7567110..1d29483adb64 100644 --- a/include/ccf/indexing/strategy.h +++ b/include/ccf/indexing/strategy.h @@ -38,7 +38,7 @@ namespace ccf::indexing * transaction. */ virtual void handle_committed_transaction( - const ccf::TxID& tx_id, const kv::ReadOnlyStorePtr& store) = 0; + const ccf::TxID& tx_id, const ccf::kv::ReadOnlyStorePtr& store) = 0; virtual void tick() {} diff --git a/include/ccf/js/common_context.h b/include/ccf/js/common_context.h index 036aaa1ed253..613de5a029f2 100644 --- a/include/ccf/js/common_context.h +++ b/include/ccf/js/common_context.h @@ -48,7 +48,7 @@ namespace ccf::js class WithKVExtension : public Base { public: - WithKVExtension(TxAccess acc, kv::Tx* tx) : Base(acc) + WithKVExtension(TxAccess acc, ccf::kv::Tx* tx) : Base(acc) { // add ccf.kv.* Base::add_extension( diff --git a/include/ccf/js/extensions/ccf/gov_effects.h b/include/ccf/js/extensions/ccf/gov_effects.h index 63fe935e1663..bfde1a7984bd 100644 --- a/include/ccf/js/extensions/ccf/gov_effects.h +++ b/include/ccf/js/extensions/ccf/gov_effects.h @@ -21,9 +21,9 @@ namespace ccf::js::extensions class GovEffectsExtension : public ExtensionInterface { public: - kv::Tx* tx; + ccf::kv::Tx* tx; - GovEffectsExtension(kv::Tx* t) : tx(t) {} + GovEffectsExtension(ccf::kv::Tx* t) : tx(t) {} void install(js::core::Context& ctx) override; }; diff --git a/include/ccf/js/extensions/ccf/kv.h b/include/ccf/js/extensions/ccf/kv.h index 51b3430190cf..8dec00d412f2 100644 --- a/include/ccf/js/extensions/ccf/kv.h +++ b/include/ccf/js/extensions/ccf/kv.h @@ -7,7 +7,7 @@ #include -namespace kv +namespace ccf::kv { class Tx; } @@ -28,7 +28,7 @@ namespace ccf::js::extensions ccf::js::NamespaceRestriction namespace_restriction; - KvExtension(kv::Tx* t, const ccf::js::NamespaceRestriction& nr = {}); + KvExtension(ccf::kv::Tx* t, const ccf::js::NamespaceRestriction& nr = {}); ~KvExtension(); void install(js::core::Context& ctx); diff --git a/include/ccf/js/registry.h b/include/ccf/js/registry.h index 8c7c0ea7d4ca..a6845eea8abd 100644 --- a/include/ccf/js/registry.h +++ b/include/ccf/js/registry.h @@ -84,7 +84,7 @@ namespace ccf::js * later be dispatched to. */ ccf::ApiResult install_custom_endpoints_v1( - kv::Tx& tx, const ccf::js::Bundle& bundle); + ccf::kv::Tx& tx, const ccf::js::Bundle& bundle); /** * Retrieve all endpoint definitions currently in-use. This returns the same @@ -93,14 +93,14 @@ namespace ccf::js * due to internal normalisation. */ ccf::ApiResult get_custom_endpoints_v1( - ccf::js::Bundle& bundle, kv::ReadOnlyTx& tx); + ccf::js::Bundle& bundle, ccf::kv::ReadOnlyTx& tx); /** * Retrieve property definition for a single JS endpoint. */ ccf::ApiResult get_custom_endpoint_properties_v1( ccf::endpoints::EndpointProperties& properties, - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const ccf::RESTVerb& verb, const ccf::endpoints::URI& uri); @@ -108,7 +108,9 @@ namespace ccf::js * Retrieve content of a single JS module. */ ccf::ApiResult get_custom_endpoint_module_v1( - std::string& code, kv::ReadOnlyTx& tx, const std::string& module_name); + std::string& code, + ccf::kv::ReadOnlyTx& tx, + const std::string& module_name); /** * Pass a function to control which maps can be accessed by JS endpoints. @@ -121,7 +123,7 @@ namespace ccf::js * bound any values specified here. */ ccf::ApiResult set_js_runtime_options_v1( - kv::Tx& tx, const ccf::JSRuntimeOptions& options); + ccf::kv::Tx& tx, const ccf::JSRuntimeOptions& options); /** * Get the options which currently control JS execution. If no value has @@ -129,14 +131,14 @@ namespace ccf::js * which will be applied instead. */ ccf::ApiResult get_js_runtime_options_v1( - ccf::JSRuntimeOptions& options, kv::ReadOnlyTx& tx); + ccf::JSRuntimeOptions& options, ccf::kv::ReadOnlyTx& tx); /** * Record action details by storing them in KV maps using a common format, * for the purposes of offline audit using the ledger. */ ccf::ApiResult record_action_for_audit_v1( - kv::Tx& tx, + ccf::kv::Tx& tx, ccf::ActionFormat format, const std::string& user_id, const std::string& action_name, @@ -148,7 +150,7 @@ namespace ccf::js * size, an authenticated timestamp (@p created_at) is required. */ ccf::ApiResult check_action_not_replayed_v1( - kv::Tx& tx, + ccf::kv::Tx& tx, uint64_t created_at, const std::span action, ccf::InvalidArgsReason& reason); @@ -157,7 +159,7 @@ namespace ccf::js /// endpoints before delegating to base implementation. ///@{ ccf::endpoints::EndpointDefinitionPtr find_endpoint( - kv::Tx& tx, ccf::RpcContext& rpc_ctx) override; + ccf::kv::Tx& tx, ccf::RpcContext& rpc_ctx) override; void execute_endpoint( ccf::endpoints::EndpointDefinitionPtr e, @@ -168,7 +170,7 @@ namespace ccf::js ccf::endpoints::CommandEndpointContext& endpoint_ctx, const ccf::TxID& tx_id) override; - void build_api(nlohmann::json& document, kv::ReadOnlyTx& tx) override; + void build_api(nlohmann::json& document, ccf::kv::ReadOnlyTx& tx) override; ///@} virtual ccf::js::extensions::Extensions get_extensions( diff --git a/include/ccf/kv/abstract_handle.h b/include/ccf/kv/abstract_handle.h index f37a9e7935c0..fa9d97190e35 100644 --- a/include/ccf/kv/abstract_handle.h +++ b/include/ccf/kv/abstract_handle.h @@ -2,7 +2,7 @@ // Licensed under the Apache 2.0 License. #pragma once -namespace kv +namespace ccf::kv { class AbstractHandle { diff --git a/include/ccf/kv/get_name.h b/include/ccf/kv/get_name.h index ad93f50357d9..7fb80d2ec309 100644 --- a/include/ccf/kv/get_name.h +++ b/include/ccf/kv/get_name.h @@ -4,7 +4,7 @@ #include -namespace kv +namespace ccf::kv { struct GetName { diff --git a/include/ccf/kv/hooks.h b/include/ccf/kv/hooks.h index 83a814fd1c7b..34e1d4972516 100644 --- a/include/ccf/kv/hooks.h +++ b/include/ccf/kv/hooks.h @@ -7,7 +7,7 @@ #include #include -namespace kv +namespace ccf::kv { class ConfigurableConsensus; diff --git a/include/ccf/kv/map.h b/include/ccf/kv/map.h index 7d19355060d5..d2cd51ce5170 100644 --- a/include/ccf/kv/map.h +++ b/include/ccf/kv/map.h @@ -10,7 +10,7 @@ #include "ccf/kv/serialisers/json_serialiser.h" #include "ccf/kv/untyped.h" -namespace kv +namespace ccf::kv { /** Defines the schema of a map accessed by a @c ccf::Tx, exposing associated * types. This map is an unordered associative container of key-value pairs. @@ -31,11 +31,11 @@ namespace kv public: // Expose correct public aliases of types using ReadOnlyHandle = - kv::ReadableMapHandle; + ccf::kv::ReadableMapHandle; using WriteOnlyHandle = - kv::WriteableMapHandle; - using Handle = kv::MapHandle; - using Diff = kv::MapDiff; + ccf::kv::WriteableMapHandle; + using Handle = ccf::kv::MapHandle; + using Diff = ccf::kv::MapDiff; using Write = std::map>; using CommitHook = CommitHook; @@ -49,7 +49,7 @@ namespace kv using GetName::GetName; private: - static Write deserialise_write(const kv::untyped::Write& w) + static Write deserialise_write(const ccf::kv::untyped::Write& w) { Write typed_writes; for (const auto& [uk, opt_uv] : w) @@ -70,16 +70,16 @@ namespace kv } public: - static kv::untyped::CommitHook wrap_commit_hook(const CommitHook& hook) + static ccf::kv::untyped::CommitHook wrap_commit_hook(const CommitHook& hook) { - return [hook](Version v, const kv::untyped::Write& w) { + return [hook](Version v, const ccf::kv::untyped::Write& w) { hook(v, deserialise_write(w)); }; } - static kv::untyped::MapHook wrap_map_hook(const MapHook& hook) + static ccf::kv::untyped::MapHook wrap_map_hook(const MapHook& hook) { - return [hook](Version v, const kv::untyped::Write& w) { + return [hook](Version v, const ccf::kv::untyped::Write& w) { return hook(v, deserialise_write(w)); }; } @@ -95,14 +95,14 @@ namespace kv template using JsonSerialisedMap = - MapSerialisedWith; + MapSerialisedWith; template using RawCopySerialisedMap = TypedMap< K, V, - kv::serialisers::BlitSerialiser, - kv::serialisers::BlitSerialiser>; + ccf::kv::serialisers::BlitSerialiser, + ccf::kv::serialisers::BlitSerialiser>; /** Short name for default-serialised maps, using JSON serialisers. Support * for custom types can be added through the DECLARE_JSON... macros. diff --git a/include/ccf/kv/map_diff.h b/include/ccf/kv/map_diff.h index 9161b4daf92d..a66ecda2995a 100644 --- a/include/ccf/kv/map_diff.h +++ b/include/ccf/kv/map_diff.h @@ -4,21 +4,21 @@ #include "ccf/kv/untyped_map_diff.h" -namespace kv +namespace ccf::kv { template class MapDiff : public AbstractHandle { protected: - kv::untyped::MapDiff map_diff; + ccf::kv::untyped::MapDiff map_diff; public: using KeyType = K; using ValueType = V; - MapDiff(kv::untyped::MapDiff map_diff_) : map_diff(map_diff_) {} + MapDiff(ccf::kv::untyped::MapDiff map_diff_) : map_diff(map_diff_) {} - MapDiff(kv::untyped::ChangeSet& changes, const std::string& map_name) : + MapDiff(ccf::kv::untyped::ChangeSet& changes, const std::string& map_name) : map_diff(changes, map_name) {} @@ -86,8 +86,8 @@ namespace kv { const auto& g = [&]( - const kv::serialisers::SerialisedEntry& k_rep, - const std::optional& v_rep) + const ccf::kv::serialisers::SerialisedEntry& k_rep, + const std::optional& v_rep) -> bool { const auto k = KSerialiser::from_serialised(k_rep); if (v_rep.has_value()) @@ -116,8 +116,8 @@ namespace kv void foreach_key(F&& f) { auto g = [&]( - const kv::serialisers::SerialisedEntry& k_rep, - const kv::serialisers::SerialisedEntry&) { + const ccf::kv::serialisers::SerialisedEntry& k_rep, + const ccf::kv::serialisers::SerialisedEntry&) { return f(KSerialiser::from_serialised(k_rep)); }; map_diff.foreach(g); @@ -133,18 +133,19 @@ namespace kv template void foreach_value(F&& f) { - auto g = [&]( - const kv::serialisers::SerialisedEntry&, - const std::optional& v_rep) { - if (v_rep.has_value()) - { - return f(VSerialiser::from_serialised(v_rep)); - } - else - { - return f(std::nullopt); - } - }; + auto g = + [&]( + const ccf::kv::serialisers::SerialisedEntry&, + const std::optional& v_rep) { + if (v_rep.has_value()) + { + return f(VSerialiser::from_serialised(v_rep)); + } + else + { + return f(std::nullopt); + } + }; map_diff.foreach(g); } diff --git a/include/ccf/kv/map_handle.h b/include/ccf/kv/map_handle.h index 6ac8e00a0c11..39c4347f2c6a 100644 --- a/include/ccf/kv/map_handle.h +++ b/include/ccf/kv/map_handle.h @@ -4,21 +4,21 @@ #include "ccf/kv/untyped_map_handle.h" -namespace kv +namespace ccf::kv { - /** Grants read access to a @c kv::Map, as part of a @c kv::Tx. + /** Grants read access to a @c ccf::kv::Map, as part of a @c ccf::kv::Tx. */ template class ReadableMapHandle { protected: - kv::untyped::MapHandle& read_handle; + ccf::kv::untyped::MapHandle& read_handle; public: using KeyType = K; using ValueType = V; - ReadableMapHandle(kv::untyped::MapHandle& uh) : read_handle(uh) {} + ReadableMapHandle(ccf::kv::untyped::MapHandle& uh) : read_handle(uh) {} /** Get name of this map. * @@ -146,8 +146,8 @@ namespace kv void foreach(F&& f) { auto g = [&]( - const kv::serialisers::SerialisedEntry& k_rep, - const kv::serialisers::SerialisedEntry& v_rep) { + const ccf::kv::serialisers::SerialisedEntry& k_rep, + const ccf::kv::serialisers::SerialisedEntry& v_rep) { return f( KSerialiser::from_serialised(k_rep), VSerialiser::from_serialised(v_rep)); @@ -169,8 +169,8 @@ namespace kv void foreach_key(F&& f) { auto g = [&]( - const kv::serialisers::SerialisedEntry& k_rep, - const kv::serialisers::SerialisedEntry&) { + const ccf::kv::serialisers::SerialisedEntry& k_rep, + const ccf::kv::serialisers::SerialisedEntry&) { return f(KSerialiser::from_serialised(k_rep)); }; read_handle.foreach(g); @@ -190,8 +190,8 @@ namespace kv void foreach_value(F&& f) { auto g = [&]( - const kv::serialisers::SerialisedEntry&, - const kv::serialisers::SerialisedEntry& v_rep) { + const ccf::kv::serialisers::SerialisedEntry&, + const ccf::kv::serialisers::SerialisedEntry& v_rep) { return f(VSerialiser::from_serialised(v_rep)); }; read_handle.foreach(g); @@ -211,16 +211,16 @@ namespace kv } }; - /** Grants write access to a @c kv::Map, as part of a @c kv::Tx. + /** Grants write access to a @c ccf::kv::Map, as part of a @c ccf::kv::Tx. */ template class WriteableMapHandle { protected: - kv::untyped::MapHandle& write_handle; + ccf::kv::untyped::MapHandle& write_handle; public: - WriteableMapHandle(kv::untyped::MapHandle& uh) : write_handle(uh) {} + WriteableMapHandle(ccf::kv::untyped::MapHandle& uh) : write_handle(uh) {} /** Write value at key. * @@ -255,10 +255,11 @@ namespace kv } }; - /** Grants read and write access to a @c kv::Map, as part of a @c kv::Tx. + /** Grants read and write access to a @c ccf::kv::Map, as part of a @c + * ccf::kv::Tx. * - * @see kv::ReadableMapHandle - * @see kv::WriteableMapHandle + * @see ccf::kv::ReadableMapHandle + * @see ccf::kv::WriteableMapHandle */ template class MapHandle : public AbstractHandle, @@ -266,13 +267,14 @@ namespace kv public WriteableMapHandle { protected: - kv::untyped::MapHandle untyped_handle; + ccf::kv::untyped::MapHandle untyped_handle; using ReadableBase = ReadableMapHandle; using WriteableBase = WriteableMapHandle; public: - MapHandle(kv::untyped::ChangeSet& changes, const std::string& map_name) : + MapHandle( + ccf::kv::untyped::ChangeSet& changes, const std::string& map_name) : ReadableBase(untyped_handle), WriteableBase(untyped_handle), untyped_handle(changes, map_name) diff --git a/include/ccf/kv/read_only_store.h b/include/ccf/kv/read_only_store.h index 9e273f49cf43..ae601906ec0f 100644 --- a/include/ccf/kv/read_only_store.h +++ b/include/ccf/kv/read_only_store.h @@ -7,7 +7,7 @@ #include -namespace kv +namespace ccf::kv { class ReadOnlyStore { @@ -15,9 +15,9 @@ namespace kv virtual ~ReadOnlyStore() = default; virtual ccf::TxID get_txid() = 0; - virtual kv::ReadOnlyTx create_read_only_tx() = 0; - virtual std::unique_ptr create_read_only_tx_ptr() = 0; - virtual kv::TxDiff create_tx_diff() = 0; + virtual ccf::kv::ReadOnlyTx create_read_only_tx() = 0; + virtual std::unique_ptr create_read_only_tx_ptr() = 0; + virtual ccf::kv::TxDiff create_tx_diff() = 0; }; using ReadOnlyStorePtr = std::shared_ptr; diff --git a/include/ccf/kv/serialisers/blit_serialiser.h b/include/ccf/kv/serialisers/blit_serialiser.h index 01cb105d6839..6af7c1a4daeb 100644 --- a/include/ccf/kv/serialisers/blit_serialiser.h +++ b/include/ccf/kv/serialisers/blit_serialiser.h @@ -5,7 +5,7 @@ #include "ccf/ds/nonstd.h" #include "ccf/kv/serialisers/serialised_entry.h" -namespace kv::serialisers +namespace ccf::kv::serialisers { // Converts values to their raw, in-memory representation. To add support for // custom types, add a specialization of BlitSerialiser for them. diff --git a/include/ccf/kv/serialisers/json_serialiser.h b/include/ccf/kv/serialisers/json_serialiser.h index 2f866ee283a8..e1f22f40eb0d 100644 --- a/include/ccf/kv/serialisers/json_serialiser.h +++ b/include/ccf/kv/serialisers/json_serialiser.h @@ -6,7 +6,7 @@ #include -namespace kv::serialisers +namespace ccf::kv::serialisers { // Converts values to and from JSON, using nlohmann JSON. To add support for // custom types, make them convertible to nlohmann::json. You may do this diff --git a/include/ccf/kv/serialisers/serialised_entry.h b/include/ccf/kv/serialisers/serialised_entry.h index 34a600780ec2..aaadf096e5b6 100644 --- a/include/ccf/kv/serialisers/serialised_entry.h +++ b/include/ccf/kv/serialisers/serialised_entry.h @@ -3,7 +3,7 @@ #pragma once #include "ccf/byte_vector.h" -namespace kv::serialisers +namespace ccf::kv::serialisers { using SerialisedEntry = ccf::ByteVector; } diff --git a/include/ccf/kv/set.h b/include/ccf/kv/set.h index cc9341ad6238..62560adc6351 100644 --- a/include/ccf/kv/set.h +++ b/include/ccf/kv/set.h @@ -9,7 +9,7 @@ #include "ccf/kv/set_handle.h" #include "ccf/kv/untyped.h" -namespace kv +namespace ccf::kv { /** Defines the schema of a set type accessed by a @c ccf::Tx. This set is an * unordered container of unique keys. Each key is either present or missing @@ -21,24 +21,26 @@ namespace kv * evaluated on the serialised form; if unequal Ks produce the same * serialisation, they will coincide within this set. * - * This is implemented as a @c kv::Map from K to Unit, and the serialisation - * of the unit values is overridable with the Unit template parameter. + * This is implemented as a @c ccf::kv::Map from K to Unit, and the + * serialisation of the unit values is overridable with the Unit template + * parameter. */ template < typename K, typename KSerialiser, - typename Unit = kv::serialisers::ZeroBlitUnitCreator> + typename Unit = ccf::kv::serialisers::ZeroBlitUnitCreator> class TypedSet : public GetName { public: - using ReadOnlyHandle = kv::ReadableSetHandle; - using WriteOnlyHandle = kv::WriteableSetHandle; - using Handle = kv::SetHandle; + using ReadOnlyHandle = ccf::kv::ReadableSetHandle; + using WriteOnlyHandle = ccf::kv::WriteableSetHandle; + using Handle = ccf::kv::SetHandle; // Note: The type V of the value `std::optional` does not matter here. // The optional type is required to differentiate additions from deletions, // and to provide a consistent interface with the more generic `TypedMap`. - using Write = std::map>; + using Write = + std::map>; using MapHook = MapHook; using CommitHook = CommitHook; @@ -48,7 +50,7 @@ namespace kv using GetName::GetName; private: - static Write deserialise_write(const kv::untyped::Write& w) + static Write deserialise_write(const ccf::kv::untyped::Write& w) { Write typed_writes; for (const auto& [uk, opt_uv] : w) @@ -68,16 +70,16 @@ namespace kv } public: - static kv::untyped::CommitHook wrap_commit_hook(const CommitHook& hook) + static ccf::kv::untyped::CommitHook wrap_commit_hook(const CommitHook& hook) { - return [hook](Version v, const kv::untyped::Write& w) { + return [hook](Version v, const ccf::kv::untyped::Write& w) { hook(v, deserialise_write(w)); }; } - static kv::untyped::MapHook wrap_map_hook(const MapHook& hook) + static ccf::kv::untyped::MapHook wrap_map_hook(const MapHook& hook) { - return [hook](Version v, const kv::untyped::Write& w) { + return [hook](Version v, const ccf::kv::untyped::Write& w) { return hook(v, deserialise_write(w)); }; } @@ -87,15 +89,16 @@ namespace kv typename K, template typename KSerialiser, - typename Unit = kv::serialisers::ZeroBlitUnitCreator> + typename Unit = ccf::kv::serialisers::ZeroBlitUnitCreator> using SetSerialisedWith = TypedSet, Unit>; template using JsonSerialisedSet = - SetSerialisedWith; + SetSerialisedWith; template - using RawCopySerialisedSet = TypedSet>; + using RawCopySerialisedSet = + TypedSet>; /** Short name for default-serialised sets, using JSON serialisers. Support * for custom types can be added through the DECLARE_JSON... macros. diff --git a/include/ccf/kv/set_handle.h b/include/ccf/kv/set_handle.h index 5c79bc423509..1d28a6c9e132 100644 --- a/include/ccf/kv/set_handle.h +++ b/include/ccf/kv/set_handle.h @@ -5,20 +5,20 @@ #include "ccf/kv/unit.h" #include "ccf/kv/untyped_map_handle.h" -namespace kv +namespace ccf::kv { - /** Grants read access to a @c kv::Set, as part of a @c kv::Tx. + /** Grants read access to a @c ccf::kv::Set, as part of a @c ccf::kv::Tx. */ template class ReadableSetHandle { protected: - kv::untyped::MapHandle& read_handle; + ccf::kv::untyped::MapHandle& read_handle; public: using KeyType = K; - ReadableSetHandle(kv::untyped::MapHandle& uh) : read_handle(uh) {} + ReadableSetHandle(ccf::kv::untyped::MapHandle& uh) : read_handle(uh) {} /** Test whether a key is present in the set. * @@ -37,7 +37,7 @@ namespace kv /** Test whether a key's presence is globally committed, meaning it has been * replciated and acknowledged by consensus protocol. * - * @see kv::ReadableMapHandle::get_globally_committed + * @see ccf::kv::ReadableMapHandle::get_globally_committed * * @param key Key to test * @@ -53,7 +53,7 @@ namespace kv * * Returns nullopt if the key is not present. * - * @see kv::ReadableMapHandle::get_version_of_previous_write + * @see ccf::kv::ReadableMapHandle::get_version_of_previous_write * * @param key Key to read * @@ -68,7 +68,7 @@ namespace kv /** Iterate over all entries in this set. * - * @see kv::ReadableMapHandle::foreach + * @see ccf::kv::ReadableMapHandle::foreach * * @tparam F Functor type. Should usually be derived implicitly from f * @param f Functor instance, taking (const K& k) and returning a @@ -79,8 +79,8 @@ namespace kv void foreach(F&& f) { auto g = [&]( - const kv::serialisers::SerialisedEntry& k_rep, - const kv::serialisers::SerialisedEntry&) { + const ccf::kv::serialisers::SerialisedEntry& k_rep, + const ccf::kv::serialisers::SerialisedEntry&) { return f(KSerialiser::from_serialised(k_rep)); }; read_handle.foreach(g); @@ -100,16 +100,16 @@ namespace kv } }; - /** Grants write access to a @c kv::Set, as part of a @c kv::Tx. + /** Grants write access to a @c ccf::kv::Set, as part of a @c ccf::kv::Tx. */ template class WriteableSetHandle { protected: - kv::untyped::MapHandle& write_handle; + ccf::kv::untyped::MapHandle& write_handle; public: - WriteableSetHandle(kv::untyped::MapHandle& uh) : write_handle(uh) {} + WriteableSetHandle(ccf::kv::untyped::MapHandle& uh) : write_handle(uh) {} /** Insert an element into this set. * @@ -143,24 +143,26 @@ namespace kv } }; - /** Grants read and write access to a @c kv::Set, as part of a @c kv::Tx. + /** Grants read and write access to a @c ccf::kv::Set, as part of a @c + * ccf::kv::Tx. * - * @see kv::ReadableSetHandle - * @see kv::WriteableSetHandle + * @see ccf::kv::ReadableSetHandle + * @see ccf::kv::WriteableSetHandle */ template - class SetHandle : public kv::AbstractHandle, + class SetHandle : public ccf::kv::AbstractHandle, public ReadableSetHandle, public WriteableSetHandle { protected: - kv::untyped::MapHandle untyped_handle; + ccf::kv::untyped::MapHandle untyped_handle; using ReadableBase = ReadableSetHandle; using WriteableBase = WriteableSetHandle; public: - SetHandle(kv::untyped::ChangeSet& changes, const std::string& map_name) : + SetHandle( + ccf::kv::untyped::ChangeSet& changes, const std::string& map_name) : ReadableBase(untyped_handle), WriteableBase(untyped_handle), untyped_handle(changes, map_name) diff --git a/include/ccf/kv/unit.h b/include/ccf/kv/unit.h index 0470c036a75f..08d00a47f7f7 100644 --- a/include/ccf/kv/unit.h +++ b/include/ccf/kv/unit.h @@ -4,23 +4,23 @@ #include "ccf/kv/serialisers/serialised_entry.h" -namespace kv::serialisers +namespace ccf::kv::serialisers { - // Unit serialisations are used as a utility type to convert kv::Maps to - // kv::Maps and kv::Sets. Specifically, these are implemented as wrappers so - // that kv::Value is essentially kv::Map, and kv::Set is - // kv::Map. - // This is used as a template parameter allowing the caller to specify what - // value is inserted into the ledger. + // Unit serialisations are used as a utility type to convert ccf::kv::Maps to + // ccf::kv::Maps and ccf::kv::Sets. Specifically, these are implemented as + // wrappers so that ccf::kv::Value is essentially ccf::kv::Map, + // and ccf::kv::Set is ccf::kv::Map. This is used as a template + // parameter allowing the caller to specify what value is inserted into the + // ledger. // This is the default UnitCreator, returning 8 null bytes for compatibility // with old ledgers (where Values were previously Maps with a single entry // at key 0, serialised as a uint64_t) struct ZeroBlitUnitCreator { - static kv::serialisers::SerialisedEntry get() + static ccf::kv::serialisers::SerialisedEntry get() { - kv::serialisers::SerialisedEntry e; + ccf::kv::serialisers::SerialisedEntry e; e.assign(sizeof(uint64_t), 0u); return e; } @@ -28,7 +28,7 @@ namespace kv::serialisers struct EmptyUnitCreator { - static kv::serialisers::SerialisedEntry get() + static ccf::kv::serialisers::SerialisedEntry get() { return {}; } diff --git a/include/ccf/kv/untyped.h b/include/ccf/kv/untyped.h index 2c3b5ed0eb0f..ddd7c601c97d 100644 --- a/include/ccf/kv/untyped.h +++ b/include/ccf/kv/untyped.h @@ -8,13 +8,13 @@ #include #include -namespace kv::untyped +namespace ccf::kv::untyped { // nullopt values represent deletions using Write = std::map< - kv::serialisers::SerialisedEntry, - std::optional>; + ccf::kv::serialisers::SerialisedEntry, + std::optional>; - using CommitHook = kv::CommitHook; - using MapHook = kv::MapHook; + using CommitHook = ccf::kv::CommitHook; + using MapHook = ccf::kv::MapHook; } \ No newline at end of file diff --git a/include/ccf/kv/untyped_map_diff.h b/include/ccf/kv/untyped_map_diff.h index ee31577467d6..cf9b68c10e7d 100644 --- a/include/ccf/kv/untyped_map_diff.h +++ b/include/ccf/kv/untyped_map_diff.h @@ -11,15 +11,15 @@ #include #include -namespace kv::untyped +namespace ccf::kv::untyped { struct ChangeSet; - class MapDiff : public kv::AbstractHandle + class MapDiff : public ccf::kv::AbstractHandle { public: - using KeyType = kv::serialisers::SerialisedEntry; - using ValueType = kv::serialisers::SerialisedEntry; + using KeyType = ccf::kv::serialisers::SerialisedEntry; + using ValueType = ccf::kv::serialisers::SerialisedEntry; using ElementVisitor = std::function& V)>; @@ -28,13 +28,13 @@ namespace kv::untyped std::function& V)>; protected: - kv::untyped::Write& writes; + ccf::kv::untyped::Write& writes; std::string map_name; void foreach_(const ElementVisitorWithEarlyOut& fn); public: - MapDiff(kv::untyped::ChangeSet& cs, const std::string& map_name); + MapDiff(ccf::kv::untyped::ChangeSet& cs, const std::string& map_name); std::optional> get(const KeyType& key); diff --git a/include/ccf/kv/untyped_map_handle.h b/include/ccf/kv/untyped_map_handle.h index 1e3e44caf032..77d0f96edfe7 100644 --- a/include/ccf/kv/untyped_map_handle.h +++ b/include/ccf/kv/untyped_map_handle.h @@ -10,17 +10,17 @@ #include #include -namespace kv::untyped +namespace ccf::kv::untyped { struct ChangeSet; - class MapHandle : public kv::AbstractHandle + class MapHandle : public ccf::kv::AbstractHandle { public: // Expose these types so that other code can use them as MyTx::KeyType or // MyMap::MapHandle::KeyType, templated on the MapHandle or Map type - using KeyType = kv::serialisers::SerialisedEntry; - using ValueType = kv::serialisers::SerialisedEntry; + using KeyType = ccf::kv::serialisers::SerialisedEntry; + using ValueType = ccf::kv::serialisers::SerialisedEntry; using ElementVisitor = std::function; @@ -29,7 +29,7 @@ namespace kv::untyped std::function; protected: - kv::untyped::ChangeSet& tx_changes; + ccf::kv::untyped::ChangeSet& tx_changes; std::string map_name; /** Get pointer to current value if this key exists, else nullptr if it does @@ -45,7 +45,7 @@ namespace kv::untyped const ElementVisitorWithEarlyOut& fn, bool always_consider_writes); public: - MapHandle(kv::untyped::ChangeSet& cs, const std::string& map_name); + MapHandle(ccf::kv::untyped::ChangeSet& cs, const std::string& map_name); std::string get_name_of_map() const; diff --git a/include/ccf/kv/value.h b/include/ccf/kv/value.h index cfc98ee92814..61aa8466149b 100644 --- a/include/ccf/kv/value.h +++ b/include/ccf/kv/value.h @@ -9,7 +9,7 @@ #include "ccf/kv/untyped.h" #include "ccf/kv/value_handle.h" -namespace kv +namespace ccf::kv { /** Defines the schema of a single-valued type accessed by a @c ccf::Tx. This * value type is a container for an optional single element of type V. This @@ -20,19 +20,20 @@ namespace kv * this V is serialised and deserialised, so it may be written to the ledger * and replicated by the consensus algorithm. * - * This is implemented as a @c kv::Map from Unit to V, and the serialisation - * of the unit key is overridable with the Unit template parameter. + * This is implemented as a @c ccf::kv::Map from Unit to V, and the + * serialisation of the unit key is overridable with the Unit template + * parameter. */ template < typename V, typename VSerialiser, - typename Unit = kv::serialisers::ZeroBlitUnitCreator> + typename Unit = ccf::kv::serialisers::ZeroBlitUnitCreator> class TypedValue : public GetName { public: - using ReadOnlyHandle = kv::ReadableValueHandle; - using WriteOnlyHandle = kv::WriteableValueHandle; - using Handle = kv::ValueHandle; + using ReadOnlyHandle = ccf::kv::ReadableValueHandle; + using WriteOnlyHandle = ccf::kv::WriteableValueHandle; + using Handle = ccf::kv::ValueHandle; using Write = std::optional; using MapHook = MapHook; @@ -43,13 +44,13 @@ namespace kv using GetName::GetName; - static kv::serialisers::SerialisedEntry create_unit() + static ccf::kv::serialisers::SerialisedEntry create_unit() { return Unit::get(); } private: - static Write deserialise_write(const kv::untyped::Write& w) + static Write deserialise_write(const ccf::kv::untyped::Write& w) { assert(w.size() == 1); // Value contains only one element const auto& value = w.begin()->second; @@ -61,16 +62,16 @@ namespace kv } public: - static kv::untyped::CommitHook wrap_commit_hook(const CommitHook& hook) + static ccf::kv::untyped::CommitHook wrap_commit_hook(const CommitHook& hook) { - return [hook](Version v, const kv::untyped::Write& w) { + return [hook](Version v, const ccf::kv::untyped::Write& w) { hook(v, deserialise_write(w)); }; } - static kv::untyped::MapHook wrap_map_hook(const MapHook& hook) + static ccf::kv::untyped::MapHook wrap_map_hook(const MapHook& hook) { - return [hook](Version v, const kv::untyped::Write& w) { + return [hook](Version v, const ccf::kv::untyped::Write& w) { return hook(v, deserialise_write(w)); }; } @@ -80,16 +81,16 @@ namespace kv typename V, template typename VSerialiser, - typename Unit = kv::serialisers::ZeroBlitUnitCreator> + typename Unit = ccf::kv::serialisers::ZeroBlitUnitCreator> using ValueSerialisedWith = TypedValue, Unit>; template using JsonSerialisedValue = - ValueSerialisedWith; + ValueSerialisedWith; template using RawCopySerialisedValue = - TypedValue>; + TypedValue>; /** Short name for default-serialised values, using JSON serialisers. Support * for custom types can be added through the DECLARE_JSON... macros. diff --git a/include/ccf/kv/value_handle.h b/include/ccf/kv/value_handle.h index 4848594a46b6..a4f587fece1a 100644 --- a/include/ccf/kv/value_handle.h +++ b/include/ccf/kv/value_handle.h @@ -5,20 +5,20 @@ #include "ccf/kv/unit.h" #include "ccf/kv/untyped_map_handle.h" -namespace kv +namespace ccf::kv { - /** Grants read access to a @c kv::Value, as part of a @c kv::Tx. + /** Grants read access to a @c ccf::kv::Value, as part of a @c ccf::kv::Tx. */ template class ReadableValueHandle { protected: - kv::untyped::MapHandle& read_handle; + ccf::kv::untyped::MapHandle& read_handle; public: using ValueType = V; - ReadableValueHandle(kv::untyped::MapHandle& uh) : read_handle(uh) {} + ReadableValueHandle(ccf::kv::untyped::MapHandle& uh) : read_handle(uh) {} /** Get the stored value. * @@ -73,7 +73,7 @@ namespace kv /** Get version when this value was last written to, by a previous * transaction. * - * @see kv::ReadableMapHandle::get_version_of_previous_write + * @see ccf::kv::ReadableMapHandle::get_version_of_previous_write * * @return Optional containing version of applied transaction which last * wrote to this value, or nullopt if such a version does not exist @@ -84,16 +84,16 @@ namespace kv } }; - /** Grants write access to a @c kv::Value, as part of a @c kv::Tx. + /** Grants write access to a @c ccf::kv::Value, as part of a @c ccf::kv::Tx. */ template class WriteableValueHandle { protected: - kv::untyped::MapHandle& write_handle; + ccf::kv::untyped::MapHandle& write_handle; public: - WriteableValueHandle(kv::untyped::MapHandle& uh) : write_handle(uh) {} + WriteableValueHandle(ccf::kv::untyped::MapHandle& uh) : write_handle(uh) {} /** Modify this value. * @@ -116,10 +116,11 @@ namespace kv } }; - /** Grants read and write access to a @c kv::Value, as part of a @c kv::Tx. + /** Grants read and write access to a @c ccf::kv::Value, as part of a @c + * ccf::kv::Tx. * - * @see kv::ReadableValueHandle - * @see kv::WriteableValueHandle + * @see ccf::kv::ReadableValueHandle + * @see ccf::kv::WriteableValueHandle */ template class ValueHandle : public AbstractHandle, @@ -127,13 +128,14 @@ namespace kv public WriteableValueHandle { protected: - kv::untyped::MapHandle untyped_handle; + ccf::kv::untyped::MapHandle untyped_handle; using ReadableBase = ReadableValueHandle; using WriteableBase = WriteableValueHandle; public: - ValueHandle(kv::untyped::ChangeSet& changes, const std::string& map_name) : + ValueHandle( + ccf::kv::untyped::ChangeSet& changes, const std::string& map_name) : ReadableBase(untyped_handle), WriteableBase(untyped_handle), untyped_handle(changes, map_name) diff --git a/include/ccf/kv/version.h b/include/ccf/kv/version.h index 2a6c07fd519f..2fea6939539e 100644 --- a/include/ccf/kv/version.h +++ b/include/ccf/kv/version.h @@ -2,7 +2,7 @@ // Licensed under the Apache 2.0 License. #pragma once -namespace kv +namespace ccf::kv { // Version indexes modifications to the local kv store. using Version = uint64_t; diff --git a/include/ccf/node/quote.h b/include/ccf/node/quote.h index 140f39d9bc19..f499857d7ead 100644 --- a/include/ccf/node/quote.h +++ b/include/ccf/node/quote.h @@ -36,7 +36,7 @@ namespace ccf static std::optional get_host_data(const QuoteInfo& quote_info); static QuoteVerificationResult verify_quote_against_store( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const QuoteInfo& quote_info, const std::vector& expected_node_public_key_der, pal::PlatformAttestationMeasurement& measurement); diff --git a/include/ccf/pal/measurement.h b/include/ccf/pal/measurement.h index 3d4e91a00bb5..3c3a8c609c6f 100644 --- a/include/ccf/pal/measurement.h +++ b/include/ccf/pal/measurement.h @@ -143,7 +143,7 @@ namespace ccf::pal DECLARE_JSON_REQUIRED_FIELDS(PlatformAttestationMeasurement, data); } -namespace kv::serialisers +namespace ccf::kv::serialisers { template struct BlitSerialiser> diff --git a/include/ccf/research/create_tx_claims_digest.h b/include/ccf/research/create_tx_claims_digest.h index f11b5092a6ce..0a0d0f304f67 100644 --- a/include/ccf/research/create_tx_claims_digest.h +++ b/include/ccf/research/create_tx_claims_digest.h @@ -13,5 +13,5 @@ namespace ccfapp * @return an optional claims digest */ std::optional get_create_tx_claims_digest( - kv::ReadOnlyTx& tx) + ccf::kv::ReadOnlyTx& tx) } diff --git a/include/ccf/research/custom_protocol_subsystem_interface.h b/include/ccf/research/custom_protocol_subsystem_interface.h index cff23ce8598a..6bcc136f32cc 100644 --- a/include/ccf/research/custom_protocol_subsystem_interface.h +++ b/include/ccf/research/custom_protocol_subsystem_interface.h @@ -46,7 +46,7 @@ namespace ccf struct Essentials { ringbuffer::WriterPtr writer; - std::shared_ptr tx; + std::shared_ptr tx; std::shared_ptr ctx; }; diff --git a/include/ccf/service/blit_serialiser_pem.h b/include/ccf/service/blit_serialiser_pem.h index 9aca59e9f8a0..3580b17af95b 100644 --- a/include/ccf/service/blit_serialiser_pem.h +++ b/include/ccf/service/blit_serialiser_pem.h @@ -5,7 +5,7 @@ #include "ccf/crypto/pem.h" #include "ccf/kv/serialisers/blit_serialiser.h" -namespace kv::serialisers +namespace ccf::kv::serialisers { template <> struct BlitSerialiser diff --git a/include/ccf/service/map.h b/include/ccf/service/map.h index d797a8ae9215..1ce6d1d10e79 100644 --- a/include/ccf/service/map.h +++ b/include/ccf/service/map.h @@ -12,24 +12,24 @@ namespace ccf // - The raw key is trivially and cheaply deserialisable. // - The JSON value can conveniently be audited offline. // Note: Maps which include large values (e.g. certificate or serialised - // Merkle tree) can use the `kv::RawCopySerialisedMap` type to maximise + // Merkle tree) can use the `ccf::kv::RawCopySerialisedMap` type to maximise // performance. template - using ServiceMap = kv::MapSerialisedWith< + using ServiceMap = ccf::kv::MapSerialisedWith< K, V, - kv::serialisers::BlitSerialiser, - kv::serialisers::JsonSerialiser>; + ccf::kv::serialisers::BlitSerialiser, + ccf::kv::serialisers::JsonSerialiser>; template - using ServiceValue = kv::ValueSerialisedWith< + using ServiceValue = ccf::kv::ValueSerialisedWith< V, - kv::serialisers::JsonSerialiser, - kv::serialisers::ZeroBlitUnitCreator>; + ccf::kv::serialisers::JsonSerialiser, + ccf::kv::serialisers::ZeroBlitUnitCreator>; template - using ServiceSet = kv::SetSerialisedWith< + using ServiceSet = ccf::kv::SetSerialisedWith< K, - kv::serialisers::BlitSerialiser, - kv::serialisers::ZeroBlitUnitCreator>; + ccf::kv::serialisers::BlitSerialiser, + ccf::kv::serialisers::ZeroBlitUnitCreator>; } \ No newline at end of file diff --git a/include/ccf/service/node_info.h b/include/ccf/service/node_info.h index b63ded939e8b..5ef730475d45 100644 --- a/include/ccf/service/node_info.h +++ b/include/ccf/service/node_info.h @@ -37,7 +37,7 @@ namespace ccf /** Set to the seqno of the latest ledger secret at the time the node is trusted */ - std::optional ledger_secret_seqno = std::nullopt; + std::optional ledger_secret_seqno = std::nullopt; /// Code identity for the node std::optional code_digest = std::nullopt; diff --git a/include/ccf/service/tables/gov.h b/include/ccf/service/tables/gov.h index 04a7709a1ad0..0487c0d2188e 100644 --- a/include/ccf/service/tables/gov.h +++ b/include/ccf/service/tables/gov.h @@ -80,7 +80,7 @@ namespace ccf ProposalInfoSummary, votes, vote_failures, failure); using ProposalMap = - kv::RawCopySerialisedMap>; + ccf::kv::RawCopySerialisedMap>; using ProposalInfoMap = ServiceMap; namespace Tables diff --git a/include/ccf/service/tables/jwt.h b/include/ccf/service/tables/jwt.h index d4e6a7866cc1..f661b742971e 100644 --- a/include/ccf/service/tables/jwt.h +++ b/include/ccf/service/tables/jwt.h @@ -86,9 +86,10 @@ namespace ccf static constexpr auto JWT_PUBLIC_SIGNING_KEY_ISSUER = "public:ccf.gov.jwt.public_signing_key_issuer"; - using JwtPublicSigningKeys = kv::RawCopySerialisedMap; + using JwtPublicSigningKeys = + ccf::kv::RawCopySerialisedMap; using JwtPublicSigningKeyIssuer = - kv::RawCopySerialisedMap; + ccf::kv::RawCopySerialisedMap; } } diff --git a/include/ccf/service/tables/members.h b/include/ccf/service/tables/members.h index 751fcb10ba71..74fb84475985 100644 --- a/include/ccf/service/tables/members.h +++ b/include/ccf/service/tables/members.h @@ -76,9 +76,9 @@ namespace ccf using MemberInfo = ServiceMap; - using MemberCerts = kv::RawCopySerialisedMap; + using MemberCerts = ccf::kv::RawCopySerialisedMap; using MemberPublicEncryptionKeys = - kv::RawCopySerialisedMap; + ccf::kv::RawCopySerialisedMap; namespace Tables { diff --git a/include/ccf/service/tables/modules.h b/include/ccf/service/tables/modules.h index 5ec0c3f19c2c..09bd07edd7d7 100644 --- a/include/ccf/service/tables/modules.h +++ b/include/ccf/service/tables/modules.h @@ -12,10 +12,10 @@ namespace ccf { using Module = std::string; - using Modules = kv::RawCopySerialisedMap; + using Modules = ccf::kv::RawCopySerialisedMap; using ModulesQuickJsBytecode = - kv::RawCopySerialisedMap>; - using ModulesQuickJsVersion = kv::RawCopySerialisedValue; + ccf::kv::RawCopySerialisedMap>; + using ModulesQuickJsVersion = ccf::kv::RawCopySerialisedValue; using InterpreterFlush = ServiceValue; namespace Tables diff --git a/include/ccf/service/tables/nodes.h b/include/ccf/service/tables/nodes.h index eb0f6db8cbed..5f25c45de825 100644 --- a/include/ccf/service/tables/nodes.h +++ b/include/ccf/service/tables/nodes.h @@ -18,7 +18,7 @@ namespace ccf { using Nodes = ServiceMap; using NodeEndorsedCertificates = - kv::RawCopySerialisedMap; + ccf::kv::RawCopySerialisedMap; namespace Tables { diff --git a/include/ccf/service/tables/service.h b/include/ccf/service/tables/service.h index 6efa6407a1c1..458e8275e8be 100644 --- a/include/ccf/service/tables/service.h +++ b/include/ccf/service/tables/service.h @@ -31,7 +31,8 @@ namespace ccf /// Status of the service ServiceStatus status = ServiceStatus::OPENING; /// Version (seqno) of previous service identity (before the last recovery) - std::optional previous_service_identity_version = std::nullopt; + std::optional previous_service_identity_version = + std::nullopt; /// Number of disaster recoveries performed on this service std::optional recovery_count = std::nullopt; /// Free-form user data, can be used by members to store additional diff --git a/include/ccf/service/tables/users.h b/include/ccf/service/tables/users.h index 5cb4aa698509..4a74f54327e4 100644 --- a/include/ccf/service/tables/users.h +++ b/include/ccf/service/tables/users.h @@ -28,7 +28,7 @@ namespace ccf DECLARE_JSON_TYPE(UserDetails) DECLARE_JSON_REQUIRED_FIELDS(UserDetails, user_data) - using UserCerts = kv::RawCopySerialisedMap; + using UserCerts = ccf::kv::RawCopySerialisedMap; using UserInfo = ServiceMap; namespace Tables diff --git a/include/ccf/tx.h b/include/ccf/tx.h index 7bcf762de378..288fd595669a 100644 --- a/include/ccf/tx.h +++ b/include/ccf/tx.h @@ -12,7 +12,7 @@ #include #include -namespace kv +namespace ccf::kv { class AbstractHandle; class AbstractMap; @@ -196,7 +196,7 @@ namespace kv * type-safety, prefer restricted handles returned by @c ro or @c wo where * possible, rather than the general @c rw. * - * @see kv::ReadOnlyTx + * @see ccf::kv::ReadOnlyTx */ class Tx : public ReadOnlyTx { diff --git a/samples/apps/basic/basic.cpp b/samples/apps/basic/basic.cpp index 5d72ab3ed2c7..090effeefe62 100644 --- a/samples/apps/basic/basic.cpp +++ b/samples/apps/basic/basic.cpp @@ -18,7 +18,7 @@ using namespace nlohmann; namespace basicapp { - using RecordsMap = kv::Map>; + using RecordsMap = ccf::kv::Map>; static constexpr auto PRIVATE_RECORDS = "records"; class BasicHandlers : public ccf::UserEndpointRegistry diff --git a/samples/apps/logging/create_tx_claims_digest.cpp b/samples/apps/logging/create_tx_claims_digest.cpp index 7ed7a48bb358..58dbe869a163 100644 --- a/samples/apps/logging/create_tx_claims_digest.cpp +++ b/samples/apps/logging/create_tx_claims_digest.cpp @@ -8,7 +8,7 @@ namespace ccfapp { std::optional get_create_tx_claims_digest( - kv::ReadOnlyTx& tx) + ccf::kv::ReadOnlyTx& tx) { auto constitution = tx.ro(ccf::Tables::CONSTITUTION)->get(); diff --git a/samples/apps/logging/logging.cpp b/samples/apps/logging/logging.cpp index 8b9586dc5e01..ac04e1f453f7 100644 --- a/samples/apps/logging/logging.cpp +++ b/samples/apps/logging/logging.cpp @@ -28,7 +28,7 @@ using namespace nlohmann; namespace loggingapp { // SNIPPET: table_definition - using RecordsMap = kv::Map; + using RecordsMap = ccf::kv::Map; static constexpr auto PUBLIC_RECORDS = "public:records"; static constexpr auto PRIVATE_RECORDS = "records"; @@ -71,7 +71,7 @@ namespace loggingapp { public: std::unique_ptr authenticate( - kv::ReadOnlyTx&, + ccf::kv::ReadOnlyTx&, const std::shared_ptr& ctx, std::string& error_reason) override { @@ -169,7 +169,7 @@ namespace loggingapp {} void handle_committed_transaction( - const ccf::TxID& tx_id, const kv::ReadOnlyStorePtr& store) + const ccf::TxID& tx_id, const ccf::kv::ReadOnlyStorePtr& store) { std::lock_guard lock(txid_lock); auto tx_diff = store->create_tx_diff(); @@ -1571,7 +1571,7 @@ namespace loggingapp // Fetch the requested range auto& historical_cache = context.get_historical_state(); - std::vector stores; + std::vector stores; if (!interesting_seqnos->empty()) { stores = diff --git a/samples/apps/programmability/programmability.cpp b/samples/apps/programmability/programmability.cpp index 8e6122258e80..894489943be4 100644 --- a/samples/apps/programmability/programmability.cpp +++ b/samples/apps/programmability/programmability.cpp @@ -19,7 +19,7 @@ using namespace nlohmann; namespace programmabilityapp { - using RecordsMap = kv::Map>; + using RecordsMap = ccf::kv::Map>; static constexpr auto PRIVATE_RECORDS = "programmability.records"; static constexpr auto CUSTOM_ENDPOINTS_NAMESPACE = "public:custom_endpoints"; @@ -43,9 +43,11 @@ namespace programmabilityapp // This is a pure helper function which can be called from either C++ or JS, // to implement common functionality in a single place static inline bool has_role_permitting_action( - kv::ReadOnlyTx& tx, const std::string& user_id, const std::string& action) + ccf::kv::ReadOnlyTx& tx, + const std::string& user_id, + const std::string& action) { - using RoleSet = kv::Set; + using RoleSet = ccf::kv::Set; auto users_handle = tx.ro(ccf::Tables::USER_INFO); const auto user_info = users_handle->get(user_id); @@ -77,9 +79,9 @@ namespace programmabilityapp // this extension object. // In this case, since the extension adds a function that wants to read from // the KV, it needs the current request's Tx. - kv::ReadOnlyTx* tx; + ccf::kv::ReadOnlyTx* tx; - MyExtension(kv::ReadOnlyTx* t) : tx(t) {} + MyExtension(ccf::kv::ReadOnlyTx* t) : tx(t) {} void install(ccf::js::core::Context& ctx) override; }; @@ -113,7 +115,7 @@ namespace programmabilityapp return JS_ThrowInternalError(ctx, "No transaction available"); } - kv::ReadOnlyTx& tx = *tx_ptr; + ccf::kv::ReadOnlyTx& tx = *tx_ptr; // Process the arguments passed to the JS function, confirming they're both // strings diff --git a/src/apps/js_generic/js_generic_base.cpp b/src/apps/js_generic/js_generic_base.cpp index bdb4bff48cc1..20175f40cad5 100644 --- a/src/apps/js_generic/js_generic_base.cpp +++ b/src/apps/js_generic/js_generic_base.cpp @@ -36,7 +36,7 @@ namespace ccfapp { using namespace std; - using namespace kv; + using namespace ccf::kv; using namespace ccf; class JSHandlers : public UserEndpointRegistry @@ -592,7 +592,7 @@ namespace ccfapp } ccf::endpoints::EndpointDefinitionPtr find_endpoint( - kv::Tx& tx, ccf::RpcContext& rpc_ctx) override + ccf::kv::Tx& tx, ccf::RpcContext& rpc_ctx) override { const auto method = rpc_ctx.get_method(); const auto verb = rpc_ctx.get_request_verb(); @@ -685,7 +685,7 @@ namespace ccfapp } std::set get_allowed_verbs( - kv::Tx& tx, const ccf::RpcContext& rpc_ctx) override + ccf::kv::Tx& tx, const ccf::RpcContext& rpc_ctx) override { const auto method = rpc_ctx.get_method(); @@ -751,7 +751,7 @@ namespace ccfapp // Since we do our own dispatch within the default handler, report the // supported methods here - void build_api(nlohmann::json& document, kv::ReadOnlyTx& tx) override + void build_api(nlohmann::json& document, ccf::kv::ReadOnlyTx& tx) override { UserEndpointRegistry::build_api(document, tx); diff --git a/src/apps/tpcc/app/tpcc_tables.h b/src/apps/tpcc/app/tpcc_tables.h index 8f3b84565652..81c603849dbd 100644 --- a/src/apps/tpcc/app/tpcc_tables.h +++ b/src/apps/tpcc/app/tpcc_tables.h @@ -19,10 +19,10 @@ namespace tpcc { template - kv::serialisers::SerialisedEntry tpcc_serialise(const T& t); + ccf::kv::serialisers::SerialisedEntry tpcc_serialise(const T& t); template - T tpcc_deserialise(const kv::serialisers::SerialisedEntry& rep); + T tpcc_deserialise(const ccf::kv::serialisers::SerialisedEntry& rep); template constexpr size_t serialised_size() @@ -106,9 +106,9 @@ namespace tpcc _Pragma("clang diagnostic push"); \ _Pragma("clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\""); \ template <> \ - kv::serialisers::SerialisedEntry tpcc_serialise(const TYPE& t) \ + ccf::kv::serialisers::SerialisedEntry tpcc_serialise(const TYPE& t) \ { \ - kv::serialisers::SerialisedEntry rep; \ + ccf::kv::serialisers::SerialisedEntry rep; \ constexpr size_t required_size = 0 _FOR_JSON_COUNT_NN(__VA_ARGS__)(POP1)( \ ADD_SERIALIZED_SIZE, TYPE, ##__VA_ARGS__); \ rep.resize(required_size); \ @@ -118,7 +118,7 @@ namespace tpcc return rep; \ } \ template <> \ - TYPE tpcc_deserialise(const kv::serialisers::SerialisedEntry& rep) \ + TYPE tpcc_deserialise(const ccf::kv::serialisers::SerialisedEntry& rep) \ { \ auto data = rep.data(); \ auto size = rep.size(); \ @@ -132,12 +132,12 @@ namespace tpcc template struct TpccSerialiser { - static kv::serialisers::SerialisedEntry to_serialised(const T& t) + static ccf::kv::serialisers::SerialisedEntry to_serialised(const T& t) { return tpcc_serialise(t); } - static T from_serialised(const kv::serialisers::SerialisedEntry& rep) + static T from_serialised(const ccf::kv::serialisers::SerialisedEntry& rep) { return tpcc_deserialise(rep); } @@ -539,7 +539,7 @@ namespace tpcc History, c_id, c_d_id, c_w_id, d_id, w_id, amount, date, data); template - using TpccMap = kv::MapSerialisedWith; + using TpccMap = ccf::kv::MapSerialisedWith; struct TpccTables { diff --git a/src/consensus/aft/impl/state.h b/src/consensus/aft/impl/state.h index 4d5e637de956..b41bc4cfe9aa 100644 --- a/src/consensus/aft/impl/state.h +++ b/src/consensus/aft/impl/state.h @@ -19,12 +19,12 @@ namespace aft class ViewHistory { // Entry i stores the first version in view i+1 - std::vector views; + std::vector views; public: static constexpr ccf::View InvalidView = ccf::VIEW_UNKNOWN; - void initialise(const std::vector& terms_) + void initialise(const std::vector& terms_) { views.clear(); for (size_t i = 0; i < terms_.size(); ++i) @@ -34,7 +34,7 @@ namespace aft LOG_DEBUG_FMT("Initialised views: {}", fmt::join(views, ", ")); } - void update(kv::Version idx, ccf::View view) + void update(ccf::kv::Version idx, ccf::View view) { LOG_DEBUG_FMT("Updating view to: {} at version: {}", view, idx); if (!views.empty()) @@ -56,7 +56,7 @@ namespace aft LOG_DEBUG_FMT("Resulting views: {}", fmt::join(views, ", ")); } - ccf::View view_at(kv::Version idx) + ccf::View view_at(ccf::kv::Version idx) { auto it = upper_bound(views.begin(), views.end(), idx); @@ -69,11 +69,11 @@ namespace aft return (it - views.begin()); } - kv::Version start_of_view(ccf::View view) + ccf::kv::Version start_of_view(ccf::View view) { if (view > views.size() || view == InvalidView) { - return kv::NoVersion; + return ccf::kv::NoVersion; } // NB: If views == {5, 10, 10}, then view 2 doesn't start at 10. View 2 @@ -81,23 +81,23 @@ namespace aft const auto tentative = views[view - 1]; if (view + 1 <= views.size() && views[view] == tentative) { - return kv::NoVersion; + return ccf::kv::NoVersion; } return tentative; } - kv::Version end_of_view(ccf::View view) + ccf::kv::Version end_of_view(ccf::View view) { // If this view has no start (potentially because it contains no // transactions), then it can't have an end - if (start_of_view(view) == kv::NoVersion) + if (start_of_view(view) == ccf::kv::NoVersion) { - return kv::NoVersion; + return ccf::kv::NoVersion; } if (view >= views.size() || view == InvalidView) { - return kv::NoVersion; + return ccf::kv::NoVersion; } // Otherwise the end of this view is the transaction before (- 1) the @@ -105,14 +105,14 @@ namespace aft return views[view] - 1; } - std::vector get_history_until( - kv::Version idx = std::numeric_limits::max()) + std::vector get_history_until( + ccf::kv::Version idx = std::numeric_limits::max()) { return {views.begin(), std::upper_bound(views.begin(), views.end(), idx)}; } // view should be non-zero as views start at one in here - std::vector get_history_since(uint64_t view) + std::vector get_history_since(uint64_t view) { if (view > views.size()) { @@ -121,7 +121,7 @@ namespace aft return {views.begin() + view - 1, views.end()}; } - void rollback(kv::Version idx) + void rollback(ccf::kv::Version idx) { auto it = upper_bound(views.begin(), views.end(), idx); views.erase(it, views.end()); @@ -157,8 +157,8 @@ namespace aft ccf::NodeId node_id; ccf::View current_view = 0; - kv::Version last_idx = 0; - kv::Version commit_idx = 0; + ccf::kv::Version last_idx = 0; + ccf::kv::Version commit_idx = 0; ViewHistory view_history; // Indices that are eligible for global commit, from a Node's perspective @@ -176,10 +176,11 @@ namespace aft // the node // Leader -> Follower, when receiving entries for a newer term // Candidate -> Follower, when receiving entries for a newer term - kv::LeadershipState leadership_state = kv::LeadershipState::None; - kv::MembershipState membership_state = kv::MembershipState::Active; + ccf::kv::LeadershipState leadership_state = ccf::kv::LeadershipState::None; + ccf::kv::MembershipState membership_state = + ccf::kv::MembershipState::Active; - std::optional retirement_phase = std::nullopt; + std::optional retirement_phase = std::nullopt; // Index at which this node observes its retirement std::optional retirement_idx = std::nullopt; // Earliest index at which this node's retirement can be committed diff --git a/src/consensus/aft/raft.h b/src/consensus/aft/raft.h index 6e8094e10414..46d1844f51d5 100644 --- a/src/consensus/aft/raft.h +++ b/src/consensus/aft/raft.h @@ -89,10 +89,10 @@ static inline void add_committable_indices_start_and_end( namespace aft { - using Configuration = kv::Configuration; + using Configuration = ccf::kv::Configuration; template - class Aft : public kv::Consensus + class Aft : public ccf::kv::Consensus { private: struct NodeState @@ -216,8 +216,8 @@ namespace aft std::shared_ptr state_, std::shared_ptr rpc_request_context_, bool public_only_ = false, - kv::MembershipState initial_membership_state_ = - kv::MembershipState::Active, + ccf::kv::MembershipState initial_membership_state_ = + ccf::kv::MembershipState::Active, ReconfigurationType reconfiguration_type_ = ReconfigurationType::ONE_TRANSACTION) : store(std::move(store_)), @@ -258,12 +258,12 @@ namespace aft bool is_primary() override { - return state->leadership_state == kv::LeadershipState::Leader; + return state->leadership_state == ccf::kv::LeadershipState::Leader; } bool is_candidate() override { - return state->leadership_state == kv::LeadershipState::Candidate; + return state->leadership_state == ccf::kv::LeadershipState::Candidate; } bool can_replicate() override @@ -284,7 +284,7 @@ namespace aft return false; } std::unique_lock guard(state->lock); - return state->leadership_state == kv::LeadershipState::Leader && + return state->leadership_state == ccf::kv::LeadershipState::Leader && (state->last_idx - state->commit_idx >= max_uncommitted_tx_count); } @@ -310,46 +310,46 @@ namespace aft bool is_backup() override { - return state->leadership_state == kv::LeadershipState::Follower; + return state->leadership_state == ccf::kv::LeadershipState::Follower; } bool is_active() const { - return state->membership_state == kv::MembershipState::Active; + return state->membership_state == ccf::kv::MembershipState::Active; } bool is_retired() const { - return state->membership_state == kv::MembershipState::Retired; + return state->membership_state == ccf::kv::MembershipState::Retired; } bool is_retired_committed() const { - return state->membership_state == kv::MembershipState::Retired && - state->retirement_phase == kv::RetirementPhase::RetiredCommitted; + return state->membership_state == ccf::kv::MembershipState::Retired && + state->retirement_phase == ccf::kv::RetirementPhase::RetiredCommitted; } bool is_retired_completed() const { - return state->membership_state == kv::MembershipState::Retired && - state->retirement_phase == kv::RetirementPhase::Completed; + return state->membership_state == ccf::kv::MembershipState::Retired && + state->retirement_phase == ccf::kv::RetirementPhase::Completed; } void set_retired_committed( - ccf::SeqNo seqno, const std::vector& node_ids) override + ccf::SeqNo seqno, const std::vector& node_ids) override { for (auto& node_id : node_ids) { if (id() == node_id) { CCF_ASSERT( - state->membership_state == kv::MembershipState::Retired, + state->membership_state == ccf::kv::MembershipState::Retired, "Node is not retired, cannot become retired committed"); CCF_ASSERT( - state->retirement_phase == kv::RetirementPhase::Completed, + state->retirement_phase == ccf::kv::RetirementPhase::Completed, "Node is not retired, cannot become retired committed"); state->retired_committed_idx = seqno; - become_retired(seqno, kv::RetirementPhase::RetiredCommitted); + become_retired(seqno, ccf::kv::RetirementPhase::RetiredCommitted); } else { @@ -531,7 +531,7 @@ namespace aft public: void add_configuration( Index idx, - const kv::Configuration::Nodes& conf, + const ccf::kv::Configuration::Nodes& conf, const std::unordered_set& new_learner_nodes = {}, const std::unordered_set& new_retired_nodes = {}) override { @@ -561,7 +561,7 @@ namespace aft configurations.back().nodes.end() && conf.find(state->node_id) == conf.end()) { - become_retired(idx, kv::RetirementPhase::Ordered); + become_retired(idx, ccf::kv::RetirementPhase::Ordered); } if (conf != configurations.back().nodes) @@ -606,9 +606,9 @@ namespace aft return get_latest_configuration_unsafe(); } - kv::ConsensusDetails get_details() override + ccf::kv::ConsensusDetails get_details() override { - kv::ConsensusDetails details; + ccf::kv::ConsensusDetails details; std::lock_guard guard(state->lock); details.primary_id = leader_id; details.current_view = state->current_view; @@ -632,11 +632,11 @@ namespace aft return details; } - bool replicate(const kv::BatchVector& entries, Term term) override + bool replicate(const ccf::kv::BatchVector& entries, Term term) override { std::lock_guard guard(state->lock); - if (state->leadership_state != kv::LeadershipState::Leader) + if (state->leadership_state != ccf::kv::LeadershipState::Leader) { RAFT_DEBUG_FMT( "Failed to replicate {} items: not leader", entries.size()); @@ -702,10 +702,10 @@ namespace aft state->membership_state, state->leadership_state); if ( - state->membership_state == kv::MembershipState::Retired && - state->retirement_phase == kv::RetirementPhase::Ordered) + state->membership_state == ccf::kv::MembershipState::Retired && + state->retirement_phase == ccf::kv::RetirementPhase::Ordered) { - become_retired(index, kv::RetirementPhase::Signed); + become_retired(index, ccf::kv::RetirementPhase::Signed); } state->committable_indices.push_back(index); start_ticking_if_necessary(); @@ -825,7 +825,7 @@ namespace aft std::unique_lock guard(state->lock); timeout_elapsed += elapsed; - if (state->leadership_state == kv::LeadershipState::Leader) + if (state->leadership_state == ccf::kv::LeadershipState::Leader) { if (timeout_elapsed >= request_timeout) { @@ -962,13 +962,13 @@ namespace aft bool can_replicate_unsafe() { - return state->leadership_state == kv::LeadershipState::Leader && + return state->leadership_state == ccf::kv::LeadershipState::Leader && !is_retired_committed(); } bool can_sign_unsafe() { - return state->leadership_state == kv::LeadershipState::Leader && + return state->leadership_state == ccf::kv::LeadershipState::Leader && !is_retired_committed(); } @@ -998,7 +998,7 @@ namespace aft const auto term_of_ae = state->view_history.view_at(start); const auto index_at_end_of_term = state->view_history.end_of_view(term_of_ae); - if (index_at_end_of_term != kv::NoVersion) + if (index_at_end_of_term != ccf::kv::NoVersion) { max_idx = index_at_end_of_term; } @@ -1116,7 +1116,7 @@ namespace aft // follower if necessary if ( state->current_view == r.term && - state->leadership_state == kv::LeadershipState::Candidate) + state->leadership_state == ccf::kv::LeadershipState::Candidate) { become_aware_of_new_term(r.term); } @@ -1216,8 +1216,9 @@ namespace aft r.idx, r.prev_idx); - std::vector< - std::tuple, kv::Version>> + std::vector, + ccf::kv::Version>> append_entries; // Finally, deserialise each entry in the batch for (Index i = r.prev_idx + 1; i <= r.idx; i++) @@ -1299,7 +1300,7 @@ namespace aft return; } - kv::TxID expected{r.term_of_idx, i}; + ccf::kv::TxID expected{r.term_of_idx, i}; auto ds = store->deserialize(entry, public_only, expected); if (ds == nullptr) { @@ -1321,8 +1322,8 @@ namespace aft void execute_append_entries_sync( std::vector, - kv::Version>>&& append_entries, + std::unique_ptr, + ccf::kv::Version>>&& append_entries, const ccf::NodeId& from, AppendEntries&& r) { @@ -1341,9 +1342,9 @@ namespace aft #endif bool track_deletes_on_missing_keys = false; - kv::ApplyResult apply_success = + ccf::kv::ApplyResult apply_success = ds->apply(track_deletes_on_missing_keys); - if (apply_success == kv::ApplyResult::FAIL) + if (apply_success == ccf::kv::ApplyResult::FAIL) { ledger->truncate(i - 1); send_append_entries_response_nack(from); @@ -1357,7 +1358,7 @@ namespace aft } bool globally_committable = - (apply_success == kv::ApplyResult::PASS_SIGNATURE); + (apply_success == ccf::kv::ApplyResult::PASS_SIGNATURE); if (globally_committable) { start_ticking_if_necessary(); @@ -1370,7 +1371,7 @@ namespace aft switch (apply_success) { - case kv::ApplyResult::FAIL: + case ccf::kv::ApplyResult::FAIL: { RAFT_FAIL_FMT("Follower failed to apply log entry: {}", i); state->last_idx--; @@ -1379,14 +1380,14 @@ namespace aft break; } - case kv::ApplyResult::PASS_SIGNATURE: + case ccf::kv::ApplyResult::PASS_SIGNATURE: { RAFT_DEBUG_FMT("Deserialising signature at {}", i); if ( - state->membership_state == kv::MembershipState::Retired && - state->retirement_phase == kv::RetirementPhase::Ordered) + state->membership_state == ccf::kv::MembershipState::Retired && + state->retirement_phase == ccf::kv::RetirementPhase::Ordered) { - become_retired(i, kv::RetirementPhase::Signed); + become_retired(i, ccf::kv::RetirementPhase::Signed); } state->committable_indices.push_back(i); @@ -1416,12 +1417,12 @@ namespace aft break; } - case kv::ApplyResult::PASS: + case ccf::kv::ApplyResult::PASS: { break; } - case kv::ApplyResult::PASS_ENCRYPTED_PAST_LEDGER_SECRET: + case ccf::kv::ApplyResult::PASS_ENCRYPTED_PAST_LEDGER_SECRET: { break; } @@ -1560,7 +1561,7 @@ namespace aft #endif // Ignore if we're not the leader. - if (state->leadership_state != kv::LeadershipState::Leader) + if (state->leadership_state != ccf::kv::LeadershipState::Leader) { RAFT_FAIL_FMT( "Recv append entries response to {} from {}: no longer leader", @@ -1811,7 +1812,7 @@ namespace aft RAFT_TRACE_JSON_OUT(j); #endif - if (state->leadership_state != kv::LeadershipState::Candidate) + if (state->leadership_state != ccf::kv::LeadershipState::Candidate) { RAFT_INFO_FMT( "Recv request vote response to {} from: {}: we aren't a candidate", @@ -1929,7 +1930,7 @@ namespace aft return; } - state->leadership_state = kv::LeadershipState::Candidate; + state->leadership_state = ccf::kv::LeadershipState::Candidate; leader_id.reset(); voted_for = state->node_id; @@ -1986,7 +1987,7 @@ namespace aft store->initialise_term(state->current_view); } - state->leadership_state = kv::LeadershipState::Leader; + state->leadership_state = ccf::kv::LeadershipState::Leader; leader_id = state->node_id; should_sign = true; @@ -2045,7 +2046,7 @@ namespace aft // receiving a conflicting AppendEntries rollback(last_committable_index()); - state->leadership_state = kv::LeadershipState::Follower; + state->leadership_state = ccf::kv::LeadershipState::Follower; RAFT_INFO_FMT( "Becoming follower {}: {}.{}", state->node_id, @@ -2077,7 +2078,7 @@ namespace aft } private: - void become_retired(Index idx, kv::RetirementPhase phase) + void become_retired(Index idx, ccf::kv::RetirementPhase phase) { RAFT_INFO_FMT( "Becoming retired, phase {} (leadership {}): {}: {} at {}", @@ -2087,7 +2088,7 @@ namespace aft state->current_view, idx); - if (phase == kv::RetirementPhase::Ordered) + if (phase == ccf::kv::RetirementPhase::Ordered) { CCF_ASSERT_FMT( !state->retirement_idx.has_value(), @@ -2096,7 +2097,7 @@ namespace aft state->retirement_idx = idx; RAFT_INFO_FMT("Node retiring at {}", idx); } - else if (phase == kv::RetirementPhase::Signed) + else if (phase == ccf::kv::RetirementPhase::Signed) { assert(state->retirement_idx.has_value()); CCF_ASSERT_FMT( @@ -2107,15 +2108,15 @@ namespace aft state->retirement_committable_idx = idx; RAFT_INFO_FMT("Node retirement committable at {}", idx); } - else if (phase == kv::RetirementPhase::RetiredCommitted) + else if (phase == ccf::kv::RetirementPhase::RetiredCommitted) { - if (state->leadership_state == kv::LeadershipState::Leader) + if (state->leadership_state == ccf::kv::LeadershipState::Leader) { ProposeRequestVote prv{.term = state->current_view}; std::optional successor = std::nullopt; Index max_match_idx = 0; - kv::ReconfigurationId reconf_id_of_max_match = 0; + ccf::kv::ReconfigurationId reconf_id_of_max_match = 0; // Pick the node that has the highest match_idx, and break // ties by looking at the highest reconfiguration id they are @@ -2131,7 +2132,7 @@ namespace aft { if (node_state.match_idx >= max_match_idx) { - kv::ReconfigurationId latest_reconf_id = 0; + ccf::kv::ReconfigurationId latest_reconf_id = 0; auto conf = configurations.rbegin(); while (conf != configurations.rend()) { @@ -2160,10 +2161,10 @@ namespace aft } leader_id.reset(); - state->leadership_state = kv::LeadershipState::None; + state->leadership_state = ccf::kv::LeadershipState::None; } - state->membership_state = kv::MembershipState::Retired; + state->membership_state = ccf::kv::MembershipState::Retired; state->retirement_phase = phase; } @@ -2221,7 +2222,7 @@ namespace aft // idx. void update_commit() { - if (state->leadership_state != kv::LeadershipState::Leader) + if (state->leadership_state != ccf::kv::LeadershipState::Leader) { throw std::logic_error( "update_commit() must only be called while this node is leader"); @@ -2357,11 +2358,11 @@ namespace aft state->commit_idx = idx; if ( is_retired() && - state->retirement_phase == kv::RetirementPhase::Signed && + state->retirement_phase == ccf::kv::RetirementPhase::Signed && state->retirement_committable_idx.has_value() && idx >= state->retirement_committable_idx.value()) { - become_retired(idx, kv::RetirementPhase::Completed); + become_retired(idx, ccf::kv::RetirementPhase::Completed); } RAFT_DEBUG_FMT("Compacting..."); @@ -2457,27 +2458,27 @@ namespace aft } if ( - state->membership_state == kv::MembershipState::Retired && - state->retirement_phase == kv::RetirementPhase::Signed) + state->membership_state == ccf::kv::MembershipState::Retired && + state->retirement_phase == ccf::kv::RetirementPhase::Signed) { assert(state->retirement_committable_idx.has_value()); if (state->retirement_committable_idx.value() > idx) { state->retirement_committable_idx = std::nullopt; - state->retirement_phase = kv::RetirementPhase::Ordered; + state->retirement_phase = ccf::kv::RetirementPhase::Ordered; } } if ( - state->membership_state == kv::MembershipState::Retired && - state->retirement_phase == kv::RetirementPhase::Ordered) + state->membership_state == ccf::kv::MembershipState::Retired && + state->retirement_phase == ccf::kv::RetirementPhase::Ordered) { assert(state->retirement_idx.has_value()); if (state->retirement_idx.value() > idx) { state->retirement_idx = std::nullopt; state->retirement_phase = std::nullopt; - state->membership_state = kv::MembershipState::Active; + state->membership_state = ccf::kv::MembershipState::Active; RAFT_DEBUG_FMT("Becoming Active after rollback"); } } @@ -2558,7 +2559,7 @@ namespace aft all_other_nodes.try_emplace( node_info.first, node_info.second, index, 0); - if (state->leadership_state == kv::LeadershipState::Leader) + if (state->leadership_state == ccf::kv::LeadershipState::Leader) { send_append_entries(node_info.first, index); } diff --git a/src/consensus/aft/raft_types.h b/src/consensus/aft/raft_types.h index a0904719ea93..b62fb8d833b0 100644 --- a/src/consensus/aft/raft_types.h +++ b/src/consensus/aft/raft_types.h @@ -23,7 +23,7 @@ namespace aft using ReplyCallback = std::function&& data)>; @@ -34,12 +34,13 @@ namespace aft public: virtual ~Store() {} virtual void compact(Index v) = 0; - virtual void rollback(const kv::TxID& tx_id, Term term_of_next_version) = 0; + virtual void rollback( + const ccf::kv::TxID& tx_id, Term term_of_next_version) = 0; virtual void initialise_term(Term t) = 0; - virtual std::unique_ptr deserialize( + virtual std::unique_ptr deserialize( const std::vector data, bool public_only = false, - const std::optional& expected_txid = std::nullopt) = 0; + const std::optional& expected_txid = std::nullopt) = 0; }; template @@ -60,7 +61,8 @@ namespace aft } } - void rollback(const kv::TxID& tx_id, Term term_of_next_version) override + void rollback( + const ccf::kv::TxID& tx_id, Term term_of_next_version) override { auto p = x.lock(); if (p) @@ -78,10 +80,10 @@ namespace aft } } - std::unique_ptr deserialize( + std::unique_ptr deserialize( const std::vector data, bool public_only = false, - const std::optional& expected_txid = std::nullopt) override + const std::optional& expected_txid = std::nullopt) override { auto p = x.lock(); if (p) diff --git a/src/consensus/aft/test/committable_suffix.cpp b/src/consensus/aft/test/committable_suffix.cpp index c3b58a8db2bb..09eb276eb278 100644 --- a/src/consensus/aft/test/committable_suffix.cpp +++ b/src/consensus/aft/test/committable_suffix.cpp @@ -205,7 +205,7 @@ DOCTEST_TEST_CASE("Retention of dead leader's commit") DOCTEST_INFO("Entry at 1.1 is received by all nodes"); { auto entry = make_ledger_entry(1, 1); - rA.replicate(kv::BatchVector{{1, entry, true, hooks}}, 1); + rA.replicate(ccf::kv::BatchVector{{1, entry, true, hooks}}, 1); DOCTEST_REQUIRE(rA.get_last_idx() == 1); DOCTEST_REQUIRE(rA.get_committed_seqno() == 0); // Size limit was reached, so periodic is not needed @@ -235,21 +235,21 @@ DOCTEST_TEST_CASE("Retention of dead leader's commit") "committed"); { auto entry = make_ledger_entry(1, 2); - rA.replicate(kv::BatchVector{{2, entry, true, hooks}}, 1); + rA.replicate(ccf::kv::BatchVector{{2, entry, true, hooks}}, 1); DOCTEST_REQUIRE(rA.get_last_idx() == 2); DOCTEST_REQUIRE(rA.get_committed_seqno() == 1); // Size limit was reached, so periodic is not needed // rA.periodic(request_timeout); entry = make_ledger_entry(1, 3); - rA.replicate(kv::BatchVector{{3, entry, true, hooks}}, 1); + rA.replicate(ccf::kv::BatchVector{{3, entry, true, hooks}}, 1); DOCTEST_REQUIRE(rA.get_last_idx() == 3); DOCTEST_REQUIRE(rA.get_committed_seqno() == 1); // Size limit was reached, so periodic is not needed // rA.periodic(request_timeout); entry = make_ledger_entry(1, 4); - rA.replicate(kv::BatchVector{{4, entry, true, hooks}}, 1); + rA.replicate(ccf::kv::BatchVector{{4, entry, true, hooks}}, 1); DOCTEST_REQUIRE(rA.get_last_idx() == 4); DOCTEST_REQUIRE(rA.get_committed_seqno() == 1); // Size limit was reached, so periodic is not needed @@ -283,7 +283,7 @@ DOCTEST_TEST_CASE("Retention of dead leader's commit") "committed"); { auto entry = make_ledger_entry(1, 5); - rA.replicate(kv::BatchVector{{5, entry, true, hooks}}, 1); + rA.replicate(ccf::kv::BatchVector{{5, entry, true, hooks}}, 1); DOCTEST_REQUIRE(rA.get_last_idx() == 5); // Size limit was reached, so periodic is not needed // rB.periodic(request_timeout); @@ -350,11 +350,11 @@ DOCTEST_TEST_CASE("Retention of dead leader's commit") DOCTEST_INFO("Node B writes some entries, though they are lost"); { auto entry = make_ledger_entry(2, 6); - rB.replicate(kv::BatchVector{{6, entry, true, hooks}}, 2); + rB.replicate(ccf::kv::BatchVector{{6, entry, true, hooks}}, 2); DOCTEST_REQUIRE(rB.get_last_idx() == 6); entry = make_ledger_entry(2, 7); - rB.replicate(kv::BatchVector{{7, entry, true, hooks}}, 2); + rB.replicate(ccf::kv::BatchVector{{7, entry, true, hooks}}, 2); DOCTEST_REQUIRE(rB.get_last_idx() == 7); // Size limit was reached, so periodic is not needed @@ -401,15 +401,15 @@ DOCTEST_TEST_CASE("Retention of dead leader's commit") DOCTEST_REQUIRE("Node C produces 3.5, 3.6, and 3.7"); { auto entry = make_ledger_entry(3, 5); - rC.replicate(kv::BatchVector{{5, entry, true, hooks}}, 3); + rC.replicate(ccf::kv::BatchVector{{5, entry, true, hooks}}, 3); DOCTEST_REQUIRE(rC.get_last_idx() == 5); entry = make_ledger_entry(3, 6); - rC.replicate(kv::BatchVector{{6, entry, true, hooks}}, 3); + rC.replicate(ccf::kv::BatchVector{{6, entry, true, hooks}}, 3); DOCTEST_REQUIRE(rC.get_last_idx() == 6); entry = make_ledger_entry(3, 7); - rC.replicate(kv::BatchVector{{7, entry, true, hooks}}, 3); + rC.replicate(ccf::kv::BatchVector{{7, entry, true, hooks}}, 3); DOCTEST_REQUIRE(rC.get_last_idx() == 7); // The early AppendEntries that describe this are lost @@ -598,7 +598,7 @@ DOCTEST_TEST_CASE_TEMPLATE("Multi-term divergence", T, WorstCase, RandomCase) { auto entry = make_ledger_entry(primary.get_view(), idx); primary.replicate( - kv::BatchVector{{idx, entry, true, hooks}}, primary.get_view()); + ccf::kv::BatchVector{{idx, entry, true, hooks}}, primary.get_view()); } // All related AppendEntries are lost @@ -627,9 +627,9 @@ DOCTEST_TEST_CASE_TEMPLATE("Multi-term divergence", T, WorstCase, RandomCase) // be committed auto entry = make_ledger_entry(1, 1); - rA.replicate(kv::BatchVector{{1, entry, true, hooks}}, 1); + rA.replicate(ccf::kv::BatchVector{{1, entry, true, hooks}}, 1); entry = make_ledger_entry(1, 2); - rA.replicate(kv::BatchVector{{2, entry, true, hooks}}, 1); + rA.replicate(ccf::kv::BatchVector{{2, entry, true, hooks}}, 1); DOCTEST_REQUIRE(rA.get_last_idx() == 2); DOCTEST_REQUIRE(rA.get_committed_seqno() == 0); // Size limit was reached, so periodic is not needed @@ -662,18 +662,18 @@ DOCTEST_TEST_CASE_TEMPLATE("Multi-term divergence", T, WorstCase, RandomCase) // Node A produces 2 additional entries that A and B have, and 2 additional // entries that are only present on A entry = make_ledger_entry(1, 3); - rA.replicate(kv::BatchVector{{3, entry, true, hooks}}, 1); + rA.replicate(ccf::kv::BatchVector{{3, entry, true, hooks}}, 1); entry = make_ledger_entry(1, 4); - rA.replicate(kv::BatchVector{{4, entry, true, hooks}}, 1); + rA.replicate(ccf::kv::BatchVector{{4, entry, true, hooks}}, 1); keep_messages_for(node_idB, channelsA->messages); DOCTEST_REQUIRE(2 == dispatch_all(nodes, node_idA)); entry = make_ledger_entry(1, 5); - rA.replicate(kv::BatchVector{{5, entry, true, hooks}}, 1); + rA.replicate(ccf::kv::BatchVector{{5, entry, true, hooks}}, 1); entry = make_ledger_entry(1, 6); - rA.replicate(kv::BatchVector{{6, entry, true, hooks}}, 1); + rA.replicate(ccf::kv::BatchVector{{6, entry, true, hooks}}, 1); channelsA->messages.clear(); channelsB->messages.clear(); @@ -936,7 +936,7 @@ DOCTEST_TEST_CASE_TEMPLATE("Multi-term divergence", T, WorstCase, RandomCase) const auto seqno = rPrimary.get_last_idx() + 1; auto final_entry = make_ledger_entry(view, seqno); rPrimary.replicate( - kv::BatchVector{{seqno, final_entry, true, hooks}}, view); + ccf::kv::BatchVector{{seqno, final_entry, true, hooks}}, view); rPrimary.periodic(request_timeout); keep_earliest_append_entries_for_each_target(channelsPrimary->messages); diff --git a/src/consensus/aft/test/driver.h b/src/consensus/aft/test/driver.h index eeb8e07603d4..3eacddc14e7d 100644 --- a/src/consensus/aft/test/driver.h +++ b/src/consensus/aft/test/driver.h @@ -48,8 +48,8 @@ struct LedgerStubProxy_Mermaid : public aft::LedgerStubProxy void put_entry( const std::vector& data, bool globally_committable, - kv::Term term, - kv::Version index) override + ccf::kv::Term term, + ccf::kv::Version index) override { RAFT_DRIVER_PRINT( "{}->>{}: [ledger] appending: {}.{}={}", @@ -78,7 +78,7 @@ struct LoggingStubStore_Mermaid : public aft::LoggingStubStoreConfig aft::LoggingStubStoreConfig::compact(idx); } - void rollback(const kv::TxID& tx_id, aft::Term t) override + void rollback(const ccf::kv::TxID& tx_id, aft::Term t) override { RAFT_DRIVER_PRINT( "{}->>{}: [KV] rolling back to {}.{}, in term {}", @@ -124,8 +124,9 @@ class RaftDriver std::vector data, const size_t lineno, bool committable = false, - const std::optional& configuration = std::nullopt, - const std::optional& retired_committed = + const std::optional& configuration = + std::nullopt, + const std::optional& retired_committed = std::nullopt) { const auto opt = find_primary_in_term(term_s, lineno); @@ -150,7 +151,7 @@ class RaftDriver configuration.has_value() ? "reconfiguration" : "raw"); aft::ReplicatedDataType type = aft::ReplicatedDataType::raw; - auto hooks = std::make_shared(); + auto hooks = std::make_shared(); if (configuration.has_value() && retired_committed.has_value()) { throw std::logic_error( @@ -184,7 +185,7 @@ class RaftDriver auto s = nlohmann::json(aft::ReplicatedData{type, data}).dump(); auto d = std::make_shared>(s.begin(), s.end()); - raft->replicate(kv::BatchVector{{idx, d, committable, hooks}}, term); + raft->replicate(ccf::kv::BatchVector{{idx, d, committable, hooks}}, term); } void add_node(ccf::NodeId node_id) @@ -199,7 +200,7 @@ class RaftDriver std::make_shared(node_id), nullptr); kv->set_set_retired_committed_hook( - [raft](aft::Index idx, const std::vector& node_ids) { + [raft](aft::Index idx, const std::vector& node_ids) { raft->set_retired_committed(idx, node_ids); }); raft->start_ticking(); @@ -220,7 +221,7 @@ class RaftDriver { // Unrealistic way to create network. Initial configuration is automatically // added to all nodes. - kv::Configuration::Nodes configuration; + ccf::kv::Configuration::Nodes configuration; for (auto const& n : node_ids) { add_node(n); @@ -248,7 +249,7 @@ class RaftDriver { throw std::logic_error("Start node already exists"); } - kv::Configuration::Nodes configuration; + ccf::kv::Configuration::Nodes configuration; add_node(start_node_id); configuration.try_emplace(start_node_id); _nodes[start_node_id].raft->force_become_primary(); @@ -264,7 +265,7 @@ class RaftDriver const std::vector& node_ids, const size_t lineno) { - kv::Configuration::Nodes retired_committed; + ccf::kv::Configuration::Nodes retired_committed; for (const auto& id : node_ids) { if (_nodes.find(id) == _nodes.end()) @@ -288,7 +289,7 @@ class RaftDriver RAFT_DRIVER_PRINT( "Note over {}: Node {} trusted", ccf::NodeId(node_id), node_id); } - kv::Configuration::Nodes configuration; + ccf::kv::Configuration::Nodes configuration; for (const auto& [id, node] : _nodes) { configuration.try_emplace(id); @@ -325,7 +326,7 @@ class RaftDriver } std::set out(nodes_out.begin(), nodes_out.end()); - kv::Configuration::Nodes configuration; + ccf::kv::Configuration::Nodes configuration; for (const auto& [id, node] : _nodes) { if (out.find(id) == out.end()) @@ -352,7 +353,7 @@ class RaftDriver std::vector node_ids, const size_t lineno) { - kv::Configuration::Nodes configuration; + ccf::kv::Configuration::Nodes configuration; for (const auto& node_id_s : node_ids) { ccf::NodeId node_id(node_id_s); diff --git a/src/consensus/aft/test/enclave.cpp b/src/consensus/aft/test/enclave.cpp index b45c3f4e064c..e1cd1ee1edba 100644 --- a/src/consensus/aft/test/enclave.cpp +++ b/src/consensus/aft/test/enclave.cpp @@ -73,9 +73,9 @@ TEST_CASE("Enclave record") bool globally_committable = false; const std::vector entry = {'a', 'b', 'c'}; - kv::SerialisedEntryHeader entry_header; + ccf::kv::SerialisedEntryHeader entry_header; - std::vector tx(kv::serialised_entry_header_size + entry.size()); + std::vector tx(ccf::kv::serialised_entry_header_size + entry.size()); auto tx_ = tx.data(); auto size_ = tx.size(); serialized::write(tx_, size_, entry_header); diff --git a/src/consensus/aft/test/logging_stub.h b/src/consensus/aft/test/logging_stub.h index 3c96755cc717..680a05acb217 100644 --- a/src/consensus/aft/test/logging_stub.h +++ b/src/consensus/aft/test/logging_stub.h @@ -30,8 +30,8 @@ namespace aft virtual void put_entry( const std::vector& original, bool globally_committable, - kv::Term term, - kv::Version index) + ccf::kv::Term term, + ccf::kv::Version index) { std::lock_guard lock(ledger_access); @@ -98,8 +98,8 @@ namespace aft // Remove the View and Index that were written during put_entry data->erase( data->begin(), - data->begin() + sizeof(size_t) + sizeof(kv::Term) + - sizeof(kv::Version)); + data->begin() + sizeof(size_t) + sizeof(ccf::kv::Term) + + sizeof(ccf::kv::Version)); } return data; @@ -286,20 +286,21 @@ namespace aft DECLARE_JSON_TYPE(ReplicatedData); DECLARE_JSON_REQUIRED_FIELDS(ReplicatedData, type, data); - class ConfigurationChangeHook : public kv::ConsensusHook + class ConfigurationChangeHook : public ccf::kv::ConsensusHook { - kv::Configuration::Nodes + ccf::kv::Configuration::Nodes new_configuration; // Absence of node means that node has been retired - kv::Version version; + ccf::kv::Version version; public: ConfigurationChangeHook( - kv::Configuration::Nodes new_configuration_, kv::Version version_) : + ccf::kv::Configuration::Nodes new_configuration_, + ccf::kv::Version version_) : new_configuration(new_configuration_), version(version_) {} - void call(kv::ConfigurableConsensus* consensus) override + void call(ccf::kv::ConfigurableConsensus* consensus) override { auto configuration = consensus->get_latest_configuration_unsafe(); std::unordered_set retired_nodes; @@ -329,7 +330,8 @@ namespace aft } }; - using RCHook = std::function&)>; + using RCHook = + std::function&)>; class LoggingStubStore { @@ -348,32 +350,32 @@ namespace aft virtual void compact(Index i) {} - virtual void rollback(const kv::TxID& tx_id, Term t) {} + virtual void rollback(const ccf::kv::TxID& tx_id, Term t) {} virtual void initialise_term(Term t) {} - kv::Version current_version() + ccf::kv::Version current_version() { - return kv::NoVersion; + return ccf::kv::NoVersion; } - class ExecutionWrapper : public kv::AbstractExecutionWrapper + class ExecutionWrapper : public ccf::kv::AbstractExecutionWrapper { private: - kv::ConsensusHookPtrs hooks; + ccf::kv::ConsensusHookPtrs hooks; aft::Term term; - kv::Version index; + ccf::kv::Version index; std::vector entry; ccf::ClaimsDigest claims_digest; std::optional commit_evidence_digest = std::nullopt; - kv::ApplyResult result; + ccf::kv::ApplyResult result; public: ExecutionWrapper( const std::vector& data_, - const std::optional& expected_txid, - kv::ConsensusHookPtrs&& hooks_) : + const std::optional& expected_txid, + ccf::kv::ConsensusHookPtrs&& hooks_) : hooks(std::move(hooks_)) { const uint8_t* data = data_.data(); @@ -381,17 +383,17 @@ namespace aft const auto committable = serialized::read(data, size); term = serialized::read(data, size); - index = serialized::read(data, size); + index = serialized::read(data, size); entry = serialized::read(data, size, size); - result = - committable ? kv::ApplyResult::PASS_SIGNATURE : kv::ApplyResult::PASS; + result = committable ? ccf::kv::ApplyResult::PASS_SIGNATURE : + ccf::kv::ApplyResult::PASS; if (expected_txid.has_value()) { if (term != expected_txid->term || index != expected_txid->version) { - result = kv::ApplyResult::FAIL; + result = ccf::kv::ApplyResult::FAIL; } } } @@ -407,12 +409,12 @@ namespace aft return std::move(commit_evidence_digest); } - kv::ApplyResult apply(bool track_deletes_on_missing_keys) override + ccf::kv::ApplyResult apply(bool track_deletes_on_missing_keys) override { return result; } - kv::ConsensusHookPtrs& get_hooks() override + ccf::kv::ConsensusHookPtrs& get_hooks() override { return hooks; } @@ -427,7 +429,7 @@ namespace aft return term; } - kv::Version get_index() override + ccf::kv::Version get_index() override { return index; } @@ -448,22 +450,22 @@ namespace aft } }; - virtual std::unique_ptr deserialize( + virtual std::unique_ptr deserialize( const std::vector& data, bool public_only = false, - const std::optional& expected_txid = std::nullopt) + const std::optional& expected_txid = std::nullopt) { - kv::ConsensusHookPtrs hooks = {}; + ccf::kv::ConsensusHookPtrs hooks = {}; return std::make_unique( data, expected_txid, std::move(hooks)); } - bool flag_enabled(kv::AbstractStore::Flag) + bool flag_enabled(ccf::kv::AbstractStore::Flag) { return false; } - void unset_flag(kv::AbstractStore::Flag) {} + void unset_flag(ccf::kv::AbstractStore::Flag) {} }; class LoggingStubStoreConfig : public LoggingStubStore @@ -483,7 +485,7 @@ namespace aft { if (version <= i) { - std::vector retired_committed_node_ids; + std::vector retired_committed_node_ids; for (auto& [node_id, _] : configuration.items()) { retired_committed_node_ids.push_back(node_id); @@ -503,7 +505,7 @@ namespace aft retired_committed_entries.end()); } - virtual void rollback(const kv::TxID& tx_id, Term t) override + virtual void rollback(const ccf::kv::TxID& tx_id, Term t) override { retired_committed_entries.erase( std::remove_if( @@ -513,10 +515,10 @@ namespace aft retired_committed_entries.end()); } - virtual std::unique_ptr deserialize( + virtual std::unique_ptr deserialize( const std::vector& data, bool public_only = false, - const std::optional& expected_txid = std::nullopt) override + const std::optional& expected_txid = std::nullopt) override { // Set reconfiguration hook if there are any new nodes // Read wrapping term and version @@ -524,19 +526,21 @@ namespace aft auto size = data.size(); const auto committable = serialized::read(data_, size); serialized::read(data_, size); - auto version = serialized::read(data_, size); + auto version = serialized::read(data_, size); ReplicatedData r = nlohmann::json::parse(std::span{data_, size}); - kv::ConsensusHookPtrs hooks = {}; + ccf::kv::ConsensusHookPtrs hooks = {}; if (r.type == ReplicatedDataType::reconfiguration) { - kv::Configuration::Nodes configuration = nlohmann::json::parse(r.data); + ccf::kv::Configuration::Nodes configuration = + nlohmann::json::parse(r.data); auto hook = std::make_unique( configuration, version); hooks.push_back(std::move(hook)); } if (r.type == ReplicatedDataType::retired_committed) { - kv::Configuration::Nodes configuration = nlohmann::json::parse(r.data); + ccf::kv::Configuration::Nodes configuration = + nlohmann::json::parse(r.data); retired_committed_entries.emplace_back(version, configuration); } diff --git a/src/consensus/aft/test/main.cpp b/src/consensus/aft/test/main.cpp index 6ff7d98d483f..e3a9bac2c6d5 100644 --- a/src/consensus/aft/test/main.cpp +++ b/src/consensus/aft/test/main.cpp @@ -14,7 +14,7 @@ using ms = std::chrono::milliseconds; DOCTEST_TEST_CASE("Single node startup" * doctest::test_suite("single")) { - ccf::NodeId node_id = kv::test::PrimaryNodeId; + ccf::NodeId node_id = ccf::kv::test::PrimaryNodeId; auto kv_store = std::make_shared(node_id); TRaft r0( @@ -26,7 +26,7 @@ DOCTEST_TEST_CASE("Single node startup" * doctest::test_suite("single")) nullptr); r0.start_ticking(); - kv::Configuration::Nodes config; + ccf::kv::Configuration::Nodes config; config.try_emplace(node_id); r0.add_configuration(0, config); @@ -50,7 +50,7 @@ DOCTEST_TEST_CASE("Single node startup" * doctest::test_suite("single")) DOCTEST_TEST_CASE("Single node commit" * doctest::test_suite("single")) { - ccf::NodeId node_id = kv::test::PrimaryNodeId; + ccf::NodeId node_id = ccf::kv::test::PrimaryNodeId; auto kv_store = std::make_shared(node_id); TRaft r0( @@ -80,9 +80,9 @@ DOCTEST_TEST_CASE("Single node commit" * doctest::test_suite("single")) entry->push_back(2); entry->push_back(3); - auto hooks = std::make_shared(); + auto hooks = std::make_shared(); - r0.replicate(kv::BatchVector{{i, entry, true, hooks}}, 1); + r0.replicate(ccf::kv::BatchVector{{i, entry, true, hooks}}, 1); DOCTEST_REQUIRE(r0.get_last_idx() == i); DOCTEST_REQUIRE(r0.get_committed_seqno() == i); } @@ -91,10 +91,10 @@ DOCTEST_TEST_CASE("Single node commit" * doctest::test_suite("single")) DOCTEST_TEST_CASE( "Multiple nodes startup and election" * doctest::test_suite("multiple")) { - ccf::NodeId node_id0 = kv::test::PrimaryNodeId; - ccf::NodeId node_id1 = kv::test::FirstBackupNodeId; - ccf::NodeId node_id2 = kv::test::SecondBackupNodeId; - ccf::NodeId node_id3 = kv::test::ThirdBackupNodeId; + ccf::NodeId node_id0 = ccf::kv::test::PrimaryNodeId; + ccf::NodeId node_id1 = ccf::kv::test::FirstBackupNodeId; + ccf::NodeId node_id2 = ccf::kv::test::SecondBackupNodeId; + ccf::NodeId node_id3 = ccf::kv::test::ThirdBackupNodeId; auto kv_store0 = std::make_shared(node_id0); auto kv_store1 = std::make_shared(node_id1); @@ -275,9 +275,9 @@ DOCTEST_TEST_CASE( DOCTEST_TEST_CASE( "Multiple nodes append entries" * doctest::test_suite("multiple")) { - ccf::NodeId node_id0 = kv::test::PrimaryNodeId; - ccf::NodeId node_id1 = kv::test::FirstBackupNodeId; - ccf::NodeId node_id2 = kv::test::SecondBackupNodeId; + ccf::NodeId node_id0 = ccf::kv::test::PrimaryNodeId; + ccf::NodeId node_id1 = ccf::kv::test::FirstBackupNodeId; + ccf::NodeId node_id2 = ccf::kv::test::SecondBackupNodeId; auto kv_store0 = std::make_shared(node_id0); auto kv_store1 = std::make_shared(node_id1); @@ -359,12 +359,13 @@ DOCTEST_TEST_CASE( DOCTEST_INFO("Try to replicate on a follower, and fail"); std::vector entry = {1, 2, 3}; auto data = std::make_shared>(entry); - auto hooks = std::make_shared(); + auto hooks = std::make_shared(); DOCTEST_REQUIRE_FALSE( - r1.replicate(kv::BatchVector{{1, data, true, hooks}}, 1)); + r1.replicate(ccf::kv::BatchVector{{1, data, true, hooks}}, 1)); DOCTEST_INFO("Tell the leader to replicate a message"); - DOCTEST_REQUIRE(r0.replicate(kv::BatchVector{{1, data, true, hooks}}, 1)); + DOCTEST_REQUIRE( + r0.replicate(ccf::kv::BatchVector{{1, data, true, hooks}}, 1)); DOCTEST_REQUIRE(r0.ledger->ledger.size() == 1); // The test ledger adds its own header. Confirm that the expected data is @@ -411,9 +412,9 @@ DOCTEST_TEST_CASE( DOCTEST_TEST_CASE("Multiple nodes late join" * doctest::test_suite("multiple")) { - ccf::NodeId node_id0 = kv::test::PrimaryNodeId; - ccf::NodeId node_id1 = kv::test::FirstBackupNodeId; - ccf::NodeId node_id2 = kv::test::SecondBackupNodeId; + ccf::NodeId node_id0 = ccf::kv::test::PrimaryNodeId; + ccf::NodeId node_id1 = ccf::kv::test::FirstBackupNodeId; + ccf::NodeId node_id2 = ccf::kv::test::SecondBackupNodeId; auto kv_store0 = std::make_shared(node_id0); auto kv_store1 = std::make_shared(node_id1); @@ -475,8 +476,9 @@ DOCTEST_TEST_CASE("Multiple nodes late join" * doctest::test_suite("multiple")) std::vector first_entry = {1, 2, 3}; auto data = std::make_shared>(first_entry); - auto hooks = std::make_shared(); - DOCTEST_REQUIRE(r0.replicate(kv::BatchVector{{1, data, true, hooks}}, 1)); + auto hooks = std::make_shared(); + DOCTEST_REQUIRE( + r0.replicate(ccf::kv::BatchVector{{1, data, true, hooks}}, 1)); r0.periodic(request_timeout); DOCTEST_REQUIRE( @@ -528,8 +530,8 @@ DOCTEST_TEST_CASE("Multiple nodes late join" * doctest::test_suite("multiple")) DOCTEST_TEST_CASE("Recv append entries logic" * doctest::test_suite("multiple")) { - ccf::NodeId node_id0 = kv::test::PrimaryNodeId; - ccf::NodeId node_id1 = kv::test::FirstBackupNodeId; + ccf::NodeId node_id0 = ccf::kv::test::PrimaryNodeId; + ccf::NodeId node_id1 = ccf::kv::test::FirstBackupNodeId; auto kv_store0 = std::make_shared(node_id0); auto kv_store1 = std::make_shared(node_id1); @@ -548,7 +550,7 @@ DOCTEST_TEST_CASE("Recv append entries logic" * doctest::test_suite("multiple")) std::make_shared(), std::make_shared(node_id1), nullptr); - auto hooks = std::make_shared(); + auto hooks = std::make_shared(); aft::Configuration::Nodes config0; config0[node_id0] = {}; @@ -586,8 +588,10 @@ DOCTEST_TEST_CASE("Recv append entries logic" * doctest::test_suite("multiple")) std::vector second_entry = {2, 2, 2}; auto data_2 = std::make_shared>(second_entry); - DOCTEST_REQUIRE(r0.replicate(kv::BatchVector{{1, data_1, true, hooks}}, 1)); - DOCTEST_REQUIRE(r0.replicate(kv::BatchVector{{2, data_2, true, hooks}}, 1)); + DOCTEST_REQUIRE( + r0.replicate(ccf::kv::BatchVector{{1, data_1, true, hooks}}, 1)); + DOCTEST_REQUIRE( + r0.replicate(ccf::kv::BatchVector{{2, data_2, true, hooks}}, 1)); DOCTEST_REQUIRE(r0.ledger->ledger.size() == 2); r0.periodic(request_timeout); DOCTEST_REQUIRE(r0c->messages.size() == 1); @@ -608,7 +612,8 @@ DOCTEST_TEST_CASE("Recv append entries logic" * doctest::test_suite("multiple")) { std::vector third_entry = {3, 3, 3}; auto data = std::make_shared>(third_entry); - DOCTEST_REQUIRE(r0.replicate(kv::BatchVector{{3, data, true, hooks}}, 1)); + DOCTEST_REQUIRE( + r0.replicate(ccf::kv::BatchVector{{3, data, true, hooks}}, 1)); DOCTEST_REQUIRE(r0.ledger->ledger.size() == 3); // Simulate that the append entries was not deserialised successfully @@ -640,7 +645,8 @@ DOCTEST_TEST_CASE("Recv append entries logic" * doctest::test_suite("multiple")) { std::vector fourth_entry = {4, 4, 4}; auto data = std::make_shared>(fourth_entry); - DOCTEST_REQUIRE(r0.replicate(kv::BatchVector{{4, data, true, hooks}}, 1)); + DOCTEST_REQUIRE( + r0.replicate(ccf::kv::BatchVector{{4, data, true, hooks}}, 1)); DOCTEST_REQUIRE(r0.ledger->ledger.size() == 4); r0.periodic(request_timeout); DOCTEST_REQUIRE(r0c->messages.size() == 1); @@ -653,7 +659,8 @@ DOCTEST_TEST_CASE("Recv append entries logic" * doctest::test_suite("multiple")) { std::vector fifth_entry = {5, 5, 5}; auto data = std::make_shared>(fifth_entry); - DOCTEST_REQUIRE(r0.replicate(kv::BatchVector{{5, data, true, hooks}}, 1)); + DOCTEST_REQUIRE( + r0.replicate(ccf::kv::BatchVector{{5, data, true, hooks}}, 1)); DOCTEST_REQUIRE(r0.ledger->ledger.size() == 5); r0.periodic(request_timeout); DOCTEST_REQUIRE(r0c->messages.size() == 1); @@ -682,7 +689,8 @@ DOCTEST_TEST_CASE("Recv append entries logic" * doctest::test_suite("multiple")) { std::vector entry_6 = {6, 6, 6}; auto data = std::make_shared>(entry_6); - DOCTEST_REQUIRE(r0.replicate(kv::BatchVector{{6, data, true, hooks}}, 1)); + DOCTEST_REQUIRE( + r0.replicate(ccf::kv::BatchVector{{6, data, true, hooks}}, 1)); DOCTEST_REQUIRE(r0.ledger->ledger.size() == 6); } const auto last_correct_version = r0.ledger->ledger.size(); @@ -691,7 +699,8 @@ DOCTEST_TEST_CASE("Recv append entries logic" * doctest::test_suite("multiple")) { std::vector entry_7 = {7, 7, 7}; auto data = std::make_shared>(entry_7); - DOCTEST_REQUIRE(r0.replicate(kv::BatchVector{{7, data, true, hooks}}, 1)); + DOCTEST_REQUIRE( + r0.replicate(ccf::kv::BatchVector{{7, data, true, hooks}}, 1)); DOCTEST_REQUIRE(r0.ledger->ledger.size() == 7); dead_branch = r0.ledger->ledger.back(); } @@ -712,7 +721,8 @@ DOCTEST_TEST_CASE("Recv append entries logic" * doctest::test_suite("multiple")) { std::vector entry_7b = {7, 7, 'b'}; auto data = std::make_shared>(entry_7b); - DOCTEST_REQUIRE(r0.replicate(kv::BatchVector{{7, data, true, hooks}}, 4)); + DOCTEST_REQUIRE( + r0.replicate(ccf::kv::BatchVector{{7, data, true, hooks}}, 4)); DOCTEST_REQUIRE(r0.ledger->ledger.size() == 7); live_branch = r0.ledger->ledger.back(); } @@ -720,7 +730,8 @@ DOCTEST_TEST_CASE("Recv append entries logic" * doctest::test_suite("multiple")) { std::vector entry_8 = {8, 8, 8}; auto data = std::make_shared>(entry_8); - DOCTEST_REQUIRE(r0.replicate(kv::BatchVector{{8, data, true, hooks}}, 4)); + DOCTEST_REQUIRE( + r0.replicate(ccf::kv::BatchVector{{8, data, true, hooks}}, 4)); DOCTEST_REQUIRE(r0.ledger->ledger.size() == 8); DOCTEST_REQUIRE(r0.ledger->ledger.size() > last_correct_version); } @@ -771,9 +782,9 @@ DOCTEST_TEST_CASE("Exceed append entries limit") { ccf::logger::config::level() = LoggerLevel::INFO; - ccf::NodeId node_id0 = kv::test::PrimaryNodeId; - ccf::NodeId node_id1 = kv::test::FirstBackupNodeId; - ccf::NodeId node_id2 = kv::test::SecondBackupNodeId; + ccf::NodeId node_id0 = ccf::kv::test::PrimaryNodeId; + ccf::NodeId node_id1 = ccf::kv::test::FirstBackupNodeId; + ccf::NodeId node_id2 = ccf::kv::test::SecondBackupNodeId; auto kv_store0 = std::make_shared(node_id0); auto kv_store1 = std::make_shared(node_id1); @@ -847,8 +858,9 @@ DOCTEST_TEST_CASE("Exceed append entries limit") for (size_t i = 1; i <= num_big_entries; ++i) { - auto hooks = std::make_shared(); - DOCTEST_REQUIRE(r0.replicate(kv::BatchVector{{i, data, true, hooks}}, 1)); + auto hooks = std::make_shared(); + DOCTEST_REQUIRE( + r0.replicate(ccf::kv::BatchVector{{i, data, true, hooks}}, 1)); const auto received_ae = dispatch_all_and_DOCTEST_CHECK( nodes, node_id0, r0c->messages, [&i](const auto& msg) { @@ -864,9 +876,9 @@ DOCTEST_TEST_CASE("Exceed append entries limit") for (size_t i = num_big_entries + 1; i <= individual_entries; ++i) { - auto hooks = std::make_shared(); + auto hooks = std::make_shared(); DOCTEST_REQUIRE( - r0.replicate(kv::BatchVector{{i, smaller_data, true, hooks}}, 1)); + r0.replicate(ccf::kv::BatchVector{{i, smaller_data, true, hooks}}, 1)); dispatch_all(nodes, node_id0, r0c->messages); } @@ -925,8 +937,8 @@ DOCTEST_TEST_CASE( "Nodes only run for election when they should" * doctest::test_suite("multiple")) { - ccf::NodeId node_id0 = kv::test::PrimaryNodeId; - ccf::NodeId node_id1 = kv::test::FirstBackupNodeId; + ccf::NodeId node_id0 = ccf::kv::test::PrimaryNodeId; + ccf::NodeId node_id1 = ccf::kv::test::FirstBackupNodeId; auto kv_store0 = std::make_shared(node_id0); auto kv_store1 = std::make_shared(node_id1); diff --git a/src/consensus/aft/test/test_common.h b/src/consensus/aft/test/test_common.h index dcf5011ecdce..cbbe6810766e 100644 --- a/src/consensus/aft/test/test_common.h +++ b/src/consensus/aft/test/test_common.h @@ -24,7 +24,7 @@ static const std::chrono::milliseconds election_timeout = election_timeout_; static const ccf::consensus::Configuration raft_settings{ request_timeout_, election_timeout_, max_uncommitted_tx_count_}; -static auto hooks = std::make_shared(); +static auto hooks = std::make_shared(); static aft::ChannelStubProxy* channel_stub_proxy(const TRaft& r) { diff --git a/src/consensus/aft/test/view_history.cpp b/src/consensus/aft/test/view_history.cpp index 493a0db13159..63a65554c875 100644 --- a/src/consensus/aft/test/view_history.cpp +++ b/src/consensus/aft/test/view_history.cpp @@ -19,8 +19,8 @@ TEST_CASE("Advancing view history" * doctest::test_suite("viewhistory")) CHECK(history.view_at(3) == ViewHistory::InvalidView); CHECK(history.view_at(4) == ViewHistory::InvalidView); - CHECK(history.start_of_view(1) == kv::NoVersion); - CHECK(history.end_of_view(1) == kv::NoVersion); + CHECK(history.start_of_view(1) == ccf::kv::NoVersion); + CHECK(history.end_of_view(1) == ccf::kv::NoVersion); } { @@ -64,9 +64,9 @@ TEST_CASE("Advancing view history" * doctest::test_suite("viewhistory")) CHECK(history.start_of_view(2) == 3); CHECK(history.end_of_view(2) == 3); CHECK(history.start_of_view(3) == 4); - CHECK(history.end_of_view(3) == kv::NoVersion); - CHECK(history.start_of_view(4) == kv::NoVersion); - CHECK(history.end_of_view(4) == kv::NoVersion); + CHECK(history.end_of_view(3) == ccf::kv::NoVersion); + CHECK(history.start_of_view(4) == ccf::kv::NoVersion); + CHECK(history.end_of_view(4) == ccf::kv::NoVersion); } } @@ -143,14 +143,14 @@ TEST_CASE("Edge case view histories" * doctest::test_suite("viewhistory")) CHECK(history.view_at(4) == 4); CHECK(history.start_of_view(4) == 2); - CHECK(history.end_of_view(4) == kv::NoVersion); - - CHECK(history.start_of_view(1) == kv::NoVersion); - CHECK(history.end_of_view(1) == kv::NoVersion); - CHECK(history.start_of_view(2) == kv::NoVersion); - CHECK(history.end_of_view(2) == kv::NoVersion); - CHECK(history.start_of_view(3) == kv::NoVersion); - CHECK(history.end_of_view(3) == kv::NoVersion); + CHECK(history.end_of_view(4) == ccf::kv::NoVersion); + + CHECK(history.start_of_view(1) == ccf::kv::NoVersion); + CHECK(history.end_of_view(1) == ccf::kv::NoVersion); + CHECK(history.start_of_view(2) == ccf::kv::NoVersion); + CHECK(history.end_of_view(2) == ccf::kv::NoVersion); + CHECK(history.start_of_view(3) == ccf::kv::NoVersion); + CHECK(history.end_of_view(3) == ccf::kv::NoVersion); } } @@ -168,12 +168,12 @@ TEST_CASE("Initialised view histories" * doctest::test_suite("viewhistory")) CHECK(history.start_of_view(1) == 2); CHECK(history.end_of_view(1) == 3); - CHECK(history.start_of_view(2) == kv::NoVersion); - CHECK(history.end_of_view(2) == kv::NoVersion); + CHECK(history.start_of_view(2) == ccf::kv::NoVersion); + CHECK(history.end_of_view(2) == ccf::kv::NoVersion); CHECK(history.start_of_view(3) == 4); CHECK(history.end_of_view(3) == 9); CHECK(history.start_of_view(4) == 10); - CHECK(history.end_of_view(4) == kv::NoVersion); + CHECK(history.end_of_view(4) == ccf::kv::NoVersion); CHECK_THROWS(history.initialise({2, 1})); CHECK_THROWS(history.initialise({1, 2, 1})); @@ -203,8 +203,8 @@ TEST_CASE("Initialised view histories" * doctest::test_suite("viewhistory")) CHECK(history.view_at(19) == 6); CHECK(history.view_at(20) == 6); - CHECK(history.start_of_view(1) == kv::NoVersion); - CHECK(history.end_of_view(1) == kv::NoVersion); + CHECK(history.start_of_view(1) == ccf::kv::NoVersion); + CHECK(history.end_of_view(1) == ccf::kv::NoVersion); CHECK(history.start_of_view(3) == 3); CHECK(history.end_of_view(3) == 4); CHECK(history.start_of_view(4) == 5); @@ -212,7 +212,7 @@ TEST_CASE("Initialised view histories" * doctest::test_suite("viewhistory")) CHECK(history.start_of_view(5) == 6); CHECK(history.end_of_view(5) == 11); CHECK(history.start_of_view(6) == 12); - CHECK(history.end_of_view(6) == kv::NoVersion); + CHECK(history.end_of_view(6) == ccf::kv::NoVersion); } } @@ -234,23 +234,28 @@ TEST_CASE( { INFO("Test that view history is correct"); - REQUIRE(history.get_history_until(kv::NoVersion).size() == 0); - REQUIRE(history.get_history_until(1) == std::vector({1})); - REQUIRE(history.get_history_until(2) == std::vector({1, 2})); - REQUIRE(history.get_history_until(3) == std::vector({1, 2})); - REQUIRE(history.get_history_until(4) == std::vector({1, 2})); + REQUIRE(history.get_history_until(ccf::kv::NoVersion).size() == 0); + REQUIRE(history.get_history_until(1) == std::vector({1})); REQUIRE( - history.get_history_until(5) == std::vector({1, 2, 5, 5})); + history.get_history_until(2) == std::vector({1, 2})); REQUIRE( - history.get_history_until(9) == std::vector({1, 2, 5, 5})); + history.get_history_until(3) == std::vector({1, 2})); + REQUIRE( + history.get_history_until(4) == std::vector({1, 2})); + REQUIRE( + history.get_history_until(5) == + std::vector({1, 2, 5, 5})); + REQUIRE( + history.get_history_until(9) == + std::vector({1, 2, 5, 5})); REQUIRE( history.get_history_until(10) == - std::vector({1, 2, 5, 5, 10})); + std::vector({1, 2, 5, 5, 10})); REQUIRE( history.get_history_until(11) == - std::vector({1, 2, 5, 5, 10})); + std::vector({1, 2, 5, 5, 10})); REQUIRE( history.get_history_until() == - std::vector({1, 2, 5, 5, 10})); + std::vector({1, 2, 5, 5, 10})); } } diff --git a/src/consensus/ledger_enclave.h b/src/consensus/ledger_enclave.h index 55fca34c16cf..d90c7d1c534e 100644 --- a/src/consensus/ledger_enclave.h +++ b/src/consensus/ledger_enclave.h @@ -25,8 +25,9 @@ namespace consensus */ static std::vector get_entry(const uint8_t*& data, size_t& size) { - auto header = serialized::peek(data, size); - size_t entry_size = kv::serialised_entry_header_size + header.size; + auto header = + serialized::peek(data, size); + size_t entry_size = ccf::kv::serialised_entry_header_size + header.size; std::vector entry(data, data + entry_size); serialized::skip(data, size, entry_size); return entry; @@ -51,8 +52,8 @@ namespace consensus void put_entry( const std::vector& entry, bool globally_committable, - kv::Term term, - kv::Version index) + ccf::kv::Term term, + ccf::kv::Version index) { put_entry(entry.data(), entry.size(), globally_committable, term, index); } @@ -72,8 +73,8 @@ namespace consensus const uint8_t* data, size_t size, bool globally_committable, - kv::Term term, - kv::Version index) + ccf::kv::Term term, + ccf::kv::Version index) { serializer::ByteRange byte_range = {data, size}; RINGBUFFER_WRITE_MESSAGE( @@ -90,7 +91,8 @@ namespace consensus */ static void skip_entry(const uint8_t*& data, size_t& size) { - auto header = serialized::read(data, size); + auto header = + serialized::read(data, size); serialized::skip(data, size, header.size); } diff --git a/src/ds/test/map_test.cpp b/src/ds/test/map_test.cpp index c6cb70bede4d..ad14e3553ec8 100644 --- a/src/ds/test/map_test.cpp +++ b/src/ds/test/map_test.cpp @@ -22,8 +22,8 @@ struct CollisionHash } }; -using K = kv::serialisers::SerialisedEntry; -using V = kv::serialisers::SerialisedEntry; +using K = ccf::kv::serialisers::SerialisedEntry; +using V = ccf::kv::serialisers::SerialisedEntry; constexpr static size_t max_key_value_size = 128; namespace map diff --git a/src/enclave/rpc_handler.h b/src/enclave/rpc_handler.h index e6b9411bfca7..f4dd857798ff 100644 --- a/src/enclave/rpc_handler.h +++ b/src/enclave/rpc_handler.h @@ -11,7 +11,7 @@ #include #include -namespace kv +namespace ccf::kv { class CommittableTx; } diff --git a/src/endpoints/authentication/all_of_auth.cpp b/src/endpoints/authentication/all_of_auth.cpp index d300627fcefb..ab1180cdce91 100644 --- a/src/endpoints/authentication/all_of_auth.cpp +++ b/src/endpoints/authentication/all_of_auth.cpp @@ -66,7 +66,7 @@ namespace ccf } std::unique_ptr AllOfAuthnPolicy::authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) { diff --git a/src/endpoints/authentication/cert_auth.cpp b/src/endpoints/authentication/cert_auth.cpp index 552c61c76283..af23aaa89ea6 100644 --- a/src/endpoints/authentication/cert_auth.cpp +++ b/src/endpoints/authentication/cert_auth.cpp @@ -104,7 +104,7 @@ namespace ccf UserCertAuthnPolicy::~UserCertAuthnPolicy() = default; std::unique_ptr UserCertAuthnPolicy::authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) { @@ -141,7 +141,7 @@ namespace ccf MemberCertAuthnPolicy::~MemberCertAuthnPolicy() = default; std::unique_ptr MemberCertAuthnPolicy::authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) { @@ -167,7 +167,7 @@ namespace ccf } std::unique_ptr NodeCertAuthnPolicy::authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) { diff --git a/src/endpoints/authentication/cose_auth.cpp b/src/endpoints/authentication/cose_auth.cpp index 8032110c4e38..65c9c2d3d6f3 100644 --- a/src/endpoints/authentication/cose_auth.cpp +++ b/src/endpoints/authentication/cose_auth.cpp @@ -300,7 +300,7 @@ namespace ccf MemberCOSESign1AuthnPolicy::~MemberCOSESign1AuthnPolicy() = default; std::unique_ptr MemberCOSESign1AuthnPolicy::authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) { @@ -406,7 +406,7 @@ namespace ccf "Signer must be a member identity registered with this service."}}); std::unique_ptr ActiveMemberCOSESign1AuthnPolicy::authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) { @@ -441,7 +441,7 @@ namespace ccf std::unique_ptr UserCOSESign1AuthnPolicy:: _authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) { @@ -502,7 +502,7 @@ namespace ccf } std::unique_ptr UserCOSESign1AuthnPolicy::authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) { @@ -533,7 +533,7 @@ namespace ccf "Signer must be a user identity registered with this service."}}); std::unique_ptr TypedUserCOSESign1AuthnPolicy::authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) { diff --git a/src/endpoints/authentication/empty_auth.cpp b/src/endpoints/authentication/empty_auth.cpp index 6b5246e3b41b..f94d57d9f6fd 100644 --- a/src/endpoints/authentication/empty_auth.cpp +++ b/src/endpoints/authentication/empty_auth.cpp @@ -6,7 +6,7 @@ namespace ccf { std::unique_ptr EmptyAuthnPolicy::authenticate( - kv::ReadOnlyTx&, const std::shared_ptr&, std::string&) + ccf::kv::ReadOnlyTx&, const std::shared_ptr&, std::string&) { return std::make_unique(); } diff --git a/src/endpoints/authentication/jwt_auth.cpp b/src/endpoints/authentication/jwt_auth.cpp index 34c8d8686c43..466adba15eb9 100644 --- a/src/endpoints/authentication/jwt_auth.cpp +++ b/src/endpoints/authentication/jwt_auth.cpp @@ -115,7 +115,7 @@ namespace ccf JwtAuthnPolicy::~JwtAuthnPolicy() = default; std::unique_ptr JwtAuthnPolicy::authenticate( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::shared_ptr& ctx, std::string& error_reason) { diff --git a/src/endpoints/base_endpoint_registry.cpp b/src/endpoints/base_endpoint_registry.cpp index 2f7e66fae74e..8fad34065603 100644 --- a/src/endpoints/base_endpoint_registry.cpp +++ b/src/endpoints/base_endpoint_registry.cpp @@ -115,7 +115,7 @@ namespace ccf } ApiResult BaseEndpointRegistry::generate_openapi_document_v1( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const std::string& title, const std::string& description, const std::string& document_version, @@ -136,7 +136,7 @@ namespace ccf } ApiResult BaseEndpointRegistry::get_quote_for_this_node_v1( - kv::ReadOnlyTx& tx, QuoteInfo& quote_info) + ccf::kv::ReadOnlyTx& tx, QuoteInfo& quote_info) { try { @@ -175,7 +175,7 @@ namespace ccf } ApiResult BaseEndpointRegistry::get_quotes_for_all_trusted_nodes_v1( - kv::ReadOnlyTx& tx, std::map& quotes) + ccf::kv::ReadOnlyTx& tx, std::map& quotes) { try { @@ -230,7 +230,7 @@ namespace ccf } ApiResult BaseEndpointRegistry::get_user_data_v1( - kv::ReadOnlyTx& tx, const UserId& user_id, nlohmann::json& user_data) + ccf::kv::ReadOnlyTx& tx, const UserId& user_id, nlohmann::json& user_data) { try { @@ -252,7 +252,9 @@ namespace ccf } ApiResult BaseEndpointRegistry::get_member_data_v1( - kv::ReadOnlyTx& tx, const MemberId& member_id, nlohmann::json& member_data) + ccf::kv::ReadOnlyTx& tx, + const MemberId& member_id, + nlohmann::json& member_data) { try { @@ -274,7 +276,9 @@ namespace ccf } ApiResult BaseEndpointRegistry::get_user_cert_v1( - kv::ReadOnlyTx& tx, const UserId& user_id, ccf::crypto::Pem& user_cert_pem) + ccf::kv::ReadOnlyTx& tx, + const UserId& user_id, + ccf::crypto::Pem& user_cert_pem) { try { @@ -296,7 +300,7 @@ namespace ccf } ApiResult BaseEndpointRegistry::get_member_cert_v1( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const MemberId& member_id, ccf::crypto::Pem& member_cert_pem) { diff --git a/src/endpoints/endpoint_registry.cpp b/src/endpoints/endpoint_registry.cpp index 8e30dda2bfeb..32f0da7e776d 100644 --- a/src/endpoints/endpoint_registry.cpp +++ b/src/endpoints/endpoint_registry.cpp @@ -304,7 +304,8 @@ namespace ccf::endpoints default_endpoint = std::move(tmp); } - void EndpointRegistry::build_api(nlohmann::json& document, kv::ReadOnlyTx&) + void EndpointRegistry::build_api( + nlohmann::json& document, ccf::kv::ReadOnlyTx&) { // Add common components: // - Descriptions of each kind of forwarding @@ -389,7 +390,7 @@ namespace ccf::endpoints void EndpointRegistry::init_handlers() {} EndpointDefinitionPtr EndpointRegistry::find_endpoint( - kv::Tx&, ccf::RpcContext& rpc_ctx) + ccf::kv::Tx&, ccf::RpcContext& rpc_ctx) { auto method = rpc_ctx.get_method(); auto endpoints_for_exact_method = fully_qualified_endpoints.find(method); @@ -497,7 +498,7 @@ namespace ccf::endpoints } std::set EndpointRegistry::get_allowed_verbs( - kv::Tx& tx, const ccf::RpcContext& rpc_ctx) + ccf::kv::Tx& tx, const ccf::RpcContext& rpc_ctx) { auto method = rpc_ctx.get_method(); @@ -555,12 +556,12 @@ namespace ccf::endpoints // Default implementation does nothing void EndpointRegistry::tick(std::chrono::milliseconds) {} - void EndpointRegistry::set_consensus(kv::Consensus* c) + void EndpointRegistry::set_consensus(ccf::kv::Consensus* c) { consensus = c; } - void EndpointRegistry::set_history(kv::TxHistory* h) + void EndpointRegistry::set_history(ccf::kv::TxHistory* h) { history = h; } diff --git a/src/endpoints/grpc/grpc.h b/src/endpoints/grpc/grpc.h index 00bf26274484..5cf134e3a18b 100644 --- a/src/endpoints/grpc/grpc.h +++ b/src/endpoints/grpc/grpc.h @@ -187,8 +187,8 @@ namespace ccf }; } - // Note: For now, only command endpoints (i.e. with no kv::Tx) support gRPC - // server streaming. + // Note: For now, only command endpoints (i.e. with no ccf::kv::Tx) support + // gRPC server streaming. template endpoints::CommandEndpointFunction grpc_command_unary_stream_adapter( const GrpcCommandUnaryStreamEndpoint& f) diff --git a/src/host/ledger.h b/src/host/ledger.h index 40df74a39f8c..37ecd504f3e8 100644 --- a/src/host/ledger.h +++ b/src/host/ledger.h @@ -288,12 +288,13 @@ namespace asynchost total_len = sizeof(positions_offset_header_t); auto len = total_file_size - total_len; - kv::SerialisedEntryHeader entry_header = {}; + ccf::kv::SerialisedEntryHeader entry_header = {}; size_t current_idx = start_idx; - while (len >= kv::serialised_entry_header_size) + while (len >= ccf::kv::serialised_entry_header_size) { if ( - fread(&entry_header, kv::serialised_entry_header_size, 1, file) != + fread( + &entry_header, ccf::kv::serialised_entry_header_size, 1, file) != 1) { LOG_FAIL_FMT( @@ -303,7 +304,7 @@ namespace asynchost return; } - len -= kv::serialised_entry_header_size; + len -= ccf::kv::serialised_entry_header_size; const auto& entry_size = entry_header.size; if (len < entry_size) @@ -330,7 +331,7 @@ namespace asynchost current_idx++; positions.push_back(total_len); - total_len += (kv::serialised_entry_header_size + entry_size); + total_len += (ccf::kv::serialised_entry_header_size + entry_size); } completed = false; } @@ -1297,9 +1298,10 @@ namespace asynchost TimeBoundLogger log_if_slow(fmt::format( "Writing ledger entry - {} bytes, committable={}", size, committable)); - auto header = serialized::peek(data, size); + auto header = + serialized::peek(data, size); - if (header.flags & kv::EntryFlags::FORCE_LEDGER_CHUNK_BEFORE) + if (header.flags & ccf::kv::EntryFlags::FORCE_LEDGER_CHUNK_BEFORE) { LOG_TRACE_FMT( "Forcing ledger chunk before entry as required by the entry header " @@ -1314,7 +1316,7 @@ namespace asynchost } bool force_chunk_after = - header.flags & kv::EntryFlags::FORCE_LEDGER_CHUNK_AFTER; + header.flags & ccf::kv::EntryFlags::FORCE_LEDGER_CHUNK_AFTER; if (force_chunk_after) { if (!committable) diff --git a/src/host/test/ledger.cpp b/src/host/test/ledger.cpp index 1da62c2801b6..f0320a0654c5 100644 --- a/src/host/test/ledger.cpp +++ b/src/host/test/ledger.cpp @@ -149,12 +149,12 @@ void verify_framed_entries_range( const uint8_t* data = &framed_entries[pos]; size_t size = framed_entries.size() - pos; - auto header = serialized::read(data, size); + auto header = serialized::read(data, size); auto header_size = header.size; REQUIRE(header_size == sizeof(TestLedgerEntry)); REQUIRE(TestLedgerEntry(data, size).value() == idx); - pos += kv::serialised_entry_header_size + sizeof(TestLedgerEntry); + pos += ccf::kv::serialised_entry_header_size + sizeof(TestLedgerEntry); idx++; } @@ -169,7 +169,7 @@ void read_entry_from_ledger(Ledger& ledger, size_t idx) auto& entry = framed_entry->data; const uint8_t* data = entry.data(); auto size = entry.size(); - auto header = serialized::read(data, size); + auto header = serialized::read(data, size); auto header_size = header.size; REQUIRE(header_size == sizeof(TestLedgerEntry)); @@ -212,11 +212,11 @@ std::vector make_ledger_entry(size_t idx, uint8_t header_flags = 0) { auto e = TestLedgerEntry(idx); std::vector framed_entry( - kv::serialised_entry_header_size + sizeof(TestLedgerEntry)); + ccf::kv::serialised_entry_header_size + sizeof(TestLedgerEntry)); auto data = framed_entry.data(); auto size = framed_entry.size(); - kv::SerialisedEntryHeader header; + ccf::kv::SerialisedEntryHeader header; header.set_size(sizeof(TestLedgerEntry)); header.flags = header_flags; @@ -283,7 +283,7 @@ size_t get_entries_per_chunk(size_t chunk_threshold) // size of each entry return ceil( (static_cast(chunk_threshold - sizeof(size_t))) / - (kv::serialised_entry_header_size + sizeof(TestLedgerEntry))); + (ccf::kv::serialised_entry_header_size + sizeof(TestLedgerEntry))); } // Assumes that no entries have been written yet @@ -385,7 +385,7 @@ TEST_CASE("Regular chunking") // Write a new committable entry that forces a new ledger chunk is_committable = true; - entry_submitter.write(is_committable, kv::FORCE_LEDGER_CHUNK_AFTER); + entry_submitter.write(is_committable, ccf::kv::FORCE_LEDGER_CHUNK_AFTER); REQUIRE(number_of_files_in_ledger_dir() == number_of_files_after); // Because of forcing a new chunk, the next entry will create a new chunk @@ -396,7 +396,7 @@ TEST_CASE("Regular chunking") REQUIRE(number_of_files_in_ledger_dir() == number_of_files_after + 1); is_committable = true; - entry_submitter.write(is_committable, kv::FORCE_LEDGER_CHUNK_BEFORE); + entry_submitter.write(is_committable, ccf::kv::FORCE_LEDGER_CHUNK_BEFORE); // A new chunk is created before, as the entry is committable and forced REQUIRE(number_of_files_in_ledger_dir() == number_of_files_after + 2); } @@ -1078,7 +1078,7 @@ void corrupt_ledger_file( else if (corrupt_first_hdr) { REQUIRE(fread(&table_offset, sizeof(table_offset), 1, file) == 1); - kv::SerialisedEntryHeader entry_header = {.size = 0xffffffff}; + ccf::kv::SerialisedEntryHeader entry_header = {.size = 0xffffffff}; fwrite(&entry_header, sizeof(entry_header), 1, file); } else if (corrupt_last_entry) @@ -1087,7 +1087,7 @@ void corrupt_ledger_file( std::vector last_entry = {}; while (true) { - kv::SerialisedEntryHeader entry_header = {}; + ccf::kv::SerialisedEntryHeader entry_header = {}; if (fread(&entry_header, sizeof(entry_header), 1, file) != 1) { break; @@ -1396,7 +1396,7 @@ TEST_CASE("Chunking according to entry header flag") INFO("Write an entry with the ledger chunking after header flag enabled"); { entry_submitter.write( - is_committable, kv::EntryFlags::FORCE_LEDGER_CHUNK_AFTER); + is_committable, ccf::kv::EntryFlags::FORCE_LEDGER_CHUNK_AFTER); REQUIRE(number_of_files_in_ledger_dir() == 1); @@ -1419,7 +1419,7 @@ TEST_CASE("Chunking according to entry header flag") { auto ledger_files_count = number_of_files_in_ledger_dir(); entry_submitter.write( - is_committable, kv::EntryFlags::FORCE_LEDGER_CHUNK_BEFORE); + is_committable, ccf::kv::EntryFlags::FORCE_LEDGER_CHUNK_BEFORE); // Forcing a new chunk before creating a new chunk to store this entry REQUIRE(number_of_files_in_ledger_dir() == ledger_files_count + 1); diff --git a/src/indexing/historical_transaction_fetcher.h b/src/indexing/historical_transaction_fetcher.h index 024f8f43a9f1..cf357d824c38 100644 --- a/src/indexing/historical_transaction_fetcher.h +++ b/src/indexing/historical_transaction_fetcher.h @@ -19,15 +19,15 @@ namespace ccf::indexing historical_cache(sc) {} - kv::ReadOnlyStorePtr deserialise_transaction( + ccf::kv::ReadOnlyStorePtr deserialise_transaction( ccf::SeqNo seqno, const uint8_t* data, size_t size) override { - kv::ApplyResult result; + ccf::kv::ApplyResult result; ccf::ClaimsDigest claims_digest; bool has_commit_evidence; auto store = historical_cache->deserialise_ledger_entry( seqno, data, size, result, claims_digest, has_commit_evidence); - if (store != nullptr && result != kv::ApplyResult::FAIL) + if (store != nullptr && result != ccf::kv::ApplyResult::FAIL) { return store; } @@ -39,7 +39,7 @@ namespace ccf::indexing return nullptr; } - std::vector fetch_transactions( + std::vector fetch_transactions( const SeqNoCollection& seqnos) override { const ccf::historical::CompoundHandle handle{ diff --git a/src/indexing/strategies/seqnos_by_key_bucketed.cpp b/src/indexing/strategies/seqnos_by_key_bucketed.cpp index 020ca9a31eef..474197645060 100644 --- a/src/indexing/strategies/seqnos_by_key_bucketed.cpp +++ b/src/indexing/strategies/seqnos_by_key_bucketed.cpp @@ -436,7 +436,9 @@ namespace ccf::indexing::strategies size_t max_buckets_) : VisitEachEntryInMap(map_name_, "SeqnosByKey") { - if (kv::get_security_domain(map_name_) != kv::SecurityDomain::PUBLIC) + if ( + ccf::kv::get_security_domain(map_name_) != + ccf::kv::SecurityDomain::PUBLIC) { throw std::logic_error(fmt::format( "This Strategy ({}) is currently only implemented for public tables, " diff --git a/src/indexing/strategies/visit_each_entry_in_map.cpp b/src/indexing/strategies/visit_each_entry_in_map.cpp index b8ea9bc08e9a..7c947b6eb74d 100644 --- a/src/indexing/strategies/visit_each_entry_in_map.cpp +++ b/src/indexing/strategies/visit_each_entry_in_map.cpp @@ -14,12 +14,12 @@ namespace ccf::indexing::strategies {} void VisitEachEntryInMap::handle_committed_transaction( - const ccf::TxID& tx_id, const kv::ReadOnlyStorePtr& store) + const ccf::TxID& tx_id, const ccf::kv::ReadOnlyStorePtr& store) { // NB: Get an untyped view over the map with the same name. This saves // deserialisation here, where we hand on the raw key and value. auto tx = store->create_read_only_tx(); - auto handle = tx.ro(map_name); + auto handle = tx.ro(map_name); handle->foreach([this, &tx_id](const auto& k, const auto& v) { visit_entry(tx_id, k, v); diff --git a/src/indexing/test/common.h b/src/indexing/test/common.h index 37a24f5e7275..37dd75f3f88e 100644 --- a/src/indexing/test/common.h +++ b/src/indexing/test/common.h @@ -8,16 +8,16 @@ // Needed by TestTransactionFetcher #include "kv/test/null_encryptor.h" -using MapA = kv::Map; +using MapA = ccf::kv::Map; static MapA map_a("public:map_a"); -using MapB = kv::Map; +using MapB = ccf::kv::Map; static MapB map_b("public:map_b"); -using ValueA = kv::Value; +using ValueA = ccf::kv::Value; static ValueA value_a("public:value_a"); -using SetA = kv::Set; +using SetA = ccf::kv::Set; static SetA set_a("public:set_a"); static const std::chrono::milliseconds step_time(10); @@ -25,16 +25,16 @@ static const std::chrono::milliseconds step_time(10); class TestTransactionFetcher : public ccf::indexing::TransactionFetcher { public: - std::shared_ptr encryptor = - std::make_shared(); + std::shared_ptr encryptor = + std::make_shared(); ccf::SeqNoCollection requested; - std::unordered_map fetched_stores; + std::unordered_map fetched_stores; - kv::ReadOnlyStorePtr deserialise_transaction( + ccf::kv::ReadOnlyStorePtr deserialise_transaction( ccf::SeqNo seqno, const uint8_t* data, size_t size) { - auto store = std::make_shared( + auto store = std::make_shared( false /* Do not start from very first seqno */, true /* Make use of historical secrets */); @@ -48,7 +48,7 @@ class TestTransactionFetcher : public ccf::indexing::TransactionFetcher } auto result = exec->apply(); - if (result == kv::ApplyResult::FAIL) + if (result == ccf::kv::ApplyResult::FAIL) { return nullptr; } @@ -56,10 +56,10 @@ class TestTransactionFetcher : public ccf::indexing::TransactionFetcher return store; } - std::vector fetch_transactions( + std::vector fetch_transactions( const ccf::SeqNoCollection& seqnos) { - std::vector stores; + std::vector stores; for (auto seqno : seqnos) { @@ -87,11 +87,11 @@ class AllCommittableWrapper : public TConsensus public: using TConsensus::TConsensus; - bool replicate(const kv::BatchVector& entries_, ccf::View view) override + bool replicate(const ccf::kv::BatchVector& entries_, ccf::View view) override { // Rather than building a history that produces real signatures, we just // overwrite the entries here to say that everything is committable - kv::BatchVector entries(entries_); + ccf::kv::BatchVector entries(entries_); for (auto& [seqno, data, committable, hooks] : entries) { committable = true; @@ -101,7 +101,8 @@ class AllCommittableWrapper : public TConsensus } }; -using AllCommittableConsensus = AllCommittableWrapper; +using AllCommittableConsensus = + AllCommittableWrapper; using ExpectedSeqNos = std::set; @@ -161,7 +162,7 @@ static inline bool check_seqnos( return true; } -using Action = std::function; +using Action = std::function; struct ActionDesc { ExpectedSeqNos& expected; @@ -169,7 +170,7 @@ struct ActionDesc }; static inline bool create_transactions( - kv::Store& kv_store, + ccf::kv::Store& kv_store, const std::vector& actions, size_t count = ccf::indexing::Indexer::MAX_REQUESTABLE * 3) { @@ -185,7 +186,7 @@ static inline bool create_transactions( } } - if (tx.commit() != kv::CommitResult::SUCCESS) + if (tx.commit() != ccf::kv::CommitResult::SUCCESS) { return false; } diff --git a/src/indexing/test/indexing.cpp b/src/indexing/test/indexing.cpp index e721aaebbfe9..382f430339c2 100644 --- a/src/indexing/test/indexing.cpp +++ b/src/indexing/test/indexing.cpp @@ -41,11 +41,11 @@ static std::vector create_actions( ExpectedSeqNos& seqnos_2) { std::vector actions; - actions.push_back({seqnos_hello, [](size_t i, kv::Tx& tx) { + actions.push_back({seqnos_hello, [](size_t i, ccf::kv::Tx& tx) { tx.wo(map_a)->put("hello", "value doesn't matter"); return true; }}); - actions.push_back({seqnos_saluton, [](size_t i, kv::Tx& tx) { + actions.push_back({seqnos_saluton, [](size_t i, ccf::kv::Tx& tx) { if (i % 2 == 0) { tx.wo(map_a)->put("saluton", "value doesn't matter"); @@ -53,7 +53,7 @@ static std::vector create_actions( } return false; }}); - actions.push_back({seqnos_1, [](size_t i, kv::Tx& tx) { + actions.push_back({seqnos_1, [](size_t i, ccf::kv::Tx& tx) { if (i % 3 == 0) { tx.wo(map_b)->put(1, 42); @@ -61,7 +61,7 @@ static std::vector create_actions( } return false; }}); - actions.push_back({seqnos_2, [](size_t i, kv::Tx& tx) { + actions.push_back({seqnos_2, [](size_t i, ccf::kv::Tx& tx) { if (i % 4 == 0) { tx.wo(map_b)->put(2, 42); @@ -75,7 +75,7 @@ static std::vector create_actions( template void run_tests( const std::function& tick_until_caught_up, - kv::Store& kv_store, + ccf::kv::Store& kv_store, ccf::indexing::Indexer& indexer, ExpectedSeqNos& seqnos_hello, ExpectedSeqNos& seqnos_saluton, @@ -172,7 +172,7 @@ void run_tests( // Uses stub classes to test just indexing logic in isolation TEST_CASE("basic indexing" * doctest::test_suite("indexing")) { - kv::Store kv_store; + ccf::kv::Store kv_store; auto consensus = std::make_shared(); kv_store.set_consensus(consensus); @@ -180,7 +180,7 @@ TEST_CASE("basic indexing" * doctest::test_suite("indexing")) auto fetcher = std::make_shared(); ccf::indexing::Indexer indexer(fetcher); - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); REQUIRE_THROWS(indexer.install_strategy(nullptr)); @@ -253,8 +253,8 @@ TEST_CASE("basic indexing" * doctest::test_suite("indexing")) index_b); } -kv::Version rekey( - kv::Store& kv_store, +ccf::kv::Version rekey( + ccf::kv::Store& kv_store, const std::shared_ptr& ledger_secrets) { ccf::ShareManager share_manager(ledger_secrets); @@ -262,7 +262,7 @@ kv::Version rekey( auto tx = kv_store.create_tx(); auto new_ledger_secret = ccf::make_ledger_secret(); share_manager.issue_recovery_shares(tx, new_ledger_secret); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); auto tx_version = tx.commit_version(); @@ -275,7 +275,7 @@ kv::Version rekey( } aft::LedgerStubProxy* add_raft_consensus( - std::shared_ptr kv_store, + std::shared_ptr kv_store, std::shared_ptr indexer) { using TRaft = aft::Aft; @@ -285,7 +285,7 @@ aft::LedgerStubProxy* add_raft_consensus( const ccf::consensus::Configuration settings{{"20ms"}, {"100ms"}}; auto consensus = std::make_shared( settings, - std::make_unique>(kv_store), + std::make_unique>(kv_store), std::make_unique(node_id), std::make_shared(), std::make_shared(node_id), @@ -309,7 +309,7 @@ TEST_CASE_TEMPLATE( IndexA, LazyIndexA) { - auto kv_store_p = std::make_shared(); + auto kv_store_p = std::make_shared(); auto& kv_store = *kv_store_p; auto ledger_secrets = std::make_shared(); @@ -350,7 +350,7 @@ TEST_CASE_TEMPLATE( member_info->put(member_id, {ccf::MemberStatus::ACTIVE}); member_public_encryption_keys->put( member_id, ccf::crypto::make_rsa_key_pair()->public_key_pem()); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } ExpectedSeqNos seqnos_hello, seqnos_saluton, seqnos_1, seqnos_2; @@ -457,7 +457,7 @@ const auto max_multithread_run_time = 100s; TEST_CASE( "multi-threaded indexing - in memory" * doctest::test_suite("indexing")) { - auto kv_store_p = std::make_shared(); + auto kv_store_p = std::make_shared(); auto& kv_store = *kv_store_p; auto ledger_secrets = std::make_shared(); @@ -501,7 +501,7 @@ TEST_CASE( member_info->put(member_id, {ccf::MemberStatus::ACTIVE}); member_public_encryption_keys->put( member_id, ccf::crypto::make_rsa_key_pair()->public_key_pem()); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } std::atomic finished = false; @@ -528,7 +528,7 @@ TEST_CASE( tx.wo(map_b)->put(42, i); } - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); ++i; std::this_thread::yield(); } @@ -661,19 +661,20 @@ TEST_CASE( class MockTransactionFetcher : public ccf::indexing::TransactionFetcher { - std::shared_ptr encryptor; + std::shared_ptr encryptor; public: aft::LedgerStubProxy* ledger; - MockTransactionFetcher(const std::shared_ptr& e) : + MockTransactionFetcher( + const std::shared_ptr& e) : encryptor(e) {} - kv::ReadOnlyStorePtr deserialise_transaction( + ccf::kv::ReadOnlyStorePtr deserialise_transaction( ccf::SeqNo seqno, const uint8_t* data, size_t size) override { - auto store = std::make_shared( + auto store = std::make_shared( false /* Do not start from very first seqno */, true /* Make use of historical secrets */); @@ -687,7 +688,7 @@ class MockTransactionFetcher : public ccf::indexing::TransactionFetcher } auto result = exec->apply(); - if (result == kv::ApplyResult::FAIL) + if (result == ccf::kv::ApplyResult::FAIL) { return nullptr; } @@ -695,10 +696,10 @@ class MockTransactionFetcher : public ccf::indexing::TransactionFetcher return store; } - std::vector fetch_transactions( + std::vector fetch_transactions( const ccf::SeqNoCollection& seqnos) override { - std::vector ret; + std::vector ret; for (const auto& seqno : seqnos) { @@ -723,7 +724,7 @@ TEST_CASE( INFO("Using seed: ", seed); srand(seed); - auto kv_store_p = std::make_shared(); + auto kv_store_p = std::make_shared(); auto& kv_store = *kv_store_p; auto ledger_secrets = std::make_shared(); @@ -790,7 +791,7 @@ TEST_CASE( member_info->put(member_id, {ccf::MemberStatus::ACTIVE}); member_public_encryption_keys->put( member_id, ccf::crypto::make_rsa_key_pair()->public_key_pem()); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } std::atomic all_submitted = false; @@ -824,7 +825,7 @@ TEST_CASE( tx.wo(map_b)->put(42, i); } - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); ++i; std::this_thread::yield(); } diff --git a/src/indexing/test/lfs.cpp b/src/indexing/test/lfs.cpp index a14c7467eda9..c3b05a1d319d 100644 --- a/src/indexing/test/lfs.cpp +++ b/src/indexing/test/lfs.cpp @@ -42,11 +42,11 @@ static std::vector create_actions( ExpectedSeqNos& seqnos_value) { std::vector actions; - actions.push_back({seqnos_hello, [](size_t i, kv::Tx& tx) { + actions.push_back({seqnos_hello, [](size_t i, ccf::kv::Tx& tx) { tx.wo(map_a)->put("hello", "value doesn't matter"); return true; }}); - actions.push_back({seqnos_saluton, [](size_t i, kv::Tx& tx) { + actions.push_back({seqnos_saluton, [](size_t i, ccf::kv::Tx& tx) { if (i % 2 == 0) { tx.wo(map_a)->put("saluton", "value doesn't matter"); @@ -54,7 +54,7 @@ static std::vector create_actions( } return false; }}); - actions.push_back({seqnos_1, [](size_t i, kv::Tx& tx) { + actions.push_back({seqnos_1, [](size_t i, ccf::kv::Tx& tx) { if (i % 3 == 0) { tx.wo(map_b)->put(1, 42); @@ -62,7 +62,7 @@ static std::vector create_actions( } return false; }}); - actions.push_back({seqnos_2, [](size_t i, kv::Tx& tx) { + actions.push_back({seqnos_2, [](size_t i, ccf::kv::Tx& tx) { if (i % 4 == 0) { tx.wo(map_b)->put(2, 42); @@ -70,7 +70,7 @@ static std::vector create_actions( } return false; }}); - actions.push_back({seqnos_set, [](size_t i, kv::Tx& tx) { + actions.push_back({seqnos_set, [](size_t i, ccf::kv::Tx& tx) { if (i % 5 == 0) { tx.wo(set_a)->insert("set key"); @@ -78,7 +78,7 @@ static std::vector create_actions( } return false; }}); - actions.push_back({seqnos_value, [](size_t i, kv::Tx& tx) { + actions.push_back({seqnos_value, [](size_t i, ccf::kv::Tx& tx) { if (i % 6 == 0) { tx.wo(value_a)->put("value doesn't matter"); @@ -181,7 +181,7 @@ TEST_CASE("Basic cache" * doctest::test_suite("lfs")) TEST_CASE("Integrated cache" * doctest::test_suite("lfs")) { - kv::Store kv_store; + ccf::kv::Store kv_store; auto consensus = std::make_shared(); kv_store.set_consensus(consensus); @@ -189,7 +189,7 @@ TEST_CASE("Integrated cache" * doctest::test_suite("lfs")) auto fetcher = std::make_shared(); ccf::indexing::Indexer indexer(fetcher); - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); messaging::BufferProcessor host_bp("lfs_host"); @@ -394,7 +394,7 @@ TEST_CASE("Integrated cache" * doctest::test_suite("lfs")) auto index_b = std::make_shared(map_b, node_context, 100, 4); REQUIRE(indexer.install_strategy(index_b)); - kv::TxID current_ = kv_store.current_txid(); + ccf::kv::TxID current_ = kv_store.current_txid(); ccf::TxID current{current_.term, current_.version}; REQUIRE(index_a->get_indexed_watermark() == current); REQUIRE(index_b->get_indexed_watermark() == ccf::TxID()); @@ -505,7 +505,7 @@ TEST_CASE("Integrated cache" * doctest::test_suite("lfs")) void run_sparse_index_test(size_t bucket_size, size_t num_buckets) { - kv::Store kv_store; + ccf::kv::Store kv_store; auto consensus = std::make_shared(); kv_store.set_consensus(consensus); @@ -513,7 +513,7 @@ void run_sparse_index_test(size_t bucket_size, size_t num_buckets) auto fetcher = std::make_shared(); ccf::indexing::Indexer indexer(fetcher); - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); messaging::BufferProcessor host_bp("lfs_host"); @@ -565,7 +565,7 @@ void run_sparse_index_test(size_t bucket_size, size_t num_buckets) { handle_b->put(k, k); } - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); const auto seqno = tx.get_txid()->version; for (const auto& k : keys) { @@ -580,7 +580,7 @@ void run_sparse_index_test(size_t bucket_size, size_t num_buckets) auto tx = kv_store.create_tx(); auto handle_a = tx.wo(map_a); handle_a->put("ignore", "ignore"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } }; diff --git a/src/indexing/transaction_fetcher_interface.h b/src/indexing/transaction_fetcher_interface.h index 6309d3be37ed..6743ab6b644f 100644 --- a/src/indexing/transaction_fetcher_interface.h +++ b/src/indexing/transaction_fetcher_interface.h @@ -12,10 +12,10 @@ namespace ccf::indexing public: virtual ~TransactionFetcher() = default; - virtual kv::ReadOnlyStorePtr deserialise_transaction( + virtual ccf::kv::ReadOnlyStorePtr deserialise_transaction( ccf::SeqNo seqno, const uint8_t* data, size_t size) = 0; - virtual std::vector fetch_transactions( + virtual std::vector fetch_transactions( const SeqNoCollection& seqnos) = 0; }; } diff --git a/src/js/extensions/ccf/historical.cpp b/src/js/extensions/ccf/historical.cpp index a6974c5b4fd5..29531960ab5d 100644 --- a/src/js/extensions/ccf/historical.cpp +++ b/src/js/extensions/ccf/historical.cpp @@ -19,8 +19,8 @@ namespace ccf::js::extensions struct HistoricalHandle { ccf::historical::StatePtr state; - std::unique_ptr tx; - std::unordered_map + std::unique_ptr tx; + std::unordered_map kv_handles = {}; }; std::unordered_map historical_handles; @@ -305,7 +305,7 @@ namespace ccf::js::extensions if (hit->second == nullptr) { - kv::ReadOnlyTx* tx = it->second.tx.get(); + ccf::kv::ReadOnlyTx* tx = it->second.tx.get(); if (tx == nullptr) { LOG_FAIL_FMT("Can't rehydrate MapHandle - no transaction"); diff --git a/src/js/extensions/ccf/kv.cpp b/src/js/extensions/ccf/kv.cpp index 85f3d63a72fb..68cb664c2e30 100644 --- a/src/js/extensions/ccf/kv.cpp +++ b/src/js/extensions/ccf/kv.cpp @@ -17,10 +17,11 @@ namespace ccf::js::extensions { struct KvExtension::Impl { - kv::Tx* tx; - std::unordered_map kv_handles = {}; + ccf::kv::Tx* tx; + std::unordered_map kv_handles = + {}; - Impl(kv::Tx* t) : tx(t){}; + Impl(ccf::kv::Tx* t) : tx(t){}; }; namespace @@ -54,7 +55,7 @@ namespace ccf::js::extensions if (it->second == nullptr) { - kv::Tx* tx = extension->impl->tx; + ccf::kv::Tx* tx = extension->impl->tx; if (tx == nullptr) { LOG_FAIL_FMT("Can't rehydrate MapHandle - no transaction context"); @@ -129,7 +130,8 @@ namespace ccf::js::extensions } } - KvExtension::KvExtension(kv::Tx* t, const ccf::js::NamespaceRestriction& nr) : + KvExtension::KvExtension( + ccf::kv::Tx* t, const ccf::js::NamespaceRestriction& nr) : namespace_restriction(nr) { impl = std::make_unique(t); diff --git a/src/js/extensions/ccf/kv_helpers.h b/src/js/extensions/ccf/kv_helpers.h index c81224e26faf..c288c1510de8 100644 --- a/src/js/extensions/ccf/kv_helpers.h +++ b/src/js/extensions/ccf/kv_helpers.h @@ -8,7 +8,7 @@ namespace ccf::js::extensions::kvhelpers { - using KVMap = ::kv::untyped::Map; + using KVMap = ::ccf::kv::untyped::Map; using ROHandleGetter = KVMap::ReadOnlyHandle* (*)(js::core::Context& jsctx, JSValueConst this_val); diff --git a/src/js/extensions/ccf/network.h b/src/js/extensions/ccf/network.h index e1cb42fbdc4b..f722c5c0044c 100644 --- a/src/js/extensions/ccf/network.h +++ b/src/js/extensions/ccf/network.h @@ -19,9 +19,9 @@ namespace ccf::js::extensions { public: ccf::NetworkState* network_state; - kv::Tx* tx; + ccf::kv::Tx* tx; - NetworkExtension(ccf::NetworkState* ns, kv::Tx* t) : + NetworkExtension(ccf::NetworkState* ns, ccf::kv::Tx* t) : network_state(ns), tx(t) {} diff --git a/src/js/extensions/ccf/node.h b/src/js/extensions/ccf/node.h index 87272f21dcda..f19ff6169ab2 100644 --- a/src/js/extensions/ccf/node.h +++ b/src/js/extensions/ccf/node.h @@ -22,9 +22,9 @@ namespace ccf::js::extensions { public: ccf::AbstractGovernanceEffects* gov_effects; - kv::Tx* tx; + ccf::kv::Tx* tx; - NodeExtension(ccf::AbstractGovernanceEffects* ge, kv::Tx* t) : + NodeExtension(ccf::AbstractGovernanceEffects* ge, ccf::kv::Tx* t) : gov_effects(ge), tx(t) {} diff --git a/src/js/permissions_checks.h b/src/js/permissions_checks.h index a9e39c4711a0..f0418262d708 100644 --- a/src/js/permissions_checks.h +++ b/src/js/permissions_checks.h @@ -17,11 +17,11 @@ namespace ccf::js // source of truth for these restrictions. This code is formatted to attempt // to make it clear how it maps directly to that table. const auto [privacy_of_table, namespace_of_table] = - kv::parse_map_name(table_name); + ccf::kv::parse_map_name(table_name); switch (privacy_of_table) { - case (kv::SecurityDomain::PRIVATE): + case (ccf::kv::SecurityDomain::PRIVATE): { // The only time private tables can be used, is on private application // tables in an application context. Governance should neither read from @@ -29,13 +29,13 @@ namespace ccf::js // tables exist then applications should not be able to read them. if ( execution_context == TxAccess::APP_RW && - namespace_of_table == kv::AccessCategory::APPLICATION) + namespace_of_table == ccf::kv::AccessCategory::APPLICATION) { return KVAccessPermissions::READ_WRITE; } else if ( execution_context == TxAccess::APP_RO && - namespace_of_table == kv::AccessCategory::APPLICATION) + namespace_of_table == ccf::kv::AccessCategory::APPLICATION) { return KVAccessPermissions::READ_ONLY; } @@ -45,16 +45,16 @@ namespace ccf::js } } - case (kv::SecurityDomain::PUBLIC): + case (ccf::kv::SecurityDomain::PUBLIC): { switch (namespace_of_table) { - case kv::AccessCategory::INTERNAL: + case ccf::kv::AccessCategory::INTERNAL: { return KVAccessPermissions::READ_ONLY; } - case kv::AccessCategory::GOVERNANCE: + case ccf::kv::AccessCategory::GOVERNANCE: { if (execution_context == TxAccess::GOV_RW) { @@ -66,7 +66,7 @@ namespace ccf::js } } - case kv::AccessCategory::APPLICATION: + case ccf::kv::AccessCategory::APPLICATION: { switch (execution_context) { @@ -87,7 +87,7 @@ namespace ccf::js } } - case (kv::SecurityDomain::SECURITY_DOMAIN_MAX): + case (ccf::kv::SecurityDomain::SECURITY_DOMAIN_MAX): { throw std::logic_error(fmt::format( "Unexpected security domain (max) for table {}", table_name)); diff --git a/src/js/registry.cpp b/src/js/registry.cpp index 7c0aca82163c..4a159f7d329b 100644 --- a/src/js/registry.cpp +++ b/src/js/registry.cpp @@ -505,7 +505,7 @@ namespace ccf::js } ccf::ApiResult DynamicJSEndpointRegistry::install_custom_endpoints_v1( - kv::Tx& tx, const ccf::js::Bundle& bundle) + ccf::kv::Tx& tx, const ccf::js::Bundle& bundle) { try { @@ -585,7 +585,7 @@ namespace ccf::js } ccf::ApiResult DynamicJSEndpointRegistry::get_custom_endpoints_v1( - ccf::js::Bundle& bundle, kv::ReadOnlyTx& tx) + ccf::js::Bundle& bundle, ccf::kv::ReadOnlyTx& tx) { try { @@ -631,7 +631,7 @@ namespace ccf::js ccf::ApiResult DynamicJSEndpointRegistry::get_custom_endpoint_properties_v1( ccf::endpoints::EndpointProperties& properties, - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const ccf::RESTVerb& verb, const ccf::endpoints::URI& uri) { @@ -659,7 +659,7 @@ namespace ccf::js } ccf::ApiResult DynamicJSEndpointRegistry::get_custom_endpoint_module_v1( - std::string& code, kv::ReadOnlyTx& tx, const std::string& module_name) + std::string& code, ccf::kv::ReadOnlyTx& tx, const std::string& module_name) { try { @@ -690,7 +690,7 @@ namespace ccf::js } ccf::ApiResult DynamicJSEndpointRegistry::set_js_runtime_options_v1( - kv::Tx& tx, const ccf::JSRuntimeOptions& options) + ccf::kv::Tx& tx, const ccf::JSRuntimeOptions& options) { try { @@ -704,7 +704,7 @@ namespace ccf::js } ccf::ApiResult DynamicJSEndpointRegistry::get_js_runtime_options_v1( - ccf::JSRuntimeOptions& options, kv::ReadOnlyTx& tx) + ccf::JSRuntimeOptions& options, ccf::kv::ReadOnlyTx& tx) { try { @@ -721,7 +721,7 @@ namespace ccf::js } ccf::endpoints::EndpointDefinitionPtr DynamicJSEndpointRegistry:: - find_endpoint(kv::Tx& tx, ccf::RpcContext& rpc_ctx) + find_endpoint(ccf::kv::Tx& tx, ccf::RpcContext& rpc_ctx) { // Look up the endpoint definition // First in the user-defined endpoints, and then fall-back to built-ins @@ -847,7 +847,7 @@ namespace ccf::js // Since we do our own dispatch (overriding find_endpoint), make sure we // describe those operations in the auto-generated OpenAPI void DynamicJSEndpointRegistry::build_api( - nlohmann::json& document, kv::ReadOnlyTx& tx) + nlohmann::json& document, ccf::kv::ReadOnlyTx& tx) { ccf::UserEndpointRegistry::build_api(document, tx); @@ -883,7 +883,7 @@ namespace ccf::js } ccf::ApiResult DynamicJSEndpointRegistry::check_action_not_replayed_v1( - kv::Tx& tx, + ccf::kv::Tx& tx, uint64_t created_at, const std::span action, ccf::InvalidArgsReason& reason) @@ -894,7 +894,7 @@ namespace ccf::js const auto action_digest = ccf::crypto::sha256(action.data(), action.size()); - using RecentActions = kv::Set; + using RecentActions = ccf::kv::Set; auto recent_actions = tx.rw(recent_actions_map); auto key = @@ -953,7 +953,7 @@ namespace ccf::js } ccf::ApiResult DynamicJSEndpointRegistry::record_action_for_audit_v1( - kv::Tx& tx, + ccf::kv::Tx& tx, ccf::ActionFormat format, const std::string& user_id, const std::string& action_name, @@ -961,8 +961,8 @@ namespace ccf::js { try { - using AuditInputValue = kv::Value>; - using AuditInfoValue = kv::Value; + using AuditInputValue = ccf::kv::Value>; + using AuditInfoValue = ccf::kv::Value; auto audit_input = tx.template rw(audit_input_map); audit_input->put(action_body); diff --git a/src/kv/apply_changes.h b/src/kv/apply_changes.h index ce6bf58be3bc..841878c8378c 100644 --- a/src/kv/apply_changes.h +++ b/src/kv/apply_changes.h @@ -9,7 +9,7 @@ #include #include -namespace kv +namespace ccf::kv { // All collections of Map must be ordered so that we lock their contained // maps in a stable order. The order here is by map name @@ -37,7 +37,7 @@ namespace kv static inline std::optional apply_changes( OrderedChanges& changes, VersionResolver version_resolver_fn, - kv::ConsensusHookPtrs& hooks, + ccf::kv::ConsensusHookPtrs& hooks, const MapCollection& new_maps, const std::optional& new_maps_conflict_version, bool track_read_versions, @@ -115,7 +115,7 @@ namespace kv // This is to avoid recursively locking version_lock by calling // current_version() in the commit_reserved case. - kv::Version current_v; + ccf::kv::Version current_v; if (new_maps_conflict_version.has_value()) { current_v = *new_maps_conflict_version; @@ -135,7 +135,7 @@ namespace kv if (ok && has_writes) { // Get the version number to be used for this commit. - kv::Version version_last_new_map; + ccf::kv::Version version_last_new_map; std::tie(version, version_last_new_map) = version_resolver_fn(!new_maps.empty()); diff --git a/src/kv/committable_tx.h b/src/kv/committable_tx.h index cd2c61b6e4b9..7f73f5902531 100644 --- a/src/kv/committable_tx.h +++ b/src/kv/committable_tx.h @@ -12,7 +12,7 @@ #include -namespace kv +namespace ccf::kv { class CommittableTx : public Tx, public AbstractChangeContainer { @@ -32,7 +32,7 @@ namespace kv Version version = NoVersion; - kv::TxHistory::RequestID req_id; + ccf::kv::TxHistory::RequestID req_id; TxFlags flags = 0; SerialisedEntryFlags entry_flags = 0; @@ -119,9 +119,10 @@ namespace kv * replication * * A transaction can either succeed and replicate - * (`kv::CommitResult::SUCCESS`), fail because of a conflict with other - * transactions (`kv::CommitResult::FAIL_CONFLICT`), or succeed locally, but - * fail to replicate (`kv::CommitResult::FAIL_NO_REPLICATE`). + * (`ccf::kv::CommitResult::SUCCESS`), fail because of a conflict with other + * transactions (`ccf::kv::CommitResult::FAIL_CONFLICT`), or succeed + * locally, but fail to replicate + * (`ccf::kv::CommitResult::FAIL_NO_REPLICATE`). * * Transactions that fail are rolled back, no matter the reason. * @@ -154,7 +155,7 @@ namespace kv this->pimpl->store->lock_map_set(); } - kv::ConsensusHookPtrs hooks; + ccf::kv::ConsensusHookPtrs hooks; std::optional new_maps_conflict_version = std::nullopt; @@ -297,7 +298,7 @@ namespace kv /** Version for the transaction set * - * @return Committed version, or `kv::NoVersion` otherwise + * @return Committed version, or `ccf::kv::NoVersion` otherwise */ Version get_version() { @@ -344,12 +345,12 @@ namespace kv pimpl->commit_view = view_; } - void set_req_id(const kv::TxHistory::RequestID& req_id_) + void set_req_id(const ccf::kv::TxHistory::RequestID& req_id_) { req_id = req_id_; } - const kv::TxHistory::RequestID& get_req_id() + const ccf::kv::TxHistory::RequestID& get_req_id() { return req_id; } diff --git a/src/kv/compacted_version_conflict.h b/src/kv/compacted_version_conflict.h index f41fcb3cae39..9c0605621819 100644 --- a/src/kv/compacted_version_conflict.h +++ b/src/kv/compacted_version_conflict.h @@ -4,7 +4,7 @@ #include -namespace kv +namespace ccf::kv { class CompactedVersionConflict { diff --git a/src/kv/deserialise.h b/src/kv/deserialise.h index 75c1fdf2bf36..f3c4e8855cd0 100644 --- a/src/kv/deserialise.h +++ b/src/kv/deserialise.h @@ -11,7 +11,7 @@ #include -namespace kv +namespace ccf::kv { class ExecutionWrapperStore { @@ -19,20 +19,20 @@ namespace kv virtual bool fill_maps( const std::vector& data, bool public_only, - kv::Version& v, - kv::Term& view, - kv::OrderedChanges& changes, - kv::MapCollection& new_maps, + ccf::kv::Version& v, + ccf::kv::Term& view, + ccf::kv::OrderedChanges& changes, + ccf::kv::MapCollection& new_maps, ccf::ClaimsDigest& claims_digest, std::optional& commit_evidence_digest, bool ignore_strict_versions = false) = 0; virtual bool commit_deserialised( - kv::OrderedChanges& changes, - kv::Version v, - kv::Term term, + ccf::kv::OrderedChanges& changes, + ccf::kv::Version v, + ccf::kv::Term term, const MapCollection& new_maps, - kv::ConsensusHookPtrs& hooks, + ccf::kv::ConsensusHookPtrs& hooks, bool track_deletes_on_missing_keys) = 0; }; @@ -43,11 +43,11 @@ namespace kv std::shared_ptr history; const std::vector data; bool public_only; - kv::Version version; + ccf::kv::Version version; Term term; OrderedChanges changes; MapCollection new_maps; - kv::ConsensusHookPtrs hooks; + ccf::kv::ConsensusHookPtrs hooks; ccf::ClaimsDigest claims_digest; std::optional commit_evidence_digest = {}; @@ -162,7 +162,7 @@ namespace kv return success; } - kv::ConsensusHookPtrs& get_hooks() override + ccf::kv::ConsensusHookPtrs& get_hooks() override { return hooks; } @@ -177,7 +177,7 @@ namespace kv return term; } - kv::Version get_index() override + ccf::kv::Version get_index() override { return version; } diff --git a/src/kv/encryptor.h b/src/kv/encryptor.h index 62521206600d..a872d8052a66 100644 --- a/src/kv/encryptor.h +++ b/src/kv/encryptor.h @@ -8,7 +8,7 @@ #include #include -namespace kv +namespace ccf::kv { template class TxEncryptor : public AbstractTxEncryptor diff --git a/src/kv/generic_serialise_wrapper.h b/src/kv/generic_serialise_wrapper.h index 8da93e80788b..1fe9722b011a 100644 --- a/src/kv/generic_serialise_wrapper.h +++ b/src/kv/generic_serialise_wrapper.h @@ -10,10 +10,10 @@ #include -namespace kv +namespace ccf::kv { - using SerialisedKey = kv::serialisers::SerialisedEntry; - using SerialisedValue = kv::serialisers::SerialisedEntry; + using SerialisedKey = ccf::kv::serialisers::SerialisedEntry; + using SerialisedValue = ccf::kv::serialisers::SerialisedEntry; template class GenericSerialiseWrapper @@ -299,7 +299,7 @@ namespace kv std::optional init( const uint8_t* data, size_t size, - kv::Term& term, + ccf::kv::Term& term, bool historical_hint = false) { current_reader = &public_reader; diff --git a/src/kv/kv_types.h b/src/kv/kv_types.h index 5b77fd9c8220..fbad8485a76a 100644 --- a/src/kv/kv_types.h +++ b/src/kv/kv_types.h @@ -36,7 +36,7 @@ namespace aft struct Request; } -namespace kv +namespace ccf::kv { // Term describes an epoch of Versions. It is incremented when global kv's // writer(s) changes. Term and Version combined give a unique identifier for @@ -401,16 +401,16 @@ namespace kv virtual Result verify_and_sign( ccf::PrimarySignature& signature, Term* term, - kv::Configuration::Nodes& nodes) = 0; + ccf::kv::Configuration::Nodes& nodes) = 0; virtual bool verify( Term* term = nullptr, ccf::PrimarySignature* sig = nullptr) = 0; virtual void try_emit_signature() = 0; virtual void emit_signature() = 0; virtual ccf::crypto::Sha256Hash get_replicated_state_root() = 0; virtual std::tuple< - kv::TxID /* TxID of last transaction seen by history */, + ccf::kv::TxID /* TxID of last transaction seen by history */, ccf::crypto::Sha256Hash /* root as of TxID */, - kv::Term /* term_of_next_version */> + ccf::kv::Term /* term_of_next_version */> get_replicated_state_txid_and_root() = 0; virtual std::vector get_proof(Version v) = 0; virtual bool verify_proof(const std::vector& proof) = 0; @@ -420,11 +420,11 @@ namespace kv virtual void append(const std::vector& data) = 0; virtual void append_entry( const ccf::crypto::Sha256Hash& digest, - std::optional expected_term = std::nullopt) = 0; + std::optional expected_term = std::nullopt) = 0; virtual void rollback( - const kv::TxID& tx_id, kv::Term term_of_next_version_) = 0; + const ccf::kv::TxID& tx_id, ccf::kv::Term term_of_next_version_) = 0; virtual void compact(Version v) = 0; - virtual void set_term(kv::Term) = 0; + virtual void set_term(ccf::kv::Term) = 0; virtual std::vector serialise_tree(size_t to) = 0; virtual void set_endorsed_certificate(const ccf::crypto::Pem& cert) = 0; virtual void start_signature_emit_timer() = 0; @@ -578,9 +578,9 @@ namespace kv public: virtual ~AbstractSnapshotter(){}; - virtual bool record_committable(kv::Version v) = 0; - virtual void commit(kv::Version v, bool generate_snapshot) = 0; - virtual void rollback(kv::Version v) = 0; + virtual bool record_committable(ccf::kv::Version v) = 0; + virtual void commit(ccf::kv::Version v, bool generate_snapshot) = 0; + virtual void rollback(ccf::kv::Version v) = 0; }; using SnapshotterPtr = std::shared_ptr; @@ -649,12 +649,12 @@ namespace kv { public: virtual ~AbstractExecutionWrapper() = default; - virtual kv::ApplyResult apply( + virtual ccf::kv::ApplyResult apply( bool track_deletes_on_missing_keys = false) = 0; - virtual kv::ConsensusHookPtrs& get_hooks() = 0; + virtual ccf::kv::ConsensusHookPtrs& get_hooks() = 0; virtual const std::vector& get_entry() = 0; - virtual kv::Term get_term() = 0; - virtual kv::Version get_index() = 0; + virtual ccf::kv::Term get_term() = 0; + virtual ccf::kv::Version get_index() = 0; virtual bool support_async_execution() = 0; virtual bool is_public_only() = 0; virtual ccf::ClaimsDigest&& consume_claims_digest() = 0; @@ -782,7 +782,7 @@ namespace kv FMT_BEGIN_NAMESPACE template <> -struct formatter +struct formatter { template constexpr auto parse(ParseContext& ctx) @@ -791,8 +791,8 @@ struct formatter } template - auto format(const kv::Configuration::Nodes& nodes, FormatContext& ctx) const - -> decltype(ctx.out()) + auto format(const ccf::kv::Configuration::Nodes& nodes, FormatContext& ctx) + const -> decltype(ctx.out()) { std::set node_ids; for (auto& [nid, _] : nodes) @@ -804,7 +804,7 @@ struct formatter }; template <> -struct formatter +struct formatter { template constexpr auto parse(ParseContext& ctx) @@ -813,7 +813,7 @@ struct formatter } template - auto format(const kv::MembershipState& state, FormatContext& ctx) const + auto format(const ccf::kv::MembershipState& state, FormatContext& ctx) const -> decltype(ctx.out()) { const auto s = nlohmann::json(state).get(); @@ -822,7 +822,7 @@ struct formatter }; template <> -struct formatter +struct formatter { template constexpr auto parse(ParseContext& ctx) @@ -831,7 +831,7 @@ struct formatter } template - auto format(const kv::LeadershipState& state, FormatContext& ctx) const + auto format(const ccf::kv::LeadershipState& state, FormatContext& ctx) const -> decltype(ctx.out()) { const auto s = nlohmann::json(state).get(); diff --git a/src/kv/raw_serialise.h b/src/kv/raw_serialise.h index 97ea576460af..e3ef83a18e98 100644 --- a/src/kv/raw_serialise.h +++ b/src/kv/raw_serialise.h @@ -9,7 +9,7 @@ #include #include -namespace kv +namespace ccf::kv { class RawWriter { @@ -82,7 +82,7 @@ namespace kv { if constexpr ( ccf::nonstd::is_std_vector::value || - std::is_same_v) + std::is_same_v) { serialise_entry(entry.size() * sizeof(typename T::value_type)); if (entry.size() > 0) @@ -184,7 +184,7 @@ namespace kv { if constexpr ( ccf::nonstd::is_std_vector::value || - std::is_same_v) + std::is_same_v) { size_t entry_offset = 0; size_t entry_size = read_size_prefixed_entry(entry_offset); @@ -207,14 +207,14 @@ namespace kv return ret; } - else if constexpr (std::is_same_v) + else if constexpr (std::is_same_v) { uint8_t entry_type = read_entry(); - if (entry_type > static_cast(kv::EntryType::MAX)) + if (entry_type > static_cast(ccf::kv::EntryType::MAX)) throw std::logic_error( fmt::format("Invalid EntryType: {}", entry_type)); - return kv::EntryType(entry_type); + return ccf::kv::EntryType(entry_type); } else if constexpr (std::is_same_v) { diff --git a/src/kv/serialised_entry_format.h b/src/kv/serialised_entry_format.h index ab5a78c0f739..0426861f9d28 100644 --- a/src/kv/serialised_entry_format.h +++ b/src/kv/serialised_entry_format.h @@ -6,7 +6,7 @@ #include -namespace kv +namespace ccf::kv { static constexpr auto entry_format_v1 = 1; using SerialisedEntryFlags = uint8_t; diff --git a/src/kv/serialiser_declare.h b/src/kv/serialiser_declare.h index 1959c5308588..73fe5758bd42 100644 --- a/src/kv/serialiser_declare.h +++ b/src/kv/serialiser_declare.h @@ -2,7 +2,7 @@ // Licensed under the Apache 2.0 License. #pragma once -namespace kv +namespace ccf::kv { // This awkward forward declaration allows the -templated serialisers to // depend on kv_types.h, and removes the reverse dependency. Once these diff --git a/src/kv/snapshot.h b/src/kv/snapshot.h index d50302fb1f7e..af306e77e387 100644 --- a/src/kv/snapshot.h +++ b/src/kv/snapshot.h @@ -4,21 +4,22 @@ #include "kv/kv_types.h" -namespace kv +namespace ccf::kv { class StoreSnapshot : public AbstractStore::AbstractSnapshot { private: Version version; - std::vector> snapshots; + std::vector> snapshots; std::optional> hash_at_snapshot = std::nullopt; std::optional> view_history = std::nullopt; public: StoreSnapshot(Version version_) : version(version_) {} - void add_map_snapshot(std::unique_ptr snapshot) + void add_map_snapshot( + std::unique_ptr snapshot) { snapshots.push_back(std::move(snapshot)); } @@ -53,7 +54,7 @@ namespace kv KvStoreSerialiser serialiser( encryptor, {0, version}, - kv::EntryType::Snapshot, + ccf::kv::EntryType::Snapshot, 0, {}, ccf::no_claims(), diff --git a/src/kv/store.h b/src/kv/store.h index 60f677f0d6ee..e1789e4ef663 100644 --- a/src/kv/store.h +++ b/src/kv/store.h @@ -18,7 +18,7 @@ #include #include -namespace kv +namespace ccf::kv { class StoreState { @@ -26,14 +26,15 @@ namespace kv // All collections of Map must be ordered so that we lock their contained // maps in a stable order. The order here is by map name. The version // indicates the version at which the Map was created. - using Maps = std:: - map>>; + using Maps = std::map< + std::string, + std::pair>>; ccf::pal::Mutex maps_lock; Maps maps; ccf::pal::Mutex version_lock; std::atomic version = 0; - Version last_new_map = kv::NoVersion; + Version last_new_map = ccf::kv::NoVersion; std::atomic compacted = 0; // Calls to Store::commit are made atomic by taking this lock. @@ -68,7 +69,7 @@ namespace kv pending_txs.clear(); version = 0; - last_new_map = kv::NoVersion; + last_new_map = ccf::kv::NoVersion; compacted = 0; term_of_next_version = 0; term_of_last_version = 0; @@ -85,8 +86,8 @@ namespace kv public ReadOnlyStore { private: - using Hooks = std::map; - using MapHooks = std::map; + using Hooks = std::map; + using MapHooks = std::map; Hooks global_hooks; MapHooks map_hooks; @@ -113,7 +114,7 @@ namespace kv Version v, Term term, const MapCollection& new_maps, - kv::ConsensusHookPtrs& hooks, + ccf::kv::ConsensusHookPtrs& hooks, bool track_deletes_on_missing_keys) override { auto c = apply_changes( @@ -232,20 +233,20 @@ namespace kv * such map exists */ std::shared_ptr get_map( - kv::Version v, const std::string& map_name) override + ccf::kv::Version v, const std::string& map_name) override { std::lock_guard mguard(maps_lock); return get_map_internal(v, map_name); } std::shared_ptr get_map_unsafe( - kv::Version v, const std::string& map_name) override + ccf::kv::Version v, const std::string& map_name) override { return get_map_internal(v, map_name); } - std::shared_ptr get_map_internal( - kv::Version v, const std::string& map_name) + std::shared_ptr get_map_internal( + ccf::kv::Version v, const std::string& map_name) { auto search = maps.find(map_name); if (search != maps.end()) @@ -271,9 +272,9 @@ namespace kv * @param map_ Map to add */ void add_dynamic_map( - kv::Version v, const std::shared_ptr& map_) override + ccf::kv::Version v, const std::shared_ptr& map_) override { - auto map = std::dynamic_pointer_cast(map_); + auto map = std::dynamic_pointer_cast(map_); if (map == nullptr) { throw std::logic_error(fmt::format( @@ -383,17 +384,17 @@ namespace kv ApplyResult deserialise_snapshot( const uint8_t* data, size_t size, - kv::ConsensusHookPtrs& hooks, + ccf::kv::ConsensusHookPtrs& hooks, std::vector* view_history = nullptr, bool public_only = false) override { auto e = get_encryptor(); auto d = KvStoreDeserialiser( e, - public_only ? kv::SecurityDomain::PUBLIC : - std::optional()); + public_only ? ccf::kv::SecurityDomain::PUBLIC : + std::optional()); - kv::Term term; + ccf::kv::Term term; auto v_ = d.init(data, size, term, is_historical); if (!v_.has_value()) { @@ -431,12 +432,12 @@ namespace kv { const auto map_name = r.value(); - std::shared_ptr map = nullptr; + std::shared_ptr map = nullptr; auto search = maps.find(map_name); if (search == maps.end()) { - map = std::make_shared( + map = std::make_shared( this, map_name, get_security_domain(map_name)); new_maps[map_name] = map; LOG_DEBUG_FMT( @@ -688,8 +689,8 @@ namespace kv bool fill_maps( const std::vector& data, bool public_only, - kv::Version& v, - kv::Term& view, + ccf::kv::Version& v, + ccf::kv::Term& view, OrderedChanges& changes, MapCollection& new_maps, ccf::ClaimsDigest& claims_digest, @@ -705,8 +706,8 @@ namespace kv auto d = KvStoreDeserialiser( e, - public_only ? kv::SecurityDomain::PUBLIC : - std::optional()); + public_only ? ccf::kv::SecurityDomain::PUBLIC : + std::optional()); auto v_ = d.init(data.data(), data.size(), view, is_historical); if (!v_.has_value()) @@ -757,7 +758,7 @@ namespace kv auto map = get_map_internal(v, map_name); if (map == nullptr) { - auto new_map = std::make_shared( + auto new_map = std::make_shared( this, map_name, get_security_domain(map_name)); map = new_map; new_maps[map_name] = new_map; @@ -795,7 +796,7 @@ namespace kv return true; } - std::unique_ptr deserialize( + std::unique_ptr deserialize( const std::vector& data, bool public_only = false, const std::optional& expected_txid = std::nullopt) override @@ -839,7 +840,7 @@ namespace kv return version; } - kv::TxID current_txid() override + ccf::kv::TxID current_txid() override { // Must lock in case the version or read term is being incremented. std::lock_guard vguard(version_lock); @@ -965,7 +966,7 @@ namespace kv auto data_shared = std::make_shared>(std::move(data_)); auto hooks_shared = - std::make_shared(std::move(hooks_)); + std::make_shared(std::move(hooks_)); // NB: this cannot happen currently. Regular Tx only make it here if // they did succeed, and signatures cannot conflict because they @@ -1147,7 +1148,7 @@ namespace kv // rollback auto new_map = std::make_pair( NoVersion, - std::make_shared( + std::make_shared( this, name, SecurityDomain::PRIVATE)); maps[name] = new_map; map = new_map.second; @@ -1181,7 +1182,7 @@ namespace kv } void set_map_hook( - const std::string& map_name, const kv::untyped::Map::MapHook& hook) + const std::string& map_name, const ccf::kv::untyped::Map::MapHook& hook) { map_hooks[map_name] = hook; @@ -1204,7 +1205,8 @@ namespace kv } void set_global_hook( - const std::string& map_name, const kv::untyped::Map::CommitHook& hook) + const std::string& map_name, + const ccf::kv::untyped::Map::CommitHook& hook) { global_hooks[map_name] = hook; @@ -1292,5 +1294,5 @@ namespace kv } }; - using StorePtr = std::shared_ptr; + using StorePtr = std::shared_ptr; } diff --git a/src/kv/test/kv_bench.cpp b/src/kv/test/kv_bench.cpp index 02094fe40178..5107156c1e45 100644 --- a/src/kv/test/kv_bench.cpp +++ b/src/kv/test/kv_bench.cpp @@ -10,9 +10,9 @@ #include #include -using KeyType = kv::serialisers::SerialisedEntry; -using ValueType = kv::serialisers::SerialisedEntry; -using MapType = kv::untyped::Map; +using KeyType = ccf::kv::serialisers::SerialisedEntry; +using ValueType = ccf::kv::serialisers::SerialisedEntry; +using MapType = ccf::kv::untyped::Map; inline void clobber_memory() { @@ -39,23 +39,24 @@ std::shared_ptr create_ledger_secrets() return secrets; } -std::string build_map_name(const std::string& core_name, kv::SecurityDomain sd) +std::string build_map_name( + const std::string& core_name, ccf::kv::SecurityDomain sd) { - if (sd == kv::SecurityDomain::PUBLIC) + if (sd == ccf::kv::SecurityDomain::PUBLIC) { - return fmt::format("{}{}", kv::public_domain_prefix, core_name); + return fmt::format("{}{}", ccf::kv::public_domain_prefix, core_name); } return core_name; } // Test functions -template +template static void serialise(picobench::state& s) { ccf::logger::config::level() = LoggerLevel::INFO; - kv::Store kv_store; + ccf::kv::Store kv_store; auto secrets = create_ledger_secrets(); auto encryptor = std::make_shared(secrets); kv_store.set_encryptor(encryptor); @@ -77,20 +78,20 @@ static void serialise(picobench::state& s) s.start_timer(); auto rc = tx.commit(); - if (rc != kv::CommitResult::SUCCESS) + if (rc != ccf::kv::CommitResult::SUCCESS) throw std::logic_error("Transaction commit failed: " + std::to_string(rc)); s.stop_timer(); } -template +template static void deserialise(picobench::state& s) { ccf::logger::config::level() = LoggerLevel::INFO; - kv::Store kv_store; - kv::Store kv_store2; + ccf::kv::Store kv_store; + ccf::kv::Store kv_store2; - auto consensus = std::make_shared(); + auto consensus = std::make_shared(); kv_store.set_consensus(consensus); auto secrets = create_ledger_secrets(); @@ -117,7 +118,7 @@ static void deserialise(picobench::state& s) s.start_timer(); auto rc = kv_store2.deserialize(consensus->get_latest_data().value())->apply(); - if (rc != kv::ApplyResult::PASS) + if (rc != ccf::kv::ApplyResult::PASS) throw std::logic_error( "Transaction deserialisation failed: " + std::to_string(rc)); s.stop_timer(); @@ -128,7 +129,7 @@ static void commit_latency(picobench::state& s) { ccf::logger::config::level() = LoggerLevel::INFO; - kv::Store kv_store; + ccf::kv::Store kv_store; auto secrets = create_ledger_secrets(); auto encryptor = std::make_shared(secrets); kv_store.set_encryptor(encryptor); @@ -150,7 +151,7 @@ static void commit_latency(picobench::state& s) } auto rc = tx.commit(); - if (rc != kv::CommitResult::SUCCESS) + if (rc != ccf::kv::CommitResult::SUCCESS) { throw std::logic_error( "Transaction commit failed: " + std::to_string(rc)); @@ -166,7 +167,7 @@ static void ser_snap(picobench::state& s) { ccf::logger::config::level() = LoggerLevel::INFO; - kv::Store kv_store; + ccf::kv::Store kv_store; auto secrets = create_ledger_secrets(); auto encryptor = std::make_shared(secrets); kv_store.set_encryptor(encryptor); @@ -185,14 +186,14 @@ static void ser_snap(picobench::state& s) } auto rc = tx.commit(); - if (rc != kv::CommitResult::SUCCESS) + if (rc != ccf::kv::CommitResult::SUCCESS) throw std::logic_error("Transaction commit failed: " + std::to_string(rc)); s.start_timer(); - std::unique_ptr snap = nullptr; + std::unique_ptr snap = nullptr; { - kv::ScopedStoreMapsLock maps_lock(&kv_store); + ccf::kv::ScopedStoreMapsLock maps_lock(&kv_store); snap = kv_store.snapshot_unsafe_maps(tx.commit_version()); } kv_store.serialise_snapshot(std::move(snap)); @@ -204,8 +205,8 @@ static void des_snap(picobench::state& s) { ccf::logger::config::level() = LoggerLevel::INFO; - kv::Store kv_store; - kv::Store kv_store2; + ccf::kv::Store kv_store; + ccf::kv::Store kv_store2; auto secrets = create_ledger_secrets(); auto encryptor = std::make_shared(secrets); kv_store.set_encryptor(encryptor); @@ -225,17 +226,17 @@ static void des_snap(picobench::state& s) } auto rc = tx.commit(); - if (rc != kv::CommitResult::SUCCESS) + if (rc != ccf::kv::CommitResult::SUCCESS) throw std::logic_error("Transaction commit failed: " + std::to_string(rc)); - std::unique_ptr snap = nullptr; + std::unique_ptr snap = nullptr; { - kv::ScopedStoreMapsLock maps_lock(&kv_store); + ccf::kv::ScopedStoreMapsLock maps_lock(&kv_store); snap = kv_store.snapshot_unsafe_maps(tx.commit_version()); } auto serialised_snap = kv_store.serialise_snapshot(std::move(snap)); - kv::ConsensusHookPtrs hooks; + ccf::kv::ConsensusHookPtrs hooks; s.start_timer(); kv_store2.deserialise_snapshot( serialised_snap.data(), serialised_snap.size(), hooks); @@ -245,7 +246,7 @@ static void des_snap(picobench::state& s) const std::vector tx_count = {10, 100, 1000}; const uint32_t sample_size = 100; -using SD = kv::SecurityDomain; +using SD = ccf::kv::SecurityDomain; PICOBENCH_SUITE("commit_latency"); PICOBENCH(commit_latency<10>).iterations(tx_count).samples(10).baseline(); diff --git a/src/kv/test/kv_contention.cpp b/src/kv/test/kv_contention.cpp index 2cd77c259bcb..62a4178b2244 100644 --- a/src/kv/test/kv_contention.cpp +++ b/src/kv/test/kv_contention.cpp @@ -17,12 +17,12 @@ #include #include -class SlowStubConsensus : public kv::test::StubConsensus +class SlowStubConsensus : public ccf::kv::test::StubConsensus { public: - using kv::test::StubConsensus::StubConsensus; + using ccf::kv::test::StubConsensus::StubConsensus; - bool replicate(const kv::BatchVector& entries, ccf::View view) override + bool replicate(const ccf::kv::BatchVector& entries, ccf::View view) override { if (rand() % 2 == 0) { @@ -30,7 +30,7 @@ class SlowStubConsensus : public kv::test::StubConsensus std::this_thread::sleep_for(std::chrono::milliseconds(delay)); } - return kv::test::StubConsensus::replicate(entries, view); + return ccf::kv::test::StubConsensus::replicate(entries, view); } }; @@ -42,7 +42,7 @@ DOCTEST_TEST_CASE("Concurrent kv access" * doctest::test_suite("concurrency")) // commit them. A single thread continually compacts the kv to the latest // entry. The goal is for these commits and compactions to avoid deadlock - using MapType = kv::Map; + using MapType = ccf::kv::Map; constexpr size_t max_k = 32; constexpr size_t thread_count = 16; @@ -54,7 +54,7 @@ DOCTEST_TEST_CASE("Concurrent kv access" * doctest::test_suite("concurrency")) struct ThreadArgs { std::vector maps; - kv::Store* kv_store; + ccf::kv::Store* kv_store; std::atomic* counter; }; ThreadArgs args[thread_count] = {}; @@ -124,12 +124,12 @@ DOCTEST_TEST_CASE("Concurrent kv access" * doctest::test_suite("concurrency")) // Try to commit const auto result = tx.commit(); - if (result == kv::CommitResult::SUCCESS) + if (result == ccf::kv::CommitResult::SUCCESS) { break; } } - catch (const kv::CompactedVersionConflict& e) + catch (const ccf::kv::CompactedVersionConflict& e) { // Retry on conflict continue; @@ -154,7 +154,7 @@ DOCTEST_TEST_CASE("Concurrent kv access" * doctest::test_suite("concurrency")) struct CompactArgs { - kv::Store* kv_store; + ccf::kv::Store* kv_store; std::atomic* tx_counter; std::atomic* compact_state; }; @@ -162,10 +162,10 @@ DOCTEST_TEST_CASE("Concurrent kv access" * doctest::test_suite("concurrency")) static constexpr auto iterations = 20; for (auto i = 0; i < iterations; ++i) { - kv::Store kv_store; + ccf::kv::Store kv_store; auto consensus = std::make_shared(); kv_store.set_consensus(consensus); - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); // Keep atomic count of running threads @@ -254,13 +254,13 @@ DOCTEST_TEST_CASE( { // Many threads attempt to produce a chain of transactions pointing at the // previous write to a single key, at that key. - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); constexpr auto store_commit_term = 2; kv_store.initialise_term(store_commit_term); - using MapType = kv::Map; + using MapType = ccf::kv::Map; MapType map("public:foo"); constexpr size_t k = 42; @@ -293,13 +293,13 @@ DOCTEST_TEST_CASE( h->put(k, j); const auto result = tx.commit(); - if (result == kv::CommitResult::SUCCESS) + if (result == ccf::kv::CommitResult::SUCCESS) { // Succeeded break; } - DOCTEST_REQUIRE(result == kv::CommitResult::FAIL_CONFLICT); + DOCTEST_REQUIRE(result == ccf::kv::CommitResult::FAIL_CONFLICT); ++conflict_count; // Sleep before retrying diff --git a/src/kv/test/kv_dynamic_tables.cpp b/src/kv/test/kv_dynamic_tables.cpp index 04b2ccc993ff..4d7553be8817 100644 --- a/src/kv/test/kv_dynamic_tables.cpp +++ b/src/kv/test/kv_dynamic_tables.cpp @@ -8,17 +8,17 @@ struct MapTypes { - using StringString = kv::Map; - using NumNum = kv::Map; - using NumString = kv::Map; - using StringNum = kv::Map; + using StringString = ccf::kv::Map; + using NumNum = ccf::kv::Map; + using NumString = ccf::kv::Map; + using StringNum = ccf::kv::Map; }; TEST_CASE("Basic dynamic table" * doctest::test_suite("dynamic")) { - kv::Store kv_store; + ccf::kv::Store kv_store; - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); constexpr auto map_name = "mapA"; @@ -31,7 +31,7 @@ TEST_CASE("Basic dynamic table" * doctest::test_suite("dynamic")) auto handle = tx.rw(map_name); handle->put("foo", "bar"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -79,7 +79,7 @@ TEST_CASE("Basic dynamic table" * doctest::test_suite("dynamic")) auto a = tx.rw(map_name); a->put("foo", "baz"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); { auto check_tx = kv_store.create_tx(); @@ -118,9 +118,9 @@ TEST_CASE("Basic dynamic table" * doctest::test_suite("dynamic")) TEST_CASE("Dynamic table opacity" * doctest::test_suite("dynamic")) { - kv::Store kv_store; + ccf::kv::Store kv_store; - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); constexpr auto map_name = "dynamic_map"; @@ -138,7 +138,7 @@ TEST_CASE("Dynamic table opacity" * doctest::test_suite("dynamic")) { INFO("First transaction commits successfully"); - REQUIRE(tx1.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx1.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -152,7 +152,7 @@ TEST_CASE("Dynamic table opacity" * doctest::test_suite("dynamic")) { INFO("Second transaction conflicts"); - REQUIRE(tx2.commit() == kv::CommitResult::FAIL_CONFLICT); + REQUIRE(tx2.commit() == ccf::kv::CommitResult::FAIL_CONFLICT); } { @@ -164,7 +164,7 @@ TEST_CASE("Dynamic table opacity" * doctest::test_suite("dynamic")) handle3->put("foo", "baz"); REQUIRE(handle3->get("foo").value() == "baz"); - REQUIRE(tx3.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx3.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -180,9 +180,9 @@ TEST_CASE("Dynamic table opacity" * doctest::test_suite("dynamic")) TEST_CASE( "Dynamic table visibility by version" * doctest::test_suite("dynamic")) { - kv::Store kv_store; + ccf::kv::Store kv_store; - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); constexpr auto map_name = "dynamic_map"; @@ -203,7 +203,7 @@ TEST_CASE( // tx3 takes a read dependency at an early version, before the map is visible auto handle3_static = tx3.rw(other_map); - REQUIRE(tx1.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx1.commit() == ccf::kv::CommitResult::SUCCESS); // Even after commit, the new map is not visible to tx3 because it is reading // from an earlier version @@ -218,9 +218,9 @@ TEST_CASE( TEST_CASE("Read only handles" * doctest::test_suite("dynamic")) { - kv::Store kv_store; + ccf::kv::Store kv_store; - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); constexpr auto dynamic_map_a = "dynamic_map_a"; @@ -253,7 +253,7 @@ TEST_CASE("Read only handles" * doctest::test_suite("dynamic")) a->put("foo", "bar"); b->put("foo", "baz"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -273,9 +273,9 @@ TEST_CASE("Read only handles" * doctest::test_suite("dynamic")) TEST_CASE("Mixed map dependencies" * doctest::test_suite("dynamic")) { - kv::Store kv_store; + ccf::kv::Store kv_store; - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); constexpr auto key = "foo"; @@ -285,7 +285,7 @@ TEST_CASE("Mixed map dependencies" * doctest::test_suite("dynamic")) auto tx = kv_store.create_tx(); auto handle = tx.rw(prior_map); handle->put(key, "bar"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } constexpr auto dynamic_map_a = "dynamic_map_a"; @@ -302,8 +302,8 @@ TEST_CASE("Mixed map dependencies" * doctest::test_suite("dynamic")) handle1->put(42, "hello"); handle2->put("hello", 42); - REQUIRE(tx1.commit() == kv::CommitResult::SUCCESS); - REQUIRE(tx2.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx1.commit() == ccf::kv::CommitResult::SUCCESS); + REQUIRE(tx2.commit() == ccf::kv::CommitResult::SUCCESS); } SUBCASE("Map creation blocked by standard conflict") @@ -326,8 +326,8 @@ TEST_CASE("Mixed map dependencies" * doctest::test_suite("dynamic")) dynamic_handle->put("hello world", 42); } - REQUIRE(tx1.commit() == kv::CommitResult::SUCCESS); - REQUIRE(tx2.commit() == kv::CommitResult::FAIL_CONFLICT); + REQUIRE(tx1.commit() == ccf::kv::CommitResult::SUCCESS); + REQUIRE(tx2.commit() == ccf::kv::CommitResult::FAIL_CONFLICT); tx2 = kv_store.create_tx(); @@ -349,14 +349,14 @@ TEST_CASE("Mixed map dependencies" * doctest::test_suite("dynamic")) TEST_CASE("Dynamic map serialisation" * doctest::test_suite("dynamic")) { - auto consensus = std::make_shared(); - auto encryptor = std::make_shared(); - kv::Store kv_store; + auto consensus = std::make_shared(); + auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; kv_store.set_encryptor(encryptor); kv_store.set_consensus(consensus); - kv::Store kv_store_target; + ccf::kv::Store kv_store_target; kv_store_target.set_encryptor(encryptor); const auto map_name = "new_map"; @@ -368,7 +368,7 @@ TEST_CASE("Dynamic map serialisation" * doctest::test_suite("dynamic")) auto tx = kv_store.create_tx(); auto handle = tx.rw(map_name); handle->put(key, value); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -377,7 +377,7 @@ TEST_CASE("Dynamic map serialisation" * doctest::test_suite("dynamic")) REQUIRE(latest_data.has_value()); REQUIRE( kv_store_target.deserialize(latest_data.value())->apply() == - kv::ApplyResult::PASS); + ccf::kv::ApplyResult::PASS); auto tx_target = kv_store_target.create_tx(); auto handle_target = tx_target.rw(map_name); @@ -389,40 +389,40 @@ TEST_CASE("Dynamic map serialisation" * doctest::test_suite("dynamic")) TEST_CASE("Dynamic map snapshot serialisation" * doctest::test_suite("dynamic")) { - kv::Store store; - auto encryptor = std::make_shared(); + ccf::kv::Store store; + auto encryptor = std::make_shared(); store.set_encryptor(encryptor); constexpr auto map_name = "string_map"; - kv::Version snapshot_version; + ccf::kv::Version snapshot_version; INFO("Create maps in original store"); { auto tx1 = store.create_tx(); auto handle_1 = tx1.rw(map_name); handle_1->put("foo", "foo"); - REQUIRE(tx1.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx1.commit() == ccf::kv::CommitResult::SUCCESS); auto tx2 = store.create_tx(); auto handle_2 = tx2.rw(map_name); handle_2->put("bar", "bar"); - REQUIRE(tx2.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx2.commit() == ccf::kv::CommitResult::SUCCESS); snapshot_version = tx2.commit_version(); } INFO("Create snapshot of original store"); - std::unique_ptr snapshot = nullptr; + std::unique_ptr snapshot = nullptr; { - kv::ScopedStoreMapsLock maps_lock(&store); + ccf::kv::ScopedStoreMapsLock maps_lock(&store); snapshot = store.snapshot_unsafe_maps(snapshot_version); } auto serialised_snapshot = store.serialise_snapshot(std::move(snapshot)); INFO("Apply snapshot to create maps in new store"); { - kv::ConsensusHookPtrs hooks; - kv::Store new_store; + ccf::kv::ConsensusHookPtrs hooks; + ccf::kv::Store new_store; new_store.set_encryptor(encryptor); new_store.deserialise_snapshot( serialised_snapshot.data(), serialised_snapshot.size(), hooks); @@ -442,9 +442,9 @@ TEST_CASE("Dynamic map snapshot serialisation" * doctest::test_suite("dynamic")) TEST_CASE("Mid rollback safety" * doctest::test_suite("dynamic")) { - kv::Store kv_store; + ccf::kv::Store kv_store; - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); constexpr auto map_name = "my_new_map"; @@ -457,7 +457,7 @@ TEST_CASE("Mid rollback safety" * doctest::test_suite("dynamic")) auto handle = tx.rw(map_name); handle->put("foo", "bar"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -481,16 +481,16 @@ TEST_CASE("Mid rollback safety" * doctest::test_suite("dynamic")) handle->put("foo", "baz"); const auto result = tx.commit(); - REQUIRE(result == kv::CommitResult::FAIL_CONFLICT); + REQUIRE(result == ccf::kv::CommitResult::FAIL_CONFLICT); } } TEST_CASE( "Security domain is determined by map name" * doctest::test_suite("dynamic")) { - kv::Store kv_store; + ccf::kv::Store kv_store; - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); { @@ -498,7 +498,7 @@ TEST_CASE( auto handle = tx.rw("public:foo"); handle->put("foo", "bar"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -506,7 +506,7 @@ TEST_CASE( auto handle = tx.rw("foo"); handle->put("hello", "world"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -530,9 +530,9 @@ TEST_CASE( TEST_CASE("Swapping dynamic maps" * doctest::test_suite("dynamic")) { - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); - kv::Store s1; + ccf::kv::Store s1; s1.set_encryptor(encryptor); { @@ -541,7 +541,7 @@ TEST_CASE("Swapping dynamic maps" * doctest::test_suite("dynamic")) auto v1 = tx.rw("bar"); v0->put("hello", "world"); v1->put(42, "everything"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -550,7 +550,7 @@ TEST_CASE("Swapping dynamic maps" * doctest::test_suite("dynamic")) auto v1 = tx.rw("baz"); v0->put("hello", "goodbye"); v1->put("saluton", 100); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -558,10 +558,10 @@ TEST_CASE("Swapping dynamic maps" * doctest::test_suite("dynamic")) auto tx = s1.create_tx(); auto v0 = tx.rw("public:source_state"); v0->put("store", "source"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } - kv::Store s2; + ccf::kv::Store s2; s2.set_encryptor(encryptor); // Ensure source store is at _at least_ the same version as source store @@ -571,7 +571,7 @@ TEST_CASE("Swapping dynamic maps" * doctest::test_suite("dynamic")) auto tx = s2.create_tx(); auto v0 = tx.rw("public:target_state"); v0->put("store", "target"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } s1.compact(s1.current_version()); diff --git a/src/kv/test/kv_serialisation.cpp b/src/kv/test/kv_serialisation.cpp index ccb664ad403b..3baa402eec83 100644 --- a/src/kv/test/kv_serialisation.cpp +++ b/src/kv/test/kv_serialisation.cpp @@ -13,10 +13,10 @@ struct MapTypes { - using StringString = kv::Map; - using NumNum = kv::Map; - using NumString = kv::Map; - using StringNum = kv::Map; + using StringString = ccf::kv::Map; + using NumNum = ccf::kv::Map; + using NumString = ccf::kv::Map; + using StringNum = ccf::kv::Map; }; TEST_CASE( @@ -26,14 +26,14 @@ TEST_CASE( // No need for an encryptor here as all maps are public. Both serialisation // and deserialisation should succeed. - kv::Store kv_store; + ccf::kv::Store kv_store; - auto consensus = std::make_shared(); + auto consensus = std::make_shared(); kv_store.set_consensus(consensus); - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); - kv::Store kv_store_target; + ccf::kv::Store kv_store_target; kv_store_target.set_encryptor(encryptor); MapTypes::StringString map("public:pub_map"); @@ -53,7 +53,7 @@ TEST_CASE( handle0->put(k1, v1); handle0->put(k2, v1); handle0->put(k3, v1); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } const auto first_version = kv_store.current_version(); @@ -68,7 +68,7 @@ TEST_CASE( // no change to k1, write to k2, remove k3 handle0->put(k2, v2); handle0->remove(k3); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } const auto second_version = kv_store.current_version(); @@ -80,7 +80,7 @@ TEST_CASE( INFO("Deserialise first transaction in target store"); REQUIRE( kv_store_target.deserialize(first_tx_serialised.value())->apply() == - kv::ApplyResult::PASS); + ccf::kv::ApplyResult::PASS); auto tx_target = kv_store_target.create_tx(); auto handle_target = tx_target.ro(map); @@ -105,7 +105,7 @@ TEST_CASE( INFO("Deserialise second transaction in target store"); REQUIRE( kv_store_target.deserialize(second_tx_serialised.value())->apply() == - kv::ApplyResult::PASS); + ccf::kv::ApplyResult::PASS); auto tx_target = kv_store_target.create_tx(); auto handle_target = tx_target.ro(map); @@ -130,13 +130,13 @@ TEST_CASE( "Serialise/deserialise private map only" * doctest::test_suite("serialisation")) { - auto consensus = std::make_shared(); - auto encryptor = std::make_shared(); + auto consensus = std::make_shared(); + auto encryptor = std::make_shared(); - kv::Store kv_store; + ccf::kv::Store kv_store; kv_store.set_consensus(consensus); - kv::Store kv_store_target; + ccf::kv::Store kv_store_target; kv_store_target.set_encryptor(encryptor); SUBCASE( @@ -145,7 +145,7 @@ TEST_CASE( auto tx = kv_store.create_tx(); auto handle0 = tx.rw("priv_map"); handle0->put("privk1", "privv1"); - REQUIRE_THROWS_AS(tx.commit(), kv::KvSerialiserException); + REQUIRE_THROWS_AS(tx.commit(), ccf::kv::KvSerialiserException); } SUBCASE("Commit private transaction with encryptor") @@ -156,7 +156,7 @@ TEST_CASE( auto tx = kv_store.create_tx(); auto handle0 = tx.rw("priv_map"); handle0->put("privk1", "privv1"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } INFO("Deserialise transaction in target store"); @@ -165,7 +165,7 @@ TEST_CASE( REQUIRE(latest_data.has_value()); REQUIRE( kv_store_target.deserialize(latest_data.value())->apply() == - kv::ApplyResult::PASS); + ccf::kv::ApplyResult::PASS); auto tx_target = kv_store_target.create_tx(); auto handle_target = tx_target.rw("priv_map"); @@ -178,17 +178,17 @@ TEST_CASE( "Serialise/deserialise private map and public maps" * doctest::test_suite("serialisation")) { - auto consensus = std::make_shared(); - auto encryptor = std::make_shared(); + auto consensus = std::make_shared(); + auto encryptor = std::make_shared(); - kv::Store kv_store; + ccf::kv::Store kv_store; kv_store.set_consensus(consensus); kv_store.set_encryptor(encryptor); constexpr auto priv_map = "priv_map"; constexpr auto pub_map = "public:pub_map"; - kv::Store kv_store_target; + ccf::kv::Store kv_store_target; kv_store_target.set_encryptor(encryptor); INFO("Commit to public and private map in source store"); @@ -200,7 +200,7 @@ TEST_CASE( handle_priv->put("privk1", "privv1"); handle_pub->put("pubk1", "pubv1"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } INFO("Deserialise transaction in target store"); @@ -209,7 +209,7 @@ TEST_CASE( REQUIRE(latest_data.has_value()); REQUIRE( kv_store_target.deserialize(latest_data.value())->apply() != - kv::ApplyResult::FAIL); + ccf::kv::ApplyResult::FAIL); auto tx_target = kv_store_target.create_tx(); auto handle_priv = tx_target.rw(priv_map); @@ -223,14 +223,14 @@ TEST_CASE( TEST_CASE( "Serialise/deserialise removed keys" * doctest::test_suite("serialisation")) { - auto consensus = std::make_shared(); - auto encryptor = std::make_shared(); + auto consensus = std::make_shared(); + auto encryptor = std::make_shared(); - kv::Store kv_store; + ccf::kv::Store kv_store; kv_store.set_consensus(consensus); kv_store.set_encryptor(encryptor); - kv::Store kv_store_target; + ccf::kv::Store kv_store_target; kv_store_target.set_encryptor(encryptor); INFO("Commit new keys in source store and deserialise in target store"); @@ -241,13 +241,13 @@ TEST_CASE( handle->put("key1", "value1"); handle2->put("key2", "value2"); handle2->put("key3", "value3"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); const auto latest_data = consensus->get_latest_data(); REQUIRE(latest_data.has_value()); REQUIRE( kv_store_target.deserialize(latest_data.value())->apply() != - kv::ApplyResult::FAIL); + ccf::kv::ApplyResult::FAIL); auto tx_target = kv_store_target.create_tx(); auto handle_target = tx_target.rw("map"); @@ -281,7 +281,7 @@ TEST_CASE( handle_->remove("key3"); handle_->put("key3", "value3"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); // Make sure keys have been marked as deleted in source store auto tx2 = kv_store.create_tx(); @@ -296,7 +296,7 @@ TEST_CASE( REQUIRE(latest_data.has_value()); REQUIRE( kv_store_target.deserialize(latest_data.value())->apply() != - kv::ApplyResult::FAIL); + ccf::kv::ApplyResult::FAIL); auto tx_target = kv_store_target.create_tx(); auto handle_target = tx_target.rw("map"); @@ -322,7 +322,7 @@ DECLARE_JSON_REQUIRED_FIELDS(CustomClass, s, n); // Not really intended to be extended, but lets us use the BlitSerialiser for // this specific type -namespace kv::serialisers +namespace ccf::kv::serialisers { template <> struct BlitSerialiser @@ -373,11 +373,12 @@ struct CustomSerialiser static constexpr auto size_of_n = 8; static constexpr auto size_of_size_of_s = 8; - static kv::serialisers::SerialisedEntry to_serialised(const CustomClass& cc) + static ccf::kv::serialisers::SerialisedEntry to_serialised( + const CustomClass& cc) { const auto s_size = cc.s.size(); const auto total_size = size_of_n + size_of_size_of_s + s_size; - kv::serialisers::SerialisedEntry serialised(total_size); + ccf::kv::serialisers::SerialisedEntry serialised(total_size); uint8_t* data = serialised.data(); memcpy(data, (const uint8_t*)&cc.n, size_of_n); data += size_of_n; @@ -388,7 +389,7 @@ struct CustomSerialiser } static CustomClass from_serialised( - const kv::serialisers::SerialisedEntry& ser) + const ccf::kv::serialisers::SerialisedEntry& ser) { CustomClass cc; const uint8_t* data = ser.data(); @@ -405,7 +406,7 @@ struct CustomSerialiser struct CustomJsonSerialiser { - using Bytes = kv::serialisers::SerialisedEntry; + using Bytes = ccf::kv::serialisers::SerialisedEntry; static Bytes to_serialised(const CustomClass& c) { @@ -439,7 +440,7 @@ struct VPrefix template struct CustomVerboseDumbSerialiser { - using Bytes = kv::serialisers::SerialisedEntry; + using Bytes = ccf::kv::serialisers::SerialisedEntry; static Bytes to_serialised(const CustomClass& c) { @@ -471,25 +472,26 @@ struct CustomVerboseDumbSerialiser } }; -using JsonSerialisedMap = kv::JsonSerialisedMap; -using RawCopySerialisedMap = kv::RawCopySerialisedMap; -using MixSerialisedMapB = kv::TypedMap< +using JsonSerialisedMap = ccf::kv::JsonSerialisedMap; +using RawCopySerialisedMap = + ccf::kv::RawCopySerialisedMap; +using MixSerialisedMapB = ccf::kv::TypedMap< CustomClass, CustomClass, - kv::serialisers::JsonSerialiser, - kv::serialisers::BlitSerialiser>; + ccf::kv::serialisers::JsonSerialiser, + ccf::kv::serialisers::BlitSerialiser>; // SNIPPET_START: CustomSerialisedMap definition -using CustomSerialisedMap = - kv::TypedMap; +using CustomSerialisedMap = ccf::kv:: + TypedMap; // SNIPPET_END: CustomSerialisedMap definition -using CustomJsonMap = kv::TypedMap< +using CustomJsonMap = ccf::kv::TypedMap< CustomClass, CustomClass, CustomJsonSerialiser, CustomJsonSerialiser>; -using VerboseSerialisedMap = kv::TypedMap< +using VerboseSerialisedMap = ccf::kv::TypedMap< CustomClass, CustomClass, CustomVerboseDumbSerialiser, @@ -505,8 +507,8 @@ TEST_CASE_TEMPLATE( CustomJsonMap, VerboseSerialisedMap) { - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); MapType map("public:map"); @@ -519,7 +521,7 @@ TEST_CASE_TEMPLATE( INFO("Serialise/Deserialise 2 kv stores"); { - kv::Store kv_store2; + ccf::kv::Store kv_store2; kv_store2.set_encryptor(encryptor); MapType map2("public:map"); @@ -533,10 +535,10 @@ TEST_CASE_TEMPLATE( tx.commit_reserved(); auto& success = success_; auto& data = data_; - REQUIRE(success == kv::CommitResult::SUCCESS); + REQUIRE(success == ccf::kv::CommitResult::SUCCESS); kv_store.compact(kv_store.current_version()); - REQUIRE(kv_store2.deserialize(data)->apply() == kv::ApplyResult::PASS); + REQUIRE(kv_store2.deserialize(data)->apply() == ccf::kv::ApplyResult::PASS); auto tx2 = kv_store2.create_tx(); auto handle2 = tx2.rw(map2); @@ -564,11 +566,11 @@ TEST_CASE("nlohmann (de)serialisation" * doctest::test_suite("serialisation")) SUBCASE("baseline") { - auto consensus = std::make_shared(); - using Table = kv::Map, std::string>; - kv::Store s0, s1; + auto consensus = std::make_shared(); + using Table = ccf::kv::Map, std::string>; + ccf::kv::Store s0, s1; s0.set_consensus(consensus); - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); s0.set_encryptor(encryptor); s1.set_encryptor(encryptor); @@ -576,21 +578,22 @@ TEST_CASE("nlohmann (de)serialisation" * doctest::test_suite("serialisation")) auto tx = s0.create_tx(); tx.rw(t)->put(k1, v1); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); const auto latest_data = consensus->get_latest_data(); REQUIRE(latest_data.has_value()); REQUIRE( - s1.deserialize(latest_data.value())->apply() != kv::ApplyResult::FAIL); + s1.deserialize(latest_data.value())->apply() != + ccf::kv::ApplyResult::FAIL); } SUBCASE("nlohmann") { - auto consensus = std::make_shared(); - using Table = kv::Map; - kv::Store s0, s1; + auto consensus = std::make_shared(); + using Table = ccf::kv::Map; + ccf::kv::Store s0, s1; s0.set_consensus(consensus); - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); s0.set_encryptor(encryptor); s1.set_encryptor(encryptor); @@ -599,12 +602,13 @@ TEST_CASE("nlohmann (de)serialisation" * doctest::test_suite("serialisation")) auto tx = s0.create_tx(); tx.rw(t)->put(k0, v0); tx.rw(t)->put(k1, v1); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); const auto latest_data = consensus->get_latest_data(); REQUIRE(latest_data.has_value()); REQUIRE( - s1.deserialize(latest_data.value())->apply() != kv::ApplyResult::FAIL); + s1.deserialize(latest_data.value())->apply() != + ccf::kv::ApplyResult::FAIL); } } @@ -613,7 +617,7 @@ struct NonSerialisable struct NonSerialiser { - using Bytes = kv::serialisers::SerialisedEntry; + using Bytes = ccf::kv::serialisers::SerialisedEntry; static Bytes to_serialised(const NonSerialisable& ns) { @@ -628,23 +632,23 @@ struct NonSerialiser TEST_CASE("Exceptional serdes" * doctest::test_suite("serialisation")) { - auto encryptor = std::make_shared(); - auto consensus = std::make_shared(); + auto encryptor = std::make_shared(); + auto consensus = std::make_shared(); - kv::Store store; + ccf::kv::Store store; store.set_consensus(consensus); store.set_encryptor(encryptor); - kv::TypedMap< + ccf::kv::TypedMap< NonSerialisable, size_t, NonSerialiser, - kv::serialisers::JsonSerialiser> + ccf::kv::serialisers::JsonSerialiser> bad_map_k("bad_map_k"); - kv::TypedMap< + ccf::kv::TypedMap< size_t, NonSerialisable, - kv::serialisers::JsonSerialiser, + ccf::kv::serialisers::JsonSerialiser, NonSerialiser> bad_map_v("bad_map_v"); @@ -665,17 +669,17 @@ TEST_CASE( "Serialise/deserialise maps with claims" * doctest::test_suite("serialisation")) { - auto consensus = std::make_shared(); - auto encryptor = std::make_shared(); + auto consensus = std::make_shared(); + auto encryptor = std::make_shared(); - kv::Store kv_store; + ccf::kv::Store kv_store; kv_store.set_consensus(consensus); kv_store.set_encryptor(encryptor); constexpr auto priv_map = "priv_map"; constexpr auto pub_map = "public:pub_map"; - kv::Store kv_store_target; + ccf::kv::Store kv_store_target; kv_store_target.set_encryptor(encryptor); ccf::ClaimsDigest claims_digest; @@ -690,7 +694,7 @@ TEST_CASE( handle_priv->put("privk1", "privv1"); handle_pub->put("pubk1", "pubv1"); - REQUIRE(tx.commit(claims_digest) == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit(claims_digest) == ccf::kv::CommitResult::SUCCESS); } INFO("Deserialise transaction in target store and extract claims"); @@ -698,7 +702,7 @@ TEST_CASE( const auto latest_data = consensus->get_latest_data(); REQUIRE(latest_data.has_value()); auto wrapper = kv_store_target.deserialize(latest_data.value()); - REQUIRE(wrapper->apply() != kv::ApplyResult::FAIL); + REQUIRE(wrapper->apply() != ccf::kv::ApplyResult::FAIL); auto deserialised_claims = wrapper->consume_claims_digest(); REQUIRE(claims_digest == deserialised_claims); diff --git a/src/kv/test/kv_snapshot.cpp b/src/kv/test/kv_snapshot.cpp index 6a8043a743be..03f59e32fde2 100644 --- a/src/kv/test/kv_snapshot.cpp +++ b/src/kv/test/kv_snapshot.cpp @@ -10,10 +10,10 @@ struct MapTypes { - using StringString = kv::Map; - using NumNum = kv::Map; - using StringValue = kv::Value; - using StringSet = kv::Set; + using StringString = ccf::kv::Map; + using NumNum = ccf::kv::Map; + using StringValue = ccf::kv::Value; + using StringSet = ccf::kv::Set; }; MapTypes::StringString string_map("public:string_map"); @@ -21,12 +21,12 @@ MapTypes::NumNum num_map("public:num_map"); TEST_CASE("Simple snapshot" * doctest::test_suite("snapshot")) { - kv::Store store; - auto encryptor = std::make_shared(); + ccf::kv::Store store; + auto encryptor = std::make_shared(); store.set_encryptor(encryptor); - kv::Version first_snapshot_version = kv::NoVersion; - kv::Version second_snapshot_version = kv::NoVersion; + ccf::kv::Version first_snapshot_version = ccf::kv::NoVersion; + ccf::kv::Version second_snapshot_version = ccf::kv::NoVersion; INFO("Apply transactions to original store"); { @@ -36,7 +36,7 @@ TEST_CASE("Simple snapshot" * doctest::test_suite("snapshot")) handle_1s->put("baz", "hello"); auto handle_1n = tx1.rw(num_map); handle_1n->put(42, 100); - REQUIRE(tx1.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx1.commit() == ccf::kv::CommitResult::SUCCESS); first_snapshot_version = tx1.commit_version(); auto tx2 = store.create_tx(); @@ -44,7 +44,7 @@ TEST_CASE("Simple snapshot" * doctest::test_suite("snapshot")) handle_2s->remove("baz"); auto handle_2n = tx2.rw(num_map); handle_2n->put(42, 123); - REQUIRE(tx2.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx2.commit() == ccf::kv::CommitResult::SUCCESS); second_snapshot_version = tx2.commit_version(); auto tx3 = store.create_tx(); @@ -53,9 +53,10 @@ TEST_CASE("Simple snapshot" * doctest::test_suite("snapshot")) // Do not commit tx3 } - std::unique_ptr first_snapshot = nullptr; + std::unique_ptr first_snapshot = + nullptr; { - kv::ScopedStoreMapsLock maps_lock(&store); + ccf::kv::ScopedStoreMapsLock maps_lock(&store); first_snapshot = store.snapshot_unsafe_maps(first_snapshot_version); } auto first_serialised_snapshot = @@ -63,16 +64,16 @@ TEST_CASE("Simple snapshot" * doctest::test_suite("snapshot")) INFO("Apply snapshot at 1 to new store"); { - kv::Store new_store; + ccf::kv::Store new_store; new_store.set_encryptor(encryptor); - kv::ConsensusHookPtrs hooks; + ccf::kv::ConsensusHookPtrs hooks; REQUIRE_EQ( new_store.deserialise_snapshot( first_serialised_snapshot.data(), first_serialised_snapshot.size(), hooks), - kv::ApplyResult::PASS); + ccf::kv::ApplyResult::PASS); REQUIRE_EQ(new_store.current_version(), first_snapshot_version); auto tx1 = new_store.create_tx(); @@ -113,10 +114,10 @@ TEST_CASE("Simple snapshot" * doctest::test_suite("snapshot")) } } - std::unique_ptr second_snapshot = + std::unique_ptr second_snapshot = nullptr; { - kv::ScopedStoreMapsLock maps_lock(&store); + ccf::kv::ScopedStoreMapsLock maps_lock(&store); second_snapshot = store.snapshot_unsafe_maps(second_snapshot_version); } auto second_serialised_snapshot = @@ -124,11 +125,11 @@ TEST_CASE("Simple snapshot" * doctest::test_suite("snapshot")) INFO("Apply snapshot at 2 to new store"); { - kv::Store new_store; + ccf::kv::Store new_store; new_store.set_encryptor(encryptor); - kv::ConsensusHookPtrs hooks; + ccf::kv::ConsensusHookPtrs hooks; new_store.deserialise_snapshot( second_serialised_snapshot.data(), second_serialised_snapshot.size(), @@ -200,12 +201,12 @@ TEST_CASE("Old snapshots" * doctest::test_suite("snapshot")) } const auto raw_snapshot = ccf::crypto::raw_from_b64(raw_snapshot_b64); - kv::Store new_store; + ccf::kv::Store new_store; - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); new_store.set_encryptor(encryptor); - kv::ConsensusHookPtrs hooks; + ccf::kv::ConsensusHookPtrs hooks; new_store.deserialise_snapshot( raw_snapshot.data(), raw_snapshot.size(), hooks); @@ -255,37 +256,37 @@ TEST_CASE( "Commit transaction while applying snapshot" * doctest::test_suite("snapshot")) { - kv::Store store; - auto encryptor = std::make_shared(); + ccf::kv::Store store; + auto encryptor = std::make_shared(); store.set_encryptor(encryptor); MapTypes::StringString string_map("public:string_map"); - kv::Version snapshot_version = kv::NoVersion; + ccf::kv::Version snapshot_version = ccf::kv::NoVersion; INFO("Apply transactions to original store"); { auto tx1 = store.create_tx(); auto handle_1 = tx1.rw("public:string_map"); handle_1->put("foo", "foo"); - REQUIRE(tx1.commit() == kv::CommitResult::SUCCESS); // Committed at 1 + REQUIRE(tx1.commit() == ccf::kv::CommitResult::SUCCESS); // Committed at 1 auto tx2 = store.create_tx(); auto handle_2 = tx2.rw("public:string_map"); handle_2->put("bar", "bar"); - REQUIRE(tx2.commit() == kv::CommitResult::SUCCESS); // Committed at 2 + REQUIRE(tx2.commit() == ccf::kv::CommitResult::SUCCESS); // Committed at 2 snapshot_version = tx2.commit_version(); } - std::unique_ptr snapshot = nullptr; + std::unique_ptr snapshot = nullptr; { - kv::ScopedStoreMapsLock maps_lock(&store); + ccf::kv::ScopedStoreMapsLock maps_lock(&store); snapshot = store.snapshot_unsafe_maps(snapshot_version); } auto serialised_snapshot = store.serialise_snapshot(std::move(snapshot)); INFO("Apply snapshot while committing a transaction"); { - kv::Store new_store; + ccf::kv::Store new_store; new_store.set_encryptor(encryptor); auto tx = new_store.create_tx(); @@ -293,33 +294,33 @@ TEST_CASE( handle->put("in", "flight"); // tx is not committed until the snapshot is deserialised - kv::ConsensusHookPtrs hooks; + ccf::kv::ConsensusHookPtrs hooks; new_store.deserialise_snapshot( serialised_snapshot.data(), serialised_snapshot.size(), hooks); // Transaction conflicts as snapshot was applied while transaction was in // flight - REQUIRE(tx.commit() == kv::CommitResult::FAIL_CONFLICT); + REQUIRE(tx.commit() == ccf::kv::CommitResult::FAIL_CONFLICT); // Try again auto tx2 = new_store.create_tx(); auto handle2 = tx2.rw("public:string_map"); handle2->put("baz", "baz"); - REQUIRE(tx2.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx2.commit() == ccf::kv::CommitResult::SUCCESS); } } TEST_CASE("Commit hooks with snapshot" * doctest::test_suite("snapshot")) { - kv::Store store; - auto encryptor = std::make_shared(); + ccf::kv::Store store; + auto encryptor = std::make_shared(); store.set_encryptor(encryptor); constexpr auto string_map = "public:string_map"; constexpr auto string_value = "public:string_value"; constexpr auto string_set = "public:string_set"; - kv::Version snapshot_version = kv::NoVersion; + ccf::kv::Version snapshot_version = ccf::kv::NoVersion; using MapWrite = MapTypes::StringString::Write; using ValueWrite = MapTypes::StringValue::Write; @@ -332,27 +333,27 @@ TEST_CASE("Commit hooks with snapshot" * doctest::test_suite("snapshot")) std::vector global_set_writes; auto map_hook = - [&](kv::Version v, const MapWrite& w) -> kv::ConsensusHookPtr { + [&](ccf::kv::Version v, const MapWrite& w) -> ccf::kv::ConsensusHookPtr { local_map_writes.push_back(w); - return kv::ConsensusHookPtr(nullptr); + return ccf::kv::ConsensusHookPtr(nullptr); }; - auto global_map_hook = [&](kv::Version v, const MapWrite& w) { + auto global_map_hook = [&](ccf::kv::Version v, const MapWrite& w) { global_map_writes.push_back(w); }; auto value_hook = - [&](kv::Version v, const ValueWrite& w) -> kv::ConsensusHookPtr { + [&](ccf::kv::Version v, const ValueWrite& w) -> ccf::kv::ConsensusHookPtr { local_value_writes.push_back(w); - return kv::ConsensusHookPtr(nullptr); + return ccf::kv::ConsensusHookPtr(nullptr); }; - auto global_value_hook = [&](kv::Version v, const ValueWrite& w) { + auto global_value_hook = [&](ccf::kv::Version v, const ValueWrite& w) { global_value_writes.push_back(w); }; auto set_hook = - [&](kv::Version v, const SetWrite& w) -> kv::ConsensusHookPtr { + [&](ccf::kv::Version v, const SetWrite& w) -> ccf::kv::ConsensusHookPtr { local_set_writes.push_back(w); - return kv::ConsensusHookPtr(nullptr); + return ccf::kv::ConsensusHookPtr(nullptr); }; - auto global_set_hook = [&](kv::Version v, const SetWrite& w) { + auto global_set_hook = [&](ccf::kv::Version v, const SetWrite& w) { global_set_writes.push_back(w); }; @@ -368,7 +369,7 @@ TEST_CASE("Commit hooks with snapshot" * doctest::test_suite("snapshot")) auto set_handle = tx.rw(string_set); set_handle->insert("foo"); set_handle->insert("bar"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); // Committed at 1 + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); // Committed at 1 } { @@ -382,19 +383,19 @@ TEST_CASE("Commit hooks with snapshot" * doctest::test_suite("snapshot")) auto set_handle = tx.rw(string_set); set_handle->insert("baz"); set_handle->remove("bar"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); // Committed at 2 + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); // Committed at 2 snapshot_version = tx.commit_version(); } } - std::unique_ptr snapshot = nullptr; + std::unique_ptr snapshot = nullptr; { - kv::ScopedStoreMapsLock maps_lock(&store); + ccf::kv::ScopedStoreMapsLock maps_lock(&store); snapshot = store.snapshot_unsafe_maps(snapshot_version); } auto serialised_snapshot = store.serialise_snapshot(std::move(snapshot)); - kv::Store new_store; + ccf::kv::Store new_store; new_store.set_encryptor(encryptor); MapTypes::StringString new_string_map(string_map); @@ -419,7 +420,7 @@ TEST_CASE("Commit hooks with snapshot" * doctest::test_suite("snapshot")) { INFO("Deserialise snapshot"); { - kv::ConsensusHookPtrs hooks; + ccf::kv::ConsensusHookPtrs hooks; new_store.deserialise_snapshot( serialised_snapshot.data(), serialised_snapshot.size(), hooks); } @@ -518,15 +519,15 @@ TEST_CASE("Commit hooks with snapshot" * doctest::test_suite("snapshot")) value_handle->clear(); auto set_handle = tx.rw(string_set); set_handle->clear(); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); snapshot_version = tx.commit_version(); { - kv::ScopedStoreMapsLock maps_lock(&store); + ccf::kv::ScopedStoreMapsLock maps_lock(&store); snapshot = store.snapshot_unsafe_maps(snapshot_version); } serialised_snapshot = store.serialise_snapshot(std::move(snapshot)); - kv::ConsensusHookPtrs hooks; + ccf::kv::ConsensusHookPtrs hooks; new_store.deserialise_snapshot( serialised_snapshot.data(), serialised_snapshot.size(), hooks); diff --git a/src/kv/test/kv_test.cpp b/src/kv/test/kv_test.cpp index 9ea5e1c2e4a5..ad35888def7e 100644 --- a/src/kv/test/kv_test.cpp +++ b/src/kv/test/kv_test.cpp @@ -23,19 +23,19 @@ struct MapTypes { - using StringString = kv::Map; - using NumNum = kv::Map; - using NumString = kv::Map; - using StringNum = kv::Map; - using UntypedMap = kv::untyped::Map; + using StringString = ccf::kv::Map; + using NumNum = ccf::kv::Map; + using NumString = ccf::kv::Map; + using StringNum = ccf::kv::Map; + using UntypedMap = ccf::kv::untyped::Map; }; TEST_CASE("Map name parsing") { - using SD = kv::SecurityDomain; - using AC = kv::AccessCategory; + using SD = ccf::kv::SecurityDomain; + using AC = ccf::kv::AccessCategory; - auto parse = kv::parse_map_name; + auto parse = ccf::kv::parse_map_name; auto mp = std::make_pair; REQUIRE(parse("foo") == mp(SD::PRIVATE, AC::APPLICATION)); @@ -58,8 +58,8 @@ TEST_CASE("Map name parsing") TEST_CASE("Reads/writes and deletions") { - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); MapTypes::StringString map("public:map"); @@ -71,7 +71,7 @@ TEST_CASE("Reads/writes and deletions") INFO("Start empty transaction"); { auto tx = kv_store.create_tx(); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE_THROWS_AS(tx.commit(), std::logic_error); } @@ -89,7 +89,7 @@ TEST_CASE("Reads/writes and deletions") REQUIRE(va.has_value()); REQUIRE(va.value() == v1); REQUIRE(!handle->get_version_of_previous_write(k).has_value()); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } const auto commit_v = kv_store.current_version(); @@ -105,7 +105,7 @@ TEST_CASE("Reads/writes and deletions") const auto ver = handle->get_version_of_previous_write(k); REQUIRE(ver.has_value()); REQUIRE(ver.value() == commit_v); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } INFO("Remove keys"); @@ -128,7 +128,7 @@ TEST_CASE("Reads/writes and deletions") REQUIRE(!va.has_value()); handle->put(k, v1); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -147,7 +147,7 @@ TEST_CASE("Reads/writes and deletions") handle->put(k, v1); auto va = handle->get_globally_committed(k); REQUIRE(!va.has_value()); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -156,7 +156,7 @@ TEST_CASE("Reads/writes and deletions") REQUIRE(handle2->has(k)); handle2->remove(k); REQUIRE(!handle2->has(k)); - REQUIRE(tx2.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx2.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -171,13 +171,13 @@ TEST_CASE("Reads/writes and deletions") TEST_CASE("sets and values") { - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); { - INFO("kv::Set"); - using Set = kv::Set; + INFO("ccf::kv::Set"); + using Set = ccf::kv::Set; Set set("public:set"); constexpr auto k1 = "key1"; constexpr auto k2 = "key2"; @@ -209,7 +209,7 @@ TEST_CASE("sets and values") REQUIRE(!set_handle->contains_globally_committed(k1)); REQUIRE(!set_handle->contains_globally_committed(k2)); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -232,7 +232,7 @@ TEST_CASE("sets and values") REQUIRE(std_set.size() == 1); REQUIRE(std_set.find(k1) != std_set.end()); REQUIRE(std_set.find(k2) == std_set.end()); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -275,7 +275,7 @@ TEST_CASE("sets and values") REQUIRE(set_handle->contains_globally_committed(k1)); REQUIRE(!set_handle->contains_globally_committed(k2)); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -305,12 +305,13 @@ TEST_CASE("sets and values") std::vector local_writes; std::vector global_writes; - auto map_hook = - [&](kv::Version v, const Set::Write& w) -> kv::ConsensusHookPtr { + auto map_hook = [&]( + ccf::kv::Version v, + const Set::Write& w) -> ccf::kv::ConsensusHookPtr { local_writes.push_back(w); - return kv::ConsensusHookPtr(nullptr); + return ccf::kv::ConsensusHookPtr(nullptr); }; - auto global_hook = [&](kv::Version v, const Set::Write& w) { + auto global_hook = [&](ccf::kv::Version v, const Set::Write& w) { global_writes.push_back(w); }; @@ -326,7 +327,7 @@ TEST_CASE("sets and values") set_handle->insert(k1); set_handle->insert(k2); set_handle->remove(k2); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE(global_writes.size() == 0); REQUIRE(local_writes.size() == 1); @@ -345,7 +346,7 @@ TEST_CASE("sets and values") auto set_handle = tx.rw(set); set_handle->remove(k1); set_handle->insert(k2); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE(local_writes.size() == 1); const auto& latest_writes = local_writes.front(); @@ -362,7 +363,7 @@ TEST_CASE("sets and values") auto tx = kv_store.create_tx(); auto set_handle = tx.rw(set); set_handle->insert(k1); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); kv_store.compact(kv_store.current_version()); @@ -383,8 +384,8 @@ TEST_CASE("sets and values") } { - INFO("kv::Value"); - using Value = kv::Value; + INFO("ccf::kv::Value"); + using Value = ccf::kv::Value; Value val1("public:value1"); Value val2("public:value2"); @@ -415,7 +416,7 @@ TEST_CASE("sets and values") h2->clear(); REQUIRE(!h2->has()); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -429,7 +430,7 @@ TEST_CASE("sets and values") auto h2 = tx.rw(val2); REQUIRE(!h2->has()); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -441,7 +442,7 @@ TEST_CASE("sets and values") h1->clear(); REQUIRE(!h1->has()); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -452,12 +453,13 @@ TEST_CASE("sets and values") std::vector local_writes; std::vector global_writes; - auto map_hook = - [&](kv::Version v, const Value::Write& w) -> kv::ConsensusHookPtr { + auto map_hook = [&]( + ccf::kv::Version v, + const Value::Write& w) -> ccf::kv::ConsensusHookPtr { local_writes.push_back(w); - return kv::ConsensusHookPtr(nullptr); + return ccf::kv::ConsensusHookPtr(nullptr); }; - auto global_hook = [&](kv::Version v, const Value::Write& w) { + auto global_hook = [&](ccf::kv::Version v, const Value::Write& w) { global_writes.push_back(w); }; @@ -470,7 +472,7 @@ TEST_CASE("sets and values") { auto tx = kv_store.create_tx(); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE(local_writes.size() == 0); // Commit without puts } @@ -479,7 +481,7 @@ TEST_CASE("sets and values") auto h1 = tx.rw(val1); h1->put(v1); h1->put(v2); // Override previous value - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE(global_writes.size() == 0); REQUIRE(local_writes.size() == 1); @@ -492,7 +494,7 @@ TEST_CASE("sets and values") auto tx = kv_store.create_tx(); auto h1 = tx.rw(val1); h1->clear(); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE(local_writes.size() == 1); auto latest_writes = local_writes.front(); @@ -507,7 +509,7 @@ TEST_CASE("sets and values") auto tx = kv_store.create_tx(); auto h1 = tx.rw(val1); h1->put(v3); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); kv_store.compact(kv_store.current_version()); @@ -524,10 +526,10 @@ TEST_CASE("sets and values") // Sanity check that transactions can handle a mix of maps, sets, and values INFO("Mixed"); - using TMap = kv::Map; - using TSet = kv::Set; - kv::Value map_name_val("public:map_name"); - kv::Value set_name_val("public:set_name"); + using TMap = ccf::kv::Map; + using TSet = ccf::kv::Set; + ccf::kv::Value map_name_val("public:map_name"); + ccf::kv::Value set_name_val("public:set_name"); constexpr auto n_entries = 10; @@ -554,7 +556,7 @@ TEST_CASE("sets and values") REQUIRE(map_handle->size() == n_entries); REQUIRE(set_handle->size() == n_entries); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -594,16 +596,16 @@ TEST_CASE("sets and values") REQUIRE(map_handle->size() == n_entries); REQUIRE(set_handle->size() == n_entries); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } } } struct CustomUnitCreator { - static kv::serialisers::SerialisedEntry get() + static ccf::kv::serialisers::SerialisedEntry get() { - kv::serialisers::SerialisedEntry e; + ccf::kv::serialisers::SerialisedEntry e; for (size_t i = 0; i < 42; ++i) { @@ -624,16 +626,16 @@ TEST_CASE("serialisation of Unit type") const auto v3 = "saluton"; { - INFO("The default unit type allows migration to/from a kv::Map"); + INFO("The default unit type allows migration to/from a ccf::kv::Map"); - using TValue = kv::RawCopySerialisedValue; - using TValueEquivalent = kv::RawCopySerialisedMap; + using TValue = ccf::kv::RawCopySerialisedValue; + using TValueEquivalent = ccf::kv::RawCopySerialisedMap; - using TSet = kv::RawCopySerialisedSet; - using TSetEquivalent = kv::RawCopySerialisedMap; + using TSet = ccf::kv::RawCopySerialisedSet; + using TSetEquivalent = ccf::kv::RawCopySerialisedMap; - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); { @@ -648,7 +650,7 @@ TEST_CASE("serialisation of Unit type") set_handle->put(v2, 1); // Will be visible in TSet handle, but would be // written with different value - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -665,7 +667,7 @@ TEST_CASE("serialisation of Unit type") set_handle->insert(v2); set_handle->insert(v3); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -685,68 +687,68 @@ TEST_CASE("serialisation of Unit type") REQUIRE(set_handle->has(v3)); REQUIRE(*set_handle->get(v3) == 0); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } } { INFO("Custom UnitCreators produce distinct ledger entries"); - using ValueA = kv::TypedValue< + using ValueA = ccf::kv::TypedValue< std::string, - kv::serialisers::BlitSerialiser, - kv::serialisers::ZeroBlitUnitCreator>; + ccf::kv::serialisers::BlitSerialiser, + ccf::kv::serialisers::ZeroBlitUnitCreator>; std::vector entry_a; { - auto consensus = std::make_shared(); - kv::Store kv_store; - auto encryptor = std::make_shared(); + auto consensus = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); kv_store.set_consensus(consensus); auto tx = kv_store.create_tx(); auto val_handle = tx.rw(value_name); val_handle->put(v1); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); const auto e = consensus->get_latest_data(); REQUIRE(e.has_value()); entry_a = e.value(); } - using ValueB = kv::TypedValue< + using ValueB = ccf::kv::TypedValue< std::string, - kv::serialisers::BlitSerialiser, - kv::serialisers::EmptyUnitCreator>; + ccf::kv::serialisers::BlitSerialiser, + ccf::kv::serialisers::EmptyUnitCreator>; std::vector entry_b; { - auto consensus = std::make_shared(); - kv::Store kv_store; - auto encryptor = std::make_shared(); + auto consensus = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); kv_store.set_consensus(consensus); auto tx = kv_store.create_tx(); auto val_handle = tx.rw(value_name); val_handle->put(v1); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); const auto e = consensus->get_latest_data(); REQUIRE(e.has_value()); entry_b = e.value(); } - using ValueC = kv::TypedValue< + using ValueC = ccf::kv::TypedValue< std::string, - kv::serialisers::BlitSerialiser, + ccf::kv::serialisers::BlitSerialiser, CustomUnitCreator>; std::vector entry_c; { - auto consensus = std::make_shared(); - kv::Store kv_store; - auto encryptor = std::make_shared(); + auto consensus = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); kv_store.set_consensus(consensus); auto tx = kv_store.create_tx(); auto val_handle = tx.rw(value_name); val_handle->put(v1); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); const auto e = consensus->get_latest_data(); REQUIRE(e.has_value()); entry_c = e.value(); @@ -760,8 +762,8 @@ TEST_CASE("serialisation of Unit type") TEST_CASE("multiple handles") { - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); MapTypes::NumString map("public:map"); @@ -796,8 +798,8 @@ TEST_CASE("multiple handles") TEST_CASE("clear") { - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); MapTypes::StringString map("public:map"); @@ -812,7 +814,7 @@ TEST_CASE("clear") auto handle = tx.rw(map); handle->put(k1, v); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } SUBCASE("Basic") @@ -831,7 +833,7 @@ TEST_CASE("clear") REQUIRE(!handle->has(k1)); REQUIRE(!handle->has(k2)); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -841,7 +843,7 @@ TEST_CASE("clear") REQUIRE(!handle->has(k1)); REQUIRE(!handle->has(k2)); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } } @@ -855,17 +857,17 @@ TEST_CASE("clear") auto tx2 = kv_store.create_tx(); auto handle2 = tx2.rw(map); handle2->put(k2, v); - REQUIRE(tx2.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx2.commit() == ccf::kv::CommitResult::SUCCESS); INFO("clear() conflicts and must be retried"); - REQUIRE(tx1.commit() == kv::CommitResult::FAIL_CONFLICT); + REQUIRE(tx1.commit() == ccf::kv::CommitResult::FAIL_CONFLICT); } } TEST_CASE("get_version_of_previous_write") { - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); MapTypes::StringString map("public:map"); @@ -883,7 +885,7 @@ TEST_CASE("get_version_of_previous_write") handle->put(k1, v1); handle->put(k2, v1); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } const auto first_version = kv_store.current_version(); @@ -894,7 +896,7 @@ TEST_CASE("get_version_of_previous_write") handle->put(k1, v2); handle->remove(k2); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } const auto second_version = kv_store.current_version(); @@ -966,7 +968,7 @@ TEST_CASE("get_version_of_previous_write") } // This conflicts with tx_other so is not committed - REQUIRE(tx.commit() == kv::CommitResult::FAIL_CONFLICT); + REQUIRE(tx.commit() == ccf::kv::CommitResult::FAIL_CONFLICT); } } @@ -990,8 +992,8 @@ TEST_CASE("get_version_of_previous_write") TEST_CASE("size") { - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); MapTypes::StringString map("public:map"); @@ -1021,7 +1023,7 @@ TEST_CASE("size") handle->put(k1, v); REQUIRE(handle->size() == 2); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -1052,7 +1054,7 @@ TEST_CASE("size") } REQUIRE(handle->size() == 0); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -1082,15 +1084,15 @@ TEST_CASE("size") }); REQUIRE(claimed_size == manual_size); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } } } TEST_CASE("foreach") { - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); MapTypes::StringString map("public:map"); @@ -1138,7 +1140,7 @@ TEST_CASE("foreach") auto handle = tx.rw(map); handle->put("key1", "value1"); handle->put("key2", "value2"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); auto tx2 = kv_store.create_tx(); auto handle2 = tx2.rw(map); @@ -1154,7 +1156,7 @@ TEST_CASE("foreach") auto handle = tx.rw(map); handle->put("key1", "value1"); handle->put("key2", "value2"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); auto tx2 = kv_store.create_tx(); auto handle2 = tx2.rw(map); @@ -1175,14 +1177,14 @@ TEST_CASE("foreach") handle->put("key1", "value1"); handle->put("key2", "value2"); handle->put("key3", "value3"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { auto tx = kv_store.create_tx(); auto handle = tx.rw(map); handle->remove("key1"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -1227,7 +1229,7 @@ TEST_CASE("foreach") // never see the third) }); REQUIRE(ctr == 2); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -1273,12 +1275,12 @@ TEST_CASE("foreach") template struct NoDeserialise { - static kv::serialisers::SerialisedEntry to_serialised(const T& t) + static ccf::kv::serialisers::SerialisedEntry to_serialised(const T& t) { - return kv::serialisers::JsonSerialiser::to_serialised(t); + return ccf::kv::serialisers::JsonSerialiser::to_serialised(t); } - static T from_serialised(const kv::serialisers::SerialisedEntry& s) + static T from_serialised(const ccf::kv::serialisers::SerialisedEntry& s) { throw std::logic_error("This deserialiser should not be called"); } @@ -1286,14 +1288,14 @@ struct NoDeserialise TEST_CASE("foreach_key") { - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); - kv::MapSerialisedWith< + ccf::kv::MapSerialisedWith< std::string, std::string, - kv::serialisers::JsonSerialiser, + ccf::kv::serialisers::JsonSerialiser, NoDeserialise> map("public:map"); @@ -1303,7 +1305,7 @@ TEST_CASE("foreach_key") handle->put("k1", "v1"); handle->put("k2", "v2"); handle->put("k3", "v3"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -1323,15 +1325,15 @@ TEST_CASE("foreach_key") TEST_CASE("foreach_value") { - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); - kv::MapSerialisedWith< + ccf::kv::MapSerialisedWith< std::string, std::string, NoDeserialise, - kv::serialisers::JsonSerialiser> + ccf::kv::serialisers::JsonSerialiser> map("public:map"); { @@ -1340,7 +1342,7 @@ TEST_CASE("foreach_value") handle->put("k1", "v1"); handle->put("k2", "v2"); handle->put("k3", "v3"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -1359,8 +1361,8 @@ TEST_CASE("foreach_value") TEST_CASE("Modifications during foreach iteration") { - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); MapTypes::NumString map("public:map"); @@ -1379,7 +1381,7 @@ TEST_CASE("Modifications during foreach iteration") handle->put(i, value1); } - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } auto tx = kv_store.create_tx(); @@ -1622,8 +1624,8 @@ TEST_CASE("Modifications during foreach iteration") TEST_CASE("Read-only tx") { - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); MapTypes::StringString map("public:map"); @@ -1641,7 +1643,7 @@ TEST_CASE("Read-only tx") auto va = handle->get(k); REQUIRE(va.has_value()); REQUIRE(va.value() == v1); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } INFO("Do only reads with an overpowered Tx"); @@ -1697,8 +1699,8 @@ TEST_CASE("Read-only tx") TEST_CASE("Rollback and compact") { - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); MapTypes::StringString map("public:map"); @@ -1711,13 +1713,13 @@ TEST_CASE("Rollback and compact") auto tx2 = kv_store.create_tx(); auto handle = tx.rw(map); handle->put(k, v1); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); kv_store.rollback({kv_store.commit_view(), 0}, kv_store.commit_view()); auto handle2 = tx2.rw(map); auto v = handle2->get(k); REQUIRE(!v.has_value()); - REQUIRE(tx2.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx2.commit() == ccf::kv::CommitResult::SUCCESS); } INFO("Read committed key"); @@ -1726,7 +1728,7 @@ TEST_CASE("Rollback and compact") auto tx2 = kv_store.create_tx(); auto handle = tx.rw(map); handle->put(k, v1); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); kv_store.compact(kv_store.current_version()); auto handle2 = tx2.rw(map); @@ -1741,7 +1743,7 @@ TEST_CASE("Rollback and compact") auto tx2 = kv_store.create_tx(); auto handle = tx.rw(map); handle->remove(k); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); kv_store.compact(kv_store.current_version()); auto handle2 = tx2.rw(map); @@ -1756,16 +1758,17 @@ TEST_CASE("Local commit hooks") std::vector local_writes; std::vector global_writes; - auto map_hook = [&](kv::Version v, const Write& w) -> kv::ConsensusHookPtr { + auto map_hook = + [&](ccf::kv::Version v, const Write& w) -> ccf::kv::ConsensusHookPtr { local_writes.push_back(w); - return kv::ConsensusHookPtr(nullptr); + return ccf::kv::ConsensusHookPtr(nullptr); }; - auto global_hook = [&](kv::Version v, const Write& w) { + auto global_hook = [&](ccf::kv::Version v, const Write& w) { global_writes.push_back(w); }; - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); constexpr auto map_name = "public:map"; MapTypes::StringString map(map_name); @@ -1780,7 +1783,7 @@ TEST_CASE("Local commit hooks") handle->put("key1", "value1"); handle->put("key2", "value2"); handle->remove("key2"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE(global_writes.size() == 0); REQUIRE(local_writes.size() == 1); @@ -1797,7 +1800,7 @@ TEST_CASE("Local commit hooks") auto tx = kv_store.create_tx(); auto handle = tx.rw(map); handle->remove("key1"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE(global_writes.size() == 0); REQUIRE(local_writes.size() == 1); @@ -1818,7 +1821,7 @@ TEST_CASE("Local commit hooks") auto tx = kv_store.create_tx(); auto handle = tx.rw(map); handle->put("key2", "value2"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE(local_writes.size() == 0); REQUIRE(global_writes.size() == 0); @@ -1833,7 +1836,7 @@ TEST_CASE("Local commit hooks") auto handle = tx.rw(map); handle->remove("key2"); handle->put("key3", "value3"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE(global_writes.size() == 0); REQUIRE(local_writes.size() == 1); @@ -1860,20 +1863,20 @@ TEST_CASE("Global commit hooks") struct GlobalHookInput { - kv::Version version; + ccf::kv::Version version; Write writes; }; std::vector global_writes; - auto global_hook = [&](kv::Version v, const Write& w) { + auto global_hook = [&](ccf::kv::Version v, const Write& w) { global_writes.emplace_back(GlobalHookInput({v, w})); }; - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); - using MapT = kv::Map; + using MapT = ccf::kv::Map; MapT map_with_hook("public:map_with_hook"); kv_store.set_global_hook( map_with_hook.get_name(), map_with_hook.wrap_commit_hook(global_hook)); @@ -1892,7 +1895,7 @@ TEST_CASE("Global commit hooks") auto tx1 = kv_store.create_tx(); auto handle_hook = tx1.rw(map_with_hook); handle_hook->put("key1", "value1"); - REQUIRE(tx1.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx1.commit() == ccf::kv::CommitResult::SUCCESS); kv_store.compact(1); @@ -1912,11 +1915,11 @@ TEST_CASE("Global commit hooks") auto tx3 = kv_store.create_tx(); auto handle_hook = tx1.rw(map_with_hook); handle_hook->put("key1", "value1"); - REQUIRE(tx1.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx1.commit() == ccf::kv::CommitResult::SUCCESS); handle_hook = tx2.rw(map_with_hook); handle_hook->put("key2", "value2"); - REQUIRE(tx2.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx2.commit() == ccf::kv::CommitResult::SUCCESS); const auto compact_version = kv_store.current_version(); @@ -1924,7 +1927,7 @@ TEST_CASE("Global commit hooks") // version of the store auto handle_no_hook = tx3.rw(map_no_hook); handle_no_hook->put("key3", "value3"); - REQUIRE(tx3.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx3.commit() == ccf::kv::CommitResult::SUCCESS); kv_store.compact(compact_version); @@ -1949,19 +1952,19 @@ TEST_CASE("Global commit hooks") auto tx3 = kv_store.create_tx(); auto handle_hook = tx1.rw(map_with_hook); handle_hook->put("key1", "value1"); - REQUIRE(tx1.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx1.commit() == ccf::kv::CommitResult::SUCCESS); // This does not affect map_with_hook but still increments the current // version of the store auto handle_no_hook = tx2.rw(map_no_hook); handle_no_hook->put("key2", "value2"); - REQUIRE(tx2.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx2.commit() == ccf::kv::CommitResult::SUCCESS); const auto compact_version = kv_store.current_version(); handle_hook = tx3.rw(map_with_hook); handle_hook->put("key3", "value3"); - REQUIRE(tx3.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx3.commit() == ccf::kv::CommitResult::SUCCESS); kv_store.compact(compact_version); @@ -1981,14 +1984,14 @@ TEST_CASE("Global commit hooks") auto tx2 = kv_store.create_tx(); auto handle_hook = tx1.rw(map_with_hook); handle_hook->put("key1", "value1"); - REQUIRE(tx1.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx1.commit() == ccf::kv::CommitResult::SUCCESS); kv_store.compact(kv_store.current_version()); global_writes.clear(); handle_hook = tx2.rw(map_with_hook); handle_hook->put("key2", "value2"); - REQUIRE(tx2.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx2.commit() == ccf::kv::CommitResult::SUCCESS); kv_store.compact(kv_store.current_version()); @@ -2004,8 +2007,8 @@ TEST_CASE("Global commit hooks") TEST_CASE("Deserialising from other Store") { - auto encryptor = std::make_shared(); - kv::Store store; + auto encryptor = std::make_shared(); + ccf::kv::Store store; store.set_encryptor(encryptor); MapTypes::NumString public_map("public:public"); @@ -2019,18 +2022,18 @@ TEST_CASE("Deserialising from other Store") tx1.commit_reserved(); auto& success = success_; auto& data = data_; - REQUIRE(success == kv::CommitResult::SUCCESS); + REQUIRE(success == ccf::kv::CommitResult::SUCCESS); - kv::Store clone; + ccf::kv::Store clone; clone.set_encryptor(encryptor); - REQUIRE(clone.deserialize(data)->apply() == kv::ApplyResult::PASS); + REQUIRE(clone.deserialize(data)->apply() == ccf::kv::ApplyResult::PASS); } TEST_CASE("Deserialise return status") { - kv::Store store; - auto encryptor = std::make_shared(); + ccf::kv::Store store; + auto encryptor = std::make_shared(); store.set_encryptor(encryptor); ccf::Signatures signatures(ccf::Tables::SIGNATURES); @@ -2043,8 +2046,8 @@ TEST_CASE("Deserialise return status") constexpr auto default_curve = ccf::crypto::CurveID::SECP384R1; auto kp = ccf::crypto::make_key_pair(default_curve); - auto history = - std::make_shared(store, kv::test::PrimaryNodeId, *kp); + auto history = std::make_shared( + store, ccf::kv::test::PrimaryNodeId, *kp); store.set_history(history); { @@ -2055,26 +2058,26 @@ TEST_CASE("Deserialise return status") tx.commit_reserved(); auto& success = success_; auto& data = data_; - REQUIRE(success == kv::CommitResult::SUCCESS); + REQUIRE(success == ccf::kv::CommitResult::SUCCESS); - REQUIRE(store.deserialize(data)->apply() == kv::ApplyResult::PASS); + REQUIRE(store.deserialize(data)->apply() == ccf::kv::ApplyResult::PASS); } { auto tx = store.create_reserved_tx(store.next_txid()); auto sig_handle = tx.rw(signatures); auto tree_handle = tx.rw(serialised_tree); - ccf::PrimarySignature sigv(kv::test::PrimaryNodeId, 2); + ccf::PrimarySignature sigv(ccf::kv::test::PrimaryNodeId, 2); sig_handle->put(sigv); tree_handle->put({}); auto [success_, data_, claims_digest, commit_evidence_digest, hooks] = tx.commit_reserved(); auto& success = success_; auto& data = data_; - REQUIRE(success == kv::CommitResult::SUCCESS); + REQUIRE(success == ccf::kv::CommitResult::SUCCESS); REQUIRE( - store.deserialize(data)->apply() == kv::ApplyResult::PASS_SIGNATURE); + store.deserialize(data)->apply() == ccf::kv::ApplyResult::PASS_SIGNATURE); } INFO("Signature transactions with additional contents should fail"); @@ -2082,26 +2085,26 @@ TEST_CASE("Deserialise return status") auto tx = store.create_reserved_tx(store.next_txid()); auto sig_handle = tx.rw(signatures); auto data_handle = tx.rw(data); - ccf::PrimarySignature sigv(kv::test::PrimaryNodeId, 2); + ccf::PrimarySignature sigv(ccf::kv::test::PrimaryNodeId, 2); sig_handle->put(sigv); data_handle->put(43, 43); auto [success_, data_, claims_digest, commit_evidence_digest, hooks] = tx.commit_reserved(); auto& success = success_; auto& data = data_; - REQUIRE(success == kv::CommitResult::SUCCESS); + REQUIRE(success == ccf::kv::CommitResult::SUCCESS); - REQUIRE(store.deserialize(data)->apply() == kv::ApplyResult::FAIL); + REQUIRE(store.deserialize(data)->apply() == ccf::kv::ApplyResult::FAIL); } } TEST_CASE("Map swap between stores") { - auto encryptor = std::make_shared(); - kv::Store s1; + auto encryptor = std::make_shared(); + ccf::kv::Store s1; s1.set_encryptor(encryptor); - kv::Store s2; + ccf::kv::Store s2; s2.set_encryptor(encryptor); MapTypes::NumNum d("data"); @@ -2111,14 +2114,14 @@ TEST_CASE("Map swap between stores") auto tx = s1.create_tx(); auto v = tx.rw(d); v->put(42, 42); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { auto tx = s1.create_tx(); auto v = tx.rw(pd); v->put(14, 14); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } const auto target_version = s1.current_version(); @@ -2127,7 +2130,7 @@ TEST_CASE("Map swap between stores") auto tx = s2.create_tx(); auto v = tx.rw(d); v->put(41, 41); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } s2.swap_private_maps(s1); @@ -2167,13 +2170,13 @@ TEST_CASE("Map swap between stores") TEST_CASE("Private recovery map swap") { - auto encryptor = std::make_shared(); - kv::Store s1; + auto encryptor = std::make_shared(); + ccf::kv::Store s1; s1.set_encryptor(encryptor); MapTypes::NumNum priv1("private"); MapTypes::NumString pub1("public:data"); - kv::Store s2; + ccf::kv::Store s2; s2.set_encryptor(encryptor); MapTypes::NumNum priv2("private"); MapTypes::NumString pub2("public:data"); @@ -2309,8 +2312,8 @@ TEST_CASE("Private recovery map swap") TEST_CASE("Conflict resolution") { - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); MapTypes::StringString map("public:map"); @@ -2319,10 +2322,10 @@ TEST_CASE("Conflict resolution") auto tx = kv_store.create_tx(); auto handle = tx.rw(map); handle->put("foo", "initial"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } - auto try_write = [&](kv::Tx& tx, const std::string& s) { + auto try_write = [&](ccf::kv::Tx& tx, const std::string& s) { auto handle = tx.rw(map); // Introduce read-dependency @@ -2365,14 +2368,14 @@ TEST_CASE("Conflict resolution") // A second transaction is committed, conflicting with the first try_write(tx2, "baz"); const auto res2 = tx2.commit(); - REQUIRE(res2 == kv::CommitResult::SUCCESS); + REQUIRE(res2 == ccf::kv::CommitResult::SUCCESS); confirm_state({"baz"}, {"bar"}); } // Trying to commit first transaction produces a conflict auto res1 = tx1.commit(); - REQUIRE(res1 == kv::CommitResult::FAIL_CONFLICT); + REQUIRE(res1 == ccf::kv::CommitResult::FAIL_CONFLICT); confirm_state({"baz"}, {"bar"}); // A third transaction just wants to read the value @@ -2386,13 +2389,13 @@ TEST_CASE("Conflict resolution") // Expected results are committed res1 = tx1.commit(); - REQUIRE(res1 == kv::CommitResult::SUCCESS); + REQUIRE(res1 == ccf::kv::CommitResult::SUCCESS); confirm_state({"baz", "buzz"}, {"bar"}); // Third transaction completes later, has no conflicts but reports the earlier // version it read auto res3 = tx3.commit(); - REQUIRE(res3 == kv::CommitResult::SUCCESS); + REQUIRE(res3 == ccf::kv::CommitResult::SUCCESS); REQUIRE(tx1.commit_version() > tx2.commit_version()); REQUIRE(tx3.get_txid()->version >= tx2.get_txid()->version); @@ -2419,8 +2422,8 @@ TEST_CASE("Conflict resolution - removals") auto c = Cases(i); INFO("Considering case " << c); - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); MapTypes::StringString map("public:map"); @@ -2428,7 +2431,7 @@ TEST_CASE("Conflict resolution - removals") // Ensure maps already exist, by making prior writes auto tx = kv_store.create_tx(); tx.rw(map)->put("", ""); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } // Simulate parallel execution by interleaving tx steps @@ -2477,12 +2480,12 @@ TEST_CASE("Conflict resolution - removals") { auto handle = tx2.rw(map); handle->put(k, "hello"); - REQUIRE(tx2.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx2.commit() == ccf::kv::CommitResult::SUCCESS); } const auto expected = c == Cases::ReadSameKey ? - kv::CommitResult::FAIL_CONFLICT : - kv::CommitResult::SUCCESS; + ccf::kv::CommitResult::FAIL_CONFLICT : + ccf::kv::CommitResult::SUCCESS; CHECK_EQ(tx1.commit(), expected); @@ -2508,8 +2511,8 @@ TEST_CASE("Conflict resolution - removals") TEST_CASE("Cross-map conflicts") { - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); MapTypes::StringString source("public:source"); MapTypes::StringString dest("public:dest"); @@ -2520,7 +2523,7 @@ TEST_CASE("Cross-map conflicts") auto tx = kv_store.create_tx(); auto source_handle = tx.wo(source); source_handle->put("hello", "world"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } { @@ -2541,11 +2544,11 @@ TEST_CASE("Cross-map conflicts") auto interfere_tx = kv_store.create_tx(); auto src_handle = interfere_tx.wo(source); src_handle->put("hello", "alice"); - REQUIRE(interfere_tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(interfere_tx.commit() == ccf::kv::CommitResult::SUCCESS); } INFO("Copying operation should conflict on commit"); - REQUIRE(copy_tx.commit() == kv::CommitResult::FAIL_CONFLICT); + REQUIRE(copy_tx.commit() == ccf::kv::CommitResult::FAIL_CONFLICT); } { @@ -2570,11 +2573,11 @@ TEST_CASE("Cross-map conflicts") auto interfere_tx = kv_store.create_tx(); auto src_handle = interfere_tx.wo(source); src_handle->put("hello", "bob"); - REQUIRE(interfere_tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(interfere_tx.commit() == ccf::kv::CommitResult::SUCCESS); } INFO("Moving operation should conflict on commit"); - REQUIRE(move_tx.commit() == kv::CommitResult::FAIL_CONFLICT); + REQUIRE(move_tx.commit() == ccf::kv::CommitResult::FAIL_CONFLICT); } } @@ -2585,8 +2588,8 @@ std::string rand_string(size_t i) TEST_CASE("Mid-tx compaction") { - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); MapTypes::StringNum map_a("public:A"); MapTypes::StringNum map_b("public:B"); @@ -2610,7 +2613,7 @@ TEST_CASE("Mid-tx compaction") handle_b->put(key_b, new_val); const auto result = tx.commit(); - REQUIRE(result == kv::CommitResult::SUCCESS); + REQUIRE(result == ccf::kv::CommitResult::SUCCESS); }; increment_vals(); @@ -2631,7 +2634,7 @@ TEST_CASE("Mid-tx compaction") REQUIRE(a_opt == b_opt); const auto result = tx.commit(); - REQUIRE(result == kv::CommitResult::SUCCESS); + REQUIRE(result == ccf::kv::CommitResult::SUCCESS); } { @@ -2649,7 +2652,7 @@ TEST_CASE("Mid-tx compaction") REQUIRE(a_opt == b_opt); const auto result = tx.commit(); - REQUIRE(result == kv::CommitResult::SUCCESS); + REQUIRE(result == ccf::kv::CommitResult::SUCCESS); } { @@ -2679,9 +2682,9 @@ TEST_CASE("Mid-tx compaction") REQUIRE(a_opt == b_opt); const auto result = tx.commit(); - REQUIRE(result == kv::CommitResult::SUCCESS); + REQUIRE(result == ccf::kv::CommitResult::SUCCESS); } - catch (const kv::CompactedVersionConflict& e) + catch (const ccf::kv::CompactedVersionConflict& e) { threw = true; } @@ -2694,8 +2697,8 @@ TEST_CASE("Mid-tx compaction") TEST_CASE("Store clear") { - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); kv_store.initialise_term(42); @@ -2715,7 +2718,7 @@ TEST_CASE("Store clear") handle_a->put("key" + std::to_string(i), 42); handle_b->put("key" + std::to_string(i), 42); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } auto current_version = kv_store.current_version(); @@ -2749,18 +2752,18 @@ TEST_CASE("Store clear") TEST_CASE("Reported TxID after commit") { - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); - auto consensus = std::make_shared(); + auto consensus = std::make_shared(); kv_store.set_consensus(consensus); const auto map_name = "public:map"; MapTypes::StringString map(map_name); auto store_last_seqno = kv_store.current_version(); - kv::Term initial_term = 2; - kv::Term store_commit_term = initial_term; - kv::Term store_read_term = 0; + ccf::kv::Term initial_term = 2; + ccf::kv::Term store_commit_term = initial_term; + ccf::kv::Term store_read_term = 0; INFO("Initialise store"); { @@ -2772,13 +2775,14 @@ TEST_CASE("Reported TxID after commit") auto tx = kv_store.create_tx(); auto handle = tx.rw(map); handle->put("key", "value"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); store_read_term = store_commit_term; } REQUIRE(kv_store.current_version() == store_last_seqno); REQUIRE_EQ( - kv_store.current_txid(), kv::TxID(store_read_term, store_last_seqno)); + kv_store.current_txid(), + ccf::kv::TxID(store_read_term, store_last_seqno)); } INFO("Empty committed tx"); @@ -2790,7 +2794,7 @@ TEST_CASE("Reported TxID after commit") // Tx is not yet committed REQUIRE_THROWS_AS(tx.get_txid(), std::logic_error); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); // Committed transaction was not assigned a TxID because it was empty REQUIRE_FALSE(tx.get_txid().has_value()); @@ -2807,7 +2811,7 @@ TEST_CASE("Reported TxID after commit") // No need to read a key, acquiring a map handle is sufficient to acquire a // valid TxID - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); // Reported TxID includes store read term and last seqno auto tx_id = tx.get_txid(); @@ -2827,7 +2831,7 @@ TEST_CASE("Reported TxID after commit") // Rollback at the current TxID, in the next term kv_store.rollback(kv_store.current_txid(), ++store_commit_term); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); auto tx_id = tx.get_txid(); REQUIRE(tx_id.has_value()); @@ -2845,7 +2849,7 @@ TEST_CASE("Reported TxID after commit") auto tx = kv_store.create_tx(); auto handle = tx.ro(map); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); auto tx_id = tx.get_txid(); REQUIRE(tx_id.has_value()); @@ -2862,7 +2866,7 @@ TEST_CASE("Reported TxID after commit") auto tx = kv_store.create_tx(); auto handle = tx.ro(map); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); auto tx_id = tx.get_txid(); REQUIRE(tx_id.has_value()); @@ -2877,7 +2881,7 @@ TEST_CASE("Reported TxID after commit") auto tx = kv_store.create_tx(); auto handle = tx.rw(map); handle->put("key", "value"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); store_last_seqno = kv_store.current_version(); store_read_term = store_commit_term; @@ -2893,7 +2897,7 @@ TEST_CASE("Reported TxID after commit") // Read-only tx should report the new term auto tx = kv_store.create_tx(); auto handle = tx.ro(map); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); auto tx_id = tx.get_txid(); REQUIRE(tx_id.has_value()); @@ -2907,7 +2911,7 @@ TEST_CASE("Reported TxID after commit") auto tx = kv_store.create_tx(); auto handle = tx.ro(map); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); auto tx_id = tx.get_txid(); REQUIRE(tx_id.has_value()); @@ -2926,7 +2930,7 @@ TEST_CASE("Reported TxID after commit") auto tx = kv_store.create_tx(); auto handle = tx.ro(map); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); auto tx_id = tx.get_txid(); REQUIRE(tx_id.has_value()); @@ -2986,19 +2990,19 @@ std::map kv_map_range(H& h, std::optional from, std::optional to) TEST_CASE("Range") { - using KVMap = kv::untyped::Map; + using KVMap = ccf::kv::untyped::Map; using KeyType = KVMap::K; using ValueType = KVMap::V; using RefMap = std::map; - using Serialiser = kv::serialisers::JsonSerialiser; + using Serialiser = ccf::kv::serialisers::JsonSerialiser; size_t size = 100; size_t entries_space_size = size * 10; const auto map_name = "public:map"; const ValueType empty_value = {}; - kv::Store kv_store; - auto encryptor = std::make_shared(); + ccf::kv::Store kv_store; + auto encryptor = std::make_shared(); kv_store.set_encryptor(encryptor); RefMap ref; @@ -3020,7 +3024,7 @@ TEST_CASE("Range") h->put(serialised_key, empty_value); ref[serialised_key] = empty_value; } - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } INFO("Compare ranges between KV map and reference"); @@ -3076,7 +3080,7 @@ TEST_CASE("Range") h->remove(key_to_remove); REQUIRE(ref.erase(key_to_remove) == 1); } - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } INFO("Range does not include key"); @@ -3127,9 +3131,9 @@ TEST_CASE("Range") TEST_CASE("Ledger entry chunk request") { - kv::Store store; - auto encryptor = std::make_shared(); - auto consensus = std::make_shared(); + ccf::kv::Store store; + auto encryptor = std::make_shared(); + auto consensus = std::make_shared(); store.set_encryptor(encryptor); store.set_consensus(consensus); @@ -3143,15 +3147,15 @@ TEST_CASE("Ledger entry chunk request") constexpr auto default_curve = ccf::crypto::CurveID::SECP384R1; auto kp = ccf::crypto::make_key_pair(default_curve); - auto history = - std::make_shared(store, kv::test::PrimaryNodeId, *kp); + auto history = std::make_shared( + store, ccf::kv::test::PrimaryNodeId, *kp); store.set_history(history); SUBCASE("Chunk at next signature") { // Ledger chunk flag is not set in the store REQUIRE(!store.flag_enabled( - kv::AbstractStore::Flag::LEDGER_CHUNK_AT_NEXT_SIGNATURE)); + ccf::kv::AbstractStore::Flag::LEDGER_CHUNK_AT_NEXT_SIGNATURE)); INFO("Add a transaction with the chunking flag enabled"); { @@ -3159,16 +3163,16 @@ TEST_CASE("Ledger entry chunk request") auto tx = store.create_tx(); // Request a ledger chunk at the next signature - tx.set_flag(kv::CommittableTx::Flag::LEDGER_CHUNK_AT_NEXT_SIGNATURE); + tx.set_flag(ccf::kv::CommittableTx::Flag::LEDGER_CHUNK_AT_NEXT_SIGNATURE); auto h1 = tx.rw(map); h1->put("key", "value"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } // Flag is now set in the store REQUIRE(store.flag_enabled( - kv::AbstractStore::Flag::LEDGER_CHUNK_AT_NEXT_SIGNATURE)); + ccf::kv::AbstractStore::Flag::LEDGER_CHUNK_AT_NEXT_SIGNATURE)); INFO("Roll back the last transaction"); { @@ -3178,7 +3182,7 @@ TEST_CASE("Ledger entry chunk request") // Ledger chunk flag is still set in the store REQUIRE(store.flag_enabled( - kv::AbstractStore::Flag::LEDGER_CHUNK_AT_NEXT_SIGNATURE)); + ccf::kv::AbstractStore::Flag::LEDGER_CHUNK_AT_NEXT_SIGNATURE)); // Roll the last transaction back to clear the flag in the store store.rollback( @@ -3187,7 +3191,7 @@ TEST_CASE("Ledger entry chunk request") // Ledger chunk flag is not set in the store anymore REQUIRE(!store.flag_enabled( - kv::AbstractStore::Flag::LEDGER_CHUNK_AT_NEXT_SIGNATURE)); + ccf::kv::AbstractStore::Flag::LEDGER_CHUNK_AT_NEXT_SIGNATURE)); } INFO("Add another transaction with the chunking flag enabled"); @@ -3196,16 +3200,16 @@ TEST_CASE("Ledger entry chunk request") auto tx = store.create_tx(); // Request a ledger chunk at the next signature again - tx.set_flag(kv::CommittableTx::Flag::LEDGER_CHUNK_AT_NEXT_SIGNATURE); + tx.set_flag(ccf::kv::CommittableTx::Flag::LEDGER_CHUNK_AT_NEXT_SIGNATURE); auto h1 = tx.rw(map); h1->put("key", "value"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } // Ledger chunk flag is now set in the store REQUIRE(store.flag_enabled( - kv::AbstractStore::Flag::LEDGER_CHUNK_AT_NEXT_SIGNATURE)); + ccf::kv::AbstractStore::Flag::LEDGER_CHUNK_AT_NEXT_SIGNATURE)); INFO( "Add a signature transaction which triggers chunk via entry header flag"); @@ -3214,29 +3218,31 @@ TEST_CASE("Ledger entry chunk request") auto tx = store.create_reserved_tx(txid); auto sig_handle = tx.rw(signatures); auto tree_handle = tx.rw(serialised_tree); - ccf::PrimarySignature sigv(kv::test::PrimaryNodeId, txid.version); + ccf::PrimarySignature sigv(ccf::kv::test::PrimaryNodeId, txid.version); sig_handle->put(sigv); tree_handle->put({}); auto [success_, data_, claims_digest, commit_evidence_digest, hooks] = tx.commit_reserved(); auto& success = success_; auto& data = data_; - REQUIRE(success == kv::CommitResult::SUCCESS); + REQUIRE(success == ccf::kv::CommitResult::SUCCESS); REQUIRE( - store.deserialize(data)->apply() == kv::ApplyResult::PASS_SIGNATURE); + store.deserialize(data)->apply() == + ccf::kv::ApplyResult::PASS_SIGNATURE); // Header flag is set in the last entry const uint8_t* entry_data = data.data(); size_t entry_data_size = data.size(); - auto header = serialized::peek( + auto header = serialized::peek( entry_data, entry_data_size); - REQUIRE((header.flags & kv::EntryFlags::FORCE_LEDGER_CHUNK_AFTER) != 0); + REQUIRE( + (header.flags & ccf::kv::EntryFlags::FORCE_LEDGER_CHUNK_AFTER) != 0); } // Ledger chunk flag is not set in the store anymore REQUIRE(!store.flag_enabled( - kv::AbstractStore::Flag::LEDGER_CHUNK_AT_NEXT_SIGNATURE)); + ccf::kv::AbstractStore::Flag::LEDGER_CHUNK_AT_NEXT_SIGNATURE)); } SUBCASE("Chunk before this transaction") @@ -3249,11 +3255,11 @@ TEST_CASE("Ledger entry chunk request") auto tx = store.create_tx(); // Request a ledger chunk before tx - tx.set_flag(kv::CommittableTx::Flag::LEDGER_CHUNK_BEFORE_THIS_TX); + tx.set_flag(ccf::kv::CommittableTx::Flag::LEDGER_CHUNK_BEFORE_THIS_TX); auto h1 = tx.rw(map); h1->put("key", "value"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } INFO("Verify that flag is included in serialised entry"); @@ -3264,15 +3270,16 @@ TEST_CASE("Ledger entry chunk request") const uint8_t* entry_data = data.data(); size_t entry_data_size = data.size(); - auto header = serialized::peek( + auto header = serialized::peek( entry_data, entry_data_size); - REQUIRE((header.flags & kv::EntryFlags::FORCE_LEDGER_CHUNK_BEFORE) != 0); + REQUIRE( + (header.flags & ccf::kv::EntryFlags::FORCE_LEDGER_CHUNK_BEFORE) != 0); } } SUBCASE("Chunk when the snapshotter requires one") { - store.set_flag(kv::AbstractStore::Flag::SNAPSHOT_AT_NEXT_SIGNATURE); + store.set_flag(ccf::kv::AbstractStore::Flag::SNAPSHOT_AT_NEXT_SIGNATURE); INFO("Add a signature that triggers a snapshot"); { @@ -3285,24 +3292,26 @@ TEST_CASE("Ledger entry chunk request") // Add the signature auto sig_handle = tx.rw(signatures); auto tree_handle = tx.rw(serialised_tree); - ccf::PrimarySignature sigv(kv::test::PrimaryNodeId, txid.version); + ccf::PrimarySignature sigv(ccf::kv::test::PrimaryNodeId, txid.version); sig_handle->put(sigv); tree_handle->put({}); auto [success_, data_, claims_digest, commit_evidence_digest, hooks] = tx.commit_reserved(); auto& success = success_; auto& data = data_; - REQUIRE(success == kv::CommitResult::SUCCESS); + REQUIRE(success == ccf::kv::CommitResult::SUCCESS); REQUIRE( - store.deserialize(data)->apply() == kv::ApplyResult::PASS_SIGNATURE); + store.deserialize(data)->apply() == + ccf::kv::ApplyResult::PASS_SIGNATURE); // Check that the ledger chunk header flag is set in the last entry const uint8_t* entry_data = data.data(); size_t entry_data_size = data.size(); - auto header = serialized::peek( + auto header = serialized::peek( entry_data, entry_data_size); - REQUIRE((header.flags & kv::EntryFlags::FORCE_LEDGER_CHUNK_AFTER) != 0); + REQUIRE( + (header.flags & ccf::kv::EntryFlags::FORCE_LEDGER_CHUNK_AFTER) != 0); } } } diff --git a/src/kv/test/null_encryptor.h b/src/kv/test/null_encryptor.h index c9a7b44deb51..c845fa66a3d2 100644 --- a/src/kv/test/null_encryptor.h +++ b/src/kv/test/null_encryptor.h @@ -4,7 +4,7 @@ #include "kv/kv_types.h" -namespace kv +namespace ccf::kv { // NullTxEncryptor does not decrypt or verify integrity class NullTxEncryptor : public AbstractTxEncryptor diff --git a/src/kv/test/stub_consensus.h b/src/kv/test/stub_consensus.h index 413861f8f68f..b6469ca56597 100644 --- a/src/kv/test/stub_consensus.h +++ b/src/kv/test/stub_consensus.h @@ -9,7 +9,7 @@ #include #include -namespace kv::test +namespace ccf::kv::test { static NodeId PrimaryNodeId = std::string("PrimaryNodeId"); static NodeId FirstBackupNodeId = std::string("FirstBackupNodeId"); diff --git a/src/kv/tx.cpp b/src/kv/tx.cpp index 5f628de656cc..8501efa53954 100644 --- a/src/kv/tx.cpp +++ b/src/kv/tx.cpp @@ -9,7 +9,7 @@ #include "kv/tx_pimpl.h" #include "kv/untyped_map.h" -namespace kv +namespace ccf::kv { MapChanges::MapChanges( const std::shared_ptr& m, @@ -75,15 +75,15 @@ namespace kv // NB: The created maps are always untyped. Only the handles over them // are typed - auto new_map = std::make_shared( - pimpl->store, map_name, kv::get_security_domain(map_name)); + auto new_map = std::make_shared( + pimpl->store, map_name, ccf::kv::get_security_domain(map_name)); pimpl->created_maps[map_name] = new_map; abstract_map = new_map; } auto untyped_map = - std::dynamic_pointer_cast(abstract_map); + std::dynamic_pointer_cast(abstract_map); if (untyped_map == nullptr) { throw std::logic_error( diff --git a/src/kv/tx_pimpl.h b/src/kv/tx_pimpl.h index 7944c9fb7315..db9ee90373e9 100644 --- a/src/kv/tx_pimpl.h +++ b/src/kv/tx_pimpl.h @@ -4,7 +4,7 @@ #include "ccf/tx.h" -namespace kv +namespace ccf::kv { struct BaseTx::PrivateImpl { diff --git a/src/kv/untyped_change_set.h b/src/kv/untyped_change_set.h index a20aa7f2b29f..6385ec84b2a3 100644 --- a/src/kv/untyped_change_set.h +++ b/src/kv/untyped_change_set.h @@ -14,7 +14,7 @@ # include "ds/rb_map.h" #endif -namespace kv::untyped +namespace ccf::kv::untyped { using SerialisedEntry = ccf::ByteVector; using SerialisedKeyHasher = std::hash; @@ -23,7 +23,7 @@ namespace kv::untyped using V = SerialisedEntry; using H = SerialisedKeyHasher; - using VersionV = kv::VersionV; + using VersionV = ccf::kv::VersionV; #ifndef KV_STATE_RB using State = champ::Map; @@ -46,19 +46,19 @@ namespace kv::untyped public: const size_t rollback_counter = {}; - const kv::untyped::State state = {}; - const kv::untyped::State committed = {}; + const ccf::kv::untyped::State state = {}; + const ccf::kv::untyped::State committed = {}; const Version start_version = {}; Version read_version = NoVersion; - kv::untyped::Read reads = {}; - kv::untyped::Write writes = {}; + ccf::kv::untyped::Read reads = {}; + ccf::kv::untyped::Write writes = {}; ChangeSet( size_t rollbacks, - kv::untyped::State& current_state, - kv::untyped::State& committed_state, - kv::untyped::Write changed_writes, + ccf::kv::untyped::State& current_state, + ccf::kv::untyped::State& committed_state, + ccf::kv::untyped::Write changed_writes, Version current_version) : rollback_counter(rollbacks), state(current_state), @@ -81,10 +81,11 @@ namespace kv::untyped // obliterates the current state. struct SnapshotChangeSet : public ChangeSet { - const kv::untyped::State state; + const ccf::kv::untyped::State state; const Version version; - SnapshotChangeSet(kv::untyped::State&& snapshot_state, Version version_) : + SnapshotChangeSet( + ccf::kv::untyped::State&& snapshot_state, Version version_) : state(std::move(snapshot_state)), version(version_) {} @@ -101,15 +102,15 @@ namespace kv::untyped namespace map { template <> - inline size_t get_size( - const kv::untyped::VersionV& data) + inline size_t get_size( + const ccf::kv::untyped::VersionV& data) { return sizeof(uint64_t) + sizeof(data.version) + data.value.size(); } template <> - inline size_t serialize( - const kv::untyped::VersionV& t, uint8_t*& data, size_t& size) + inline size_t serialize( + const ccf::kv::untyped::VersionV& t, uint8_t*& data, size_t& size) { uint64_t data_size = sizeof(t.version) + t.value.size(); serialized::write( @@ -131,29 +132,29 @@ namespace map } template <> - inline kv::untyped::VersionV deserialize( + inline ccf::kv::untyped::VersionV deserialize( const uint8_t*& data, size_t& size) { - kv::untyped::VersionV ret; + ccf::kv::untyped::VersionV ret; uint64_t data_size = serialized::read(data, size); - kv::Version version = serialized::read(data, size); + ccf::kv::Version version = serialized::read(data, size); ret.version = version; - data_size -= sizeof(kv::Version); + data_size -= sizeof(ccf::kv::Version); ret.value.append(data, data + data_size); serialized::skip(data, size, data_size); return ret; } template <> - inline size_t get_size( - const kv::untyped::SerialisedEntry& data) + inline size_t get_size( + const ccf::kv::untyped::SerialisedEntry& data) { return sizeof(uint64_t) + data.size(); } template <> - inline size_t serialize( - const kv::untyped::SerialisedEntry& t, uint8_t*& data, size_t& size) + inline size_t serialize( + const ccf::kv::untyped::SerialisedEntry& t, uint8_t*& data, size_t& size) { uint64_t data_size = t.size(); serialized::write( @@ -167,11 +168,11 @@ namespace map } template <> - inline kv::untyped::SerialisedEntry deserialize( - const uint8_t*& data, size_t& size) + inline ccf::kv::untyped::SerialisedEntry deserialize< + ccf::kv::untyped::SerialisedEntry>(const uint8_t*& data, size_t& size) { uint64_t data_size = serialized::read(data, size); - kv::untyped::SerialisedEntry ret; + ccf::kv::untyped::SerialisedEntry ret; ret.append(data, data + data_size); serialized::skip(data, size, data_size); return ret; diff --git a/src/kv/untyped_map.h b/src/kv/untyped_map.h index 587c50b24223..ccfab022f5c7 100644 --- a/src/kv/untyped_map.h +++ b/src/kv/untyped_map.h @@ -16,7 +16,7 @@ #include #include -namespace kv::untyped +namespace ccf::kv::untyped { struct LocalCommit { @@ -33,7 +33,7 @@ namespace kv::untyped LocalCommit* next = nullptr; LocalCommit* prev = nullptr; }; - using LocalCommits = ds::DLList; + using LocalCommits = ::ds::DLList; struct Roll { @@ -68,14 +68,14 @@ namespace kv::untyped class Map : public AbstractMap { public: - using K = kv::untyped::SerialisedEntry; - using V = kv::untyped::SerialisedEntry; - using H = kv::untyped::SerialisedKeyHasher; + using K = ccf::kv::untyped::SerialisedEntry; + using V = ccf::kv::untyped::SerialisedEntry; + using H = ccf::kv::untyped::SerialisedKeyHasher; - using StateSnapshot = kv::untyped::State::Snapshot; + using StateSnapshot = ccf::kv::untyped::State::Snapshot; - using CommitHook = kv::untyped::CommitHook; - using MapHook = kv::untyped::MapHook; + using CommitHook = ccf::kv::untyped::CommitHook; + using MapHook = ccf::kv::untyped::MapHook; private: AbstractStore* store; @@ -293,7 +293,7 @@ namespace kv::untyped private: const std::string name; const SecurityDomain security_domain; - const kv::Version version; + const ccf::kv::Version version; std::unique_ptr map_snapshot; @@ -301,7 +301,7 @@ namespace kv::untyped Snapshot( const std::string& name_, SecurityDomain security_domain_, - kv::Version version_, + ccf::kv::Version version_, std::unique_ptr&& map_snapshot_) : name(name_), security_domain(security_domain_), @@ -327,10 +327,10 @@ namespace kv::untyped }; // Public typedefs for external consumption - using ReadOnlyHandle = kv::untyped::MapHandle; - using WriteOnlyHandle = kv::untyped::MapHandle; - using Handle = kv::untyped::MapHandle; - using Diff = kv::untyped::MapDiff; + using ReadOnlyHandle = ccf::kv::untyped::MapHandle; + using WriteOnlyHandle = ccf::kv::untyped::MapHandle; + using Handle = ccf::kv::untyped::MapHandle; + using Diff = ccf::kv::untyped::MapDiff; Map( AbstractStore* store_, @@ -357,7 +357,7 @@ namespace kv::untyped bool include_reads) override { const auto non_abstract = - dynamic_cast(changes); + dynamic_cast(changes); if (non_abstract == nullptr) { LOG_FAIL_FMT("Unable to serialise map due to type mismatch"); @@ -560,7 +560,7 @@ namespace kv::untyped /** Get store that the map belongs to * - * @return Pointer to `kv::AbstractStore` + * @return Pointer to `ccf::kv::AbstractStore` */ AbstractStore* get_store() override { @@ -802,7 +802,7 @@ namespace kv::untyped { if (current->version <= version) { - kv::untyped::Write writes; + ccf::kv::untyped::Write writes; if (track_deletes_on_missing_keys) { writes = current->writes; diff --git a/src/kv/untyped_map_diff.cpp b/src/kv/untyped_map_diff.cpp index 4361bb8b020c..e544347bce31 100644 --- a/src/kv/untyped_map_diff.cpp +++ b/src/kv/untyped_map_diff.cpp @@ -5,7 +5,7 @@ #include "kv/untyped_change_set.h" -namespace kv::untyped +namespace ccf::kv::untyped { void MapDiff::foreach_(const MapDiff::ElementVisitorWithEarlyOut& f) { @@ -20,7 +20,8 @@ namespace kv::untyped } } - MapDiff::MapDiff(kv::untyped::ChangeSet& cs, const std::string& map_name) : + MapDiff::MapDiff( + ccf::kv::untyped::ChangeSet& cs, const std::string& map_name) : writes(cs.writes), map_name(map_name) {} diff --git a/src/kv/untyped_map_handle.cpp b/src/kv/untyped_map_handle.cpp index edcbb601501c..be4a1fafd384 100644 --- a/src/kv/untyped_map_handle.cpp +++ b/src/kv/untyped_map_handle.cpp @@ -5,7 +5,7 @@ #include "kv/untyped_change_set.h" -namespace kv::untyped +namespace ccf::kv::untyped { const MapHandle::ValueType* MapHandle::read_key(const KeyType& key) { @@ -85,7 +85,7 @@ namespace kv::untyped } MapHandle::MapHandle( - kv::untyped::ChangeSet& cs, const std::string& map_name) : + ccf::kv::untyped::ChangeSet& cs, const std::string& map_name) : tx_changes(cs), map_name(map_name) {} diff --git a/src/kv/version_v.h b/src/kv/version_v.h index 71ed5725def0..576cbe19b808 100644 --- a/src/kv/version_v.h +++ b/src/kv/version_v.h @@ -2,7 +2,7 @@ // Licensed under the Apache 2.0 License. #pragma once -namespace kv +namespace ccf::kv { using Version = uint64_t; diff --git a/src/node/ccf_acme_client.h b/src/node/ccf_acme_client.h index 0e9918ef954c..467c4d2923de 100644 --- a/src/node/ccf_acme_client.h +++ b/src/node/ccf_acme_client.h @@ -77,7 +77,7 @@ namespace ccf std::shared_ptr rpc_map, std::shared_ptr rpc_sessions, std::shared_ptr challenge_frontend, - std::shared_ptr store, + std::shared_ptr store, std::shared_ptr account_key_pair = nullptr, std::shared_ptr challenge_handler_ = nullptr) : ACME::Client(get_client_config(config), account_key_pair), @@ -105,7 +105,7 @@ namespace ccf } virtual void check_expiry( - std::shared_ptr tables, + std::shared_ptr tables, std::unique_ptr& identity) { auto now = std::chrono::system_clock::now(); @@ -143,7 +143,7 @@ namespace ccf std::shared_ptr rpc_map; std::shared_ptr rpc_sessions; std::shared_ptr challenge_frontend; - std::shared_ptr store; + std::shared_ptr store; std::shared_ptr challenge_handler; void install_wildcard_response() diff --git a/src/node/encryptor.h b/src/node/encryptor.h index c1d7ca28c835..dfb50c901291 100644 --- a/src/node/encryptor.h +++ b/src/node/encryptor.h @@ -47,5 +47,5 @@ namespace ccf } }; - using NodeEncryptor = kv::TxEncryptor; + using NodeEncryptor = ccf::kv::TxEncryptor; } \ No newline at end of file diff --git a/src/node/endpoint_context_impl.h b/src/node/endpoint_context_impl.h index b8d1393726d4..faae3ec335fc 100644 --- a/src/node/endpoint_context_impl.h +++ b/src/node/endpoint_context_impl.h @@ -11,11 +11,11 @@ namespace ccf // to user apps) struct EndpointContextImpl : public ccf::endpoints::EndpointContext { - std::unique_ptr owned_tx = nullptr; + std::unique_ptr owned_tx = nullptr; EndpointContextImpl( const std::shared_ptr& r, - std::unique_ptr t) : + std::unique_ptr t) : ccf::endpoints::EndpointContext(r, *t), owned_tx(std::move(t)) {} diff --git a/src/node/gov/handlers/proposals.h b/src/node/gov/handlers/proposals.h index 40c49c7f6a24..c0d89aa86133 100644 --- a/src/node/gov/handlers/proposals.h +++ b/src/node/gov/handlers/proposals.h @@ -29,7 +29,7 @@ namespace ccf::gov::endpoints }; ProposalSubmissionResult validate_proposal_submission_time( - kv::Tx& tx, + ccf::kv::Tx& tx, const std::string& created_at, const std::vector& request_digest, const ccf::ProposalId& proposal_id) @@ -93,7 +93,7 @@ namespace ccf::gov::endpoints } void record_cose_governance_history( - kv::Tx& tx, + ccf::kv::Tx& tx, const MemberId& caller_id, const std::span& cose_sign1) { @@ -104,7 +104,7 @@ namespace ccf::gov::endpoints } void remove_all_other_non_open_proposals( - kv::Tx& tx, const ProposalId& proposal_id) + ccf::kv::Tx& tx, const ProposalId& proposal_id) { auto p = tx.rw(jsgov::Tables::PROPOSALS); auto pi = @@ -131,7 +131,7 @@ namespace ccf::gov::endpoints void resolve_proposal( ccfapp::AbstractNodeContext& context, ccf::NetworkState& network, - kv::Tx& tx, + ccf::kv::Tx& tx, const ProposalId& proposal_id, const std::span& proposal_bytes, ccf::jsgov::ProposalInfo& proposal_info, diff --git a/src/node/historical_queries.h b/src/node/historical_queries.h index bfc30b5be321..0eec326355f0 100644 --- a/src/node/historical_queries.h +++ b/src/node/historical_queries.h @@ -66,7 +66,7 @@ namespace ccf::historical static constexpr auto slow_fetch_threshold = std::chrono::milliseconds(1000); static std::optional get_signature( - const kv::StorePtr& sig_store) + const ccf::kv::StorePtr& sig_store) { auto tx = sig_store->create_read_only_tx(); auto signatures = tx.ro(ccf::Tables::SIGNATURES); @@ -74,7 +74,7 @@ namespace ccf::historical } static std::optional> get_tree( - const kv::StorePtr& sig_store) + const ccf::kv::StorePtr& sig_store) { auto tx = sig_store->create_read_only_tx(); auto tree = @@ -85,7 +85,7 @@ namespace ccf::historical class StateCacheImpl { protected: - kv::Store& source_store; + ccf::kv::Store& source_store; std::shared_ptr source_ledger_secrets; ringbuffer::WriterPtr to_host; @@ -135,7 +135,7 @@ namespace ccf::historical RequestStage current_stage = RequestStage::Fetching; ccf::crypto::Sha256Hash entry_digest = {}; ccf::ClaimsDigest claims_digest = {}; - kv::StorePtr store = nullptr; + ccf::kv::StorePtr store = nullptr; bool is_signature = false; TxReceiptImplPtr receipt = nullptr; ccf::TxID transaction_id; @@ -568,7 +568,7 @@ namespace ccf::historical void process_deserialised_store( const StoreDetailsPtr& details, - const kv::StorePtr& store, + const ccf::kv::StorePtr& store, const ccf::crypto::Sha256Hash& entry_digest, ccf::SeqNo seqno, bool is_signature, @@ -667,7 +667,7 @@ namespace ccf::historical } bool handle_encrypted_past_ledger_secret( - const kv::StorePtr& store, LedgerSecretPtr encrypting_secret) + const ccf::kv::StorePtr& store, LedgerSecretPtr encrypting_secret) { // Read encrypted secrets from store auto tx = store->create_read_only_tx(); @@ -832,10 +832,10 @@ namespace ccf::historical } } - std::vector states_to_stores( + std::vector states_to_stores( const std::vector& states) { - std::vector stores; + std::vector stores; for (size_t i = 0; i < states.size(); i++) { stores.push_back(states[i]->store); @@ -845,7 +845,7 @@ namespace ccf::historical public: StateCacheImpl( - kv::Store& store, + ccf::kv::Store& store, const std::shared_ptr& secrets, const ringbuffer::WriterPtr& host_writer) : source_store(store), @@ -856,7 +856,7 @@ namespace ccf::historical std::make_shared(historical_ledger_secrets)) {} - kv::ReadOnlyStorePtr get_store_at( + ccf::kv::ReadOnlyStorePtr get_store_at( const CompoundHandle& handle, ccf::SeqNo seqno, ExpiryDuration seconds_until_expiry) @@ -870,7 +870,7 @@ namespace ccf::historical return range[0]; } - kv::ReadOnlyStorePtr get_store_at( + ccf::kv::ReadOnlyStorePtr get_store_at( const CompoundHandle& handle, ccf::SeqNo seqno) { return get_store_at(handle, seqno, default_expiry_duration); @@ -895,7 +895,7 @@ namespace ccf::historical return get_state_at(handle, seqno, default_expiry_duration); } - std::vector get_store_range( + std::vector get_store_range( const CompoundHandle& handle, ccf::SeqNo start_seqno, ccf::SeqNo end_seqno, @@ -908,7 +908,7 @@ namespace ccf::historical false)); } - std::vector get_store_range( + std::vector get_store_range( const CompoundHandle& handle, ccf::SeqNo start_seqno, ccf::SeqNo end_seqno) @@ -939,7 +939,7 @@ namespace ccf::historical handle, start_seqno, end_seqno, default_expiry_duration); } - std::vector get_stores_for( + std::vector get_stores_for( const CompoundHandle& handle, const SeqNoCollection& seqnos, ExpiryDuration seconds_until_expiry) @@ -948,7 +948,7 @@ namespace ccf::historical get_states_internal(handle, seqnos, seconds_until_expiry, false)); } - std::vector get_stores_for( + std::vector get_stores_for( const CompoundHandle& handle, const SeqNoCollection& seqnos) { return get_stores_for(handle, seqnos, default_expiry_duration); @@ -1008,7 +1008,7 @@ namespace ccf::historical return false; } - kv::ApplyResult deserialise_result; + ccf::kv::ApplyResult deserialise_result; ccf::ClaimsDigest claims_digest; bool has_commit_evidence; auto store = deserialise_ledger_entry( @@ -1019,7 +1019,7 @@ namespace ccf::historical claims_digest, has_commit_evidence); - if (deserialise_result == kv::ApplyResult::FAIL) + if (deserialise_result == ccf::kv::ApplyResult::FAIL) { return false; } @@ -1061,7 +1061,7 @@ namespace ccf::historical } const auto is_signature = - deserialise_result == kv::ApplyResult::PASS_SIGNATURE; + deserialise_result == ccf::kv::ApplyResult::PASS_SIGNATURE; update_earliest_known_ledger_secret(); @@ -1117,8 +1117,9 @@ namespace ccf::historical while (size > 0) { const auto header = - serialized::peek(data, size); - const auto whole_size = header.size + kv::serialised_entry_header_size; + serialized::peek(data, size); + const auto whole_size = + header.size + ccf::kv::serialised_entry_header_size; all_accepted &= handle_ledger_entry(seqno, data, whole_size); data += whole_size; size -= whole_size; @@ -1165,16 +1166,16 @@ namespace ccf::historical } } - kv::StorePtr deserialise_ledger_entry( + ccf::kv::StorePtr deserialise_ledger_entry( ccf::SeqNo seqno, const uint8_t* data, size_t size, - kv::ApplyResult& result, + ccf::kv::ApplyResult& result, ccf::ClaimsDigest& claims_digest, bool& has_commit_evidence) { // Create a new store and try to deserialise this entry into it - kv::StorePtr store = std::make_shared( + ccf::kv::StorePtr store = std::make_shared( false /* Do not start from very first seqno */, true /* Make use of historical secrets */); @@ -1209,7 +1210,7 @@ namespace ccf::historical auto exec = store->deserialize({data, data + size}, public_only); if (exec == nullptr) { - result = kv::ApplyResult::FAIL; + result = ccf::kv::ApplyResult::FAIL; return nullptr; } @@ -1226,7 +1227,7 @@ namespace ccf::historical "Exception while attempting to deserialise entry {}: {}", seqno, e.what()); - result = kv::ApplyResult::FAIL; + result = ccf::kv::ApplyResult::FAIL; } return store; @@ -1324,7 +1325,7 @@ namespace ccf::historical StateCache(Ts&&... ts) : StateCacheImpl(std::forward(ts)...) {} - kv::ReadOnlyStorePtr get_store_at( + ccf::kv::ReadOnlyStorePtr get_store_at( RequestHandle handle, ccf::SeqNo seqno, ExpiryDuration seconds_until_expiry) override @@ -1333,7 +1334,7 @@ namespace ccf::historical make_compound_handle(handle), seqno, seconds_until_expiry); } - kv::ReadOnlyStorePtr get_store_at( + ccf::kv::ReadOnlyStorePtr get_store_at( RequestHandle handle, ccf::SeqNo seqno) override { return StateCacheImpl::get_store_at(make_compound_handle(handle), seqno); @@ -1353,7 +1354,7 @@ namespace ccf::historical return StateCacheImpl::get_state_at(make_compound_handle(handle), seqno); } - std::vector get_store_range( + std::vector get_store_range( RequestHandle handle, ccf::SeqNo start_seqno, ccf::SeqNo end_seqno, @@ -1366,7 +1367,7 @@ namespace ccf::historical seconds_until_expiry); } - std::vector get_store_range( + std::vector get_store_range( RequestHandle handle, ccf::SeqNo start_seqno, ccf::SeqNo end_seqno) override @@ -1397,7 +1398,7 @@ namespace ccf::historical make_compound_handle(handle), start_seqno, end_seqno); } - std::vector get_stores_for( + std::vector get_stores_for( RequestHandle handle, const SeqNoCollection& seqnos, ExpiryDuration seconds_until_expiry) override @@ -1406,7 +1407,7 @@ namespace ccf::historical make_compound_handle(handle), seqnos, seconds_until_expiry); } - std::vector get_stores_for( + std::vector get_stores_for( RequestHandle handle, const SeqNoCollection& seqnos) override { return StateCacheImpl::get_stores_for( diff --git a/src/node/historical_queries_adapter.cpp b/src/node/historical_queries_adapter.cpp index 25001b0ebb13..6615545d15d8 100644 --- a/src/node/historical_queries_adapter.cpp +++ b/src/node/historical_queries_adapter.cpp @@ -191,7 +191,7 @@ namespace ccf::historical } HistoricalTxStatus is_tx_committed_v2( - kv::Consensus* consensus, + ccf::kv::Consensus* consensus, ccf::View view, ccf::SeqNo seqno, std::string& error_reason) diff --git a/src/node/historical_queries_utils.cpp b/src/node/historical_queries_utils.cpp index 08337d602455..eaa0281e1537 100644 --- a/src/node/historical_queries_utils.cpp +++ b/src/node/historical_queries_utils.cpp @@ -17,7 +17,7 @@ namespace ccf namespace historical { std::optional find_previous_service_identity( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, ccf::historical::StatePtr& state, AbstractStateCache& state_cache) { @@ -61,7 +61,7 @@ namespace ccf } bool populate_service_endorsements( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, ccf::historical::StatePtr& state, AbstractStateCache& state_cache, std::shared_ptr diff --git a/src/node/history.h b/src/node/history.h index 983cc9f35eba..89f2fee6c816 100644 --- a/src/node/history.h +++ b/src/node/history.h @@ -24,7 +24,7 @@ FMT_BEGIN_NAMESPACE template <> -struct formatter +struct formatter { template constexpr auto parse(ParseContext& ctx) @@ -33,7 +33,7 @@ struct formatter } template - auto format(const kv::TxHistory::RequestID& p, FormatContext& ctx) const + auto format(const ccf::kv::TxHistory::RequestID& p, FormatContext& ctx) const { return format_to( ctx.out(), "", std::get<0>(p), std::get<1>(p)); @@ -86,21 +86,21 @@ namespace ccf LOG_TRACE_FMT("History [{}] {}", flag, h); } - class NullTxHistoryPendingTx : public kv::PendingTx + class NullTxHistoryPendingTx : public ccf::kv::PendingTx { - kv::TxID txid; - kv::Store& store; + ccf::kv::TxID txid; + ccf::kv::Store& store; NodeId id; public: NullTxHistoryPendingTx( - kv::TxID txid_, kv::Store& store_, const NodeId& id_) : + ccf::kv::TxID txid_, ccf::kv::Store& store_, const NodeId& id_) : txid(txid_), store(store_), id(id_) {} - kv::PendingTxInfo call() override + ccf::kv::PendingTxInfo call() override { auto sig = store.create_reserved_tx(txid); auto signatures = @@ -114,18 +114,19 @@ namespace ccf } }; - class NullTxHistory : public kv::TxHistory + class NullTxHistory : public ccf::kv::TxHistory { - kv::Store& store; + ccf::kv::Store& store; NodeId id; protected: - kv::Version version = 0; - kv::Term term_of_last_version = 0; - kv::Term term_of_next_version = 0; + ccf::kv::Version version = 0; + ccf::kv::Term term_of_last_version = 0; + ccf::kv::Term term_of_next_version = 0; public: - NullTxHistory(kv::Store& store_, const NodeId& id_, ccf::crypto::KeyPair&) : + NullTxHistory( + ccf::kv::Store& store_, const NodeId& id_, ccf::crypto::KeyPair&) : store(store_), id(id_) {} @@ -137,36 +138,40 @@ namespace ccf void append_entry( const ccf::crypto::Sha256Hash& digest, - std::optional term_of_next_version_ = std::nullopt) override + std::optional term_of_next_version_ = + std::nullopt) override { version++; } - kv::TxHistory::Result verify_and_sign( - PrimarySignature&, kv::Term*, kv::Configuration::Nodes&) override + ccf::kv::TxHistory::Result verify_and_sign( + PrimarySignature&, + ccf::kv::Term*, + ccf::kv::Configuration::Nodes&) override { - return kv::TxHistory::Result::OK; + return ccf::kv::TxHistory::Result::OK; } - bool verify(kv::Term*, ccf::PrimarySignature*) override + bool verify(ccf::kv::Term*, ccf::PrimarySignature*) override { return true; } - void set_term(kv::Term t) override + void set_term(ccf::kv::Term t) override { term_of_last_version = t; term_of_next_version = t; } - void rollback(const kv::TxID& tx_id, kv::Term commit_term_) override + void rollback( + const ccf::kv::TxID& tx_id, ccf::kv::Term commit_term_) override { version = tx_id.version; term_of_last_version = tx_id.term; term_of_next_version = commit_term_; } - void compact(kv::Version) override {} + void compact(ccf::kv::Version) override {} bool init_from_snapshot(const std::vector&) override { @@ -195,7 +200,7 @@ namespace ccf return ccf::crypto::Sha256Hash(std::to_string(version)); } - std::tuple + std::tuple get_replicated_state_txid_and_root() override { return { @@ -204,7 +209,7 @@ namespace ccf term_of_next_version}; } - std::vector get_proof(kv::Version) override + std::vector get_proof(ccf::kv::Version) override { return {}; } @@ -301,20 +306,20 @@ namespace ccf }; template - class MerkleTreeHistoryPendingTx : public kv::PendingTx + class MerkleTreeHistoryPendingTx : public ccf::kv::PendingTx { - kv::TxID txid; - kv::Store& store; - kv::TxHistory& history; + ccf::kv::TxID txid; + ccf::kv::Store& store; + ccf::kv::TxHistory& history; NodeId id; ccf::crypto::KeyPair& kp; ccf::crypto::Pem& endorsed_cert; public: MerkleTreeHistoryPendingTx( - kv::TxID txid_, - kv::Store& store_, - kv::TxHistory& history_, + ccf::kv::TxID txid_, + ccf::kv::Store& store_, + ccf::kv::TxHistory& history_, const NodeId& id_, ccf::crypto::KeyPair& kp_, ccf::crypto::Pem& endorsed_cert_) : @@ -326,7 +331,7 @@ namespace ccf endorsed_cert(endorsed_cert_) {} - kv::PendingTxInfo call() override + ccf::kv::PendingTxInfo call() override { auto sig = store.create_reserved_tx(txid); auto signatures = @@ -485,9 +490,9 @@ namespace ccf }; template - class HashedTxHistory : public kv::TxHistory + class HashedTxHistory : public ccf::kv::TxHistory { - kv::Store& store; + ccf::kv::Store& store; NodeId id; T replicated_state_tree; @@ -499,14 +504,14 @@ namespace ccf size_t sig_ms_interval; ccf::pal::Mutex state_lock; - kv::Term term_of_last_version = 0; - kv::Term term_of_next_version; + ccf::kv::Term term_of_last_version = 0; + ccf::kv::Term term_of_next_version; std::optional endorsed_cert = std::nullopt; public: HashedTxHistory( - kv::Store& store_, + ccf::kv::Store& store_, const NodeId& id_, ccf::crypto::KeyPair& kp_, size_t sig_tx_interval_ = 0, @@ -549,11 +554,11 @@ namespace ccf auto sig_disp = consensus->get_signature_disposition(); switch (sig_disp) { - case kv::Consensus::SignatureDisposition::CANT_REPLICATE: + case ccf::kv::Consensus::SignatureDisposition::CANT_REPLICATE: { break; } - case kv::Consensus::SignatureDisposition::CAN_SIGN: + case ccf::kv::Consensus::SignatureDisposition::CAN_SIGN: { if (self->store.committable_gap() > 0) { @@ -561,7 +566,7 @@ namespace ccf } break; } - case kv::Consensus::SignatureDisposition::SHOULD_SIGN: + case ccf::kv::Consensus::SignatureDisposition::SHOULD_SIGN: { should_emit_signature = true; break; @@ -638,28 +643,28 @@ namespace ccf return replicated_state_tree.get_root(); } - std::tuple + std::tuple get_replicated_state_txid_and_root() override { std::lock_guard guard(state_lock); return { {term_of_last_version, - static_cast(replicated_state_tree.end_index())}, + static_cast(replicated_state_tree.end_index())}, replicated_state_tree.get_root(), term_of_next_version}; } - kv::TxHistory::Result verify_and_sign( + ccf::kv::TxHistory::Result verify_and_sign( PrimarySignature& sig, - kv::Term* term, - kv::Configuration::Nodes& config) override + ccf::kv::Term* term, + ccf::kv::Configuration::Nodes& config) override { if (!verify(term, &sig)) { - return kv::TxHistory::Result::FAIL; + return ccf::kv::TxHistory::Result::FAIL; } - kv::TxHistory::Result result = kv::TxHistory::Result::OK; + ccf::kv::TxHistory::Result result = ccf::kv::TxHistory::Result::OK; sig.node = id; sig.sig = kp.sign_hash(sig.root.h.data(), sig.root.h.size()); @@ -668,7 +673,8 @@ namespace ccf } bool verify( - kv::Term* term = nullptr, PrimarySignature* signature = nullptr) override + ccf::kv::Term* term = nullptr, + PrimarySignature* signature = nullptr) override { auto tx = store.create_read_only_tx(); auto signatures = @@ -709,7 +715,7 @@ namespace ccf } } - void set_term(kv::Term t) override + void set_term(ccf::kv::Term t) override { // This should only be called once, when the store first knows about its // term @@ -719,7 +725,7 @@ namespace ccf } void rollback( - const kv::TxID& tx_id, kv::Term term_of_next_version_) override + const ccf::kv::TxID& tx_id, ccf::kv::Term term_of_next_version_) override { std::lock_guard guard(state_lock); LOG_TRACE_FMT("Rollback to {}.{}", tx_id.term, tx_id.version); @@ -729,7 +735,7 @@ namespace ccf log_hash(replicated_state_tree.get_root(), ROLLBACK); } - void compact(kv::Version v) override + void compact(ccf::kv::Version v) override { std::lock_guard guard(state_lock); // Receipts can only be retrieved to the flushed index. Keep a range of @@ -784,7 +790,7 @@ namespace ccf true); } - std::vector get_proof(kv::Version index) override + std::vector get_proof(ccf::kv::Version index) override { std::lock_guard guard(state_lock); return replicated_state_tree.get_proof(index).to_v(); @@ -814,7 +820,7 @@ namespace ccf void append_entry( const ccf::crypto::Sha256Hash& digest, - std::optional expected_term_of_next_version = + std::optional expected_term_of_next_version = std::nullopt) override { log_hash(digest, APPEND); diff --git a/src/node/hooks.h b/src/node/hooks.h index 8517493957d9..2ca2536a0e3b 100644 --- a/src/node/hooks.h +++ b/src/node/hooks.h @@ -16,15 +16,15 @@ namespace ccf std::string port; }; - class ConfigurationChangeHook : public kv::ConsensusHook + class ConfigurationChangeHook : public ccf::kv::ConsensusHook { - kv::Version version; + ccf::kv::Version version; std::map> cfg_delta; std::unordered_set learners; std::unordered_set retired_nodes; public: - ConfigurationChangeHook(kv::Version version_, const Nodes::Write& w) : + ConfigurationChangeHook(ccf::kv::Version version_, const Nodes::Write& w) : version(version_) { for (const auto& [node_id, opt_ni] : w) @@ -64,7 +64,7 @@ namespace ccf } } - void call(kv::ConfigurableConsensus* consensus) override + void call(ccf::kv::ConfigurableConsensus* consensus) override { auto configuration = consensus->get_latest_configuration_unsafe(); for (const auto& [node_id, opt_ni] : cfg_delta) diff --git a/src/node/jwt_key_auto_refresh.h b/src/node/jwt_key_auto_refresh.h index 9b6932798d51..5b223b6a0df3 100644 --- a/src/node/jwt_key_auto_refresh.h +++ b/src/node/jwt_key_auto_refresh.h @@ -18,7 +18,7 @@ namespace ccf private: size_t refresh_interval_s; NetworkState& network; - std::shared_ptr consensus; + std::shared_ptr consensus; std::shared_ptr rpcsessions; std::shared_ptr rpc_map; ccf::crypto::KeyPairPtr node_sign_kp; @@ -29,7 +29,7 @@ namespace ccf JwtKeyAutoRefresh( size_t refresh_interval_s, NetworkState& network, - const std::shared_ptr& consensus, + const std::shared_ptr& consensus, const std::shared_ptr& rpcsessions, const std::shared_ptr& rpc_map, const ccf::crypto::KeyPairPtr& node_sign_kp, diff --git a/src/node/ledger_secret.h b/src/node/ledger_secret.h index 02a7fbca51df..8552e55ac430 100644 --- a/src/node/ledger_secret.h +++ b/src/node/ledger_secret.h @@ -19,7 +19,8 @@ namespace ccf { std::vector raw_key; std::shared_ptr key; - std::optional previous_secret_stored_version = std::nullopt; + std::optional previous_secret_stored_version = + std::nullopt; std::optional commit_secret = std::nullopt; const ccf::crypto::HashBytes& get_commit_secret() @@ -59,7 +60,7 @@ namespace ccf LedgerSecret( std::vector&& raw_key_, - std::optional previous_secret_stored_version_ = + std::optional previous_secret_stored_version_ = std::nullopt) : raw_key(raw_key_), key(ccf::crypto::make_key_aes_gcm(std::move(raw_key_))), diff --git a/src/node/ledger_secrets.h b/src/node/ledger_secrets.h index 12803e4023d1..c30223d876d9 100644 --- a/src/node/ledger_secrets.h +++ b/src/node/ledger_secrets.h @@ -16,7 +16,7 @@ namespace ccf { - using LedgerSecretsMap = std::map; + using LedgerSecretsMap = std::map; using VersionedLedgerSecret = LedgerSecretsMap::value_type; class LedgerSecrets @@ -30,13 +30,13 @@ namespace ccf // All rollback that would result in the removal of some of these secrets // would imply that the transaction that added the node itself was rolled // back. - kv::Version initial_latest_ledger_secret_version = 0; + ccf::kv::Version initial_latest_ledger_secret_version = 0; std::optional last_used_secret_it = std::nullopt; LedgerSecretPtr get_secret_for_version( - kv::Version version, bool historical_hint = false) + ccf::kv::Version version, bool historical_hint = false) { if (ledger_secrets.empty()) { @@ -91,7 +91,7 @@ namespace ccf return std::prev(search)->second; } - void take_dependency_on_secrets(kv::ReadOnlyTx& tx) + void take_dependency_on_secrets(ccf::kv::ReadOnlyTx& tx) { // Ledger secrets are not stored in the KV. Instead, they are // cached in a unique LedgerSecrets instance that can be accessed @@ -107,7 +107,7 @@ namespace ccf public: LedgerSecrets() = default; - void init(kv::Version initial_version = 1) + void init(ccf::kv::Version initial_version = 1) { std::lock_guard guard(lock); @@ -126,7 +126,7 @@ namespace ccf initial_latest_ledger_secret_version = ledger_secrets.rbegin()->first; } - void adjust_previous_secret_stored_version(kv::Version version) + void adjust_previous_secret_stored_version(ccf::kv::Version version) { // To be able to lookup the last active ledger secret before the service // crashed, the ledger secret created after the public recovery is @@ -166,7 +166,7 @@ namespace ccf return *ledger_secrets.begin(); } - VersionedLedgerSecret get_latest(kv::ReadOnlyTx& tx) + VersionedLedgerSecret get_latest(ccf::kv::ReadOnlyTx& tx) { std::lock_guard guard(lock); @@ -182,7 +182,7 @@ namespace ccf } std::pair> - get_latest_and_penultimate(kv::ReadOnlyTx& tx) + get_latest_and_penultimate(ccf::kv::ReadOnlyTx& tx) { std::lock_guard guard(lock); @@ -204,7 +204,8 @@ namespace ccf } LedgerSecretsMap get( - kv::ReadOnlyTx& tx, std::optional up_to = std::nullopt) + ccf::kv::ReadOnlyTx& tx, + std::optional up_to = std::nullopt) { std::lock_guard guard(lock); @@ -245,7 +246,7 @@ namespace ccf } std::shared_ptr get_encryption_key_for( - kv::Version version, bool historical_hint = false) + ccf::kv::Version version, bool historical_hint = false) { std::lock_guard guard(lock); auto ls = get_secret_for_version(version, historical_hint); @@ -257,13 +258,13 @@ namespace ccf } LedgerSecretPtr get_secret_for( - kv::Version version, bool historical_hint = false) + ccf::kv::Version version, bool historical_hint = false) { std::lock_guard guard(lock); return get_secret_for_version(version, historical_hint); } - void set_secret(kv::Version version, LedgerSecretPtr&& secret) + void set_secret(ccf::kv::Version version, LedgerSecretPtr&& secret) { std::lock_guard guard(lock); @@ -277,7 +278,7 @@ namespace ccf LOG_INFO_FMT("Added new ledger secret at seqno {}", version); } - void rollback(kv::Version version) + void rollback(ccf::kv::Version version) { std::lock_guard guard(lock); if (ledger_secrets.empty()) diff --git a/src/node/node_signature_verify.h b/src/node/node_signature_verify.h index 1c0b50308938..b3b7bacf59cd 100644 --- a/src/node/node_signature_verify.h +++ b/src/node/node_signature_verify.h @@ -9,7 +9,7 @@ namespace ccf { static bool verify_node_signature( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const NodeId& node_id, const uint8_t* expected_sig, size_t expected_sig_size, @@ -57,7 +57,7 @@ namespace ccf } static bool verify_node_signature( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const NodeId& node_id, const std::vector& expected_sig, const ccf::crypto::Sha256Hash& expected_root) diff --git a/src/node/node_state.h b/src/node/node_state.h index 278be1dd51f1..ff1898473f78 100644 --- a/src/node/node_state.h +++ b/src/node/node_state.h @@ -125,15 +125,15 @@ namespace ccf NetworkState& network; - std::shared_ptr consensus; + std::shared_ptr consensus; std::shared_ptr rpc_map; std::shared_ptr indexer; std::shared_ptr n2n_channels; std::shared_ptr> cmd_forwarder; std::shared_ptr rpcsessions; - std::shared_ptr history; - std::shared_ptr encryptor; + std::shared_ptr history; + std::shared_ptr encryptor; ShareManager share_manager; std::shared_ptr snapshotter; @@ -141,11 +141,11 @@ namespace ccf // // recovery // - std::shared_ptr recovery_store; + std::shared_ptr recovery_store; - kv::Version recovery_v; + ccf::kv::Version recovery_v; ccf::crypto::Sha256Hash recovery_root; - std::vector view_history; + std::vector view_history; ::consensus::Index last_recovered_signed_idx = 0; RecoveredEncryptedLedgerSecrets recovered_encrypted_ledger_secrets = {}; LedgerSecretsMap recovered_ledger_secrets = {}; @@ -160,7 +160,7 @@ namespace ccf std::unique_ptr startup_snapshot_info = nullptr; // Set to the snapshot seqno when a node starts from one and remembered for // the lifetime of the node - kv::Version startup_seqno = 0; + ccf::kv::Version startup_seqno = 0; // ACME certificate endorsement client std::map> @@ -171,10 +171,10 @@ namespace ccf acme_challenge_handlers; size_t num_acme_interfaces = 0; - std::shared_ptr make_encryptor() + std::shared_ptr make_encryptor() { #ifdef USE_NULL_ENCRYPTOR - return std::make_shared(); + return std::make_shared(); #else return std::make_shared(network.ledger_secrets); #endif @@ -183,7 +183,7 @@ namespace ccf // Returns true if the snapshot is already verified (via embedded receipt) void initialise_startup_snapshot(bool recovery = false) { - std::shared_ptr snapshot_store; + std::shared_ptr snapshot_store; if (!recovery) { // Create a new store to verify the snapshot only @@ -206,7 +206,7 @@ namespace ccf snapshot_store = network.tables; } - kv::ConsensusHookPtrs hooks; + ccf::kv::ConsensusHookPtrs hooks; startup_snapshot_info = initialise_from_snapshot( snapshot_store, std::move(startup_snapshot), @@ -239,7 +239,7 @@ namespace ccf {} QuoteVerificationResult verify_quote( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const QuoteInfo& quote_info_, const std::vector& expected_node_public_key_der, pal::PlatformAttestationMeasurement& measurement) override @@ -670,12 +670,12 @@ namespace ccf } View view = VIEW_UNKNOWN; - std::vector view_history_ = {}; + std::vector view_history_ = {}; if (startup_snapshot_info) { // It is only possible to deserialise the entire snapshot then, // once the ledger secrets have been passed in by the network - kv::ConsensusHookPtrs hooks; + ccf::kv::ConsensusHookPtrs hooks; deserialise_snapshot( network.tables, startup_snapshot_info->raw, @@ -837,9 +837,10 @@ namespace ccf network.tables->set_map_hook( network.jwt_issuers.get_name(), - [this](kv::Version, const kv::untyped::Write&) -> kv::ConsensusHookPtr { + [this](ccf::kv::Version, const ccf::kv::untyped::Write&) + -> ccf::kv::ConsensusHookPtr { jwt_key_auto_refresh->schedule_once(); - return kv::ConsensusHookPtr(nullptr); + return ccf::kv::ConsensusHookPtr(nullptr); }); } @@ -889,12 +890,12 @@ namespace ccf // When reading the private ledger, deserialise in the recovery store - kv::ApplyResult result = kv::ApplyResult::FAIL; + ccf::kv::ApplyResult result = ccf::kv::ApplyResult::FAIL; try { auto r = network.tables->deserialize(entry, true); result = r->apply(); - if (result == kv::ApplyResult::FAIL) + if (result == ccf::kv::ApplyResult::FAIL) { LOG_FAIL_FMT( "Failed to deserialise public ledger entry: {}", result); @@ -918,7 +919,7 @@ namespace ccf } // If the ledger entry is a signature, it is safe to compact the store - if (result == kv::ApplyResult::PASS_SIGNATURE) + if (result == ccf::kv::ApplyResult::PASS_SIGNATURE) { // If the ledger entry is a signature, it is safe to compact the store network.tables->compact(last_recovered_idx); @@ -1009,8 +1010,8 @@ namespace ccf snapshotter->init_after_public_recovery(); snapshotter->set_snapshot_generation(false); - kv::Version index = 0; - kv::Term view = 0; + ccf::kv::Version index = 0; + ccf::kv::Term view = 0; auto ls = tx.ro(network.signatures)->get(); if (ls.has_value()) @@ -1069,11 +1070,11 @@ namespace ccf LOG_INFO_FMT("Deserialising private ledger entry [{}]", entry.size()); // When reading the private ledger, deserialise in the recovery store - kv::ApplyResult result = kv::ApplyResult::FAIL; + ccf::kv::ApplyResult result = ccf::kv::ApplyResult::FAIL; try { result = recovery_store->deserialize(entry)->apply(); - if (result == kv::ApplyResult::FAIL) + if (result == ccf::kv::ApplyResult::FAIL) { LOG_FAIL_FMT( "Failed to deserialise private ledger entry: {}", result); @@ -1093,7 +1094,7 @@ namespace ccf return; } - if (result == kv::ApplyResult::PASS_SIGNATURE) + if (result == ccf::kv::ApplyResult::PASS_SIGNATURE) { recovery_store->compact(last_recovered_idx); } @@ -1169,7 +1170,7 @@ namespace ccf // we need to recover soon again. trigger_snapshot(tx); - if (tx.commit() != kv::CommitResult::SUCCESS) + if (tx.commit() != ccf::kv::CommitResult::SUCCESS) { throw std::logic_error( "Could not commit transaction when finishing network recovery"); @@ -1191,8 +1192,9 @@ namespace ccf network.encrypted_ledger_secrets.get_name(), network.encrypted_ledger_secrets.wrap_map_hook( [this]( - kv::Version version, const EncryptedLedgerSecretsInfo::Write& w) - -> kv::ConsensusHookPtr { + ccf::kv::Version version, + const EncryptedLedgerSecretsInfo::Write& w) + -> ccf::kv::ConsensusHookPtr { if (!w.has_value()) { throw std::logic_error(fmt::format( @@ -1206,7 +1208,7 @@ namespace ccf network.tables->unset_map_hook( network.encrypted_ledger_secrets.get_name()); - return kv::ConsensusHookPtr(nullptr); + return ccf::kv::ConsensusHookPtr(nullptr); })); } @@ -1238,7 +1240,7 @@ namespace ccf // void setup_private_recovery_store() { - recovery_store = std::make_shared( + recovery_store = std::make_shared( true /* Check transactions in order */, true /* Make use of historical secrets */); auto recovery_history = std::make_shared( @@ -1261,8 +1263,8 @@ namespace ccf if (startup_snapshot_info) { - std::vector view_history_; - kv::ConsensusHookPtrs hooks; + std::vector view_history_; + ccf::kv::ConsensusHookPtrs hooks; deserialise_snapshot( recovery_store, startup_snapshot_info->raw, @@ -1279,34 +1281,35 @@ namespace ccf recovery_v); } - void trigger_recovery_shares_refresh(kv::Tx& tx) override + void trigger_recovery_shares_refresh(ccf::kv::Tx& tx) override { share_manager.shuffle_recovery_shares(tx); } - void trigger_ledger_chunk(kv::Tx& tx) override + void trigger_ledger_chunk(ccf::kv::Tx& tx) override { - auto tx_ = static_cast(&tx); + auto tx_ = static_cast(&tx); if (tx_ == nullptr) { throw std::logic_error("Could not cast tx to CommittableTx"); } - tx_->set_flag(kv::CommittableTx::Flag::LEDGER_CHUNK_AT_NEXT_SIGNATURE); + tx_->set_flag( + ccf::kv::CommittableTx::Flag::LEDGER_CHUNK_AT_NEXT_SIGNATURE); } - void trigger_snapshot(kv::Tx& tx) override + void trigger_snapshot(ccf::kv::Tx& tx) override { - auto committable_tx = static_cast(&tx); + auto committable_tx = static_cast(&tx); if (committable_tx == nullptr) { throw std::logic_error("Could not cast tx to CommittableTx"); } committable_tx->set_flag( - kv::CommittableTx::Flag::SNAPSHOT_AT_NEXT_SIGNATURE); + ccf::kv::CommittableTx::Flag::SNAPSHOT_AT_NEXT_SIGNATURE); } void trigger_acme_refresh( - kv::Tx& tx, + ccf::kv::Tx& tx, const std::optional>& interfaces = std::nullopt) override { @@ -1393,7 +1396,7 @@ namespace ccf } void transition_service_to_open( - kv::Tx& tx, + ccf::kv::Tx& tx, AbstractGovernanceEffects::ServiceIdentities identities) override { std::lock_guard guard(lock); @@ -1492,7 +1495,7 @@ namespace ccf } } - void initiate_private_recovery(kv::Tx& tx) override + void initiate_private_recovery(ccf::kv::Tx& tx) override { std::lock_guard guard(lock); sm.expect(NodeStartupState::partOfPublicNetwork); @@ -1671,7 +1674,7 @@ namespace ccf } } - bool rekey_ledger(kv::Tx& tx) override + bool rekey_ledger(ccf::kv::Tx& tx) override { std::lock_guard guard(lock); sm.expect(NodeStartupState::partOfNetwork); @@ -1708,7 +1711,7 @@ namespace ccf return self; } - kv::Version get_startup_snapshot_seqno() override + ccf::kv::Version get_startup_snapshot_seqno() override { std::lock_guard guard(lock); return startup_seqno; @@ -2018,13 +2021,13 @@ namespace ccf network.tables->set_map_hook( network.secrets.get_name(), network.secrets.wrap_map_hook( - [this](kv::Version hook_version, const Secrets::Write& w) - -> kv::ConsensusHookPtr { + [this](ccf::kv::Version hook_version, const Secrets::Write& w) + -> ccf::kv::ConsensusHookPtr { // Used to rekey the ledger on a live service if (!is_part_of_network()) { // Ledger rekey is not allowed during recovery - return kv::ConsensusHookPtr(nullptr); + return ccf::kv::ConsensusHookPtr(nullptr); } const auto& ledger_secrets_for_nodes = w; @@ -2060,13 +2063,13 @@ namespace ccf } } - return kv::ConsensusHookPtr(nullptr); + return ccf::kv::ConsensusHookPtr(nullptr); })); network.tables->set_global_hook( network.secrets.get_name(), network.secrets.wrap_commit_hook([this]( - kv::Version hook_version, + ccf::kv::Version hook_version, const Secrets::Write& w) { // Used on recovery to initiate private recovery on backup nodes. if (!is_part_of_public_network()) @@ -2131,7 +2134,7 @@ namespace ccf network.encrypted_submitted_shares.get_name(), network.encrypted_submitted_shares.wrap_commit_hook( [this]( - kv::Version hook_version, + ccf::kv::Version hook_version, const EncryptedSubmittedShares::Write& w) { // Initiate recovery procedure from global hook, once all recovery // shares have been submitted (i.e. recovered_ledger_secrets is @@ -2161,7 +2164,7 @@ namespace ccf network.tables->set_global_hook( network.nodes.get_name(), network.nodes.wrap_commit_hook( - [this](kv::Version hook_version, const Nodes::Write& w) { + [this](ccf::kv::Version hook_version, const Nodes::Write& w) { std::vector retired_committed_nodes; for (const auto& [node_id, node_info] : w) { @@ -2184,8 +2187,9 @@ namespace ccf network.node_endorsed_certificates.get_name(), network.node_endorsed_certificates.wrap_map_hook( [this]( - kv::Version hook_version, - const NodeEndorsedCertificates::Write& w) -> kv::ConsensusHookPtr { + ccf::kv::Version hook_version, + const NodeEndorsedCertificates::Write& w) + -> ccf::kv::ConsensusHookPtr { for (auto const& [node_id, endorsed_certificate] : w) { if (node_id != self) @@ -2206,14 +2210,14 @@ namespace ccf n2n_channels->set_endorsed_node_cert(endorsed_node_cert.value()); } - return kv::ConsensusHookPtr(nullptr); + return ccf::kv::ConsensusHookPtr(nullptr); })); network.tables->set_global_hook( network.node_endorsed_certificates.get_name(), network.node_endorsed_certificates.wrap_commit_hook( [this]( - kv::Version hook_version, + ccf::kv::Version hook_version, const NodeEndorsedCertificates::Write& w) { for (auto const& [node_id, endorsed_certificate] : w) { @@ -2259,7 +2263,7 @@ namespace ccf network.tables->set_global_hook( network.service.get_name(), network.service.wrap_commit_hook( - [this](kv::Version hook_version, const Service::Write& w) { + [this](ccf::kv::Version hook_version, const Service::Write& w) { if (!w.has_value()) { throw std::logic_error("Unexpected deletion in service value"); @@ -2293,7 +2297,8 @@ namespace ccf network.tables->set_global_hook( network.acme_certificates.get_name(), network.acme_certificates.wrap_commit_hook( - [this](kv::Version hook_version, const ACMECertificates::Write& w) { + [this]( + ccf::kv::Version hook_version, const ACMECertificates::Write& w) { for (auto const& [interface_id, interface] : config.network.rpc_interfaces) { @@ -2318,7 +2323,7 @@ namespace ccf })); } - kv::Version get_last_recovered_signed_idx() override + ccf::kv::Version get_last_recovered_signed_idx() override { // On recovery, only one node recovers the public ledger and is thus // aware of the version at which the new ledger secret is applicable @@ -2335,8 +2340,9 @@ namespace ccf network.encrypted_ledger_secrets.get_name(), network.encrypted_ledger_secrets.wrap_map_hook( [this]( - kv::Version version, const EncryptedLedgerSecretsInfo::Write& w) - -> kv::ConsensusHookPtr { + ccf::kv::Version version, + const EncryptedLedgerSecretsInfo::Write& w) + -> ccf::kv::ConsensusHookPtr { auto encrypted_ledger_secret_info = w; if (!encrypted_ledger_secret_info.has_value()) { @@ -2363,7 +2369,7 @@ namespace ccf recovered_encrypted_ledger_secrets.emplace_back( std::move(encrypted_ledger_secret_info.value())); - return kv::ConsensusHookPtr(nullptr); + return ccf::kv::ConsensusHookPtr(nullptr); })); } @@ -2433,11 +2439,12 @@ namespace ccf auto node_client = std::make_shared( rpc_map, node_sign_kp, self_signed_node_cert, endorsed_node_cert); - kv::MembershipState membership_state = kv::MembershipState::Active; + ccf::kv::MembershipState membership_state = + ccf::kv::MembershipState::Active; consensus = std::make_shared( consensus_config, - std::make_unique>(network.tables), + std::make_unique>(network.tables), std::make_unique<::consensus::LedgerEnclave>(writer_factory), n2n_channels, shared_state, @@ -2454,8 +2461,8 @@ namespace ccf network.tables->set_map_hook( network.nodes.get_name(), network.nodes.wrap_map_hook( - [](kv::Version version, const Nodes::Write& w) - -> kv::ConsensusHookPtr { + [](ccf::kv::Version version, const Nodes::Write& w) + -> ccf::kv::ConsensusHookPtr { return std::make_unique(version, w); })); @@ -2469,33 +2476,33 @@ namespace ccf network.signatures.get_name(), network.signatures.wrap_map_hook( [s = this->snapshotter]( - kv::Version version, const Signatures::Write& w) { + ccf::kv::Version version, const Signatures::Write& w) { assert(w.has_value()); auto sig = w.value(); s->record_signature(version, sig.sig, sig.node, sig.cert); - return kv::ConsensusHookPtr(nullptr); + return ccf::kv::ConsensusHookPtr(nullptr); })); network.tables->set_map_hook( network.serialise_tree.get_name(), network.serialise_tree.wrap_map_hook( [s = this->snapshotter]( - kv::Version version, const SerialisedMerkleTree::Write& w) { + ccf::kv::Version version, const SerialisedMerkleTree::Write& w) { assert(w.has_value()); auto tree = w.value(); s->record_serialised_tree(version, tree); - return kv::ConsensusHookPtr(nullptr); + return ccf::kv::ConsensusHookPtr(nullptr); })); network.tables->set_map_hook( network.snapshot_evidence.get_name(), network.snapshot_evidence.wrap_map_hook( [s = this->snapshotter]( - kv::Version version, const SnapshotEvidence::Write& w) { + ccf::kv::Version version, const SnapshotEvidence::Write& w) { assert(w.has_value()); auto snapshot_evidence = w.value(); s->record_snapshot_evidence_idx(version, snapshot_evidence); - return kv::ConsensusHookPtr(nullptr); + return ccf::kv::ConsensusHookPtr(nullptr); })); setup_basic_hooks(); @@ -2653,7 +2660,7 @@ namespace ccf snapshotter->write_snapshot(snapshot_buf, request_id); } - virtual std::shared_ptr get_store() override + virtual std::shared_ptr get_store() override { return network.tables; } diff --git a/src/node/quote.cpp b/src/node/quote.cpp index 63f4882c610e..f475576ddcee 100644 --- a/src/node/quote.cpp +++ b/src/node/quote.cpp @@ -12,7 +12,7 @@ namespace ccf { bool verify_enclave_measurement_against_uvm_endorsements( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const pal::PlatformAttestationMeasurement& quote_measurement, const std::vector& uvm_endorsements) { @@ -44,7 +44,7 @@ namespace ccf } QuoteVerificationResult verify_enclave_measurement_against_store( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const pal::PlatformAttestationMeasurement& quote_measurement, const QuoteFormat& quote_format, const std::optional>& uvm_endorsements = std::nullopt) @@ -155,7 +155,7 @@ namespace ccf } QuoteVerificationResult verify_host_data_against_store( - kv::ReadOnlyTx& tx, const QuoteInfo& quote_info) + ccf::kv::ReadOnlyTx& tx, const QuoteInfo& quote_info) { if (quote_info.format != QuoteFormat::amd_sev_snp_v1) { @@ -180,7 +180,7 @@ namespace ccf } QuoteVerificationResult AttestationProvider::verify_quote_against_store( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const QuoteInfo& quote_info, const std::vector& expected_node_public_key_der, pal::PlatformAttestationMeasurement& measurement) diff --git a/src/node/rpc/custom_protocol_subsystem.h b/src/node/rpc/custom_protocol_subsystem.h index 1e1d3b373f75..a2a4c928b466 100644 --- a/src/node/rpc/custom_protocol_subsystem.h +++ b/src/node/rpc/custom_protocol_subsystem.h @@ -60,7 +60,7 @@ namespace ccf std::shared_ptr r = std::make_shared(); r->writer = node_state.get_writer_factory().create_writer_to_outside(); auto store = node_state.get_store(); - r->tx = std::make_shared(store.get()); + r->tx = std::make_shared(store.get()); r->ctx = std::make_shared( nullptr, *r->tx); return r; diff --git a/src/node/rpc/frontend.h b/src/node/rpc/frontend.h index 82e8efa933a3..5cb9bb746fc6 100644 --- a/src/node/rpc/frontend.h +++ b/src/node/rpc/frontend.h @@ -35,7 +35,7 @@ namespace ccf class RpcFrontend : public RpcHandler, public ForwardedRpcHandler { protected: - kv::Store& tables; + ccf::kv::Store& tables; endpoints::EndpointRegistry& endpoints; ccfapp::AbstractNodeContext& node_context; @@ -43,9 +43,9 @@ namespace ccf ccf::pal::Mutex open_lock; bool is_open_ = false; - kv::Consensus* consensus; + ccf::kv::Consensus* consensus; std::shared_ptr cmd_forwarder; - kv::TxHistory* history; + ccf::kv::TxHistory* history; size_t sig_tx_interval = 5000; std::chrono::milliseconds sig_ms_interval = std::chrono::milliseconds(1000); @@ -72,7 +72,7 @@ namespace ccf } endpoints::EndpointDefinitionPtr find_endpoint( - std::shared_ptr ctx, kv::CommittableTx& tx) + std::shared_ptr ctx, ccf::kv::CommittableTx& tx) { const auto endpoint = endpoints.find_endpoint(tx, *ctx); if (endpoint == nullptr) @@ -186,7 +186,7 @@ namespace ccf std::optional resolve_redirect_location( const RedirectionResolverConfig& resolver, - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const ccf::ListenInterfaceID& incoming_interface) { switch (resolver.kind) @@ -263,7 +263,7 @@ namespace ccf } bool check_redirect( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, std::shared_ptr ctx, const endpoints::EndpointDefinitionPtr& endpoint, const ccf::NodeInfoNetwork_v2::NetInterface::Redirections& redirections) @@ -418,7 +418,7 @@ namespace ccf std::unique_ptr get_authenticated_identity( std::shared_ptr ctx, - kv::CommittableTx& tx, + ccf::kv::CommittableTx& tx, const endpoints::EndpointDefinitionPtr& endpoint) { if (endpoint->authn_policies.empty()) @@ -493,7 +493,7 @@ namespace ccf void forward( std::shared_ptr ctx, - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const endpoints::EndpointDefinitionPtr& endpoint) { // HTTP/2 does not support forwarding @@ -632,7 +632,7 @@ namespace ccf } } - std::unique_ptr tx_p = tables.create_tx_ptr(); + std::unique_ptr tx_p = tables.create_tx_ptr(); set_root_on_proposals(*ctx, *tx_p); if (attempts > 0) @@ -771,12 +771,12 @@ namespace ccf } // else args owns a valid Tx relating to a non-pending response, which // should be applied - kv::CommittableTx& tx = *args.owned_tx; - kv::CommitResult result = tx.commit(ctx->claims, false); + ccf::kv::CommittableTx& tx = *args.owned_tx; + ccf::kv::CommitResult result = tx.commit(ctx->claims, false); switch (result) { - case kv::CommitResult::SUCCESS: + case ccf::kv::CommitResult::SUCCESS: { auto tx_id = tx.get_txid(); if (tx_id.has_value() && consensus != nullptr) @@ -826,12 +826,12 @@ namespace ccf return; } - case kv::CommitResult::FAIL_CONFLICT: + case ccf::kv::CommitResult::FAIL_CONFLICT: { break; } - case kv::CommitResult::FAIL_NO_REPLICATE: + case ccf::kv::CommitResult::FAIL_NO_REPLICATE: { ctx->clear_response_headers(); ctx->set_error( @@ -843,7 +843,7 @@ namespace ccf } } } - catch (const kv::CompactedVersionConflict& e) + catch (const ccf::kv::CompactedVersionConflict& e) { // The executing transaction failed because of a conflicting // compaction. Reset and retry @@ -874,7 +874,7 @@ namespace ccf return; } - catch (const kv::KvSerialiserException& e) + catch (const ccf::kv::KvSerialiserException& e) { // If serialising the committed transaction fails, there is no way // to recover safely (https://github.com/microsoft/CCF/issues/338). @@ -912,7 +912,7 @@ namespace ccf public: RpcFrontend( - kv::Store& tables_, + ccf::kv::Store& tables_, endpoints::EndpointRegistry& handlers_, ccfapp::AbstractNodeContext& node_context_) : tables(tables_), @@ -950,7 +950,7 @@ namespace ccf } void set_root_on_proposals( - const ccf::RpcContextImpl& ctx, kv::CommittableTx& tx) + const ccf::RpcContextImpl& ctx, ccf::kv::CommittableTx& tx) { if (endpoints.request_needs_root(ctx)) { diff --git a/src/node/rpc/gov_effects.h b/src/node/rpc/gov_effects.h index 906189f091d9..5141559d234d 100644 --- a/src/node/rpc/gov_effects.h +++ b/src/node/rpc/gov_effects.h @@ -16,33 +16,33 @@ namespace ccf GovernanceEffects(AbstractNodeState& impl_) : impl(impl_) {} void transition_service_to_open( - kv::Tx& tx, ServiceIdentities identities) override + ccf::kv::Tx& tx, ServiceIdentities identities) override { impl.transition_service_to_open(tx, identities); } - bool rekey_ledger(kv::Tx& tx) override + bool rekey_ledger(ccf::kv::Tx& tx) override { return impl.rekey_ledger(tx); } - void trigger_recovery_shares_refresh(kv::Tx& tx) override + void trigger_recovery_shares_refresh(ccf::kv::Tx& tx) override { impl.trigger_recovery_shares_refresh(tx); } - void trigger_ledger_chunk(kv::Tx& tx) override + void trigger_ledger_chunk(ccf::kv::Tx& tx) override { impl.trigger_ledger_chunk(tx); } - void trigger_snapshot(kv::Tx& tx) override + void trigger_snapshot(ccf::kv::Tx& tx) override { impl.trigger_snapshot(tx); } void trigger_acme_refresh( - kv::Tx& tx, + ccf::kv::Tx& tx, const std::optional>& interfaces = std::nullopt) override { diff --git a/src/node/rpc/gov_effects_interface.h b/src/node/rpc/gov_effects_interface.h index 85210d62f072..a1e460a20ad3 100644 --- a/src/node/rpc/gov_effects_interface.h +++ b/src/node/rpc/gov_effects_interface.h @@ -25,13 +25,13 @@ namespace ccf }; virtual void transition_service_to_open( - kv::Tx& tx, ServiceIdentities identities) = 0; - virtual bool rekey_ledger(kv::Tx& tx) = 0; - virtual void trigger_recovery_shares_refresh(kv::Tx& tx) = 0; - virtual void trigger_ledger_chunk(kv::Tx& tx) = 0; - virtual void trigger_snapshot(kv::Tx& tx) = 0; + ccf::kv::Tx& tx, ServiceIdentities identities) = 0; + virtual bool rekey_ledger(ccf::kv::Tx& tx) = 0; + virtual void trigger_recovery_shares_refresh(ccf::kv::Tx& tx) = 0; + virtual void trigger_ledger_chunk(ccf::kv::Tx& tx) = 0; + virtual void trigger_snapshot(ccf::kv::Tx& tx) = 0; virtual void trigger_acme_refresh( - kv::Tx& tx, + ccf::kv::Tx& tx, const std::optional>& interfaces = std::nullopt) = 0; }; diff --git a/src/node/rpc/jwt_management.h b/src/node/rpc/jwt_management.h index 76c5950ab8a4..1af1cb4c8b52 100644 --- a/src/node/rpc/jwt_management.h +++ b/src/node/rpc/jwt_management.h @@ -24,7 +24,7 @@ namespace ccf { static void legacy_remove_jwt_public_signing_keys( - kv::Tx& tx, std::string issuer) + ccf::kv::Tx& tx, std::string issuer) { auto keys = tx.rw(Tables::Legacy::JWT_PUBLIC_SIGNING_KEYS); @@ -73,7 +73,8 @@ namespace ccf return true; } - static void remove_jwt_public_signing_keys(kv::Tx& tx, std::string issuer) + static void remove_jwt_public_signing_keys( + ccf::kv::Tx& tx, std::string issuer) { // Unlike resetting JWT keys for a particular issuer, removing keys can be // safely done on both table revisions, as soon as the application shouldn't @@ -123,7 +124,7 @@ namespace ccf #endif static bool set_jwt_public_signing_keys( - kv::Tx& tx, + ccf::kv::Tx& tx, const std::string& log_prefix, std::string issuer, const JwtIssuerMetadata& issuer_metadata, diff --git a/src/node/rpc/member_frontend.h b/src/node/rpc/member_frontend.h index 850977616854..b595c3396fe2 100644 --- a/src/node/rpc/member_frontend.h +++ b/src/node/rpc/member_frontend.h @@ -113,7 +113,7 @@ namespace ccf } void remove_all_other_non_open_proposals( - kv::Tx& tx, const ProposalId& proposal_id) + ccf::kv::Tx& tx, const ProposalId& proposal_id) { auto p = tx.rw(jsgov::Tables::PROPOSALS); auto pi = @@ -136,7 +136,7 @@ namespace ccf } ccf::jsgov::ProposalInfoSummary resolve_proposal( - kv::Tx& tx, + ccf::kv::Tx& tx, const ProposalId& proposal_id, const std::span& proposal_bytes, const std::string& constitution) @@ -359,13 +359,13 @@ namespace ccf } } - bool check_member_active(kv::ReadOnlyTx& tx, const MemberId& id) + bool check_member_active(ccf::kv::ReadOnlyTx& tx, const MemberId& id) { return check_member_status(tx, id, {MemberStatus::ACTIVE}); } bool check_member_status( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const MemberId& id, std::initializer_list allowed) { @@ -385,14 +385,16 @@ namespace ccf } void record_voting_history( - kv::Tx& tx, const MemberId& caller_id, const SignedReq& signed_request) + ccf::kv::Tx& tx, + const MemberId& caller_id, + const SignedReq& signed_request) { auto governance_history = tx.rw(network.governance_history); governance_history->put(caller_id, {signed_request}); } void record_cose_governance_history( - kv::Tx& tx, + ccf::kv::Tx& tx, const MemberId& caller_id, const std::span& cose_sign1) { @@ -402,7 +404,7 @@ namespace ccf } ProposalSubmissionStatus is_proposal_submission_acceptable( - kv::Tx& tx, + ccf::kv::Tx& tx, const std::string& created_at, const std::vector& request_digest, const ccf::ProposalId& proposal_id, @@ -482,9 +484,9 @@ namespace ccf void add_kv_wrapper_endpoint(T table) { constexpr bool is_map = - ccf::nonstd::is_specialization::value; + ccf::nonstd::is_specialization::value; constexpr bool is_value = - ccf::nonstd::is_specialization::value; + ccf::nonstd::is_specialization::value; if constexpr (!(is_map || is_value)) { diff --git a/src/node/rpc/no_create_tx_claims_digest.cpp b/src/node/rpc/no_create_tx_claims_digest.cpp index aff03bc8c647..0c1076557d90 100644 --- a/src/node/rpc/no_create_tx_claims_digest.cpp +++ b/src/node/rpc/no_create_tx_claims_digest.cpp @@ -6,7 +6,7 @@ namespace ccfapp { std::optional __attribute__((weak)) - get_create_tx_claims_digest(kv::ReadOnlyTx& tx) + get_create_tx_claims_digest(ccf::kv::ReadOnlyTx& tx) { return std::nullopt; } diff --git a/src/node/rpc/node_call_types.h b/src/node/rpc/node_call_types.h index cafcd8dacbfd..5e70089fcc4f 100644 --- a/src/node/rpc/node_call_types.h +++ b/src/node/rpc/node_call_types.h @@ -28,12 +28,12 @@ namespace ccf { ccf::NodeId node_id; ccf::NodeStartupState state; - kv::Version last_signed_seqno; - kv::Version startup_seqno; + ccf::kv::Version last_signed_seqno; + ccf::kv::Version startup_seqno; // Only on recovery - std::optional recovery_target_seqno; - std::optional last_recovered_seqno; + std::optional recovery_target_seqno; + std::optional last_recovered_seqno; bool stop_notice; }; @@ -86,7 +86,7 @@ namespace ccf // Always set by the joiner (node_state.h), but defaults to nullopt here // to make sure serialisation does take place now that it is OPTIONAL. std::optional consensus_type = std::nullopt; - std::optional startup_seqno = std::nullopt; + std::optional startup_seqno = std::nullopt; std::optional certificate_signing_request = std::nullopt; nlohmann::json node_data = nullptr; @@ -102,7 +102,7 @@ namespace ccf struct NetworkInfo { bool public_only = false; - kv::Version last_recovered_signed_idx = kv::NoVersion; + ccf::kv::Version last_recovered_signed_idx = ccf::kv::NoVersion; ConsensusType consensus_type = ConsensusType::CFT; std::optional reconfiguration_type = std::nullopt; // Unused, but kept for backwards compatibility @@ -117,7 +117,7 @@ namespace ccf NetworkInfo( bool public_only, - kv::Version last_recovered_signed_idx, + ccf::kv::Version last_recovered_signed_idx, ReconfigurationType reconfiguration_type, const LedgerSecretsMap& ledger_secrets, const NetworkIdentity& identity, diff --git a/src/node/rpc/node_frontend.h b/src/node/rpc/node_frontend.h index f2ec11f765b3..a0d5bcfa407f 100644 --- a/src/node/rpc/node_frontend.h +++ b/src/node/rpc/node_frontend.h @@ -117,7 +117,7 @@ namespace ccf struct ConsensusConfigDetails { - kv::ConsensusDetails details; + ccf::kv::ConsensusDetails details; }; DECLARE_JSON_TYPE(ConsensusConfigDetails); @@ -194,12 +194,12 @@ namespace ccf struct ExistingNodeInfo { NodeId node_id; - std::optional ledger_secret_seqno = std::nullopt; + std::optional ledger_secret_seqno = std::nullopt; std::optional endorsed_certificate = std::nullopt; }; std::optional check_node_exists( - kv::Tx& tx, + ccf::kv::Tx& tx, const std::vector& self_signed_node_der, std::optional node_status = std::nullopt) { @@ -234,7 +234,7 @@ namespace ccf } std::optional check_conflicting_node_network( - kv::Tx& tx, const NodeInfoNetwork& node_info_network) + ccf::kv::Tx& tx, const NodeInfoNetwork& node_info_network) { auto nodes = tx.rw(network.nodes); @@ -261,7 +261,7 @@ namespace ccf } auto add_node( - kv::Tx& tx, + ccf::kv::Tx& tx, const std::vector& node_der, const JoinNetworkNodeToNode::In& in, NodeStatus node_status, @@ -299,7 +299,7 @@ namespace ccf return make_error(code, ccf::errors::InvalidQuote, message); } - std::optional ledger_secret_seqno = std::nullopt; + std::optional ledger_secret_seqno = std::nullopt; if (node_status == NodeStatus::TRUSTED) { ledger_secret_seqno = @@ -1539,12 +1539,13 @@ namespace ccf else { // On recovery, force a new ledger chunk - auto tx_ = static_cast(&ctx.tx); + auto tx_ = static_cast(&ctx.tx); if (tx_ == nullptr) { throw std::logic_error("Could not cast tx to CommittableTx"); } - tx_->set_flag(kv::CommittableTx::Flag::LEDGER_CHUNK_BEFORE_THIS_TX); + tx_->set_flag( + ccf::kv::CommittableTx::Flag::LEDGER_CHUNK_BEFORE_THIS_TX); } auto endorsed_certificates = diff --git a/src/node/rpc/node_interface.h b/src/node/rpc/node_interface.h index 3fbcd41d90f7..6acddb4026ef 100644 --- a/src/node/rpc/node_interface.h +++ b/src/node/rpc/node_interface.h @@ -24,16 +24,17 @@ namespace ccf virtual ~AbstractNodeState() {} virtual void transition_service_to_open( - kv::Tx& tx, AbstractGovernanceEffects::ServiceIdentities identities) = 0; - virtual bool rekey_ledger(kv::Tx& tx) = 0; - virtual void trigger_recovery_shares_refresh(kv::Tx& tx) = 0; - virtual void trigger_ledger_chunk(kv::Tx& tx) = 0; - virtual void trigger_snapshot(kv::Tx& tx) = 0; + ccf::kv::Tx& tx, + AbstractGovernanceEffects::ServiceIdentities identities) = 0; + virtual bool rekey_ledger(ccf::kv::Tx& tx) = 0; + virtual void trigger_recovery_shares_refresh(ccf::kv::Tx& tx) = 0; + virtual void trigger_ledger_chunk(ccf::kv::Tx& tx) = 0; + virtual void trigger_snapshot(ccf::kv::Tx& tx) = 0; virtual void trigger_host_process_launch( const std::vector& args, const std::vector& input) = 0; virtual void trigger_acme_refresh( - kv::Tx& tx, + ccf::kv::Tx& tx, const std::optional>& interfaces = std::nullopt) = 0; virtual void install_custom_acme_challenge_handler( @@ -46,15 +47,15 @@ namespace ccf virtual bool is_reading_public_ledger() const = 0; virtual bool is_reading_private_ledger() const = 0; virtual bool is_part_of_network() const = 0; - virtual kv::Version get_last_recovered_signed_idx() = 0; - virtual void initiate_private_recovery(kv::Tx& tx) = 0; + virtual ccf::kv::Version get_last_recovered_signed_idx() = 0; + virtual void initiate_private_recovery(ccf::kv::Tx& tx) = 0; virtual ExtendedState state() = 0; virtual QuoteVerificationResult verify_quote( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const QuoteInfo& quote_info, const std::vector& expected_node_public_key_der, pal::PlatformAttestationMeasurement& measurement) = 0; - virtual kv::Version get_startup_snapshot_seqno() = 0; + virtual ccf::kv::Version get_startup_snapshot_seqno() = 0; virtual SessionMetrics get_session_metrics() = 0; virtual size_t get_jwt_attempts() = 0; virtual ccf::crypto::Pem get_self_signed_certificate() = 0; @@ -76,7 +77,7 @@ namespace ccf const std::string& app_protocol = "HTTP1", bool use_node_client_certificate = false) = 0; - virtual std::shared_ptr get_store() = 0; + virtual std::shared_ptr get_store() = 0; virtual ringbuffer::AbstractWriterFactory& get_writer_factory() = 0; }; } diff --git a/src/node/rpc/node_operation.h b/src/node/rpc/node_operation.h index 5bd7c839c882..99bd399d80de 100644 --- a/src/node/rpc/node_operation.h +++ b/src/node/rpc/node_operation.h @@ -65,12 +65,12 @@ namespace ccf return impl.can_replicate(); } - kv::Version get_last_recovered_signed_idx() override + ccf::kv::Version get_last_recovered_signed_idx() override { return impl.get_last_recovered_signed_idx(); } - kv::Version get_startup_snapshot_seqno() override + ccf::kv::Version get_startup_snapshot_seqno() override { return impl.get_startup_snapshot_seqno(); } @@ -86,7 +86,7 @@ namespace ccf } QuoteVerificationResult verify_quote( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const QuoteInfo& quote_info, const std::vector& expected_node_public_key_der, pal::PlatformAttestationMeasurement& measurement) override @@ -95,7 +95,7 @@ namespace ccf tx, quote_info, expected_node_public_key_der, measurement); } - void initiate_private_recovery(kv::Tx& tx) override + void initiate_private_recovery(ccf::kv::Tx& tx) override { impl.initiate_private_recovery(tx); } diff --git a/src/node/rpc/node_operation_interface.h b/src/node/rpc/node_operation_interface.h index 67f659f6a016..77edb89fb87b 100644 --- a/src/node/rpc/node_operation_interface.h +++ b/src/node/rpc/node_operation_interface.h @@ -15,8 +15,8 @@ namespace ccf { using ExtendedState = std::tuple< NodeStartupState, - std::optional /* recovery_target_seqno */, - std::optional /* last_recovered_seqno */>; + std::optional /* recovery_target_seqno */, + std::optional /* last_recovered_seqno */>; class AbstractNodeOperation : public ccf::AbstractNodeSubSystem { @@ -42,19 +42,19 @@ namespace ccf virtual bool can_replicate() = 0; - virtual kv::Version get_last_recovered_signed_idx() = 0; - virtual kv::Version get_startup_snapshot_seqno() = 0; + virtual ccf::kv::Version get_last_recovered_signed_idx() = 0; + virtual ccf::kv::Version get_startup_snapshot_seqno() = 0; virtual SessionMetrics get_session_metrics() = 0; virtual size_t get_jwt_attempts() = 0; virtual QuoteVerificationResult verify_quote( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const QuoteInfo& quote_info, const std::vector& expected_node_public_key_der, pal::PlatformAttestationMeasurement& measurement) = 0; - virtual void initiate_private_recovery(kv::Tx& tx) = 0; + virtual void initiate_private_recovery(ccf::kv::Tx& tx) = 0; virtual ccf::crypto::Pem get_self_signed_node_certificate() = 0; }; diff --git a/src/node/rpc/test/frontend_test.cpp b/src/node/rpc/test/frontend_test.cpp index fb86ee474ad2..5463fa3c02ed 100644 --- a/src/node/rpc/test/frontend_test.cpp +++ b/src/node/rpc/test/frontend_test.cpp @@ -42,7 +42,8 @@ class TSimpleFrontend : public RpcFrontend public: Registry registry; - TSimpleFrontend(kv::Store& tables, ccfapp::AbstractNodeContext& context) : + TSimpleFrontend( + ccf::kv::Store& tables, ccfapp::AbstractNodeContext& context) : RpcFrontend(tables, registry, context), registry(context) {} @@ -55,7 +56,8 @@ class BaseTestFrontend : public SimpleUserRpcFrontend public: ccf::StubNodeContext context; - BaseTestFrontend(kv::Store& tables) : SimpleUserRpcFrontend(tables, context) + BaseTestFrontend(ccf::kv::Store& tables) : + SimpleUserRpcFrontend(tables, context) {} // For testing only, we don't need to specify auth policies everywhere and @@ -73,7 +75,7 @@ class BaseTestFrontend : public SimpleUserRpcFrontend class TestUserFrontend : public BaseTestFrontend { public: - TestUserFrontend(kv::Store& tables) : BaseTestFrontend(tables) + TestUserFrontend(ccf::kv::Store& tables) : BaseTestFrontend(tables) { open(); @@ -101,7 +103,8 @@ class TestUserFrontend : public BaseTestFrontend class TestJsonWrappedEndpointFunction : public BaseTestFrontend { public: - TestJsonWrappedEndpointFunction(kv::Store& tables) : BaseTestFrontend(tables) + TestJsonWrappedEndpointFunction(ccf::kv::Store& tables) : + BaseTestFrontend(tables) { open(); @@ -150,7 +153,7 @@ class TestJsonWrappedEndpointFunction : public BaseTestFrontend class TestRestrictedVerbsFrontend : public BaseTestFrontend { public: - TestRestrictedVerbsFrontend(kv::Store& tables) : BaseTestFrontend(tables) + TestRestrictedVerbsFrontend(ccf::kv::Store& tables) : BaseTestFrontend(tables) { open(); @@ -175,9 +178,9 @@ class TestRestrictedVerbsFrontend : public BaseTestFrontend class TestExplicitCommitability : public BaseTestFrontend { public: - kv::Map values; + ccf::kv::Map values; - TestExplicitCommitability(kv::Store& tables) : + TestExplicitCommitability(ccf::kv::Store& tables) : BaseTestFrontend(tables), values("test_values") { @@ -208,7 +211,7 @@ class TestExplicitCommitability : public BaseTestFrontend class TestAlternativeHandlerTypes : public BaseTestFrontend { public: - TestAlternativeHandlerTypes(kv::Store& tables) : BaseTestFrontend(tables) + TestAlternativeHandlerTypes(ccf::kv::Store& tables) : BaseTestFrontend(tables) { open(); @@ -236,7 +239,7 @@ class TestAlternativeHandlerTypes : public BaseTestFrontend class TestTemplatedPaths : public BaseTestFrontend { public: - TestTemplatedPaths(kv::Store& tables) : BaseTestFrontend(tables) + TestTemplatedPaths(ccf::kv::Store& tables) : BaseTestFrontend(tables) { open(); @@ -252,7 +255,7 @@ class TestTemplatedPaths : public BaseTestFrontend class TestDecodedTemplatedPaths : public BaseTestFrontend { public: - TestDecodedTemplatedPaths(kv::Store& tables) : BaseTestFrontend(tables) + TestDecodedTemplatedPaths(ccf::kv::Store& tables) : BaseTestFrontend(tables) { open(); @@ -292,7 +295,7 @@ class TestNoCertsFrontend : public RpcFrontend ccf::endpoints::EndpointRegistry endpoints; public: - TestNoCertsFrontend(kv::Store& tables) : + TestNoCertsFrontend(ccf::kv::Store& tables) : RpcFrontend(tables, endpoints, context), endpoints("test") { @@ -343,7 +346,7 @@ class TestForwardingUserFrontEnd : public BaseTestFrontend, public RpcContextRecorder { public: - TestForwardingUserFrontEnd(kv::Store& tables) : BaseTestFrontend(tables) + TestForwardingUserFrontEnd(ccf::kv::Store& tables) : BaseTestFrontend(tables) { open(); @@ -478,7 +481,8 @@ void prepare_callers(NetworkState& network) // It is necessary to set a consensus before committing the first transaction, // so that the KV batching done before calling into replicate() stays in // order. - auto backup_consensus = std::make_shared(); + auto backup_consensus = + std::make_shared(); network.tables->set_consensus(backup_consensus); auto tx = network.tables->create_tx(); @@ -490,7 +494,7 @@ void prepare_callers(NetworkState& network) user_id = InternalTablesAccess::add_user(tx, {user_caller}); member_id = InternalTablesAccess::add_member(tx, member_cert); invalid_member_id = InternalTablesAccess::add_member(tx, invalid_caller); - CHECK(tx.commit() == kv::CommitResult::SUCCESS); + CHECK(tx.commit() == ccf::kv::CommitResult::SUCCESS); } TEST_CASE("SignedReq to and from json") @@ -869,7 +873,7 @@ TEST_CASE("Explicit commitability") { auto tx = network.tables->create_tx(); tx.rw(frontend.values)->put(0, next_value); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } for (const auto status : all_statuses) @@ -1060,7 +1064,8 @@ TEST_CASE("Forwarding" * doctest::test_suite("forwarding")) TestForwardingUserFrontEnd user_frontend_primary(*network_primary.tables); TestForwardingUserFrontEnd user_frontend_backup(*network_backup.tables); - auto primary_consensus = std::make_shared(); + auto primary_consensus = + std::make_shared(); network_primary.tables->set_consensus(primary_consensus); auto channel_stub = std::make_shared(); @@ -1068,7 +1073,8 @@ TEST_CASE("Forwarding" * doctest::test_suite("forwarding")) auto rpc_map = std::weak_ptr(); auto backup_forwarder = std::make_shared>( rpc_responder, channel_stub, rpc_map); - auto backup_consensus = std::make_shared(); + auto backup_consensus = + std::make_shared(); network_backup.tables->set_consensus(backup_consensus); auto simple_call = create_simple_request(); @@ -1116,7 +1122,7 @@ TEST_CASE("Forwarding" * doctest::test_suite("forwarding")) auto forwarded_msg = channel_stub->get_pop_back(); auto fwd_ctx = backup_forwarder->recv_forwarded_command( - kv::test::FirstBackupNodeId, + ccf::kv::test::FirstBackupNodeId, forwarded_msg.data(), forwarded_msg.size()); @@ -1148,7 +1154,7 @@ TEST_CASE("Forwarding" * doctest::test_suite("forwarding")) auto forwarded_msg = channel_stub->get_pop_back(); auto fwd_ctx = backup_forwarder->recv_forwarded_command( - kv::test::FirstBackupNodeId, + ccf::kv::test::FirstBackupNodeId, forwarded_msg.data(), forwarded_msg.size()); @@ -1206,7 +1212,8 @@ TEST_CASE("Nodefrontend forwarding" * doctest::test_suite("forwarding")) auto channel_stub = std::make_shared(); - auto primary_consensus = std::make_shared(); + auto primary_consensus = + std::make_shared(); network_primary.tables->set_consensus(primary_consensus); auto rpc_responder = std::weak_ptr(); @@ -1214,7 +1221,8 @@ TEST_CASE("Nodefrontend forwarding" * doctest::test_suite("forwarding")) auto backup_forwarder = std::make_shared>( rpc_responder, channel_stub, rpc_map); node_frontend_backup.set_cmd_forwarder(backup_forwarder); - auto backup_consensus = std::make_shared(); + auto backup_consensus = + std::make_shared(); network_backup.tables->set_consensus(backup_consensus); auto write_req = create_simple_request(); @@ -1230,7 +1238,9 @@ TEST_CASE("Nodefrontend forwarding" * doctest::test_suite("forwarding")) auto forwarded_msg = channel_stub->get_pop_back(); auto fwd_ctx = backup_forwarder->recv_forwarded_command( - kv::test::FirstBackupNodeId, forwarded_msg.data(), forwarded_msg.size()); + ccf::kv::test::FirstBackupNodeId, + forwarded_msg.data(), + forwarded_msg.size()); node_frontend_primary.process_forwarded(fwd_ctx); auto response = parse_response(fwd_ctx->serialise_response()); @@ -1253,7 +1263,8 @@ TEST_CASE("Userfrontend forwarding" * doctest::test_suite("forwarding")) auto channel_stub = std::make_shared(); - auto primary_consensus = std::make_shared(); + auto primary_consensus = + std::make_shared(); network_primary.tables->set_consensus(primary_consensus); auto rpc_responder = std::weak_ptr(); @@ -1261,7 +1272,8 @@ TEST_CASE("Userfrontend forwarding" * doctest::test_suite("forwarding")) auto backup_forwarder = std::make_shared>( rpc_responder, channel_stub, rpc_map); user_frontend_backup.set_cmd_forwarder(backup_forwarder); - auto backup_consensus = std::make_shared(); + auto backup_consensus = + std::make_shared(); network_backup.tables->set_consensus(backup_consensus); auto write_req = create_simple_request(); @@ -1275,7 +1287,9 @@ TEST_CASE("Userfrontend forwarding" * doctest::test_suite("forwarding")) auto forwarded_msg = channel_stub->get_pop_back(); auto fwd_ctx = backup_forwarder->recv_forwarded_command( - kv::test::FirstBackupNodeId, forwarded_msg.data(), forwarded_msg.size()); + ccf::kv::test::FirstBackupNodeId, + forwarded_msg.data(), + forwarded_msg.size()); user_frontend_primary.process_forwarded(fwd_ctx); auto response = parse_response(fwd_ctx->serialise_response()); @@ -1300,7 +1314,8 @@ TEST_CASE("Memberfrontend forwarding" * doctest::test_suite("forwarding")) TestForwardingMemberFrontEnd member_frontend_backup(network_backup, context); auto channel_stub = std::make_shared(); - auto primary_consensus = std::make_shared(); + auto primary_consensus = + std::make_shared(); network_primary.tables->set_consensus(primary_consensus); auto rpc_responder = std::weak_ptr(); @@ -1308,7 +1323,8 @@ TEST_CASE("Memberfrontend forwarding" * doctest::test_suite("forwarding")) auto backup_forwarder = std::make_shared>( rpc_responder, channel_stub, rpc_map); member_frontend_backup.set_cmd_forwarder(backup_forwarder); - auto backup_consensus = std::make_shared(); + auto backup_consensus = + std::make_shared(); network_backup.tables->set_consensus(backup_consensus); auto write_req = create_simple_request(); @@ -1322,7 +1338,9 @@ TEST_CASE("Memberfrontend forwarding" * doctest::test_suite("forwarding")) auto forwarded_msg = channel_stub->get_pop_back(); auto fwd_ctx = backup_forwarder->recv_forwarded_command( - kv::test::FirstBackupNodeId, forwarded_msg.data(), forwarded_msg.size()); + ccf::kv::test::FirstBackupNodeId, + forwarded_msg.data(), + forwarded_msg.size()); member_frontend_primary.process_forwarded(fwd_ctx); auto response = parse_response(fwd_ctx->serialise_response()); @@ -1335,10 +1353,10 @@ TEST_CASE("Memberfrontend forwarding" * doctest::test_suite("forwarding")) class TestConflictFrontend : public BaseTestFrontend { public: - using Values = kv::Map; + using Values = ccf::kv::Map; size_t execution_count = 0; - TestConflictFrontend(kv::Store& tables) : BaseTestFrontend(tables) + TestConflictFrontend(ccf::kv::Store& tables) : BaseTestFrontend(tables) { open(); @@ -1358,7 +1376,7 @@ class TestConflictFrontend : public BaseTestFrontend auto tx = this->tables.create_tx(); auto conflict_map = tx.template rw("test_values_conflict"); conflict_map->put(0, 42); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); // Indicate that the execution conflicted ctx.rpc_ctx->set_response_header("test-has-conflicted", "true"); @@ -1429,7 +1447,7 @@ TEST_CASE("Retry on conflict") class TestManualConflictsRegistry : public UserEndpointRegistry { public: - using MyVals = kv::Map; + using MyVals = ccf::kv::Map; static constexpr auto SRC = "source"; static constexpr auto DST = "destination"; @@ -1531,7 +1549,7 @@ class TestManualConflictsFrontend ccf::StubNodeContext context; - TestManualConflictsFrontend(kv::Store& tables) : + TestManualConflictsFrontend(ccf::kv::Store& tables) : TSimpleFrontend(tables, context) { open(); @@ -1582,7 +1600,7 @@ TEST_CASE("Manual conflicts") auto tx = network.tables->create_tx(); auto handle = tx.ro(table); auto ret = handle->get(TF::KEY); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); ccf::crypto::openssl_sha256_shutdown(); return ret; }; @@ -1594,7 +1612,7 @@ TEST_CASE("Manual conflicts") using TF = TestManualConflictsFrontend; auto handle = tx.wo(table); handle->put(key, n); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); ccf::crypto::openssl_sha256_shutdown(); }; @@ -1715,7 +1733,7 @@ TEST_CASE("Manual conflicts") using TF = TestManualConflictsFrontend; auto handle = tx.wo(TF::SRC); handle->remove(TF::KEY); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); }); const auto metrics_after = get_metrics(); @@ -1738,7 +1756,7 @@ TEST_CASE("Manual conflicts") using TF = TestManualConflictsFrontend; auto handle = tx.wo(TF::SRC); handle->clear(); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); }); const auto metrics_after = get_metrics(); @@ -1761,7 +1779,7 @@ TEST_CASE("Manual conflicts") [&]() { auto tx = network.tables->create_tx(); InternalTablesAccess::remove_user(tx, user_id); - CHECK(tx.commit() == kv::CommitResult::SUCCESS); + CHECK(tx.commit() == ccf::kv::CommitResult::SUCCESS); }, user_session, HTTP_STATUS_UNAUTHORIZED); diff --git a/src/node/rpc/test/frontend_test_infra.h b/src/node/rpc/test/frontend_test_infra.h index 359024333025..79fa237b9a3e 100644 --- a/src/node/rpc/test/frontend_test_infra.h +++ b/src/node/rpc/test/frontend_test_infra.h @@ -41,7 +41,7 @@ auto verifier_mem = ccf::crypto::make_verifier(member_cert); auto user_cert = kp -> self_sign("CN=name_user", valid_from, valid_to); auto dummy_enc_pubk = ccf::crypto::make_rsa_key_pair() -> public_key_pem(); -auto encryptor = std::make_shared(); +auto encryptor = std::make_shared(); constexpr auto default_pack = serdes::Pack::Text; @@ -133,9 +133,9 @@ void init_network(NetworkState& network) { network.tables->set_encryptor(encryptor); auto history = std::make_shared( - *network.tables, kv::test::PrimaryNodeId, *kp); + *network.tables, ccf::kv::test::PrimaryNodeId, *kp); network.tables->set_history(history); - auto consensus = std::make_shared(); + auto consensus = std::make_shared(); network.tables->set_consensus(consensus); network.identity = make_test_network_ident(); } \ No newline at end of file diff --git a/src/node/rpc/test/node_frontend_test.cpp b/src/node/rpc/test/node_frontend_test.cpp index 168afa2f3799..c99ea27ffd1e 100644 --- a/src/node/rpc/test/node_frontend_test.cpp +++ b/src/node/rpc/test/node_frontend_test.cpp @@ -65,7 +65,7 @@ void require_ledger_secrets_equal( TEST_CASE("Add a node to an opening service") { NetworkState network; - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); network.tables->set_encryptor(encryptor); auto gen_tx = network.tables->create_tx(); InternalTablesAccess::init_configuration( @@ -80,7 +80,7 @@ TEST_CASE("Add a node to an opening service") frontend.open(); // New node should not be given ledger secret past this one via join request - kv::Version up_to_ledger_secret_seqno = 4; + ccf::kv::Version up_to_ledger_secret_seqno = 4; network.ledger_secrets->set_secret( up_to_ledger_secret_seqno, make_ledger_secret()); @@ -103,7 +103,7 @@ TEST_CASE("Add a node to an opening service") InternalTablesAccess::create_service( gen_tx, network.identity->cert, ccf::TxID{}); - REQUIRE(gen_tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(gen_tx.commit() == ccf::kv::CommitResult::SUCCESS); auto tx = network.tables->create_tx(); INFO("Add first node which should be trusted straight away"); @@ -185,7 +185,7 @@ TEST_CASE("Add a node to an open service") { NetworkState network; auto gen_tx = network.tables->create_tx(); - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); network.tables->set_encryptor(encryptor); network.identity = make_test_network_ident(); @@ -198,7 +198,7 @@ TEST_CASE("Add a node to an open service") frontend.open(); // New node should not be given ledger secret past this one via join request - kv::Version up_to_ledger_secret_seqno = 4; + ccf::kv::Version up_to_ledger_secret_seqno = 4; network.ledger_secrets->set_secret( up_to_ledger_secret_seqno, make_ledger_secret()); @@ -211,7 +211,7 @@ TEST_CASE("Add a node to an open service") gen_tx, {member_cert, ccf::crypto::make_rsa_key_pair()->public_key_pem()})); REQUIRE(InternalTablesAccess::open_service(gen_tx)); - REQUIRE(gen_tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(gen_tx.commit() == ccf::kv::CommitResult::SUCCESS); // Node certificate ccf::crypto::KeyPairPtr kp = ccf::crypto::make_key_pair(); @@ -289,7 +289,7 @@ TEST_CASE("Add a node to an open service") "CN=dummy endorsed certificate", valid_from, valid_to); auto endorsed_certificate = tx.rw(network.node_endorsed_certificates); endorsed_certificate->put(joining_node_id, {dummy_endorsed_certificate}); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); // In the meantime, a new ledger secret is added. The new ledger secret // should not be passed to the new joiner via the join diff --git a/src/node/rpc/test/node_stub.h b/src/node/rpc/test/node_stub.h index e96efb672750..6ab0ddebf7cf 100644 --- a/src/node/rpc/test/node_stub.h +++ b/src/node/rpc/test/node_stub.h @@ -66,9 +66,9 @@ namespace ccf return true; } - kv::Version get_last_recovered_signed_idx() override + ccf::kv::Version get_last_recovered_signed_idx() override { - return kv::NoVersion; + return ccf::kv::NoVersion; } SessionMetrics get_session_metrics() override @@ -82,7 +82,7 @@ namespace ccf } QuoteVerificationResult verify_quote( - kv::ReadOnlyTx& tx, + ccf::kv::ReadOnlyTx& tx, const QuoteInfo& quote_info, const std::vector& expected_node_public_key_der, pal::PlatformAttestationMeasurement& measurement) override @@ -90,12 +90,12 @@ namespace ccf return QuoteVerificationResult::Verified; } - kv::Version get_startup_snapshot_seqno() override + ccf::kv::Version get_startup_snapshot_seqno() override { return 0; } - void initiate_private_recovery(kv::Tx& tx) override + void initiate_private_recovery(ccf::kv::Tx& tx) override { throw std::logic_error("Unimplemented"); } @@ -109,33 +109,33 @@ namespace ccf class StubGovernanceEffects : public ccf::AbstractGovernanceEffects { public: - void transition_service_to_open(kv::Tx& tx, ServiceIdentities) override + void transition_service_to_open(ccf::kv::Tx& tx, ServiceIdentities) override { return; } - bool rekey_ledger(kv::Tx& tx) override + bool rekey_ledger(ccf::kv::Tx& tx) override { return true; } - void trigger_recovery_shares_refresh(kv::Tx& tx) override + void trigger_recovery_shares_refresh(ccf::kv::Tx& tx) override { return; } - void trigger_ledger_chunk(kv::Tx& tx) override + void trigger_ledger_chunk(ccf::kv::Tx& tx) override { return; } - void trigger_snapshot(kv::Tx& tx) override + void trigger_snapshot(ccf::kv::Tx& tx) override { return; } void trigger_acme_refresh( - kv::Tx& tx, + ccf::kv::Tx& tx, const std::optional>& interfaces = std::nullopt) override { @@ -163,7 +163,7 @@ namespace ccf void track_deletes_on_missing_keys(bool track) {} - kv::ReadOnlyStorePtr get_store_at( + ccf::kv::ReadOnlyStorePtr get_store_at( historical::RequestHandle handle, ccf::SeqNo seqno, historical::ExpiryDuration seconds_until_expiry) @@ -171,7 +171,7 @@ namespace ccf return nullptr; } - kv::ReadOnlyStorePtr get_store_at( + ccf::kv::ReadOnlyStorePtr get_store_at( historical::RequestHandle handle, ccf::SeqNo seqno) { return nullptr; @@ -191,7 +191,7 @@ namespace ccf return nullptr; } - std::vector get_store_range( + std::vector get_store_range( historical::RequestHandle handle, ccf::SeqNo start_seqno, ccf::SeqNo end_seqno, @@ -200,7 +200,7 @@ namespace ccf return {}; } - std::vector get_store_range( + std::vector get_store_range( historical::RequestHandle handle, ccf::SeqNo start_seqno, ccf::SeqNo end_seqno) @@ -225,7 +225,7 @@ namespace ccf return {}; } - std::vector get_stores_for( + std::vector get_stores_for( historical::RequestHandle handle, const SeqNoCollection& seqnos, historical::ExpiryDuration seconds_until_expiry) @@ -233,7 +233,7 @@ namespace ccf return {}; } - std::vector get_stores_for( + std::vector get_stores_for( historical::RequestHandle handle, const SeqNoCollection& seqnos) { return {}; @@ -284,7 +284,7 @@ namespace ccf ccf::NodeId get_node_id() const override { - return kv::test::PrimaryNodeId; + return ccf::kv::test::PrimaryNodeId; } }; } diff --git a/src/node/secret_broadcast.h b/src/node/secret_broadcast.h index 86728a7209d7..fba11c73b4b7 100644 --- a/src/node/secret_broadcast.h +++ b/src/node/secret_broadcast.h @@ -18,7 +18,7 @@ namespace ccf static void broadcast_some( NetworkState& network, NodeId self, - kv::Tx& tx, + ccf::kv::Tx& tx, const LedgerSecretsMap& some_ledger_secrets) { auto secrets = tx.rw(network.secrets); @@ -46,7 +46,9 @@ namespace ccf } static void broadcast_new( - NetworkState& network, kv::Tx& tx, LedgerSecretPtr&& new_ledger_secret) + NetworkState& network, + ccf::kv::Tx& tx, + LedgerSecretPtr&& new_ledger_secret) { auto secrets = tx.rw(network.secrets); diff --git a/src/node/share_manager.h b/src/node/share_manager.h index 605cb0022e31..bdf9b24bc2d6 100644 --- a/src/node/share_manager.h +++ b/src/node/share_manager.h @@ -157,7 +157,7 @@ namespace ccf std::shared_ptr ledger_secrets; EncryptedSharesMap compute_encrypted_shares( - kv::Tx& tx, const LedgerSecretWrappingKey& ls_wrapping_key) + ccf::kv::Tx& tx, const LedgerSecretWrappingKey& ls_wrapping_key) { EncryptedSharesMap encrypted_shares; auto shares = ls_wrapping_key.get_shares(); @@ -181,7 +181,7 @@ namespace ccf } void shuffle_recovery_shares( - kv::Tx& tx, const LedgerSecretPtr& latest_ledger_secret) + ccf::kv::Tx& tx, const LedgerSecretPtr& latest_ledger_secret) { auto active_recovery_members_info = InternalTablesAccess::get_active_recovery_members(tx); @@ -224,11 +224,11 @@ namespace ccf } void set_recovery_shares_info( - kv::Tx& tx, + ccf::kv::Tx& tx, const LedgerSecretPtr& latest_ledger_secret, const std::optional& previous_ledger_secret = std::nullopt, - std::optional latest_ls_version = std::nullopt) + std::optional latest_ls_version = std::nullopt) { // First, generate a fresh ledger secrets wrapping key and wrap the // latest ledger secret with it. Then, encrypt the penultimate ledger @@ -243,7 +243,7 @@ namespace ccf Tables::ENCRYPTED_PAST_LEDGER_SECRET); std::vector encrypted_previous_secret = {}; - kv::Version version_previous_secret = kv::NoVersion; + ccf::kv::Version version_previous_secret = ccf::kv::NoVersion; if (previous_ledger_secret.has_value()) { version_previous_secret = previous_ledger_secret->first; @@ -310,7 +310,8 @@ namespace ccf return decrypted_share; } - LedgerSecretWrappingKey combine_from_encrypted_submitted_shares(kv::Tx& tx) + LedgerSecretWrappingKey combine_from_encrypted_submitted_shares( + ccf::kv::Tx& tx) { auto encrypted_submitted_shares = tx.rw( Tables::ENCRYPTED_SUBMITTED_SHARES); @@ -396,7 +397,7 @@ namespace ccf * * @param tx Store transaction object */ - void issue_recovery_shares(kv::Tx& tx) + void issue_recovery_shares(ccf::kv::Tx& tx) { auto [latest, penultimate] = ledger_secrets->get_latest_and_penultimate(tx); @@ -415,7 +416,8 @@ namespace ccf * derived from the hook at which the ledger secret is applied to the * store. */ - void issue_recovery_shares(kv::Tx& tx, LedgerSecretPtr new_ledger_secret) + void issue_recovery_shares( + ccf::kv::Tx& tx, LedgerSecretPtr new_ledger_secret) { set_recovery_shares_info( tx, new_ledger_secret, ledger_secrets->get_latest(tx)); @@ -427,13 +429,13 @@ namespace ccf * * @param tx Store transaction object */ - void shuffle_recovery_shares(kv::Tx& tx) + void shuffle_recovery_shares(ccf::kv::Tx& tx) { shuffle_recovery_shares(tx, ledger_secrets->get_latest(tx).second); } static std::optional get_encrypted_share( - kv::ReadOnlyTx& tx, const MemberId& member_id) + ccf::kv::ReadOnlyTx& tx, const MemberId& member_id) { auto recovery_shares_info = tx.ro(Tables::SHARES)->get(); @@ -453,7 +455,7 @@ namespace ccf } LedgerSecretsMap restore_recovery_shares_info( - kv::Tx& tx, + ccf::kv::Tx& tx, const RecoveredEncryptedLedgerSecrets& recovery_ledger_secrets) { // First, re-assemble the ledger secret wrapping key from the submitted @@ -526,7 +528,7 @@ namespace ccf } size_t submit_recovery_share( - kv::Tx& tx, + ccf::kv::Tx& tx, MemberId member_id, const std::vector& submitted_recovery_share) { @@ -547,7 +549,7 @@ namespace ccf return encrypted_submitted_shares->size(); } - static void clear_submitted_recovery_shares(kv::Tx& tx) + static void clear_submitted_recovery_shares(ccf::kv::Tx& tx) { auto encrypted_submitted_shares = tx.rw( Tables::ENCRYPTED_SUBMITTED_SHARES); diff --git a/src/node/snapshot_serdes.h b/src/node/snapshot_serdes.h index 2d80764bdf8c..c768987043bb 100644 --- a/src/node/snapshot_serdes.h +++ b/src/node/snapshot_serdes.h @@ -18,17 +18,17 @@ namespace ccf struct StartupSnapshotInfo { std::vector raw; - kv::Version seqno; + ccf::kv::Version seqno; // Store used to verify a snapshot (either created fresh when a node joins // from a snapshot or points to the main store when recovering from a // snapshot) - std::shared_ptr store = nullptr; + std::shared_ptr store = nullptr; StartupSnapshotInfo( - const std::shared_ptr& store_, + const std::shared_ptr& store_, std::vector&& raw_, - kv::Version seqno_) : + ccf::kv::Version seqno_) : raw(std::move(raw_)), seqno(seqno_), store(store_) @@ -36,18 +36,19 @@ namespace ccf }; static void deserialise_snapshot( - const std::shared_ptr& store, + const std::shared_ptr& store, const std::vector& snapshot, - kv::ConsensusHookPtrs& hooks, - std::vector* view_history = nullptr, + ccf::kv::ConsensusHookPtrs& hooks, + std::vector* view_history = nullptr, bool public_only = false, std::optional> prev_service_identity = std::nullopt) { const auto* data = snapshot.data(); auto size = snapshot.size(); - auto tx_hdr = serialized::peek(data, size); - auto store_snapshot_size = sizeof(kv::SerialisedEntryHeader) + tx_hdr.size; + auto tx_hdr = serialized::peek(data, size); + auto store_snapshot_size = + sizeof(ccf::kv::SerialisedEntryHeader) + tx_hdr.size; auto receipt_data = data + store_snapshot_size; auto receipt_size = size - store_snapshot_size; @@ -114,7 +115,7 @@ namespace ccf auto rc = store->deserialise_snapshot( snapshot.data(), store_snapshot_size, hooks, view_history, public_only); - if (rc != kv::ApplyResult::PASS) + if (rc != ccf::kv::ApplyResult::PASS) { throw std::logic_error(fmt::format("Failed to apply snapshot: {}", rc)); } @@ -125,10 +126,10 @@ namespace ccf }; static std::unique_ptr initialise_from_snapshot( - const std::shared_ptr& store, + const std::shared_ptr& store, std::vector&& snapshot, - kv::ConsensusHookPtrs& hooks, - std::vector* view_history = nullptr, + ccf::kv::ConsensusHookPtrs& hooks, + std::vector* view_history = nullptr, bool public_only = false, std::optional> previous_service_identity = std::nullopt) @@ -149,7 +150,7 @@ namespace ccf const std::vector& tree, const NodeId& node_id, const ccf::crypto::Pem& node_cert, - kv::Version seqno, + ccf::kv::Version seqno, const ccf::crypto::Sha256Hash& write_set_digest, const std::string& commit_evidence, ccf::crypto::Sha256Hash&& claims_digest) diff --git a/src/node/snapshotter.h b/src/node/snapshotter.h index 68e8408f96d8..cabc8f371384 100644 --- a/src/node/snapshotter.h +++ b/src/node/snapshotter.h @@ -20,7 +20,7 @@ namespace ccf { class Snapshotter : public std::enable_shared_from_this, - public kv::AbstractSnapshotter + public ccf::kv::AbstractSnapshotter { private: static constexpr auto max_tx_interval = std::numeric_limits::max(); @@ -34,14 +34,14 @@ namespace ccf ccf::pal::Mutex lock; - std::shared_ptr store; + std::shared_ptr store; // Snapshots are never generated by default (e.g. during public recovery) size_t snapshot_tx_interval = max_tx_interval; struct SnapshotInfo { - kv::Version version; + ccf::kv::Version version; ccf::crypto::Sha256Hash write_set_digest; std::string commit_evidence; ccf::crypto::Sha256Hash snapshot_digest; @@ -100,7 +100,7 @@ namespace ccf struct SnapshotMsg { std::shared_ptr self; - std::unique_ptr snapshot; + std::unique_ptr snapshot; uint32_t generation_count; }; @@ -111,7 +111,7 @@ namespace ccf } void snapshot_( - std::unique_ptr snapshot, + std::unique_ptr snapshot, uint32_t generation_count) { if (pending_snapshots.size() >= max_pending_snapshots_count) @@ -157,7 +157,7 @@ namespace ccf auto rc = tx.commit(cd, false, nullptr, capture_ws_digest_and_commit_evidence); - if (rc != kv::CommitResult::SUCCESS) + if (rc != ccf::kv::CommitResult::SUCCESS) { LOG_FAIL_FMT( "Could not commit snapshot evidence for seqno {}: {}", @@ -232,7 +232,7 @@ namespace ccf public: Snapshotter( ringbuffer::AbstractWriterFactory& writer_factory_, - std::shared_ptr& store_, + std::shared_ptr& store_, size_t snapshot_tx_interval_) : writer_factory(writer_factory_), store(store_), @@ -346,7 +346,7 @@ namespace ccf next_snapshot_indices.back().idx); bool forced = store->flag_enabled_unsafe( - kv::AbstractStore::Flag::SNAPSHOT_AT_NEXT_SIGNATURE); + ccf::kv::AbstractStore::Flag::SNAPSHOT_AT_NEXT_SIGNATURE); ::consensus::Index last_unforced_idx = last_snapshot_idx; for (auto it = next_snapshot_indices.rbegin(); @@ -367,7 +367,7 @@ namespace ccf LOG_TRACE_FMT( "{} {} as snapshot index", !due ? "Forced" : "Recorded", idx); store->unset_flag_unsafe( - kv::AbstractStore::Flag::SNAPSHOT_AT_NEXT_SIGNATURE); + ccf::kv::AbstractStore::Flag::SNAPSHOT_AT_NEXT_SIGNATURE); return due; } @@ -464,7 +464,7 @@ namespace ccf // serialisation on another thread (round-robin). Otherwise, only record // that a snapshot was generated. - kv::ScopedStoreMapsLock maps_lock(store); + ccf::kv::ScopedStoreMapsLock maps_lock(store); std::lock_guard guard(lock); update_indices(idx); diff --git a/src/node/test/encryptor.cpp b/src/node/test/encryptor.cpp index 89f4e3792f48..d6a6fc0b05b0 100644 --- a/src/node/test/encryptor.cpp +++ b/src/node/test/encryptor.cpp @@ -16,29 +16,29 @@ #include #include -kv::ConsensusHookPtrs hooks; -using StringString = kv::Map; +ccf::kv::ConsensusHookPtrs hooks; +using StringString = ccf::kv::Map; -void commit_one(kv::Store& store, StringString& map) +void commit_one(ccf::kv::Store& store, StringString& map) { auto tx = store.create_tx(); auto m = tx.rw(map); m->put("key", "value"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } bool encrypt_round_trip( ccf::NodeEncryptor& encryptor, std::vector& plain, - kv::Version version) + ccf::kv::Version version) { std::vector aad; std::vector header; std::vector cipher(plain.size()); std::vector decrypted(plain.size()); - kv::Term term = 1; - kv::Term ret_term = 0; + ccf::kv::Term term = 1; + ccf::kv::Term ret_term = 0; encryptor.encrypt(plain, aad, header, cipher, {term, version}); encryptor.decrypt(cipher, aad, header, decrypted, version, ret_term); @@ -114,8 +114,8 @@ TEST_CASE("Subsequent ciphers from same plaintext are different") std::vector serialised_header; std::vector serialised_header2; std::vector additional_data; // No additional data - kv::Version version = 10; - kv::Term term = 1; + ccf::kv::Version version = 10; + ccf::kv::Term term = 1; encryptor.encrypt( plain, additional_data, serialised_header, cipher, {term, version}); @@ -141,8 +141,8 @@ TEST_CASE("Ciphers at same seqno with different terms are different") std::vector serialised_header; std::vector serialised_header2; std::vector additional_data; // No additional data - kv::Version version = 10; - kv::Term term = 1; + ccf::kv::Version version = 10; + ccf::kv::Term term = 1; encryptor.encrypt( plain, additional_data, serialised_header, cipher, {term, version}); @@ -167,8 +167,8 @@ TEST_CASE("Ciphers at same seqno/term with and without snapshot are different") std::vector serialised_header; std::vector serialised_header2; std::vector additional_data; // No additional data - kv::Version version = 10; - kv::Term term = 1; + ccf::kv::Version version = 10; + ccf::kv::Term term = 1; encryptor.encrypt( plain, @@ -176,7 +176,7 @@ TEST_CASE("Ciphers at same seqno/term with and without snapshot are different") serialised_header, cipher, {term, version}, - kv::EntryType::Snapshot); + ccf::kv::EntryType::Snapshot); encryptor.encrypt( plain, @@ -184,7 +184,7 @@ TEST_CASE("Ciphers at same seqno/term with and without snapshot are different") serialised_header2, cipher2, {term, version}, - kv::EntryType::WriteSet); + ccf::kv::EntryType::WriteSet); // Ciphers are different because IV is different REQUIRE(cipher != cipher2); @@ -201,8 +201,8 @@ TEST_CASE("Additional data") std::vector cipher; std::vector serialised_header; std::vector additional_data(256, 0x10); - kv::Version version = 10; - kv::Term term = 1; + ccf::kv::Version version = 10; + ccf::kv::Term term = 1; // Encrypting plain at version 10 encryptor.encrypt( @@ -236,10 +236,10 @@ TEST_CASE("Additional data") TEST_CASE("KV encryption/decryption") { - auto consensus = std::make_shared(); + auto consensus = std::make_shared(); StringString map("map"); - kv::Store primary_store; - kv::Store backup_store; + ccf::kv::Store primary_store; + ccf::kv::Store backup_store; std::shared_ptr primary_ledger_secrets; std::shared_ptr backup_ledger_secrets; @@ -270,7 +270,7 @@ TEST_CASE("KV encryption/decryption") commit_one(primary_store, map); REQUIRE( backup_store.deserialize(*consensus->get_latest_data())->apply() == - kv::ApplyResult::PASS); + ccf::kv::ApplyResult::PASS); } INFO("Rekeys"); @@ -295,17 +295,17 @@ TEST_CASE("KV encryption/decryption") REQUIRE( backup_store.deserialize(*consensus->get_latest_data())->apply() == - kv::ApplyResult::PASS); + ccf::kv::ApplyResult::PASS); } } } TEST_CASE("Backup catchup from many ledger secrets") { - auto consensus = std::make_shared(); + auto consensus = std::make_shared(); StringString map("map"); - kv::Store primary_store; - kv::Store backup_store; + ccf::kv::Store primary_store; + ccf::kv::Store backup_store; std::shared_ptr primary_ledger_secrets; std::shared_ptr backup_ledger_secrets; @@ -352,7 +352,7 @@ TEST_CASE("Backup catchup from many ledger secrets") { REQUIRE( backup_store.deserialize(*std::get<1>(next_entry.value()))->apply() == - kv::ApplyResult::PASS); + ccf::kv::ApplyResult::PASS); auto tx_id = backup_store.current_txid(); tx_id.version--; @@ -362,7 +362,7 @@ TEST_CASE("Backup catchup from many ledger secrets") REQUIRE( backup_store.deserialize(*std::get<1>(next_entry.value()))->apply() == - kv::ApplyResult::PASS); + ccf::kv::ApplyResult::PASS); next_entry = consensus->pop_oldest_entry(); } @@ -371,10 +371,10 @@ TEST_CASE("Backup catchup from many ledger secrets") TEST_CASE("KV integrity verification") { - auto consensus = std::make_shared(); + auto consensus = std::make_shared(); StringString map("map"); - kv::Store primary_store; - kv::Store backup_store; + ccf::kv::Store primary_store; + ccf::kv::Store backup_store; auto ledger_secrets = std::make_shared(); ledger_secrets->init(); @@ -400,14 +400,14 @@ TEST_CASE("KV integrity verification") auto r = backup_store.deserialize(latest_data.value()); auto rr = r->apply(); - REQUIRE(rr == kv::ApplyResult::FAIL); + REQUIRE(rr == ccf::kv::ApplyResult::FAIL); } TEST_CASE("Encryptor rollback") { StringString map("map"); constexpr auto store_term = 2; - kv::Store store; + ccf::kv::Store store; store.initialise_term(2); auto ledger_secrets = std::make_shared(); diff --git a/src/node/test/historical_queries.cpp b/src/node/test/historical_queries.cpp index cfd1dd3fceb6..e7fa424d1b64 100644 --- a/src/node/test/historical_queries.cpp +++ b/src/node/test/historical_queries.cpp @@ -25,7 +25,7 @@ std::unique_ptr threading::ThreadMessaging::singleton = nullptr; -using NumToString = kv::Map; +using NumToString = ccf::kv::Map; constexpr size_t certificate_validity_period_days = 365; using namespace std::literals; @@ -37,7 +37,7 @@ auto valid_to = ccf::crypto::compute_cert_valid_to_string( struct TestState { - std::shared_ptr kv_store = nullptr; + std::shared_ptr kv_store = nullptr; std::shared_ptr ledger_secrets = nullptr; ccf::crypto::KeyPairPtr node_kp = nullptr; }; @@ -46,9 +46,9 @@ TestState create_and_init_state(bool initialise_ledger_rekey = true) { TestState ts; - ts.kv_store = std::make_shared(); - ts.kv_store->set_consensus(std::make_shared()); - auto encryptor = std::make_shared(); + ts.kv_store = std::make_shared(); + ts.kv_store->set_consensus(std::make_shared()); + auto encryptor = std::make_shared(); ts.kv_store->set_encryptor(encryptor); ts.node_kp = ccf::crypto::make_key_pair(); @@ -69,7 +69,7 @@ TestState create_and_init_state(bool initialise_ledger_rekey = true) ni.cert = ts.node_kp->self_sign("CN=Test node", valid_from, valid_to); ni.status = ccf::NodeStatus::TRUSTED; nodes->put(node_id, ni); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } // Create ledger secrets to test decrypting entries across rekeys @@ -102,13 +102,13 @@ TestState create_and_init_state(bool initialise_ledger_rekey = true) member_info->put(member_id, {ccf::MemberStatus::ACTIVE}); member_public_encryption_keys->put( member_id, ccf::crypto::make_rsa_key_pair()->public_key_pem()); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } return ts; } -kv::Version write_transactions(kv::Store& kv_store, size_t tx_count) +ccf::kv::Version write_transactions(ccf::kv::Store& kv_store, size_t tx_count) { const auto begin = kv_store.current_version(); const auto end = begin + tx_count; @@ -121,22 +121,22 @@ kv::Version write_transactions(kv::Store& kv_store, size_t tx_count) public_map->put(i, s); private_map->put(i, s); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } REQUIRE(kv_store.current_version() == end); return kv_store.current_version(); } -kv::Version write_transactions_and_signature( - kv::Store& kv_store, size_t tx_count) +ccf::kv::Version write_transactions_and_signature( + ccf::kv::Store& kv_store, size_t tx_count) { write_transactions(kv_store, tx_count); kv_store.get_history()->emit_signature(); auto consensus = - dynamic_cast(kv_store.get_consensus().get()); + dynamic_cast(kv_store.get_consensus().get()); REQUIRE(consensus != nullptr); REQUIRE(consensus->get_committed_seqno() == kv_store.current_version()); @@ -147,8 +147,8 @@ kv::Version write_transactions_and_signature( return kv_store.current_version(); } -kv::Version rekey( - kv::Store& kv_store, +ccf::kv::Version rekey( + ccf::kv::Store& kv_store, const std::shared_ptr& ledger_secrets) { ccf::ShareManager share_manager(ledger_secrets); @@ -156,7 +156,7 @@ kv::Version rekey( auto tx = kv_store.create_tx(); auto new_ledger_secret = ccf::make_ledger_secret(); share_manager.issue_recovery_shares(tx, new_ledger_secret); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); auto tx_version = tx.commit_version(); @@ -168,7 +168,8 @@ kv::Version rekey( return tx_version; } -void validate_business_transaction(kv::ReadOnlyStorePtr store, ccf::SeqNo seqno) +void validate_business_transaction( + ccf::kv::ReadOnlyStorePtr store, ccf::SeqNo seqno) { REQUIRE(store != nullptr); @@ -209,9 +210,9 @@ void validate_business_transaction( } std::map> construct_host_ledger( - std::shared_ptr c) + std::shared_ptr c) { - auto consensus = dynamic_cast(c.get()); + auto consensus = dynamic_cast(c.get()); REQUIRE(consensus != nullptr); INFO("Rebuild ledger as seen by host"); @@ -241,8 +242,8 @@ TEST_CASE("StateCache point queries") auto state = create_and_init_state(); auto& kv_store = *state.kv_store; - kv::Version low_signature_transaction; - kv::Version high_signature_transaction; + ccf::kv::Version low_signature_transaction; + ccf::kv::Version high_signature_transaction; { INFO("Build some interesting state in the store"); @@ -514,7 +515,7 @@ TEST_CASE("StateCache get store vs get state") auto state = create_and_init_state(); auto& kv_store = *state.kv_store; - kv::Version signature_transaction; + ccf::kv::Version signature_transaction; { INFO("Build some interesting state in the store"); @@ -725,7 +726,7 @@ TEST_CASE("StateCache range queries") auto state = create_and_init_state(); auto& kv_store = *state.kv_store; - std::vector signature_versions; + std::vector signature_versions; const auto begin_seqno = kv_store.current_version() + 1; @@ -749,7 +750,7 @@ TEST_CASE("StateCache range queries") return accepted; }; - auto signing_version = [&signature_versions](kv::Version seqno) { + auto signing_version = [&signature_versions](ccf::kv::Version seqno) { const auto begin = signature_versions.begin(); const auto end = signature_versions.end(); @@ -767,8 +768,8 @@ TEST_CASE("StateCache range queries") std::random_device rd; std::mt19937 g(rd()); auto fetch_and_validate_range = [&]( - kv::Version range_start, - kv::Version range_end) { + ccf::kv::Version range_start, + ccf::kv::Version range_end) { constexpr auto this_handle = 42; { auto stores = cache.get_store_range(this_handle, range_start, range_end); @@ -853,7 +854,7 @@ TEST_CASE("Incremental progress") auto state = create_and_init_state(); auto& kv_store = *state.kv_store; - std::vector signature_versions; + std::vector signature_versions; const auto begin_seqno = kv_store.current_version() + 1; @@ -953,7 +954,7 @@ TEST_CASE("StateCache sparse queries") auto state = create_and_init_state(); auto& kv_store = *state.kv_store; - std::vector signature_versions; + std::vector signature_versions; const auto begin_seqno = kv_store.current_version() + 1; @@ -977,7 +978,7 @@ TEST_CASE("StateCache sparse queries") return accepted; }; - auto signing_version = [&signature_versions](kv::Version seqno) { + auto signing_version = [&signature_versions](ccf::kv::Version seqno) { const auto begin = signature_versions.begin(); const auto end = signature_versions.end(); @@ -1086,7 +1087,7 @@ TEST_CASE("StateCache concurrent access") auto& kv_store = *state.kv_store; const auto default_handle = 0; - std::vector signature_versions; + std::vector signature_versions; const auto begin_seqno = kv_store.current_version() + 1; @@ -1217,7 +1218,7 @@ TEST_CASE("StateCache concurrent access") }; auto validate_all_stores = - [&](const std::vector& stores) { + [&](const std::vector& stores) { for (auto& store : stores) { REQUIRE(store != nullptr); @@ -1250,7 +1251,7 @@ TEST_CASE("StateCache concurrent access") auto query_random_point_store = [&](ccf::SeqNo target_seqno, size_t handle, const auto& error_printer) { - kv::ReadOnlyStorePtr store; + ccf::kv::ReadOnlyStorePtr store; auto fetch_result = [&]() { store = cache.get_store_at(handle, target_seqno); }; @@ -1277,7 +1278,7 @@ TEST_CASE("StateCache concurrent access") ccf::SeqNo range_end, size_t handle, const auto& error_printer) { - std::vector stores; + std::vector stores; auto fetch_result = [&]() { stores = cache.get_store_range(handle, range_start, range_end); }; @@ -1308,7 +1309,7 @@ TEST_CASE("StateCache concurrent access") const ccf::SeqNoCollection& seqnos, size_t handle, const auto& error_printer) { - std::vector stores; + std::vector stores; auto fetch_result = [&]() { stores = cache.get_stores_for(handle, seqnos); }; diff --git a/src/node/test/history.cpp b/src/node/test/history.cpp index 44899b4298eb..b512e6b69864 100644 --- a/src/node/test/history.cpp +++ b/src/node/test/history.cpp @@ -21,7 +21,7 @@ std::unique_ptr threading::ThreadMessaging::singleton = nullptr; -using MapT = kv::Map; +using MapT = ccf::kv::Map; constexpr size_t certificate_validity_period_days = 365; using namespace std::literals; @@ -31,20 +31,20 @@ auto valid_from = auto valid_to = ccf::crypto::compute_cert_valid_to_string( valid_from, certificate_validity_period_days); -class DummyConsensus : public kv::test::StubConsensus +class DummyConsensus : public ccf::kv::test::StubConsensus { public: - kv::Store* store; + ccf::kv::Store* store; - DummyConsensus(kv::Store* store_) : store(store_) {} + DummyConsensus(ccf::kv::Store* store_) : store(store_) {} - bool replicate(const kv::BatchVector& entries, ccf::View view) override + bool replicate(const ccf::kv::BatchVector& entries, ccf::View view) override { if (store) { REQUIRE(entries.size() == 1); return store->deserialize(*std::get<1>(entries[0]))->apply() != - kv::ApplyResult::FAIL; + ccf::kv::ApplyResult::FAIL; } return true; } @@ -59,39 +59,39 @@ class DummyConsensus : public kv::test::StubConsensus return 0; } - std::optional primary() override + std::optional primary() override { - return kv::test::FirstBackupNodeId; + return ccf::kv::test::FirstBackupNodeId; } - kv::NodeId id() override + ccf::kv::NodeId id() override { - return kv::test::PrimaryNodeId; + return ccf::kv::test::PrimaryNodeId; } }; TEST_CASE("Check signature verification") { - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); auto kp = ccf::crypto::make_key_pair(); const auto self_signed = kp->self_sign("CN=Node", valid_from, valid_to); - kv::Store primary_store; + ccf::kv::Store primary_store; primary_store.set_encryptor(encryptor); constexpr auto store_term = 2; - std::shared_ptr primary_history = + std::shared_ptr primary_history = std::make_shared( - primary_store, kv::test::PrimaryNodeId, *kp); + primary_store, ccf::kv::test::PrimaryNodeId, *kp); primary_history->set_endorsed_certificate(self_signed); primary_store.set_history(primary_history); primary_store.initialise_term(store_term); - kv::Store backup_store; + ccf::kv::Store backup_store; backup_store.set_encryptor(encryptor); - std::shared_ptr backup_history = + std::shared_ptr backup_history = std::make_shared( - backup_store, kv::test::FirstBackupNodeId, *kp); + backup_store, ccf::kv::test::FirstBackupNodeId, *kp); backup_history->set_endorsed_certificate(self_signed); backup_store.set_history(backup_history); backup_store.initialise_term(store_term); @@ -99,11 +99,11 @@ TEST_CASE("Check signature verification") ccf::Nodes nodes(ccf::Tables::NODES); ccf::Signatures signatures(ccf::Tables::SIGNATURES); - std::shared_ptr consensus = + std::shared_ptr consensus = std::make_shared(&backup_store); primary_store.set_consensus(consensus); - std::shared_ptr null_consensus = + std::shared_ptr null_consensus = std::make_shared(nullptr); backup_store.set_consensus(null_consensus); @@ -114,8 +114,8 @@ TEST_CASE("Check signature verification") ccf::NodeInfo ni; ni.encryption_pub_key = kp->public_key_pem(); ni.cert = self_signed; - tx->put(kv::test::PrimaryNodeId, ni); - REQUIRE(txs.commit() == kv::CommitResult::SUCCESS); + tx->put(ccf::kv::test::PrimaryNodeId, ni); + REQUIRE(txs.commit() == ccf::kv::CommitResult::SUCCESS); } INFO("Issue signature, and verify successfully on backup"); @@ -128,34 +128,34 @@ TEST_CASE("Check signature verification") { auto txs = primary_store.create_tx(); auto sigs = txs.rw(signatures); - ccf::PrimarySignature bogus(kv::test::PrimaryNodeId, 0); + ccf::PrimarySignature bogus(ccf::kv::test::PrimaryNodeId, 0); bogus.sig = std::vector(256, 1); sigs->put(bogus); - REQUIRE(txs.commit() == kv::CommitResult::FAIL_NO_REPLICATE); + REQUIRE(txs.commit() == ccf::kv::CommitResult::FAIL_NO_REPLICATE); } } TEST_CASE("Check signing works across rollback") { - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); auto kp = ccf::crypto::make_key_pair(); const auto self_signed = kp->self_sign("CN=Node", valid_from, valid_to); - kv::Store primary_store; + ccf::kv::Store primary_store; primary_store.set_encryptor(encryptor); constexpr auto store_term = 2; - std::shared_ptr primary_history = + std::shared_ptr primary_history = std::make_shared( - primary_store, kv::test::PrimaryNodeId, *kp); + primary_store, ccf::kv::test::PrimaryNodeId, *kp); primary_history->set_endorsed_certificate(self_signed); primary_store.set_history(primary_history); primary_store.initialise_term(store_term); - kv::Store backup_store; - std::shared_ptr backup_history = + ccf::kv::Store backup_store; + std::shared_ptr backup_history = std::make_shared( - backup_store, kv::test::FirstBackupNodeId, *kp); + backup_store, ccf::kv::test::FirstBackupNodeId, *kp); backup_history->set_endorsed_certificate(self_signed); backup_store.set_history(backup_history); backup_store.set_encryptor(encryptor); @@ -163,10 +163,10 @@ TEST_CASE("Check signing works across rollback") ccf::Nodes nodes(ccf::Tables::NODES); - std::shared_ptr consensus = + std::shared_ptr consensus = std::make_shared(&backup_store); primary_store.set_consensus(consensus); - std::shared_ptr null_consensus = + std::shared_ptr null_consensus = std::make_shared(nullptr); backup_store.set_consensus(null_consensus); @@ -177,8 +177,8 @@ TEST_CASE("Check signing works across rollback") ccf::NodeInfo ni; ni.encryption_pub_key = kp->public_key_pem(); ni.cert = self_signed; - tx->put(kv::test::PrimaryNodeId, ni); - REQUIRE(txs.commit() == kv::CommitResult::SUCCESS); + tx->put(ccf::kv::test::PrimaryNodeId, ni); + REQUIRE(txs.commit() == ccf::kv::CommitResult::SUCCESS); } auto v1_proof = primary_history->get_proof(primary_store.current_version()); @@ -188,8 +188,8 @@ TEST_CASE("Check signing works across rollback") auto txs = primary_store.create_tx(); auto tx = txs.rw(nodes); ccf::NodeInfo ni; - tx->put(kv::test::FirstBackupNodeId, ni); - REQUIRE(txs.commit() == kv::CommitResult::SUCCESS); + tx->put(ccf::kv::test::FirstBackupNodeId, ni); + REQUIRE(txs.commit() == ccf::kv::CommitResult::SUCCESS); } primary_store.rollback({store_term, 1}, primary_store.commit_view()); @@ -220,15 +220,15 @@ TEST_CASE("Check signing works across rollback") } } -class CompactingConsensus : public kv::test::StubConsensus +class CompactingConsensus : public ccf::kv::test::StubConsensus { public: - kv::Store* store; + ccf::kv::Store* store; size_t count = 0; - CompactingConsensus(kv::Store* store_) : store(store_) {} + CompactingConsensus(ccf::kv::Store* store_) : store(store_) {} - bool replicate(const kv::BatchVector& entries, ccf::View view) override + bool replicate(const ccf::kv::BatchVector& entries, ccf::View view) override { for (auto& [version, data, committable, hooks] : entries) { @@ -249,36 +249,36 @@ class CompactingConsensus : public kv::test::StubConsensus return 0; } - std::optional primary() override + std::optional primary() override { - return kv::test::PrimaryNodeId; + return ccf::kv::test::PrimaryNodeId; } - kv::NodeId id() override + ccf::kv::NodeId id() override { - return kv::test::PrimaryNodeId; + return ccf::kv::test::PrimaryNodeId; } - ccf::View get_view(kv::Version version) override + ccf::View get_view(ccf::kv::Version version) override { return 2; } }; -class TestPendingTx : public kv::PendingTx +class TestPendingTx : public ccf::kv::PendingTx { ccf::TxID txid; - kv::Store& store; + ccf::kv::Store& store; MapT& other_table; public: - TestPendingTx(ccf::TxID txid_, kv::Store& store_, MapT& other_table_) : + TestPendingTx(ccf::TxID txid_, ccf::kv::Store& store_, MapT& other_table_) : txid(txid_), store(store_), other_table(other_table_) {} - kv::PendingTxInfo call() override + ccf::kv::PendingTxInfo call() override { auto txr = store.create_reserved_tx(txid); auto txrv = txr.rw(other_table); @@ -291,8 +291,8 @@ TEST_CASE( "Batches containing but not ending on a committable transaction should not " "halt replication") { - kv::Store store; - auto encryptor = std::make_shared(); + ccf::kv::Store store; + auto encryptor = std::make_shared(); store.set_encryptor(encryptor); std::shared_ptr consensus = std::make_shared(&store); @@ -306,7 +306,7 @@ TEST_CASE( auto tx = store.create_tx(); auto txv = tx.rw(table); txv->put(0, 1); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE(consensus->count == 1); } @@ -317,7 +317,7 @@ TEST_CASE( auto tx = store.create_tx(); auto txv = tx.rw(table); txv->put(0, 2); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE(consensus->count == 1); store.commit( @@ -330,27 +330,29 @@ TEST_CASE( auto tx = store.create_tx(); auto txv = tx.rw(table); txv->put(0, 3); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE(consensus->count == 4); } } -class RollbackConsensus : public kv::test::StubConsensus +class RollbackConsensus : public ccf::kv::test::StubConsensus { public: - kv::Store* store; + ccf::kv::Store* store; size_t count = 0; - kv::Version rollback_at; - kv::Version rollback_to; + ccf::kv::Version rollback_at; + ccf::kv::Version rollback_to; RollbackConsensus( - kv::Store* store_, kv::Version rollback_at_, kv::Version rollback_to_) : + ccf::kv::Store* store_, + ccf::kv::Version rollback_at_, + ccf::kv::Version rollback_to_) : store(store_), rollback_at(rollback_at_), rollback_to(rollback_to_) {} - bool replicate(const kv::BatchVector& entries, ccf::View view) override + bool replicate(const ccf::kv::BatchVector& entries, ccf::View view) override { for (auto& [version, data, committable, hook] : entries) { @@ -371,14 +373,14 @@ class RollbackConsensus : public kv::test::StubConsensus return 0; } - std::optional primary() override + std::optional primary() override { - return kv::test::PrimaryNodeId; + return ccf::kv::test::PrimaryNodeId; } - kv::NodeId id() override + ccf::kv::NodeId id() override { - return kv::test::PrimaryNodeId; + return ccf::kv::test::PrimaryNodeId; } ccf::View get_view(ccf::SeqNo seqno) override @@ -395,8 +397,8 @@ class RollbackConsensus : public kv::test::StubConsensus TEST_CASE( "Check that empty rollback during replicate does not cause replication halts") { - kv::Store store; - auto encryptor = std::make_shared(); + ccf::kv::Store store; + auto encryptor = std::make_shared(); store.set_encryptor(encryptor); std::shared_ptr consensus = std::make_shared(&store, 2, 2); @@ -409,7 +411,7 @@ TEST_CASE( auto tx = store.create_tx(); auto txv = tx.rw(table); txv->put(0, 1); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE(consensus->count == 1); } @@ -418,7 +420,7 @@ TEST_CASE( auto tx = store.create_tx(); auto txv = tx.rw(table); txv->put(0, 2); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE(consensus->count == 2); } @@ -427,7 +429,7 @@ TEST_CASE( auto tx = store.create_tx(); auto txv = tx.rw(table); txv->put(0, 3); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE(consensus->count == 3); } } @@ -435,8 +437,8 @@ TEST_CASE( TEST_CASE( "Check that rollback during replicate does not cause replication halts") { - kv::Store store; - auto encryptor = std::make_shared(); + ccf::kv::Store store; + auto encryptor = std::make_shared(); store.set_encryptor(encryptor); std::shared_ptr consensus = std::make_shared(&store, 2, 1); @@ -449,7 +451,7 @@ TEST_CASE( auto tx = store.create_tx(); auto txv = tx.rw(table); txv->put(0, 1); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE(consensus->count == 1); } @@ -458,7 +460,7 @@ TEST_CASE( auto tx = store.create_tx(); auto txv = tx.rw(table); txv->put(0, 2); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE(consensus->count == 2); } @@ -467,7 +469,7 @@ TEST_CASE( auto tx = store.create_tx(); auto txv = tx.rw(table); txv->put(0, 3); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); REQUIRE(consensus->count == 3); } } diff --git a/src/node/test/history_bench.cpp b/src/node/test/history_bench.cpp index 1b6364acffc3..8fad0325b23f 100644 --- a/src/node/test/history_bench.cpp +++ b/src/node/test/history_bench.cpp @@ -20,7 +20,7 @@ namespace threading using namespace ccf; -class DummyConsensus : public kv::test::StubConsensus +class DummyConsensus : public ccf::kv::test::StubConsensus { public: DummyConsensus() {} @@ -71,14 +71,16 @@ static void append(picobench::state& s) { ::srand(42); - kv::Store store; + ccf::kv::Store store; auto kp = ccf::crypto::make_key_pair(); - std::shared_ptr consensus = std::make_shared(); + std::shared_ptr consensus = + std::make_shared(); store.set_consensus(consensus); - std::shared_ptr history = - std::make_shared(store, kv::test::PrimaryNodeId, *kp); + std::shared_ptr history = + std::make_shared( + store, ccf::kv::test::PrimaryNodeId, *kp); store.set_history(history); std::vector> txs; @@ -108,14 +110,16 @@ static void append_compact(picobench::state& s) { ::srand(42); - kv::Store store; + ccf::kv::Store store; auto kp = ccf::crypto::make_key_pair(); - std::shared_ptr consensus = std::make_shared(); + std::shared_ptr consensus = + std::make_shared(); store.set_consensus(consensus); - std::shared_ptr history = - std::make_shared(store, kv::test::PrimaryNodeId, *kp); + std::shared_ptr history = + std::make_shared( + store, ccf::kv::test::PrimaryNodeId, *kp); store.set_history(history); std::vector> txs; diff --git a/src/node/test/snapshot.cpp b/src/node/test/snapshot.cpp index ae2298c6b982..fa3b6a5d571f 100644 --- a/src/node/test/snapshot.cpp +++ b/src/node/test/snapshot.cpp @@ -19,13 +19,13 @@ std::unique_ptr TEST_CASE("Snapshot with merkle tree" * doctest::test_suite("snapshot")) { - auto source_consensus = std::make_shared(); - kv::Store source_store; - auto encryptor = std::make_shared(); + auto source_consensus = std::make_shared(); + ccf::kv::Store source_store; + auto encryptor = std::make_shared(); source_store.set_encryptor(encryptor); source_store.set_consensus(source_consensus); - ccf::NodeId source_node_id = kv::test::PrimaryNodeId; + ccf::NodeId source_node_id = ccf::kv::test::PrimaryNodeId; auto source_node_kp = ccf::crypto::make_key_pair(); auto source_history = std::make_shared( @@ -34,10 +34,10 @@ TEST_CASE("Snapshot with merkle tree" * doctest::test_suite("snapshot")) source_store.set_history(source_history); source_store.initialise_term(2); - kv::Map string_map("public:string_map"); + ccf::kv::Map string_map("public:string_map"); size_t transactions_count = 3; - kv::Version snapshot_version = kv::NoVersion; + ccf::kv::Version snapshot_version = ccf::kv::NoVersion; INFO("Apply transactions to original store"); { @@ -46,7 +46,7 @@ TEST_CASE("Snapshot with merkle tree" * doctest::test_suite("snapshot")) auto tx = source_store.create_tx(); auto map = tx.rw(string_map); map->put(fmt::format("key#{}", i), "value"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } } @@ -88,15 +88,15 @@ TEST_CASE("Snapshot with merkle tree" * doctest::test_suite("snapshot")) INFO("Snapshot at signature"); { - kv::Store target_store; - auto encryptor = std::make_shared(); + ccf::kv::Store target_store; + auto encryptor = std::make_shared(); target_store.set_encryptor(encryptor); INFO("Setup target store"); { auto target_node_kp = ccf::crypto::make_key_pair(); auto target_history = std::make_shared( - target_store, kv::test::PrimaryNodeId, *target_node_kp); + target_store, ccf::kv::test::PrimaryNodeId, *target_node_kp); target_history->set_endorsed_certificate({}); target_store.set_history(target_history); } @@ -105,43 +105,45 @@ TEST_CASE("Snapshot with merkle tree" * doctest::test_suite("snapshot")) INFO("Apply snapshot taken before any signature was emitted"); { - std::unique_ptr snapshot = nullptr; + std::unique_ptr snapshot = + nullptr; { - kv::ScopedStoreMapsLock maps_lock(&source_store); + ccf::kv::ScopedStoreMapsLock maps_lock(&source_store); snapshot = source_store.snapshot_unsafe_maps(snapshot_version - 1); } auto serialised_snapshot = source_store.serialise_snapshot(std::move(snapshot)); // There is no signature to read to seed the target history - std::vector view_history; - kv::ConsensusHookPtrs hooks; + std::vector view_history; + ccf::kv::ConsensusHookPtrs hooks; REQUIRE( target_store.deserialise_snapshot( serialised_snapshot.data(), serialised_snapshot.size(), hooks, - &view_history) == kv::ApplyResult::FAIL); + &view_history) == ccf::kv::ApplyResult::FAIL); } INFO("Apply snapshot taken at signature"); { - std::unique_ptr snapshot = nullptr; + std::unique_ptr snapshot = + nullptr; { - kv::ScopedStoreMapsLock maps_lock(&source_store); + ccf::kv::ScopedStoreMapsLock maps_lock(&source_store); snapshot = source_store.snapshot_unsafe_maps(snapshot_version); } auto serialised_snapshot = source_store.serialise_snapshot(std::move(snapshot)); - std::vector view_history; - kv::ConsensusHookPtrs hooks; + std::vector view_history; + ccf::kv::ConsensusHookPtrs hooks; REQUIRE( target_store.deserialise_snapshot( serialised_snapshot.data(), serialised_snapshot.size(), hooks, - &view_history) == kv::ApplyResult::PASS); + &view_history) == ccf::kv::ApplyResult::PASS); // Merkle history and view history thus far are restored when applying // snapshot @@ -157,7 +159,7 @@ TEST_CASE("Snapshot with merkle tree" * doctest::test_suite("snapshot")) auto tx = source_store.create_tx(); auto map = tx.rw(string_map); map->put("key", "value"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); auto serialised_tx = source_consensus->get_latest_data().value(); diff --git a/src/node/test/snapshotter.cpp b/src/node/test/snapshotter.cpp index 681de0972122..914fdd3a3957 100644 --- a/src/node/test/snapshotter.cpp +++ b/src/node/test/snapshotter.cpp @@ -23,7 +23,7 @@ std::unique_ptr constexpr auto buffer_size = 1024 * 16; auto kp = ccf::crypto::make_key_pair(); -using StringString = kv::Map; +using StringString = ccf::kv::Map; using rb_msg = std::pair; auto read_ringbuffer_out(ringbuffer::Circuit& circuit) @@ -92,11 +92,12 @@ void issue_transactions(ccf::NetworkState& network, size_t tx_count) auto tx = network.tables->create_tx(); auto map = tx.rw("public:map"); map->put("foo", "bar"); - REQUIRE(tx.commit() == kv::CommitResult::SUCCESS); + REQUIRE(tx.commit() == ccf::kv::CommitResult::SUCCESS); } } -size_t read_latest_snapshot_evidence(const std::shared_ptr& store) +size_t read_latest_snapshot_evidence( + const std::shared_ptr& store) { auto tx = store->create_read_only_tx(); auto h = tx.ro(ccf::Tables::SNAPSHOT_EVIDENCE); @@ -118,7 +119,7 @@ bool record_signature( bool requires_snapshot = snapshotter->record_committable(idx); snapshotter->record_signature( - idx, dummy_signature, kv::test::PrimaryNodeId, node_cert); + idx, dummy_signature, ccf::kv::test::PrimaryNodeId, node_cert); snapshotter->record_serialised_tree(idx, history->serialise_tree(idx)); return requires_snapshot; @@ -139,13 +140,13 @@ TEST_CASE("Regular snapshotting") ccf::NetworkState network; - auto consensus = std::make_shared(); + auto consensus = std::make_shared(); auto history = std::make_shared( - *network.tables.get(), kv::test::PrimaryNodeId, *kp); + *network.tables.get(), ccf::kv::test::PrimaryNodeId, *kp); network.tables->set_history(history); network.tables->initialise_term(2); network.tables->set_consensus(consensus); - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); network.tables->set_encryptor(encryptor); auto in_buffer = std::make_unique(buffer_size); @@ -302,13 +303,13 @@ TEST_CASE("Regular snapshotting") TEST_CASE("Rollback before snapshot is committed") { ccf::NetworkState network; - auto consensus = std::make_shared(); + auto consensus = std::make_shared(); auto history = std::make_shared( - *network.tables.get(), kv::test::PrimaryNodeId, *kp); + *network.tables.get(), ccf::kv::test::PrimaryNodeId, *kp); network.tables->set_history(history); network.tables->initialise_term(2); network.tables->set_consensus(consensus); - auto encryptor = std::make_shared(); + auto encryptor = std::make_shared(); network.tables->set_encryptor(encryptor); auto in_buffer = std::make_unique(buffer_size); @@ -394,7 +395,7 @@ TEST_CASE("Rollback before snapshot is committed") size_t snapshot_idx = network.tables->current_version(); network.tables->set_flag( - kv::AbstractStore::Flag::SNAPSHOT_AT_NEXT_SIGNATURE); + ccf::kv::AbstractStore::Flag::SNAPSHOT_AT_NEXT_SIGNATURE); REQUIRE_FALSE(record_signature(history, snapshotter, snapshot_idx)); snapshotter->commit(snapshot_idx, true); @@ -410,7 +411,7 @@ TEST_CASE("Rollback before snapshot is committed") REQUIRE(snapshotter->write_snapshot(snapshot, snapshot_count)); REQUIRE(!network.tables->flag_enabled( - kv::AbstractStore::Flag::SNAPSHOT_AT_NEXT_SIGNATURE)); + ccf::kv::AbstractStore::Flag::SNAPSHOT_AT_NEXT_SIGNATURE)); // Commit evidence issue_transactions(network, 1); @@ -433,9 +434,9 @@ TEST_CASE("Rekey ledger while snapshot is in progress") ccf::NetworkState network; - auto consensus = std::make_shared(); + auto consensus = std::make_shared(); auto history = std::make_shared( - *network.tables.get(), kv::test::PrimaryNodeId, *kp); + *network.tables.get(), ccf::kv::test::PrimaryNodeId, *kp); network.tables->set_history(history); network.tables->initialise_term(2); network.tables->set_consensus(consensus); @@ -467,7 +468,7 @@ TEST_CASE("Rekey ledger while snapshot is in progress") auto sigs = tx.rw(ccf::Tables::SIGNATURES); auto trees = tx.rw(ccf::Tables::SERIALISED_MERKLE_TREE); - sigs->put({kv::test::PrimaryNodeId, 0, 0, {}, {}, {}, {}}); + sigs->put({ccf::kv::test::PrimaryNodeId, 0, 0, {}, {}, {}, {}}); auto tree = history->serialise_tree(snapshot_idx - 1); trees->put(tree); tx.commit(); @@ -501,7 +502,7 @@ TEST_CASE("Rekey ledger while snapshot is in progress") // Snapshot can be deserialised to backup store ccf::NetworkState backup_network; auto backup_history = std::make_shared( - *backup_network.tables.get(), kv::test::FirstBackupNodeId, *kp); + *backup_network.tables.get(), ccf::kv::test::FirstBackupNodeId, *kp); backup_network.tables->set_history(backup_history); auto tx = network.tables->create_read_only_tx(); @@ -511,12 +512,12 @@ TEST_CASE("Rekey ledger while snapshot is in progress") std::make_shared(backup_ledger_secrets); backup_network.tables->set_encryptor(backup_encryptor); - kv::ConsensusHookPtrs hooks; - std::vector view_history; + ccf::kv::ConsensusHookPtrs hooks; + std::vector view_history; REQUIRE( backup_network.tables->deserialise_snapshot( snapshot.data(), snapshot.size(), hooks, &view_history) == - kv::ApplyResult::PASS); + ccf::kv::ApplyResult::PASS); } } diff --git a/src/service/internal_tables_access.h b/src/service/internal_tables_access.h index 956b7b626b83..660c797278cb 100644 --- a/src/service/internal_tables_access.h +++ b/src/service/internal_tables_access.h @@ -34,7 +34,7 @@ namespace ccf // instantiated InternalTablesAccess() = delete; - static void retire_active_nodes(kv::Tx& tx) + static void retire_active_nodes(ccf::kv::Tx& tx) { auto nodes = tx.rw(Tables::NODES); @@ -54,7 +54,7 @@ namespace ccf } static bool is_recovery_member( - kv::ReadOnlyTx& tx, const MemberId& member_id) + ccf::kv::ReadOnlyTx& tx, const MemberId& member_id) { auto member_encryption_public_keys = tx.ro( @@ -63,7 +63,8 @@ namespace ccf return member_encryption_public_keys->get(member_id).has_value(); } - static bool is_active_member(kv::ReadOnlyTx& tx, const MemberId& member_id) + static bool is_active_member( + ccf::kv::ReadOnlyTx& tx, const MemberId& member_id) { auto member_info = tx.ro(Tables::MEMBER_INFO); auto mi = member_info->get(member_id); @@ -76,7 +77,7 @@ namespace ccf } static std::map get_active_recovery_members( - kv::ReadOnlyTx& tx) + ccf::kv::ReadOnlyTx& tx) { auto member_info = tx.ro(Tables::MEMBER_INFO); auto member_encryption_public_keys = @@ -104,7 +105,8 @@ namespace ccf return active_recovery_members; } - static MemberId add_member(kv::Tx& tx, const NewMember& member_pub_info) + static MemberId add_member( + ccf::kv::Tx& tx, const NewMember& member_pub_info) { auto member_certs = tx.rw(Tables::MEMBER_CERTS); auto member_info = tx.rw(Tables::MEMBER_INFO); @@ -147,7 +149,7 @@ namespace ccf return id; } - static bool activate_member(kv::Tx& tx, const MemberId& member_id) + static bool activate_member(ccf::kv::Tx& tx, const MemberId& member_id) { auto member_info = tx.rw(Tables::MEMBER_INFO); @@ -176,7 +178,7 @@ namespace ccf return newly_active; } - static bool remove_member(kv::Tx& tx, const MemberId& member_id) + static bool remove_member(ccf::kv::Tx& tx, const MemberId& member_id) { auto member_certs = tx.rw(Tables::MEMBER_CERTS); auto member_encryption_public_keys = @@ -230,7 +232,7 @@ namespace ccf return true; } - static UserId add_user(kv::Tx& tx, const NewUser& new_user) + static UserId add_user(ccf::kv::Tx& tx, const NewUser& new_user) { auto user_certs = tx.rw(Tables::USER_CERTS); @@ -263,7 +265,7 @@ namespace ccf return id; } - static void remove_user(kv::Tx& tx, const UserId& user_id) + static void remove_user(ccf::kv::Tx& tx, const UserId& user_id) { // Has no effect if the user does not exist auto user_certs = tx.rw(Tables::USER_CERTS); @@ -274,14 +276,15 @@ namespace ccf } static void add_node( - kv::Tx& tx, const NodeId& id, const NodeInfo& node_info) + ccf::kv::Tx& tx, const NodeId& id, const NodeInfo& node_info) { auto node = tx.rw(Tables::NODES); node->put(id, node_info); } static auto get_trusted_nodes( - kv::ReadOnlyTx& tx, std::optional self_to_exclude = std::nullopt) + ccf::kv::ReadOnlyTx& tx, + std::optional self_to_exclude = std::nullopt) { // Returns the list of trusted nodes. If self_to_exclude is set, // self_to_exclude is not included in the list of returned nodes. @@ -315,7 +318,7 @@ namespace ccf // Service status should use a state machine, very much like NodeState. static void create_service( - kv::Tx& tx, + ccf::kv::Tx& tx, const ccf::crypto::Pem& service_cert, ccf::TxID create_txid, nlohmann::json service_data = nullptr, @@ -348,13 +351,13 @@ namespace ccf } static bool is_service_created( - kv::ReadOnlyTx& tx, const ccf::crypto::Pem& expected_service_cert) + ccf::kv::ReadOnlyTx& tx, const ccf::crypto::Pem& expected_service_cert) { auto service = tx.ro(Tables::SERVICE)->get(); return service.has_value() && service->cert == expected_service_cert; } - static bool open_service(kv::Tx& tx) + static bool open_service(ccf::kv::Tx& tx) { auto service = tx.rw(Tables::SERVICE); @@ -401,7 +404,8 @@ namespace ccf return true; } - static std::optional get_service_status(kv::ReadOnlyTx& tx) + static std::optional get_service_status( + ccf::kv::ReadOnlyTx& tx) { auto service = tx.ro(Tables::SERVICE); auto active_service = service->get(); @@ -415,7 +419,9 @@ namespace ccf } static void trust_node( - kv::Tx& tx, const NodeId& node_id, kv::Version latest_ledger_secret_seqno) + ccf::kv::Tx& tx, + const NodeId& node_id, + ccf::kv::Version latest_ledger_secret_seqno) { auto nodes = tx.rw(Tables::NODES); auto node_info = nodes->get(node_id); @@ -437,13 +443,14 @@ namespace ccf LOG_INFO_FMT("Node {} is now {}", node_id, node_info->status); } - static void set_constitution(kv::Tx& tx, const std::string& constitution) + static void set_constitution( + ccf::kv::Tx& tx, const std::string& constitution) { tx.rw(Tables::CONSTITUTION)->put(constitution); } static void trust_node_measurement( - kv::Tx& tx, + ccf::kv::Tx& tx, const pal::PlatformAttestationMeasurement& node_measurement, const QuoteFormat& platform) { @@ -477,7 +484,7 @@ namespace ccf } static void trust_node_host_data( - kv::Tx& tx, + ccf::kv::Tx& tx, const HostData& host_data, const std::optional& security_policy = std::nullopt) { @@ -497,7 +504,7 @@ namespace ccf } static void trust_node_uvm_endorsements( - kv::Tx& tx, const std::optional& uvm_endorsements) + ccf::kv::Tx& tx, const std::optional& uvm_endorsements) { if (!uvm_endorsements.has_value()) { @@ -513,7 +520,7 @@ namespace ccf } static void init_configuration( - kv::Tx& tx, const ServiceConfiguration& configuration) + ccf::kv::Tx& tx, const ServiceConfiguration& configuration) { auto config = tx.rw(Tables::CONFIGURATION); if (config->has()) @@ -526,7 +533,7 @@ namespace ccf config->put(configuration); } - static bool set_recovery_threshold(kv::Tx& tx, size_t threshold) + static bool set_recovery_threshold(ccf::kv::Tx& tx, size_t threshold) { auto config = tx.rw(Tables::CONFIGURATION); @@ -579,7 +586,7 @@ namespace ccf return true; } - static size_t get_recovery_threshold(kv::ReadOnlyTx& tx) + static size_t get_recovery_threshold(ccf::kv::ReadOnlyTx& tx) { auto config = tx.ro(Tables::CONFIGURATION); auto current_config = config->get(); diff --git a/src/service/network_tables.h b/src/service/network_tables.h index 57c6894a735e..26a6c48966c3 100644 --- a/src/service/network_tables.h +++ b/src/service/network_tables.h @@ -36,14 +36,14 @@ namespace ccf { - inline std::shared_ptr make_store() + inline std::shared_ptr make_store() { - return std::make_shared(); + return std::make_shared(); } struct NetworkTables { - std::shared_ptr tables; + std::shared_ptr tables; // // Governance tables (public:ccf.gov.*) diff --git a/src/service/tables/secrets.h b/src/service/tables/secrets.h index 2f7c2e376dcf..38c5d83aecd2 100644 --- a/src/service/tables/secrets.h +++ b/src/service/tables/secrets.h @@ -13,13 +13,14 @@ namespace ccf { // Version at which the ledger secret is applicable from (recovery // only) - std::optional version; + std::optional version; // Encrypted secret for each backup std::vector encrypted_secret = {}; // Version at which the previous secret is stored at - std::optional previous_secret_stored_version = std::nullopt; + std::optional previous_secret_stored_version = + std::nullopt; }; DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(EncryptedLedgerSecret) diff --git a/src/service/tables/shares.h b/src/service/tables/shares.h index 28191f848219..f80738fa5ea5 100644 --- a/src/service/tables/shares.h +++ b/src/service/tables/shares.h @@ -23,7 +23,8 @@ namespace ccf EncryptedSharesMap encrypted_shares; // Version at which the previous ledger secret was written to the store - std::optional previous_secret_stored_version = std::nullopt; + std::optional previous_secret_stored_version = + std::nullopt; }; DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(RecoverySharesInfo) @@ -38,18 +39,19 @@ namespace ccf std::vector encrypted_data = {}; // Version at which the ledger secret is applicable from - kv::Version version = kv::NoVersion; + ccf::kv::Version version = ccf::kv::NoVersion; // Version at which the ledger secret _before_ this one was written to the // store - std::optional previous_secret_stored_version = std::nullopt; + std::optional previous_secret_stored_version = + std::nullopt; PreviousLedgerSecretInfo() = default; PreviousLedgerSecretInfo( std::vector&& encrypted_data_, - kv::Version version_, - std::optional stored_version_) : + ccf::kv::Version version_, + std::optional stored_version_) : encrypted_data(std::move(encrypted_data_)), version(version_), previous_secret_stored_version(stored_version_) @@ -89,7 +91,7 @@ namespace ccf // integrity on the public-only transactions. However, the corresponding // shares are only written at a later version, once the previous ledger // secrets have been restored. - std::optional next_version = std::nullopt; + std::optional next_version = std::nullopt; }; // Note: Both fields are never empty at the same time diff --git a/src/service/tables/signatures.h b/src/service/tables/signatures.h index a79c75d670fc..665fe56cee78 100644 --- a/src/service/tables/signatures.h +++ b/src/service/tables/signatures.h @@ -58,7 +58,8 @@ namespace ccf using Signatures = ServiceValue; // Serialised Merkle tree at most recent signature is a single Value in the KV - using SerialisedMerkleTree = kv::RawCopySerialisedValue>; + using SerialisedMerkleTree = + ccf::kv::RawCopySerialisedValue>; namespace Tables { diff --git a/src/service/tables/snapshot_evidence.h b/src/service/tables/snapshot_evidence.h index 6f07960f04d0..a0dcb12c8fa9 100644 --- a/src/service/tables/snapshot_evidence.h +++ b/src/service/tables/snapshot_evidence.h @@ -13,7 +13,7 @@ namespace ccf /// Snapshot digest ccf::crypto::Sha256Hash hash; /// Sequence number to which the snapshot corresponds - kv::Version version; + ccf::kv::Version version; }; DECLARE_JSON_TYPE(SnapshotHash)