Skip to content

Commit

Permalink
add account type for delegator list
Browse files Browse the repository at this point in the history
  • Loading branch information
BitHaru committed Nov 22, 2020
1 parent 28ca99c commit 72b1bfd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.4)
project (rai)

set (CPACK_PACKAGE_VERSION_MAJOR "1")
set (CPACK_PACKAGE_VERSION_MINOR "3")
set (CPACK_PACKAGE_VERSION_MINOR "4")
set (CPACK_PACKAGE_VERSION_PATCH "0")

set (TAG_VERSION_STRING "V${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
Expand Down
9 changes: 5 additions & 4 deletions rai/node/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,10 +789,11 @@ void rai::NodeRpcHandler::DelegatorList()
for (const auto& i : list)
{
rai::Ptree entry;
total_weight += i.second;
entry.put("account", i.first.StringAccount());
entry.put("weight", i.second.StringDec());
entry.put("weight_in_rai", i.second.StringBalance(rai::RAI) + " RAI");
total_weight += i.weight_;
entry.put("account", i.account_.StringAccount());
entry.put("type", rai::BlockTypeToString(i.type_));
entry.put("weight", i.weight_.StringDec());
entry.put("weight_in_rai", i.weight_.StringBalance(rai::RAI) + " RAI");
list_ptree.push_back(std::make_pair("", entry));
}
response_.put_child("list", list_ptree);
Expand Down
21 changes: 12 additions & 9 deletions rai/secure/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2015,22 +2015,23 @@ void rai::Ledger::UpdateDelegatorList(const rai::Block& block)

std::lock_guard<std::mutex> lock(delegator_list_mutex_);
UpdateDelegatorList_(block.Account(), block.Representative(),
block.Balance());
block.Balance(), block.Type());
}

std::vector<std::pair<rai::Account, rai::Amount>> rai::Ledger::GetDelegatorList(
std::vector<rai::DelegatorListEntry> rai::Ledger::GetDelegatorList(
const rai::Account& rep, uint64_t max)
{
std::multimap<rai::Amount, rai::Account, std::greater<rai::Amount>>
std::multimap<rai::Amount, rai::DelegatorListEntry,
std::greater<rai::Amount>>
delegators;
std::vector<std::pair<rai::Account, rai::Amount>> result;
std::vector<rai::DelegatorListEntry> result;
std::lock_guard<std::mutex> lock(delegator_list_mutex_);

auto i = delegator_list_.get<1>().lower_bound(rep);
auto n = delegator_list_.get<1>().upper_bound(rep);
for (; i != n; ++i)
{
delegators.insert(std::make_pair(i->weight_, i->account_));
delegators.insert(std::make_pair(i->weight_, *i));
if (delegators.size() > max)
{
delegators.erase(std::prev(delegators.end()));
Expand All @@ -2041,7 +2042,7 @@ std::vector<std::pair<rai::Account, rai::Amount>> rai::Ledger::GetDelegatorList(

for (const auto& i : delegators)
{
result.emplace_back(i.second, i.first);
result.push_back(i.second);
}
return result;
}
Expand Down Expand Up @@ -2269,7 +2270,7 @@ rai::ErrorCode rai::Ledger::InitMemoryTables_(rai::Transaction& transaction)
if (enable_delegator_list_ && block->HasRepresentative())
{
UpdateDelegatorList_(account, block->Representative(),
block->Balance());
block->Balance(), block->Type());
}

if (enable_rich_list_ && block->Type() == rai::BlockType::TX_BLOCK)
Expand Down Expand Up @@ -2307,18 +2308,20 @@ void rai::Ledger::UpdateRichList_(const rai::Account& account,

void rai::Ledger::UpdateDelegatorList_(const rai::Account& account,
const rai::Account& rep,
const rai::Amount& weight)
const rai::Amount& weight,
rai::BlockType type)
{
auto it = delegator_list_.find(account);
if (it == delegator_list_.end())
{
delegator_list_.insert({account, rep, weight});
delegator_list_.insert({account, rep, weight, type});
}
else
{
delegator_list_.modify(it, [&](rai::DelegatorListEntry& data) {
data.rep_ = rep;
data.weight_ = weight;
data.type_ = type;
});
}
}
7 changes: 4 additions & 3 deletions rai/secure/ledger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class DelegatorListEntry
rai::Account account_;
rai::Account rep_;
rai::Amount weight_;
rai::BlockType type_;
};

typedef boost::multi_index_container<
Expand Down Expand Up @@ -321,8 +322,8 @@ class Ledger
void UpdateRichList(const rai::Block&);
std::vector<rai::RichListEntry> GetRichList(uint64_t);
void UpdateDelegatorList(const rai::Block&);
std::vector<std::pair<rai::Account, rai::Amount>> GetDelegatorList(
const rai::Account&, uint64_t);
std::vector<rai::DelegatorListEntry> GetDelegatorList(const rai::Account&,
uint64_t);

rai::ErrorCode UpgradeWallet(rai::Transaction&);
rai::ErrorCode UpgradeWalletV1V2(rai::Transaction&);
Expand All @@ -339,7 +340,7 @@ class Ledger
rai::ErrorCode InitMemoryTables_(rai::Transaction&);
void UpdateRichList_(const rai::Account&, const rai::Amount&);
void UpdateDelegatorList_(const rai::Account&, const rai::Account&,
const rai::Amount&);
const rai::Amount&, rai::BlockType);

static uint32_t constexpr BLOCKS_PER_INDEX = 8;
const rai::Amount RICH_LIST_MINIMUM = rai::Amount(10 * rai::RAI);
Expand Down

0 comments on commit 72b1bfd

Please sign in to comment.