Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Net_plugin first feature #44

Merged
merged 7 commits into from
Jun 26, 2017
Merged
Show file tree
Hide file tree
Changes from all 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 libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ add_library( eos_chain

target_link_libraries( eos_chain fc chainbase eos_types Logging IR WAST WASM Runtime )
target_include_directories( eos_chain
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include"
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/../wasm-jit/Include"
)

Expand Down
7 changes: 7 additions & 0 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ using chain::fork_database;
using chain::block_log;
using chain::type_index;
using chain::by_scope_name;
using chain::chain_id_type;

class chain_plugin_impl {
public:
Expand All @@ -31,6 +32,7 @@ class chain_plugin_impl {
fc::optional<fork_database> fork_db;
fc::optional<block_log> block_logger;
fc::optional<chain_controller> chain;
chain_id_type chain_id;
};


Expand Down Expand Up @@ -100,6 +102,7 @@ void chain_plugin::plugin_startup() {

my->fork_db = fork_database();
my->block_logger = block_log(my->block_log_dir);
my->chain_id = genesis.compute_chain_id();
my->chain = chain_controller(db, *my->fork_db, *my->block_logger,
initializer, native_contract::make_administrator());

Expand Down Expand Up @@ -140,6 +143,10 @@ bool chain_plugin::block_is_on_preferred_chain(const chain::block_id_type& block
chain_controller& chain_plugin::chain() { return *my->chain; }
const chain::chain_controller& chain_plugin::chain() const { return *my->chain; }

void chain_plugin::get_chain_id (chain_id_type &cid)const {
memcpy (cid.data(), my->chain_id.data(), cid.data_size());
}

namespace chain_apis {

read_only::get_info_results read_only::get_info(const read_only::get_info_params&) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class chain_plugin : public plugin<chain_plugin> {
// Only call this after plugin_startup()!
const chain_controller& chain() const;

void get_chain_id (chain::chain_id_type &cid) const;

private:
unique_ptr<class chain_plugin_impl> my;
};
Expand All @@ -97,4 +99,4 @@ FC_REFLECT(eos::chain_apis::read_only::get_info_results,
(head_block_num)(head_block_id)(head_block_time)(head_block_producer)
(recent_slots)(participation_rate))
FC_REFLECT(eos::chain_apis::read_only::get_block_params, (block_num_or_id))
FC_REFLECT(eos::chain_apis::read_only::get_types_params, (account_name))
FC_REFLECT(eos::chain_apis::read_only::get_types_params, (account_name))
20 changes: 10 additions & 10 deletions plugins/net_plugin/include/eos/net_plugin/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace eos {

struct handshake_message {
int16_t network_version = 0;
fc::sha256 chain_id; ///< used to identify chain
chain_id_type chain_id; ///< used to identify chain
fc::sha256 node_id; ///< used to identify peers and prevent self-connect
uint64_t last_irreversible_block_num = 0;
uint32_t last_irreversible_block_num = 0;
block_id_type last_irreversible_block_id;
string os;
string agent;
Expand All @@ -27,8 +27,8 @@ namespace eos {
};

struct sync_request_message {
uint64_t start_block;
uint64_t end_block;
uint32_t start_block;
uint32_t end_block;
};

struct peer_message {
Expand Down Expand Up @@ -56,13 +56,13 @@ FC_REFLECT( eos::notice_message, (known_trx)(known_blocks) )
FC_REFLECT( eos::sync_request_message, (start_block)(end_block) )
FC_REFLECT( eos::peer_message, (peers) )

/**
/**
*
Goals of Network Code
1. low latency to minimize missed blocks and potentially reduce block interval
2. minimize redundant data between blocks and transactions.
3. enable rapid sync of a new node
4. update to new boost / fc
4. update to new boost / fc



Expand Down Expand Up @@ -90,23 +90,23 @@ Goals of Network Code
wait for new validated block, transaction, or peer signal from network fiber
} else {
we assume peer is in sync mode in which case it is operating on a
request / response basis
request / response basis

wait for notice of sync from the read loop
}


read loop
read loop
if hello message
verify that peers Last Ir Block is in our state or disconnect, they are on fork
verify peer network protocol

if notice message update list of transactions known by remote peer
if trx message then insert into global state as unvalidated
if trx message then insert into global state as unvalidated
if blk summary message then insert into global state *if* we know of all dependent transactions
else close connection


if my head block < the LIB of a peer and my head block age > block interval * round_size/2 then
enter sync mode...
divide the block numbers you need to fetch among peers and send fetch request
Expand Down
Loading