Skip to content

Commit

Permalink
Merge pull request #85 from DaoCasino/randpa-prefix-tree-logging-DPM-939
Browse files Browse the repository at this point in the history
DPM-939 more logs for prefix chain tree
  • Loading branch information
adrianopol authored Mar 2, 2021
2 parents fa33ed8 + 3442f30 commit fbe0884
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ struct chain_type {
};


class NodeNotFoundError : public std::exception {};


template <typename NodeType>
class prefix_chain_tree {
using node_ptr = std::shared_ptr<NodeType>;
Expand Down Expand Up @@ -86,6 +83,15 @@ class prefix_chain_tree {
prefix_chain_tree() = delete;
prefix_chain_tree(const prefix_chain_tree&) = delete;

block_ids_type get_blocks() const {
block_ids_type blocks;
blocks.reserve(block_index.size());
for (const auto& block : block_index) {
blocks.push_back(block.first);
}
return blocks;
}

node_ptr find(const block_id_type& block_id) const {
auto itr = block_index.find(block_id);
return itr != block_index.end() ? itr->second.lock() : nullptr;
Expand All @@ -101,8 +107,6 @@ class prefix_chain_tree {
return nullptr;
}
return _add_confirmations(node, blocks, sender_key, conf);


}

void remove_confirmations() {
Expand All @@ -114,18 +118,20 @@ class prefix_chain_tree {
}
}

void insert(const chain_type& chain,
/// Try to insert chain blocks into tree. Returns false if base_block or one of blocks exists in prefix tree.
bool insert(const chain_type& chain,
const public_key_type& creator_key,
const std::set<public_key_type>& active_bp_keys) {
node_ptr node = nullptr;
block_ids_type blocks;
std::tie(node, blocks) = get_tree_node(chain);

if (!node) {
throw NodeNotFoundError();
return false;
}

insert_blocks(node, blocks, creator_key, active_bp_keys);
return true;
}

node_ptr get_final_chain_head(size_t confirmation_number) const {
Expand Down
9 changes: 4 additions & 5 deletions plugins/randpa_plugin/include/eosio/randpa_plugin/randpa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,13 +681,12 @@ class randpa {
("bpk", event.active_bp_keys)
);

try {
_prefix_tree->insert({event.prev_block_id, {event.block_id}},
event.creator_key, event.active_bp_keys);
} catch (const NodeNotFoundError& e) {
randpa_elog("Randpa cannot insert block into tree, base_block: ${base_id}, block: ${id}",
bool ok = _prefix_tree->insert({event.prev_block_id, {event.block_id}}, event.creator_key, event.active_bp_keys);
if (!ok) {
randpa_elog("Randpa cannot insert block into tree, base_block: ${base_id}, block: ${id}, block_index: ${bi}",
("base_id", event.prev_block_id)
("id", event.block_id)
("bi", _prefix_tree->get_blocks())
);
return;
}
Expand Down
3 changes: 3 additions & 0 deletions scripts/config-product.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ PRODUCT_NAME="${PRODUCT_NAME,,}" # to lower case
# core symbol name
case "$PRODUCT_NAME" in
(*daobet*)
PRODUCT_NAME=daobet
PRODUCT_NAME_OFFICIAL="DAOBet"
CORE_SYMBOL_NAME=BET
;;
(*haya*)
PRODUCT_NAME=haya
PRODUCT_NAME_OFFICIAL="Haya"
CORE_SYMBOL_NAME=SYS
;;
esac
readonly PRODUCT_NAME PRODUCT_NAME_OFFICIAL CORE_SYMBOL_NAME

0 comments on commit fbe0884

Please sign in to comment.