-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [bloc-157] add sync version of grandpa * [bloc-157] integrate grandpa
- Loading branch information
Showing
8 changed files
with
139 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
5 changes: 2 additions & 3 deletions
5
plugins/grandpa_plugin/include/eosio/grandpa_plugin/network_messages.hpp
This file contains 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
2 changes: 1 addition & 1 deletion
2
plugins/grandpa_plugin/include/eosio/grandpa_plugin/prefix_chain_tree.hpp
This file contains 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 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 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 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 @@ | ||
#pragma once | ||
#include "simulator.hpp" | ||
#include "database.hpp" | ||
#define SYNC_GRANDPA //SYNC mode | ||
#include <eosio/grandpa_plugin/grandpa.hpp> | ||
#include <mutex> | ||
|
||
|
||
|
||
class GrandpaNode: public Node { | ||
public: | ||
explicit GrandpaNode(int id, Network && net, fork_db && db): | ||
Node(id, std::move(net), std::move(db)) | ||
{ | ||
init_channels(); | ||
init_providers(); | ||
init_grandpa(); | ||
|
||
grandpa.start(); | ||
} | ||
|
||
~GrandpaNode() { | ||
grandpa.stop(); | ||
} | ||
|
||
void on_receive(uint32_t from, void* msg) override { | ||
auto data = *static_cast<grandpa_net_msg*>(msg); | ||
data.ses_id = from; | ||
in_net_ch->send(data); | ||
} | ||
|
||
void on_new_peer_event(uint32_t id) override { | ||
ev_ch->send(grandpa_event { ::on_new_peer_event { id } }); | ||
} | ||
|
||
void on_accepted_block_event(block_id_type id) override { | ||
ev_ch->send(grandpa_event { ::on_accepted_block_event { id } }); | ||
} | ||
|
||
private: | ||
void init_channels() { | ||
in_net_ch = std::make_shared<net_channel>(); | ||
out_net_ch = std::make_shared<net_channel>(); | ||
ev_ch = std::make_shared<event_channel>(); | ||
|
||
out_net_ch->subscribe([this](const grandpa_net_msg& msg) { | ||
send<grandpa_net_msg>(msg.ses_id, msg); | ||
}); | ||
} | ||
|
||
void init_providers() { | ||
prev_block_prov = std::make_shared<prev_block_prodiver>([this](const block_id_type& id) -> fc::optional<block_id_type> { | ||
auto block = db.find(id); | ||
if (!block || !block->parent) | ||
return {}; | ||
else | ||
return block->parent->block_id; | ||
}); | ||
|
||
lib_prov = std::make_shared<lib_prodiver>([this]() -> block_id_type { | ||
return db.last_irreversible_block_id(); | ||
}); | ||
|
||
prods_prov = std::make_shared<prods_provider>([]() -> vector<public_key_type> { | ||
return {}; | ||
}); | ||
} | ||
|
||
void init_grandpa() { | ||
grandpa | ||
.set_event_channel(ev_ch) | ||
.set_in_net_channel(in_net_ch) | ||
.set_out_net_channel(out_net_ch) | ||
.set_prev_block_provider(prev_block_prov) | ||
.set_lib_provider(lib_prov) | ||
.set_prods_provider(prods_prov) | ||
.set_private_key(private_key_type::generate()); | ||
} | ||
|
||
net_channel_ptr in_net_ch; | ||
net_channel_ptr out_net_ch; | ||
event_channel_ptr ev_ch; | ||
|
||
prev_block_prodiver_ptr prev_block_prov; | ||
lib_prodiver_ptr lib_prov; | ||
prods_provider_ptr prods_prov; | ||
|
||
grandpa grandpa; | ||
}; | ||
|
This file contains 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 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