Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8afbbe1
LedgerSecrets: take_dependency_on_secrets **before** taking locking l…
eddyashton Mar 13, 2026
f2127ea
Don't call force_become_primary (locking) immediately after construct…
eddyashton Mar 13, 2026
e50b453
Same pattern for init_as_backup
eddyashton Mar 13, 2026
f624aae
Expand new mutex to cover self-signed cert too. Unpick some knots
eddyashton Mar 13, 2026
edbb793
Flatten open_frontend calls
eddyashton Mar 17, 2026
a629925
Implement asynchronous frontend opening to avoid locking issues durin…
eddyashton Mar 17, 2026
c39a9aa
Remove transition_service_to_open lock, explain why
eddyashton Mar 17, 2026
b208158
Remove unnecessary suppressions
eddyashton Mar 17, 2026
c42ecdf
Merge branch 'main' of https://github.com/microsoft/CCF into tsan_tur…
eddyashton Mar 17, 2026
4658466
Merge branch 'main' of https://github.com/microsoft/CCF into tsan_tur…
eddyashton Mar 17, 2026
566c030
Tidy
eddyashton Mar 17, 2026
e183333
Fix data race in update_consensus()
eddyashton Mar 17, 2026
a27b85d
setup_basic_hooks, independently and early
eddyashton Mar 17, 2026
faa669b
Simpler - separate open and set_consensus_and_history
eddyashton Mar 17, 2026
fd8973c
Merge branch 'main' of https://github.com/microsoft/CCF into tsan_tur…
eddyashton Mar 17, 2026
8bb4a70
set_consensus_and_history in unit tests
eddyashton Mar 18, 2026
7d94327
Merge branch 'main' of https://github.com/microsoft/CCF into tsan_tur…
eddyashton Mar 18, 2026
cd9ec9a
Consistently set up hooks before deser
eddyashton Mar 18, 2026
e869e19
Merge branch 'main' of https://github.com/microsoft/CCF into tsan_tur…
eddyashton Mar 18, 2026
7a9a85c
Avoid nullptr deref on hooks pre-consensus
eddyashton Mar 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions src/consensus/aft/raft.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,39 @@ namespace aft
std::unique_ptr<LedgerProxy> ledger;
std::shared_ptr<ccf::NodeToNode> channels;

enum class StartupRole : std::uint8_t
{
Primary,
Backup,
};

// Describes the initial role and state for this node at construction
// time, before any other thread can observe it (so no lock is needed).
struct StartupState
{
StartupRole role;

// State to apply before becoming primary/backup. When nullopt for
// a primary, the node starts from scratch (genesis).
struct StateInfo
{
Index index = 0;
Term term = 0;
std::vector<Index> view_history;
Index recovery_start_index = 0;
};
std::optional<StateInfo> info = std::nullopt;
};

Aft(
const ccf::consensus::Configuration& settings_,
std::unique_ptr<Store> store_,
std::unique_ptr<LedgerProxy> ledger_,
std::shared_ptr<ccf::NodeToNode> channels_,
std::shared_ptr<aft::State> state_,
std::shared_ptr<ccf::NodeClient> rpc_request_context_,
bool public_only_ = false) :
bool public_only_ = false,
std::optional<StartupState> startup = std::nullopt) :
store(std::move(store_)),

timeout_elapsed(0),
Expand All @@ -236,7 +261,38 @@ namespace aft

ledger(std::move(ledger_)),
channels(std::move(channels_))
{}
{
if (startup.has_value())
{
const auto& s = startup.value();
if (s.info.has_value())
{
const auto& si = s.info.value();
if (s.role == StartupRole::Primary)
{
state->current_view = si.term;
state->last_idx = si.index;
state->commit_idx = si.index;
state->view_history.initialise(si.view_history);
state->view_history.update(si.index, si.term);
}
else
{
state->last_idx = si.index;
state->commit_idx = si.index;
state->view_history.initialise(si.view_history);
ledger->init(si.index, si.recovery_start_index);
become_aware_of_new_term(si.term);
}
}

if (s.role == StartupRole::Primary)
{
state->current_view += starting_view_change;
become_leader(true);
}
}
}

~Aft() override = default;

Expand Down
4 changes: 4 additions & 0 deletions src/enclave/rpc_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
namespace ccf::kv
{
class CommittableTx;
class Consensus;
class TxHistory;
}

namespace ccf
Expand All @@ -33,6 +35,8 @@ namespace ccf
virtual void tick(std::chrono::milliseconds /*elapsed*/) {}
virtual void open() = 0;
virtual bool is_open() = 0;
virtual void set_consensus_and_history(
ccf::kv::Consensus* consensus, ccf::kv::TxHistory* history) = 0;

// Used by rpcendpoint to process incoming client RPCs
virtual void process(std::shared_ptr<RpcContextImpl> ctx) = 0;
Expand Down
12 changes: 6 additions & 6 deletions src/node/ledger_secrets.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ namespace ccf

VersionedLedgerSecret get_latest(ccf::kv::ReadOnlyTx& tx)
{
std::lock_guard<ccf::pal::Mutex> guard(lock);

take_dependency_on_secrets(tx);

std::lock_guard<ccf::pal::Mutex> guard(lock);

if (ledger_secrets.empty())
{
throw std::logic_error(
Expand All @@ -186,10 +186,10 @@ namespace ccf
std::pair<VersionedLedgerSecret, std::optional<VersionedLedgerSecret>>
get_latest_and_penultimate(ccf::kv::ReadOnlyTx& tx)
{
std::lock_guard<ccf::pal::Mutex> guard(lock);

take_dependency_on_secrets(tx);

std::lock_guard<ccf::pal::Mutex> guard(lock);

if (ledger_secrets.empty())
{
throw std::logic_error(
Expand All @@ -209,10 +209,10 @@ namespace ccf
ccf::kv::ReadOnlyTx& tx,
std::optional<ccf::kv::Version> up_to = std::nullopt)
{
std::lock_guard<ccf::pal::Mutex> guard(lock);

take_dependency_on_secrets(tx);

std::lock_guard<ccf::pal::Mutex> guard(lock);

if (!up_to.has_value())
{
return ledger_secrets;
Expand Down
Loading
Loading