-
Notifications
You must be signed in to change notification settings - Fork 253
Do not process forwarded commands until node is part of the network #7936
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f6ff139
Initial plan
Copilot 13b099e
Gate forwarded commands behind part-of-network state check
Copilot 4d13d36
Add check_one_of() to StateMachine with unit test
Copilot 82c02b0
Add recv_node_inbound_message unit test; fix doctest main linking and…
Copilot 84f1c42
Fix CHANGELOG version and bump pyproject to satisfy release notes check
Copilot 642ad50
Merge branch 'main' into copilot/forwarded-messages-logic
achamayou 1edc288
Potential fix for pull request finding
achamayou e7649d3
Potential fix for pull request finding
achamayou 0c88bb7
Avoid early null deref in recv_node_inbound dispatch
Copilot c77546a
Guard nullable handlers in node inbound dispatch
Copilot fc82896
Merge branch 'main' into copilot/forwarded-messages-logic
achamayou 0cd940f
Merge branch 'main' into copilot/forwarded-messages-logic
achamayou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" | |
|
|
||
| [project] | ||
| name = "ccf" | ||
| version = "7.0.5" | ||
| version = "7.0.6" | ||
| authors = [ | ||
| { name="CCF Team", email="[email protected]" }, | ||
| ] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the Apache 2.0 License. | ||
|
|
||
| #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN | ||
| #include "../state_machine.h" | ||
|
|
||
| #include <doctest/doctest.h> | ||
|
|
||
| namespace | ||
| { | ||
| enum class Example | ||
| { | ||
| A, | ||
| B, | ||
| C, | ||
| D | ||
| }; | ||
| } | ||
|
|
||
| template <> | ||
| struct fmt::formatter<Example> : fmt::formatter<std::string_view> | ||
| { | ||
| template <typename FormatContext> | ||
| auto format(Example e, FormatContext& ctx) const | ||
| { | ||
| std::string_view name = "unknown"; | ||
| switch (e) | ||
| { | ||
| case Example::A: | ||
| name = "A"; | ||
| break; | ||
| case Example::B: | ||
| name = "B"; | ||
| break; | ||
| case Example::C: | ||
| name = "C"; | ||
| break; | ||
| case Example::D: | ||
| name = "D"; | ||
| break; | ||
| } | ||
| return fmt::formatter<std::string_view>::format(name, ctx); | ||
| } | ||
| }; | ||
|
|
||
| TEST_CASE("Basic state machine" * doctest::test_suite("state_machine")) | ||
| { | ||
| ds::StateMachine<Example> sm("example", Example::A); | ||
|
|
||
| REQUIRE(sm.value() == Example::A); | ||
| REQUIRE(sm.check(Example::A)); | ||
| REQUIRE_FALSE(sm.check(Example::B)); | ||
| REQUIRE_NOTHROW(sm.expect(Example::A)); | ||
| REQUIRE_THROWS_AS(sm.expect(Example::B), std::logic_error); | ||
|
|
||
| sm.advance(Example::B); | ||
|
|
||
| REQUIRE(sm.value() == Example::B); | ||
| REQUIRE(sm.check(Example::B)); | ||
| REQUIRE_FALSE(sm.check(Example::A)); | ||
| REQUIRE_NOTHROW(sm.expect(Example::B)); | ||
| REQUIRE_THROWS_AS(sm.expect(Example::A), std::logic_error); | ||
| } | ||
|
|
||
| TEST_CASE("check_one_of" * doctest::test_suite("state_machine")) | ||
| { | ||
| ds::StateMachine<Example> sm("example", Example::A); | ||
|
|
||
| { | ||
| INFO("Current state is part of the set"); | ||
| REQUIRE(sm.check_one_of({Example::A})); | ||
| REQUIRE(sm.check_one_of({Example::A, Example::B})); | ||
| REQUIRE(sm.check_one_of({Example::A, Example::B, Example::C})); | ||
| } | ||
|
|
||
| { | ||
| INFO("Current state is not part of the set"); | ||
| REQUIRE_FALSE(sm.check_one_of({Example::B})); | ||
| REQUIRE_FALSE(sm.check_one_of({Example::B, Example::C})); | ||
| REQUIRE_FALSE(sm.check_one_of({Example::B, Example::C, Example::D})); | ||
| } | ||
|
|
||
| { | ||
| INFO("Empty set never matches"); | ||
| REQUIRE_FALSE(sm.check_one_of({})); | ||
| } | ||
|
|
||
| { | ||
| INFO("Set membership follows state transitions"); | ||
| const std::set<Example> states{Example::B, Example::C}; | ||
| REQUIRE_FALSE(sm.check_one_of(states)); | ||
|
|
||
| sm.advance(Example::B); | ||
| REQUIRE(sm.check_one_of(states)); | ||
|
|
||
| sm.advance(Example::C); | ||
| REQUIRE(sm.check_one_of(states)); | ||
|
|
||
| sm.advance(Example::D); | ||
| REQUIRE_FALSE(sm.check_one_of(states)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the Apache 2.0 License. | ||
| #pragma once | ||
|
|
||
| #include "ccf/entity_id.h" | ||
| #include "ccf/node_startup_state.h" | ||
| #include "ds/internal_logger.h" | ||
| #include "ds/state_machine.h" | ||
| #include "node/node_types.h" | ||
|
|
||
| namespace ccf | ||
| { | ||
| // Reads a serialised node_inbound message and dispatches it to the | ||
| // appropriate handler, but only once the node is part of the network. This | ||
| // includes forwarded commands, which must not be executed until the node is | ||
| // part of the network, as some commands may otherwise exhibit undefined | ||
| // behaviour. | ||
| template <typename TForwarder, typename TChannels, typename TConsensus> | ||
| void recv_node_inbound_message( | ||
| const uint8_t* data, | ||
| size_t size, | ||
| ::ds::StateMachine<NodeStartupState>& sm, | ||
| TForwarder* cmd_forwarder, | ||
| TChannels* n2n_channels, | ||
| TConsensus* consensus) | ||
| { | ||
| auto [msg_type, from, payload] = | ||
| ringbuffer::read_message<node_inbound>(data, size); | ||
|
|
||
| const auto* payload_data = payload.data; | ||
| auto payload_size = payload.size; | ||
|
|
||
| static const std::set<NodeStartupState> active_states{ | ||
| NodeStartupState::partOfNetwork, | ||
| NodeStartupState::partOfPublicNetwork, | ||
| NodeStartupState::readingPrivateLedger}; | ||
|
|
||
| if (!sm.check_one_of(active_states)) | ||
| { | ||
| LOG_DEBUG_FMT( | ||
| "Ignoring node msg received too early - current state is {}", | ||
| sm.value()); | ||
| return; | ||
| } | ||
|
|
||
| switch (msg_type) | ||
| { | ||
| case forwarded_msg: | ||
| { | ||
| if (cmd_forwarder == nullptr) | ||
| { | ||
| LOG_FAIL_FMT( | ||
| "Ignoring forwarded node message: command forwarder not " | ||
| "initialised"); | ||
| return; | ||
| } | ||
| cmd_forwarder->recv_message(from, payload_data, payload_size); | ||
| return; | ||
| } | ||
| case channel_msg: | ||
| { | ||
| if (n2n_channels == nullptr) | ||
| { | ||
| LOG_FAIL_FMT( | ||
| "Ignoring channel node message: node-to-node channels not " | ||
| "initialised"); | ||
| return; | ||
| } | ||
| n2n_channels->recv_channel_message(from, payload_data, payload_size); | ||
| return; | ||
| } | ||
| case consensus_msg: | ||
| { | ||
| if (consensus == nullptr) | ||
| { | ||
| LOG_FAIL_FMT( | ||
| "Ignoring consensus node message: consensus not initialised"); | ||
| return; | ||
| } | ||
| consensus->recv_message(from, payload_data, payload_size); | ||
| return; | ||
| } | ||
| default: | ||
| { | ||
| throw std::logic_error(fmt::format( | ||
| "Unknown node message type: {}", static_cast<uint32_t>(msg_type))); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.