Expose node config subsystem interface (#4118)

This commit is contained in:
Christoph M. Wintersteiger 2022-08-17 17:30:39 +01:00 коммит произвёл GitHub
Родитель 02375f2cb4
Коммит 14727d0191
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
13 изменённых файлов: 212 добавлений и 138 удалений

Просмотреть файл

@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache 2.0 License.
#pragma once
#include "ccf/node/startup_config.h"
#include "ccf/node_subsystem_interface.h"
#include "ccf/service/node_info_network.h"
#include <map>
#include <regex>
namespace ccf
{
struct NodeConfigurationState
{
const StartupConfig& node_config;
std::map<NodeInfoNetwork::RpcInterfaceID, std::vector<std::regex>>
rpc_interface_regexes;
bool initialized = false;
};
class NodeConfigurationInterface : public AbstractNodeSubSystem
{
public:
virtual ~NodeConfigurationInterface() = default;
static char const* get_subsystem_name()
{
return "NodeConfiguration";
}
virtual const NodeConfigurationState& get() = 0;
};
}

Просмотреть файл

@ -0,0 +1,91 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache 2.0 License.
#pragma once
#include "ccf/crypto/curve.h"
#include "ccf/ds/unit_strings.h"
#include "ccf/service/consensus_config.h"
#include "ccf/service/node_info_network.h"
#include "ccf/service/service_config.h"
#include "ccf/service/tables/members.h"
#include <optional>
#include <string>
#include <vector>
struct CCFConfig
{
size_t worker_threads = 0;
consensus::Configuration consensus = {};
ccf::NodeInfoNetwork network = {};
struct NodeCertificateInfo
{
std::string subject_name = "CN=CCF Node";
std::vector<std::string> subject_alt_names = {};
crypto::CurveID curve_id = crypto::CurveID::SECP384R1;
size_t initial_validity_days = 1;
bool operator==(const NodeCertificateInfo&) const = default;
};
NodeCertificateInfo node_certificate = {};
struct LedgerSignatures
{
size_t tx_count = 5000;
ds::TimeString delay = {"1000ms"};
bool operator==(const LedgerSignatures&) const = default;
};
LedgerSignatures ledger_signatures = {};
struct JWT
{
ds::TimeString key_refresh_interval = {"30min"};
bool operator==(const JWT&) const = default;
};
JWT jwt = {};
};
struct StartupConfig : CCFConfig
{
// Only if joining or recovering
std::vector<uint8_t> startup_snapshot = {};
std::optional<size_t> startup_snapshot_evidence_seqno_for_1_x = std::nullopt;
std::string startup_host_time;
size_t snapshot_tx_interval = 10'000;
// Only if starting or recovering
size_t initial_service_certificate_validity_days = 1;
nlohmann::json service_data = nullptr;
nlohmann::json node_data = nullptr;
struct Start
{
std::vector<ccf::NewMember> members;
std::string constitution;
ccf::ServiceConfiguration service_configuration;
bool operator==(const Start& other) const = default;
};
Start start = {};
struct Join
{
ccf::NodeInfoNetwork::NetAddress target_rpc_address;
ds::TimeString retry_timeout = {"1000ms"};
std::vector<uint8_t> service_cert = {};
};
Join join = {};
struct Recover
{
std::optional<std::vector<uint8_t>> previous_service_identity =
std::nullopt;
};
Recover recover = {};
};

Просмотреть файл

@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache 2.0 License.
#pragma once
#include "ccf/ds/unit_strings.h"
#include "ccf/service/consensus_type.h"
namespace consensus
{
struct Configuration
{
ConsensusType type = ConsensusType::CFT;
ds::TimeString message_timeout = {"100ms"};
ds::TimeString election_timeout = {"5000ms"};
bool operator==(const Configuration&) const = default;
bool operator!=(const Configuration&) const = default;
};
}

Просмотреть файл

@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache 2.0 License.
#pragma once
enum ConsensusType
{
CFT = 0,
BFT = 1
};

Просмотреть файл

@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache 2.0 License.
#pragma once
enum ReconfigurationType
{
ONE_TRANSACTION = 0,
TWO_TRANSACTION = 1
};

Просмотреть файл

@ -0,0 +1,40 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache 2.0 License.
#pragma once
#include "ccf/service/consensus_type.h"
#include "ccf/service/reconfiguration_type.h"
#include <cstdint>
#include <optional>
namespace ccf
{
struct ServiceConfiguration
{
// Number of recovery shares required to decrypt the latest ledger secret
size_t recovery_threshold = 0;
ConsensusType consensus = ConsensusType::CFT;
/**
* Fields below are added in 2.x
*/
std::optional<size_t> maximum_node_certificate_validity_days = std::nullopt;
std::optional<size_t> maximum_service_certificate_validity_days =
std::nullopt;
std::optional<ReconfigurationType> reconfiguration_type = std::nullopt;
bool operator==(const ServiceConfiguration& other) const
{
return recovery_threshold == other.recovery_threshold &&
consensus == other.consensus &&
reconfiguration_type == other.reconfiguration_type &&
maximum_node_certificate_validity_days ==
other.maximum_node_certificate_validity_days;
}
};
}

Просмотреть файл

@ -7,6 +7,7 @@
#include "ccf/crypto/pem.h"
#include "ccf/ds/logger.h"
#include "ccf/ds/unit_strings.h"
#include "ccf/node/startup_config.h"
#include "ccf/service/node_info_network.h"
#include "ccf/service/tables/members.h"
#include "common/enclave_interface_types.h"
@ -52,41 +53,6 @@ struct EnclaveConfig
static constexpr auto node_to_node_interface_name = "node_to_node_interface";
struct CCFConfig
{
size_t worker_threads = 0;
consensus::Configuration consensus = {};
ccf::NodeInfoNetwork network = {};
struct NodeCertificateInfo
{
std::string subject_name = "CN=CCF Node";
std::vector<std::string> subject_alt_names = {};
crypto::CurveID curve_id = crypto::CurveID::SECP384R1;
size_t initial_validity_days = 1;
bool operator==(const NodeCertificateInfo&) const = default;
};
NodeCertificateInfo node_certificate = {};
struct LedgerSignatures
{
size_t tx_count = 5000;
ds::TimeString delay = {"1000ms"};
bool operator==(const LedgerSignatures&) const = default;
};
LedgerSignatures ledger_signatures = {};
struct JWT
{
ds::TimeString key_refresh_interval = {"30min"};
bool operator==(const JWT&) const = default;
};
JWT jwt = {};
};
DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(CCFConfig::NodeCertificateInfo);
DECLARE_JSON_REQUIRED_FIELDS(CCFConfig::NodeCertificateInfo)
DECLARE_JSON_OPTIONAL_FIELDS(
@ -114,48 +80,6 @@ DECLARE_JSON_OPTIONAL_FIELDS(
ledger_signatures,
jwt);
struct StartupConfig : CCFConfig
{
// Only if joining or recovering
std::vector<uint8_t> startup_snapshot = {};
std::optional<size_t> startup_snapshot_evidence_seqno_for_1_x = std::nullopt;
std::string startup_host_time;
size_t snapshot_tx_interval = 10'000;
// Only if starting or recovering
size_t initial_service_certificate_validity_days = 1;
nlohmann::json service_data = nullptr;
nlohmann::json node_data = nullptr;
struct Start
{
std::vector<ccf::NewMember> members;
std::string constitution;
ccf::ServiceConfiguration service_configuration;
bool operator==(const Start& other) const = default;
};
Start start = {};
struct Join
{
ccf::NodeInfoNetwork::NetAddress target_rpc_address;
ds::TimeString retry_timeout = {"1000ms"};
std::vector<uint8_t> service_cert = {};
};
Join join = {};
struct Recover
{
std::optional<std::vector<uint8_t>> previous_service_identity =
std::nullopt;
};
Recover recover = {};
};
DECLARE_JSON_TYPE(StartupConfig::Start);
DECLARE_JSON_REQUIRED_FIELDS(
StartupConfig::Start, members, constitution, service_configuration);

Просмотреть файл

@ -3,6 +3,7 @@
#pragma once
#include "ccf/ds/unit_strings.h"
#include "ccf/service/consensus_config.h"
#include "ccf/service/tables/nodes.h"
#include "ccf/tx_id.h"
#include "enclave/consensus_type.h"
@ -11,15 +12,6 @@
namespace consensus
{
struct Configuration
{
ConsensusType type = ConsensusType::CFT;
ds::TimeString message_timeout = {"100ms"};
ds::TimeString election_timeout = {"5000ms"};
bool operator==(const Configuration&) const = default;
bool operator!=(const Configuration&) const = default;
};
DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(Configuration);
DECLARE_JSON_REQUIRED_FIELDS(Configuration);
DECLARE_JSON_OPTIONAL_FIELDS(

Просмотреть файл

@ -3,12 +3,7 @@
#pragma once
#include "ccf/ds/json.h"
enum ConsensusType
{
CFT = 0,
BFT = 1
};
#include "ccf/service/consensus_type.h"
DECLARE_JSON_ENUM(
ConsensusType, {{ConsensusType::CFT, "CFT"}, {ConsensusType::BFT, "BFT"}})

Просмотреть файл

@ -3,12 +3,7 @@
#pragma once
#include "ccf/ds/json.h"
enum ReconfigurationType
{
ONE_TRANSACTION = 0,
TWO_TRANSACTION = 1
};
#include "ccf/service/reconfiguration_type.h"
DECLARE_JSON_ENUM(
ReconfigurationType,

Просмотреть файл

@ -2,22 +2,14 @@
// Licensed under the Apache 2.0 License.
#pragma once
#include "ccf/node_subsystem_interface.h"
#include "ccf/node/node_configuration_interface.h"
#include "node/rpc/node_interface.h"
#include <regex>
namespace ccf
{
struct NodeConfigurationState
{
const StartupConfig& node_config;
std::map<NodeInfoNetwork::RpcInterfaceID, std::vector<std::regex>>
rpc_interface_regexes;
bool initialized = false;
};
class NodeConfigurationSubsystem : public AbstractNodeSubSystem
class NodeConfigurationSubsystem : public NodeConfigurationInterface
{
protected:
AbstractNodeState& node_state;
@ -36,7 +28,7 @@ namespace ccf
return "NodeConfiguration";
}
virtual const NodeConfigurationState& get()
virtual const NodeConfigurationState& get() override
{
if (!node_config_state.initialized)
{

Просмотреть файл

@ -13,7 +13,6 @@
#include "enclave/interface.h"
#include "node/identity.h"
#include "node/ledger_secrets.h"
#include "service/tables/config.h"
#include <nlohmann/json.hpp>

Просмотреть файл

@ -3,40 +3,15 @@
#pragma once
#include "ccf/ds/json.h"
#include "enclave/consensus_type.h"
#include "enclave/reconfiguration_type.h"
#include "ccf/service/consensus_type.h"
#include "ccf/service/reconfiguration_type.h"
#include "ccf/service/service_config.h"
namespace ccf
{
static constexpr auto default_node_cert_validity_period_days = 365;
static constexpr auto default_service_cert_validity_period_days = 365;
struct ServiceConfiguration
{
// Number of recovery shares required to decrypt the latest ledger secret
size_t recovery_threshold = 0;
ConsensusType consensus = ConsensusType::CFT;
/**
* Fields below are added in 2.x
*/
std::optional<size_t> maximum_node_certificate_validity_days = std::nullopt;
std::optional<size_t> maximum_service_certificate_validity_days =
std::nullopt;
std::optional<ReconfigurationType> reconfiguration_type = std::nullopt;
bool operator==(const ServiceConfiguration& other) const
{
return recovery_threshold == other.recovery_threshold &&
consensus == other.consensus &&
reconfiguration_type == other.reconfiguration_type &&
maximum_node_certificate_validity_days ==
other.maximum_node_certificate_validity_days;
}
};
DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(ServiceConfiguration)
DECLARE_JSON_REQUIRED_FIELDS(ServiceConfiguration, recovery_threshold)
DECLARE_JSON_OPTIONAL_FIELDS(