-
Notifications
You must be signed in to change notification settings - Fork 5
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
Support sync start from certain evm height #170
Conversation
ship-start-from-canonical-height.
src/engine_plugin.cpp
Outdated
@@ -136,13 +136,16 @@ class engine_plugin_impl : std::enable_shared_from_this<engine_plugin_impl> { | |||
return silkworm::db::read_canonical_header(txn, head_num); | |||
} | |||
|
|||
std::optional<silkworm::Block> get_head_block() { | |||
std::optional<silkworm::Block> get_head_block(uint64_t override_height) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should change this function name to something like get_canonical_block_at_height
, and use a optional<uint64_t>
as a parameter. If it has no value, then use current head
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/ship_receiver_plugin.cpp
Outdated
@@ -29,21 +29,19 @@ class ship_receiver_plugin_impl : std::enable_shared_from_this<ship_receiver_plu | |||
using native_block_t = channels::native_block; | |||
static constexpr eosio::name pushtx = eosio::name("pushtx"); | |||
|
|||
void init(std::string h, std::string p, eosio::name ca, | |||
std::optional<eosio::checksum256> start_block_id, int64_t start_block_timestamp, | |||
void init(std::string h, std::string p, eosio::name ca, uint64_t input_start_height, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also move to use std::optional<uint64_t>
here for input_start_height
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/ship_receiver_plugin.hpp
Outdated
@@ -21,7 +21,7 @@ class ship_receiver_plugin : public appbase::plugin<ship_receiver_plugin> { | |||
void plugin_startup(); | |||
void plugin_shutdown(); | |||
|
|||
std::optional<channels::native_block> get_start_from_block(); | |||
uint64_t get_start_from_canonical_height(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
when overriding height when fetching header blocks.
please note that the logic for get_head_block is also changed a little bit: Now we will not try fetch canonical header at all if the override option is present. <- The overriding is meant to fix the db anyway, so we should give it a try. |
src/engine_plugin.cpp
Outdated
std::optional<silkworm::Block> get_head_block() { | ||
auto header = get_head_canonical_header(); | ||
if(!header) return {}; | ||
std::optional<silkworm::Block> get_canonical_block_at_height(const std::optional<uint64_t>& override_height) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
override_height => height
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also for small types (uint64_t) we can pass std::optional by value.
std::optional<silkworm::Block> get_canonical_block_at_height(std::optional<uint64_t> height)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/engine_plugin.cpp
Outdated
std::optional<silkworm::Block> engine_plugin::get_head_block() { | ||
return my->get_head_block(); | ||
std::optional<silkworm::Block> engine_plugin::get_canonical_block_at_height(const std::optional<uint64_t>& override_height) { | ||
return my->get_canonical_block_at_height(override_height); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/engine_plugin.hpp
Outdated
@@ -22,7 +22,7 @@ class engine_plugin : public appbase::plugin<engine_plugin> { | |||
uint32_t get_threads() const; | |||
std::string get_chain_data_dir() const; | |||
std::optional<silkworm::BlockHeader> get_head_canonical_header(); | |||
std::optional<silkworm::Block> get_head_block(); | |||
std::optional<silkworm::Block> get_canonical_block_at_height(const std::optional<uint64_t>& override_height); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/ship_receiver_plugin.cpp
Outdated
@@ -29,21 +29,19 @@ class ship_receiver_plugin_impl : std::enable_shared_from_this<ship_receiver_plu | |||
using native_block_t = channels::native_block; | |||
static constexpr eosio::name pushtx = eosio::name("pushtx"); | |||
|
|||
void init(std::string h, std::string p, eosio::name ca, | |||
std::optional<eosio::checksum256> start_block_id, int64_t start_block_timestamp, | |||
void init(std::string h, std::string p, eosio::name ca, const std::optional<uint64_t>& input_start_height, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/ship_receiver_plugin.cpp
Outdated
<< "#" << *start_from_canonical_height; | ||
} | ||
|
||
auto head_block = appbase::app().get_plugin<engine_plugin>().get_canonical_block_at_height(start_from_canonical_height); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not head_block
anymore, it could be a specific height or the head of the chain. We should change it to start_block
or similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/ship_receiver_plugin.cpp
Outdated
nb.block_num = utils::to_block_num(*start_from_block_id); | ||
return nb; | ||
} | ||
const std::optional<uint64_t>& get_start_from_canonical_height() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::optional<uint64_t>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/ship_receiver_plugin.cpp
Outdated
@@ -481,6 +468,7 @@ void ship_receiver_plugin::plugin_shutdown() { | |||
SILK_INFO << "Shutdown SHiP Receiver"; | |||
} | |||
|
|||
std::optional<channels::native_block> ship_receiver_plugin::get_start_from_block() { | |||
return my->get_start_from_block(); | |||
const std::optional<uint64_t>& ship_receiver_plugin::get_start_from_canonical_height() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::optional<uint64_t>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/ship_receiver_plugin.hpp
Outdated
@@ -21,7 +21,7 @@ class ship_receiver_plugin : public appbase::plugin<ship_receiver_plugin> { | |||
void plugin_startup(); | |||
void plugin_shutdown(); | |||
|
|||
std::optional<channels::native_block> get_start_from_block(); | |||
const std::optional<uint64_t>& get_start_from_canonical_height(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/block_conversion_plugin.cpp
Outdated
@@ -46,7 +46,8 @@ class block_conversion_plugin_impl : std::enable_shared_from_this<block_conversi | |||
} | |||
|
|||
void load_head() { | |||
auto head_block = appbase::app().get_plugin<engine_plugin>().get_head_block(); | |||
const std::optional<uint64_t>& start_from_canonical_height = appbase::app().get_plugin<ship_receiver_plugin>().get_start_from_canonical_height(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto
can be used here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Remove support for start from certain eos id functionality.
Resolve #151