Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ jobs:
uses: actions/cache/restore@v4
with:
path: ${{ env.CACHE_PATH }}
key: jam-${{ runner.os }}-${{ github.job }}-${{ env.CACHE_VERSION }}-${{ github.run_id }}
key: lean-${{ runner.os }}-${{ github.job }}-${{ env.CACHE_VERSION }}-${{ github.run_id }}
restore-keys: |
jam-${{ runner.os }}-${{ github.job }}-${{ env.CACHE_VERSION }}
jam-${{ runner.os }}-${{ github.job }}
jam-${{ runner.os }}
lean-${{ runner.os }}-${{ github.job }}-${{ env.CACHE_VERSION }}
lean-${{ runner.os }}-${{ github.job }}
lean-${{ runner.os }}

- name: "Basic init"
run: |
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

3 changes: 2 additions & 1 deletion example/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ logging:
level: trace
is_fallback: true
children:
- name: jam
- name: lean
children:
- name: modules
children:
- name: example_module
- name: synchronizer_module
- name: networking_module
- name: production_module
- name: injector
- name: application
- name: rpc
Expand Down
11 changes: 11 additions & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,14 @@ target_link_libraries(application
app_configuration
metrics
)

add_library(timeline SHARED
impl/timeline_impl.cpp
)
target_link_libraries(timeline
qtils::qtils
logger
sszpp
# app_configuration
# metrics
)
2 changes: 1 addition & 1 deletion src/app/chain_spec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <qtils/byte_vec.hpp>

#include "lean_types/types.hpp"
#include "types/types.hpp"

