Skip to content

Commit

Permalink
Merge pull request #1552 from AntelopeIO/hotstuff_logging_framework
Browse files Browse the repository at this point in the history
IF: Use FC logging framework for better management and consistency
  • Loading branch information
linh2931 authored Aug 24, 2023
2 parents 587abb1 + 14929cb commit aa926f0
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 196 deletions.
5 changes: 3 additions & 2 deletions libraries/hotstuff/chain_pacemaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ namespace eosio { namespace hotstuff {
#endif
//===============================================================================================

chain_pacemaker::chain_pacemaker(controller* chain, std::set<account_name> my_producers, bool info_logging, bool error_logging)
chain_pacemaker::chain_pacemaker(controller* chain, std::set<account_name> my_producers, fc::logger& logger)
: _chain(chain),
_qc_chain("default"_n, this, std::move(my_producers), info_logging, error_logging)
_qc_chain("default"_n, this, std::move(my_producers), logger),
_logger(logger)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace eosio::hotstuff {

//class-specific functions

chain_pacemaker(controller* chain, std::set<account_name> my_producers, bool info_logging, bool error_logging);
chain_pacemaker(controller* chain, std::set<account_name> my_producers, fc::logger& logger);

void beat();

Expand Down Expand Up @@ -69,6 +69,8 @@ namespace eosio::hotstuff {
qc_chain _qc_chain;

uint32_t _quorum_threshold = 15; //FIXME/TODO: calculate from schedule
fc::logger& _logger;

};

} // namespace eosio::hotstuff
4 changes: 3 additions & 1 deletion libraries/hotstuff/include/eosio/hotstuff/qc_chain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace eosio::hotstuff {

qc_chain() = delete;

qc_chain(name id, base_pacemaker* pacemaker, std::set<name> my_producers, bool info_logging, bool error_logging);
qc_chain(name id, base_pacemaker* pacemaker, std::set<name> my_producers, fc::logger& logger);

uint64_t get_state_version() const { return _state_version; } // calling this w/ thread sync is optional

Expand Down Expand Up @@ -143,6 +143,8 @@ namespace eosio::hotstuff {

mutable std::atomic<uint64_t> _state_version = 1;

fc::logger& _logger;

#ifdef QC_CHAIN_SIMPLE_PROPOSAL_STORE
// keep one proposal store (id -> proposal) by each height (height -> proposal store)
typedef map<fc::sha256, hs_proposal_message> proposal_store;
Expand Down
258 changes: 85 additions & 173 deletions libraries/hotstuff/qc_chain.cpp

Large diffs are not rendered by default.

27 changes: 11 additions & 16 deletions libraries/hotstuff/test/test_hotstuff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ std::vector<name> unique_replicas {
"bpp"_n, "bpq"_n, "bpr"_n,
"bps"_n, "bpt"_n, "bpu"_n };

fc::logger hotstuff_logger;

class hotstuff_test_handler {
public:

std::vector<std::pair<name, std::shared_ptr<qc_chain>>> _qc_chains;

void initialize_qc_chains(test_pacemaker& tpm, std::vector<name> info_loggers, std::vector<name> error_loggers, std::vector<name> replicas){
void initialize_qc_chains(test_pacemaker& tpm, std::vector<name> replicas){

_qc_chains.clear();

Expand All @@ -51,14 +53,7 @@ class hotstuff_test_handler {
//_qc_chains.reserve( replicas.size() );

for (name r : replicas) {

bool log = std::find(info_loggers.begin(), info_loggers.end(), r) != info_loggers.end();
bool err = std::find(error_loggers.begin(), error_loggers.end(), r) != error_loggers.end();

//If you want to force logging everything
//log = err = true;

qc_chain *qcc_ptr = new qc_chain(r, &tpm, {r}, log, err);
qc_chain *qcc_ptr = new qc_chain(r, &tpm, {r}, hotstuff_logger);
std::shared_ptr<qc_chain> qcc_shared_ptr(qcc_ptr);

_qc_chains.push_back( std::make_pair(r, qcc_shared_ptr) );
Expand Down Expand Up @@ -186,7 +181,7 @@ BOOST_AUTO_TEST_CASE(hotstuff_1) try {

hotstuff_test_handler ht;

ht.initialize_qc_chains(tpm, {"bpa"_n, "bpb"_n}, {"bpa"_n, "bpb"_n}, unique_replicas);
ht.initialize_qc_chains(tpm, unique_replicas);

tpm.set_proposer("bpa"_n);
tpm.set_leader("bpa"_n);
Expand Down Expand Up @@ -316,7 +311,7 @@ BOOST_AUTO_TEST_CASE(hotstuff_2) try {

hotstuff_test_handler ht;

ht.initialize_qc_chains(tpm, {"bpa"_n}, {"bpa"_n}, unique_replicas);
ht.initialize_qc_chains(tpm, unique_replicas);

tpm.set_proposer("bpa"_n);
tpm.set_leader("bpa"_n);
Expand Down Expand Up @@ -414,7 +409,7 @@ BOOST_AUTO_TEST_CASE(hotstuff_3) try {

hotstuff_test_handler ht;

ht.initialize_qc_chains(tpm, {"bpa"_n, "bpb"_n}, {"bpa"_n, "bpb"_n},unique_replicas);
ht.initialize_qc_chains(tpm, unique_replicas);

tpm.set_proposer("bpa"_n);
tpm.set_leader("bpa"_n);
Expand Down Expand Up @@ -546,7 +541,7 @@ BOOST_AUTO_TEST_CASE(hotstuff_4) try {

hotstuff_test_handler ht;

ht.initialize_qc_chains(tpm, {"bpa"_n, "bpb"_n}, {"bpa"_n, "bpb"_n}, unique_replicas);
ht.initialize_qc_chains(tpm, unique_replicas);

tpm.set_proposer("bpa"_n);
tpm.set_leader("bpa"_n);
Expand Down Expand Up @@ -744,9 +739,9 @@ BOOST_AUTO_TEST_CASE(hotstuff_5) try {
hotstuff_test_handler ht1;
hotstuff_test_handler ht2;

ht1.initialize_qc_chains(tpm1, {"bpe"_n}, {"bpe"_n}, replica_set_1);
ht1.initialize_qc_chains(tpm1, replica_set_1);

ht2.initialize_qc_chains(tpm2, {}, {}, replica_set_2);
ht2.initialize_qc_chains(tpm2, replica_set_2);

tpm1.set_proposer("bpe"_n); //honest leader
tpm1.set_leader("bpe"_n);
Expand Down Expand Up @@ -901,7 +896,7 @@ BOOST_AUTO_TEST_CASE(hotstuff_6) try {

hotstuff_test_handler ht;

ht.initialize_qc_chains(tpm, {"bpa"_n, "bpb"_n}, {"bpa"_n, "bpb"_n},unique_replicas);
ht.initialize_qc_chains(tpm, unique_replicas);

tpm.set_proposer("bpg"_n); // can be any proposer that's not the leader for this test
tpm.set_leader("bpa"_n);
Expand Down
8 changes: 5 additions & 3 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ FC_REFLECT(chainbase::environment, (debug)(os)(arch)(boost_version)(compiler) )
const std::string deep_mind_logger_name("deep-mind");
eosio::chain::deep_mind_handler _deep_mind_log;

const std::string hotstuff_logger_name("hotstuff");
fc::logger hotstuff_logger;

namespace eosio {

//declare operator<< and validate function for read_mode in the same namespace as read_mode itself
Expand Down Expand Up @@ -1113,9 +1116,7 @@ void chain_plugin_impl::plugin_initialize(const variables_map& options) {

void chain_plugin::create_pacemaker(std::set<chain::account_name> my_producers) {
EOS_ASSERT( !my->_chain_pacemaker, plugin_config_exception, "duplicate chain_pacemaker initialization" );
const bool info_logging = true;
const bool error_logging = true;
my->_chain_pacemaker.emplace(&chain(), std::move(my_producers), info_logging, error_logging);
my->_chain_pacemaker.emplace(&chain(), std::move(my_producers), hotstuff_logger);
}

void chain_plugin::plugin_initialize(const variables_map& options) {
Expand Down Expand Up @@ -1194,6 +1195,7 @@ void chain_plugin::plugin_shutdown() {

void chain_plugin::handle_sighup() {
_deep_mind_log.update_logger( deep_mind_logger_name );
fc::logger::update( hotstuff_logger_name, hotstuff_logger );
}

chain_apis::read_write::read_write(controller& db,
Expand Down
9 changes: 9 additions & 0 deletions programs/nodeos/logging.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@
"level": "info",
"enabled": true,
"additivity": false,
"appenders": [
"stderr",
"net"
]
},{
"name": "hotstuff",
"level": "debug",
"enabled": true,
"additivity": false,
"appenders": [
"stderr",
"net"
Expand Down

0 comments on commit aa926f0

Please sign in to comment.