-
Notifications
You must be signed in to change notification settings - Fork 3
feature: block production #7
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 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2e94d85
feature: block production (without block tree yet)
xDimon 0bc6300
feature: block tree
xDimon 7ee37a7
fix: review and format issues
xDimon 178ff9d
fix: ci issue
xDimon 218e97c
fix: tests
xDimon 67360d0
fix: wrong passing next slot
xDimon 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 was deleted.
Oops, something went wrong.
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 |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |
|
|
||
|
|
||
| # paths | ||
| PROJECT=/cpp-jam | ||
| PROJECT=/cpp-lean | ||
| VENV=$PROJECT.venv | ||
| BUILD=$PROJECT.build | ||
| VCPKG=/vcpkg | ||
|
|
||
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
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
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,97 @@ | ||
| /** | ||
| * Copyright Quadrivium LLC | ||
| * All Rights Reserved | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
|
|
||
| #include "timeline_impl.hpp" | ||
|
|
||
| #include <utility> | ||
|
|
||
| #include "app/state_manager.hpp" | ||
| #include "clock/clock.hpp" | ||
| #include "log/logger.hpp" | ||
| #include "modules/shared/prodution_types.tmp.hpp" | ||
| #include "se/impl/subscription_manager.hpp" | ||
| #include "se/subscription.hpp" | ||
| #include "se/subscription_fwd.hpp" | ||
| #include "types/config.hpp" | ||
| #include "types/constants.hpp" | ||
|
|
||
| namespace lean::app { | ||
|
|
||
| TimelineImpl::TimelineImpl(qtils::SharedRef<log::LoggingSystem> logsys, | ||
| qtils::SharedRef<StateManager> state_manager, | ||
| qtils::SharedRef<Subscription> se_manager, | ||
| qtils::SharedRef<clock::SystemClock> clock, | ||
| qtils::SharedRef<Config> config) | ||
| : logger_(logsys->getLogger("Timeline", "application")), | ||
| state_manager_(std::move(state_manager)), | ||
| config_(std::move(config)), | ||
| clock_(std::move(clock)), | ||
| se_manager_(std::move(se_manager)) { | ||
| state_manager_->takeControl(*this); | ||
| } | ||
|
|
||
| void TimelineImpl::prepare() { | ||
| on_slot_started_ = | ||
| se::SubscriberCreator<qtils::Empty, | ||
| std::shared_ptr<const messages::SlotStarted>>:: | ||
| create<EventTypes::SlotStarted>( | ||
| *se_manager_, | ||
| SubscriptionEngineHandlers::kTest, | ||
| [this](auto &, | ||
| std::shared_ptr<const messages::SlotStarted> msg) { | ||
| on_slot_started(std::move(msg)); | ||
| }); | ||
| } | ||
|
|
||
| void TimelineImpl::start() { | ||
| auto now = clock_->nowMsec(); | ||
| auto next_slot = (now - config_->genesis_time) / SLOT_DURATION_MS + 1; | ||
| auto time_to_next_slot = | ||
| config_->genesis_time + SLOT_DURATION_MS * next_slot - now; | ||
| if (time_to_next_slot < SLOT_DURATION_MS / 2) { | ||
| ++next_slot; | ||
| time_to_next_slot += SLOT_DURATION_MS; | ||
| } | ||
| SL_INFO(logger_, | ||
| "Starting timeline. Next slot is {}, starts in {}ms", | ||
| next_slot, | ||
| time_to_next_slot); | ||
| se_manager_->notifyDelayed( | ||
| std::chrono::milliseconds(time_to_next_slot), | ||
| EventTypes::SlotStarted, | ||
| std::make_shared<const messages::SlotStarted>(next_slot, 0, false)); | ||
| } | ||
|
|
||
| void TimelineImpl::stop() { | ||
| stopped_ = true; | ||
| } | ||
|
|
||
| void TimelineImpl::on_slot_started( | ||
| std::shared_ptr<const messages::SlotStarted> msg) { | ||
| if (stopped_) [[unlikely]] { | ||
| SL_INFO(logger_, "Timeline is stopped on slot {}", msg->slot); | ||
| return; | ||
| } | ||
|
|
||
| auto now = clock_->nowMsec(); | ||
| auto next_slot = (now - config_->genesis_time) / SLOT_DURATION_MS + 1; | ||
| auto time_to_next_slot = | ||
| config_->genesis_time + SLOT_DURATION_MS * next_slot - now; | ||
| if (time_to_next_slot < SLOT_DURATION_MS / 2) { | ||
| ++next_slot; | ||
| time_to_next_slot += SLOT_DURATION_MS; | ||
| } | ||
|
|
||
| SL_INFO(logger_, "Next slot is {} in {}ms", msg->slot, time_to_next_slot); | ||
|
|
||
| se_manager_->notifyDelayed( | ||
| std::chrono::milliseconds(time_to_next_slot), | ||
| EventTypes::SlotStarted, | ||
| std::make_shared<const messages::SlotStarted>(msg->slot + 1, 0, false)); | ||
| } | ||
|
|
||
| } // namespace lean::app | ||
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,66 @@ | ||
| /** | ||
| * Copyright Quadrivium LLC | ||
| * All Rights Reserved | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <qtils/empty.hpp> | ||
| #include <qtils/shared_ref.hpp> | ||
|
|
||
| #include "app/timeline.hpp" | ||
| #include "se/subscription_fwd.hpp" | ||
|
|
||
| namespace lean::messages { | ||
| struct SlotStarted; | ||
| } | ||
| namespace lean { | ||
| struct Config; | ||
| } | ||
| namespace lean::log { | ||
| class LoggingSystem; | ||
| } | ||
| namespace lean::clock { | ||
| class SystemClock; | ||
| } | ||
| namespace soralog { | ||
| class Logger; | ||
| } | ||
| namespace lean::app { | ||
| class Configuration; | ||
| class StateManager; | ||
| } | ||
|
|
||
| namespace lean::app { | ||
|
|
||
| class TimelineImpl final : public Timeline { | ||
| public: | ||
| TimelineImpl(qtils::SharedRef<log::LoggingSystem> logsys, | ||
| qtils::SharedRef<StateManager> state_manager, | ||
| qtils::SharedRef<Subscription> se_manager, | ||
| qtils::SharedRef<clock::SystemClock> clock, | ||
| qtils::SharedRef<Config> config); | ||
|
|
||
| void prepare(); | ||
| void start(); | ||
| void stop(); | ||
|
|
||
| private: | ||
| void on_slot_started(std::shared_ptr<const messages::SlotStarted> msg); | ||
|
|
||
| qtils::SharedRef<soralog::Logger> logger_; | ||
| qtils::SharedRef<StateManager> state_manager_; | ||
| qtils::SharedRef<Config> config_; | ||
| qtils::SharedRef<clock::SystemClock> clock_; | ||
| qtils::SharedRef<Subscription> se_manager_; | ||
|
|
||
| bool stopped_ = false; | ||
|
|
||
| std::shared_ptr< | ||
| BaseSubscriber<qtils::Empty, | ||
| std::shared_ptr<const messages::SlotStarted>>> | ||
| on_slot_started_; | ||
| }; | ||
|
|
||
| } // namespace lean::app |
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,17 @@ | ||
| /** | ||
| * Copyright Quadrivium LLC | ||
| * All Rights Reserved | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "utils/ctor_limiters.hpp" | ||
|
|
||
| namespace lean::app { | ||
|
|
||
| class Timeline : NonCopyable, NonMovable { | ||
| // | ||
| }; | ||
|
|
||
| } // namespace lean::app |
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.
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.