Skip to content

Commit 369ccdf

Browse files
[release/5.x] Cherry picks: Pin typescript to 5.8.3 #7157, and Set constitution during recovery (#7155) (#7159)
Co-authored-by: cjen1-msft <chrisjensen@microsoft.com>
1 parent 93d1b5c commit 369ccdf

17 files changed

Lines changed: 83 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [5.0.20]
9+
10+
[5.0.20]: https://github.com/microsoft/CCF/releases/tag/5.0.20
11+
12+
### Added
13+
14+
- Allow changing the constitution during disaster recovery via the `command.recover.constitution_files` entry in cchost. (#7155)
15+
816
## [5.0.19]
917

1018
[5.0.19]: https://github.com/microsoft/CCF/releases/tag/5.0.19

doc/host_config_schema/cchost_config.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,13 @@
414414
"previous_service_identity_file": {
415415
"type": "string",
416416
"description": "Path to the previous service certificate (PEM) file"
417+
},
418+
"constitution_files": {
419+
"type": "array",
420+
"items": {
421+
"type": "string"
422+
},
423+
"description": "List of constitution files. These typically include actions.js, validate.js, resolve.js and apply.js"
417424
}
418425
},
419426
"required": ["previous_service_identity_file"],

include/ccf/node/startup_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ struct StartupConfig : CCFConfig
114114
{
115115
std::optional<std::vector<uint8_t>> previous_service_identity =
116116
std::nullopt;
117+
std::optional<std::string> constitution = std::nullopt;
117118
};
118119
Recover recover = {};
119120
};

js/ccf-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
"node-forge": "^1.2.0",
3131
"ts-node": "^10.4.0",
3232
"typedoc": "^0.27.0",
33-
"typescript": "^5.7.2"
33+
"typescript": "^5.8.3"
3434
}
3535
}

src/common/configuration.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "ccf/crypto/curve.h"
77
#include "ccf/crypto/pem.h"
8+
#include "ccf/ds/json.h"
89
#include "ccf/ds/logger.h"
910
#include "ccf/ds/unit_strings.h"
1011
#include "ccf/node/startup_config.h"
@@ -107,8 +108,9 @@ DECLARE_JSON_REQUIRED_FIELDS(
107108
service_cert,
108109
follow_redirect);
109110

110-
DECLARE_JSON_TYPE(StartupConfig::Recover);
111+
DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(StartupConfig::Recover);
111112
DECLARE_JSON_REQUIRED_FIELDS(StartupConfig::Recover, previous_service_identity);
113+
DECLARE_JSON_OPTIONAL_FIELDS(StartupConfig::Recover, constitution);
112114

113115
DECLARE_JSON_TYPE_WITH_BASE(StartupConfig, CCFConfig);
114116
DECLARE_JSON_REQUIRED_FIELDS(

src/host/configuration.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ namespace host
163163
{
164164
size_t initial_service_certificate_validity_days = 1;
165165
std::string previous_service_identity_file;
166+
std::vector<std::string> constitution_files = {};
166167
bool operator==(const Recover&) const = default;
167168
};
168169
Recover recover = {};
@@ -221,7 +222,8 @@ namespace host
221222
DECLARE_JSON_OPTIONAL_FIELDS(
222223
CCHostConfig::Command::Recover,
223224
initial_service_certificate_validity_days,
224-
previous_service_identity_file);
225+
previous_service_identity_file,
226+
constitution_files);
225227

226228
DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(CCHostConfig::Command);
227229
DECLARE_JSON_REQUIRED_FIELDS(CCHostConfig::Command, type);

src/host/main.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,26 @@ int main(int argc, char** argv)
675675
}
676676
LOG_INFO_FMT("Reading previous service identity from {}", idf);
677677
startup_config.recover.previous_service_identity = files::slurp(idf);
678+
679+
if (!config.command.recover.constitution_files.empty())
680+
{
681+
LOG_INFO_FMT(
682+
"Reading [{}] constitution file(s) for recovery",
683+
fmt::join(config.command.recover.constitution_files, ", "));
684+
startup_config.recover.constitution = "";
685+
for (const auto& constitution_path :
686+
config.command.recover.constitution_files)
687+
{
688+
// Separate with single newlines
689+
if (!startup_config.recover.constitution->empty())
690+
{
691+
startup_config.recover.constitution.value() += '\n';
692+
}
693+
694+
startup_config.recover.constitution.value() +=
695+
files::slurp_string(constitution_path);
696+
}
697+
}
678698
}
679699
else
680700
{

src/node/node_state.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ namespace ccf
359359
{
360360
case StartType::Start:
361361
{
362+
LOG_INFO_FMT("Creating boot request");
362363
create_and_send_boot_request(
363364
aft::starting_view_change, true /* Create new consortium */);
364365
return;
@@ -1904,6 +1905,16 @@ namespace ccf
19041905
{
19051906
create_params.genesis_info = config.start;
19061907
}
1908+
create_params.recovery_constitution = config.recover.constitution;
1909+
LOG_INFO_FMT("serialise_create_request, set recovery_constitution to:");
1910+
if (create_params.recovery_constitution.has_value())
1911+
{
1912+
LOG_INFO_FMT("{}", create_params.recovery_constitution.value());
1913+
}
1914+
else
1915+
{
1916+
LOG_INFO_FMT("No recovery constitution provided");
1917+
}
19071918

19081919
create_params.node_id = self;
19091920
create_params.certificate_signing_request = node_sign_kp->create_csr(

src/node/rpc/node_call_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ namespace ccf
7474

7575
// Only set on genesis transaction, but not on recovery
7676
std::optional<StartupConfig::Start> genesis_info = std::nullopt;
77+
// Constitution to set on recovery
78+
std::optional<std::string> recovery_constitution = std::nullopt;
7779
};
7880
};
7981

src/node/rpc/node_frontend.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,11 @@ namespace ccf
15401540
}
15411541
else
15421542
{
1543+
if (in.recovery_constitution.has_value())
1544+
{
1545+
InternalTablesAccess::set_constitution(
1546+
ctx.tx, in.recovery_constitution.value());
1547+
}
15431548
// On recovery, force a new ledger chunk
15441549
auto tx_ = static_cast<ccf::kv::CommittableTx*>(&ctx.tx);
15451550
if (tx_ == nullptr)

0 commit comments

Comments
 (0)