Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Never rollback initial ledger secrets #3169

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 1 addition & 1 deletion .daily_canary
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Triggerrr
Tiggerrr
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- DNS resolution of client connections is now asynchronous.

### Fixed

- Fixed issue with new node startup which could get stuck if an election was triggered while catching up (#3169).
jumaffre marked this conversation as resolved.
Show resolved Hide resolved

## [2.0.0-dev5]

### Added
Expand Down
15 changes: 12 additions & 3 deletions src/node/ledger_secrets.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ namespace ccf
std::mutex lock;
LedgerSecretsMap ledger_secrets;

// Set once when the LedgerSecrets are initialised. This prevents a backup
// node to rollback not-yet-applicable ledger secrets when catching up.
jumaffre marked this conversation as resolved.
Show resolved Hide resolved
kv::Version initial_latest_ledger_secret_version = 0;

std::optional<LedgerSecretsMap::iterator> last_used_secret_it =
std::nullopt;

Expand Down Expand Up @@ -105,6 +109,7 @@ namespace ccf
std::lock_guard<std::mutex> guard(lock);

ledger_secrets.emplace(initial_version, make_ledger_secret());
initial_latest_ledger_secret_version = initial_version;
}

void init_from_map(LedgerSecretsMap&& ledger_secrets_)
Expand All @@ -115,6 +120,7 @@ namespace ccf
ledger_secrets.empty(), "Should only init an empty LedgerSecrets");

ledger_secrets = std::move(ledger_secrets_);
initial_latest_ledger_secret_version = ledger_secrets.rbegin()->first;
}

void adjust_previous_secret_stored_version(kv::Version version)
Expand Down Expand Up @@ -281,7 +287,9 @@ namespace ccf
while (ledger_secrets.size() > 1)
{
auto k = ledger_secrets.rbegin();
if (k->first <= version)
if (
k->first <= version ||
k->first <= initial_latest_ledger_secret_version)
{
break;
}
Expand All @@ -290,8 +298,9 @@ namespace ccf
ledger_secrets.erase(k->first);
}

// Assume that the next operation will use the first non-rollbacked secret
last_used_secret_it = std::prev(ledger_secrets.end());
// Invalidate last used ledger secret iterator. Next key usage will need
// to find the appropriate key on the slow path.
last_used_secret_it = std::nullopt;
}
};
}
12 changes: 12 additions & 0 deletions src/node/test/encryptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,18 @@ TEST_CASE("Backup catchup from many ledger secrets")
backup_store
.deserialize(*std::get<1>(next_entry.value()), ConsensusType::CFT)
->apply() == kv::ApplyResult::PASS);

auto tx_id = backup_store.current_txid();
tx_id.version--;
// While catching up, assume the backup rolls back (e.g. because of an
// election)
backup_store.rollback(tx_id, backup_store.commit_view());

REQUIRE(
backup_store
.deserialize(*std::get<1>(next_entry.value()), ConsensusType::CFT)
->apply() == kv::ApplyResult::PASS);

next_entry = consensus->pop_oldest_entry();
}
}
Expand Down
4 changes: 0 additions & 4 deletions tests/infra/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
from loguru import logger as LOG


# Optional. May be useful to avoid GitHub's low rate limits for unauthenticated clients
# https://docs.github.com/en/rest/reference/rate-limit
ENV_VAR_GITHUB_AUTH_TOKEN_NAME = "LTS_COMPATIBILITY_GH_TOKEN"

REPOSITORY_NAME = "microsoft/CCF"
REMOTE_URL = f"https://github.com/{REPOSITORY_NAME}"
BRANCH_RELEASE_PREFIX = "release/"
Expand Down