namespace lean {

Expand Down
3 changes: 3 additions & 0 deletions src/app/impl/application_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "app/configuration.hpp"
#include "app/impl/watchdog.hpp"
#include "app/state_manager.hpp"
#include "app/timeline.hpp"
#include "clock/clock.hpp"
#include "log/logger.hpp"
#include "metrics/histogram_timer.hpp"
Expand All @@ -33,13 +34,15 @@ namespace lean::app {
qtils::SharedRef<Watchdog> watchdog,
qtils::SharedRef<metrics::Exposer> metrics_exposer,
qtils::SharedRef<clock::SystemClock> system_clock,
qtils::SharedRef<Timeline> timeline,
std::shared_ptr<SeHolder>)
: logger_(logsys->getLogger("Application", "application")),
app_config_(std::move(config)),
state_manager_(std::move(state_manager)),
watchdog_(std::move(watchdog)),
metrics_exposer_(std::move(metrics_exposer)),
system_clock_(std::move(system_clock)),
timeline_(std::move(timeline)),
metrics_registry_(metrics::createRegistry()) {
// Metric for exposing name and version of node
metrics::GaugeHelper(
Expand Down
3 changes: 3 additions & 0 deletions src/app/impl/application_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace lean {
} // namespace lean

namespace lean::app {
class Timeline;
class Configuration;
class StateManager;
} // namespace lean::app
Expand Down Expand Up @@ -82,6 +83,7 @@ namespace lean::app {
qtils::SharedRef<Watchdog> watchdog,
qtils::SharedRef<metrics::Exposer> metrics_exposer,
qtils::SharedRef<clock::SystemClock> system_clock,
qtils::SharedRef<Timeline> timeline,
std::shared_ptr<SeHolder>);

void run() override;
Expand All @@ -93,6 +95,7 @@ namespace lean::app {
qtils::SharedRef<Watchdog> watchdog_;
qtils::SharedRef<metrics::Exposer> metrics_exposer_;
qtils::SharedRef<clock::SystemClock> system_clock_;
qtils::SharedRef<Timeline> timeline_;

// Metrics
std::unique_ptr<metrics::Registry> metrics_registry_;
Expand Down
93 changes: 93 additions & 0 deletions src/app/impl/timeline_impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/


#include "timeline_impl.hpp"

#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>>::
template create<EventTypes::SlotStarted>(
*se_manager_,
SubscriptionEngineHandlers::kTest,
[this](auto &,
std::shared_ptr<const messages::SlotStarted> msg) {
on_slot_started(msg);
});
}

void TimelineImpl::start() {
auto now = clock_->nowMsec();
auto since_genesis = now - config_->genesis_time;
SL_TRACE(logger_, "since genesis: {}ms", since_genesis);
auto next_slot = since_genesis / SLOT_DURATION_MS + 1;
SL_TRACE(logger_, "next slot: {}", next_slot);
auto time_to_next_slot =
config_->genesis_time + SLOT_DURATION_MS * next_slot - now;
SL_TRACE(logger_, "time to next slot {}ms", time_to_next_slot);
if (time_to_next_slot < SLOT_DURATION_MS / 2) {
SL_TRACE(logger_, "skip one next slot");
++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_) {
return;
}

SL_INFO(logger_, "Slot {} is started", msg->slot);

auto time_to_next_slot = config_->genesis_time
+ SLOT_DURATION_MS * (msg->slot + 1)
- clock_->nowMsec();
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
66 changes: 66 additions & 0 deletions src/app/impl/timeline_impl.hpp
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 {
namespace log {
class LoggingSystem;
}
struct Config;
} // namespace lean
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
17 changes: 17 additions & 0 deletions src/app/timeline.hpp
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
14 changes: 7 additions & 7 deletions src/blockchain/block_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

#include <qtils/outcome.hpp>

#include "lean_types/block.hpp"
#include "lean_types/block_body.hpp"
#include "lean_types/block_data.hpp"
#include "lean_types/block_header.hpp"
#include "lean_types/justification.hpp"
#include "lean_types/signed_block.hpp"
#include "lean_types/types.hpp"
#include "types/block.hpp"
#include "types/block_body.hpp"
#include "types/block_data.hpp"
#include "types/block_header.hpp"
#include "types/justification.hpp"
#include "types/signed_block.hpp"
#include "types/types.hpp"

namespace lean::blockchain {

Expand Down
2 changes: 1 addition & 1 deletion src/blockchain/genesis_block_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#pragma once

#include "lean_types/block_header.hpp"
#include "types/block_header.hpp"

namespace lean::blockchain {

Expand Down
2 changes: 1 addition & 1 deletion src/blockchain/impl/block_storage_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

#include "blockchain/block_storage_error.hpp"
#include "blockchain/impl/storage_util.hpp"
#include "lean_types/block_data.hpp"
#include "sszpp/ssz++.hpp"
#include "storage/predefined_keys.hpp"
#include "types/block_data.hpp"

namespace lean::blockchain {

Expand Down
2 changes: 1 addition & 1 deletion src/blockchain/impl/block_storage_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "blockchain/genesis_block_header.hpp"
#include "blockchain/impl/block_storage_impl.hpp"
#include "blockchain/impl/storage_util.hpp"
#include "lean_types/block.hpp"
#include "types/block.hpp"

namespace lean::blockchain {

Expand Down
2 changes: 1 addition & 1 deletion src/blockchain/impl/block_storage_initializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#pragma once

#include <lean_types/types.hpp>
#include <qtils/shared_ref.hpp>
#include <types/types.hpp>
#include <utils/ctor_limiters.hpp>

namespace lean::log {
Expand Down
2 changes: 1 addition & 1 deletion src/blockchain/impl/storage_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <qtils/byte_vec.hpp>

#include "lean_types/types.hpp"
#include "types/types.hpp"

// #include "primitives/block_id.hpp"
#include "serde/serialization.hpp"
Expand Down
24 changes: 12 additions & 12 deletions src/executable/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ if (CMAKE_HOST_APPLE)
option(MACOS_BIG_EXE_USE_DYLIB "compile dylib instead of exe to work around dyld cache error when loading big exe" ON)
endif ()
if (MACOS_BIG_EXE_USE_DYLIB)
add_library(jam_node SHARED jam_node.cpp)
set_target_properties(jam_node PROPERTIES PREFIX "" DEBUG_POSTFIX "")
target_compile_definitions(jam_node PRIVATE BUILD_AS_LIBRARY)
target_link_libraries(jam_node ${LIBRARIES})

add_executable(jam_node_dlopen dlopen.cpp)
set_target_properties(jam_node_dlopen PROPERTIES OUTPUT_NAME jam_node)
set_target_properties(jam_node_dlopen PROPERTIES LINKER_LANGUAGE CXX)
add_library(lean_node SHARED lean_node.cpp)
set_target_properties(lean_node PROPERTIES PREFIX "" DEBUG_POSTFIX "")
target_compile_definitions(lean_node PRIVATE BUILD_AS_LIBRARY)
target_link_libraries(lean_node ${LIBRARIES})

add_executable(lean_node_dlopen dlopen.cpp)
set_target_properties(lean_node_dlopen PROPERTIES OUTPUT_NAME lean_node)
set_target_properties(lean_node_dlopen PROPERTIES LINKER_LANGUAGE CXX)
else ()
add_executable(jam_node jam_node.cpp)
target_link_libraries(jam_node ${LIBRARIES})
add_executable(lean_node lean_node.cpp)
target_link_libraries(lean_node ${LIBRARIES})
endif ()
add_dependencies(jam_node all_modules)
add_dependencies(lean_node all_modules)

#if (BACKWARD)
# add_backward(jam_node)
# add_backward(lean_node)
#endif ()


Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/injector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ target_link_libraries(node_injector
modules
storage
blockchain
timeline
)
Loading
Loading