Commit 4a993af1 authored by Andrzej Lisak's avatar Andrzej Lisak

[ABW] effective_comment_vote_operation extended with pending payout for affected comment

value of the payout is only supplemented in AH-RocksDB plugin to only compute it when needed (HiveMind requires that value but can't compute it itself)
parent 6225b5a0
......@@ -5,8 +5,11 @@
#include <hive/chain/database.hpp>
#include <hive/chain/history_object.hpp>
#include <hive/chain/hive_objects.hpp>
#include <hive/chain/index.hpp>
#include <hive/chain/util/impacted.hpp>
#include <hive/chain/util/reward.hpp>
#include <hive/chain/util/uint256.hpp>
#include <hive/plugins/chain/chain_plugin.hpp>
......@@ -399,6 +402,74 @@ private:
std::map<account_name_type, account_history_info> _ahInfoCache;
};
struct supplement_operations_visitor
{
supplement_operations_visitor( chain::database& db ) : _db( db ) {}
typedef void result_type;
template<typename T>
void operator()( const T& op ) {}
void operator()( const effective_comment_vote_operation& op )
{
if( op.pending_payout.amount != 0 )
return; //estimated payout was already calculated
const auto* cashout = _db.find_comment_cashout( _db.get_comment( op.author, op.permlink ) );
if( cashout == nullptr && cashout->net_rshares.value <= 0 )
return; //voting can happen even after cashout; there will be no new payout though
const auto& props = _db.get_dynamic_global_properties();
const auto& hist = _db.get_feed_history();
const chain::reward_fund_object* rf = nullptr;
if( _db.has_hardfork( HIVE_HARDFORK_0_17__774 ) )
rf = &_db.get_reward_fund();
u256 total_r2 = 0;
if( _db.has_hardfork( HIVE_HARDFORK_0_17__774 ) )
total_r2 = chain::util::to256( rf->recent_claims );
else
total_r2 = chain::util::to256( props.total_reward_shares2 );
if( total_r2 > 0 )
{
asset pot;
uint128_t vshares = 0;
if( _db.has_hardfork( HIVE_HARDFORK_0_17__774 ) )
{
pot = rf->reward_balance;
vshares = chain::util::evaluate_reward_curve( cashout->net_rshares.value, rf->author_reward_curve, rf->content_constant );
}
else
{
pot = props.total_reward_fund_hive;
vshares = chain::util::evaluate_reward_curve( cashout->net_rshares.value );
}
if( !hist.current_median_history.is_null() )
pot = pot * hist.current_median_history;
u256 r2 = chain::util::to256( vshares );
r2 *= pot.amount.value;
r2 /= total_r2;
//ABW: yes, formally we should be making copy of the operation, however all things considered
//it would be a waste of time
effective_comment_vote_operation& _op = const_cast< effective_comment_vote_operation& >( op );
_op.pending_payout = asset( static_cast< uint64_t >( r2 ), pot.symbol );
}
}
chain::database& _db;
};
void supplement_operation( const operation& op, database& db )
{
supplement_operations_visitor vtor( db );
op.visit( vtor );
}
} /// anonymous
......@@ -759,7 +830,7 @@ private:
void account_history_rocksdb_plugin::impl::collectOptions(const boost::program_options::variables_map& options)
{
fc::mutable_variant_object state_opts;
fc::mutable_variant_object state_opts;
typedef std::pair< account_name_type, account_name_type > pairstring;
HIVE_LOAD_VALUE_SET(options, "account-history-rocksdb-track-account-range", _tracked_accounts, pairstring);
......@@ -1432,10 +1503,11 @@ void account_history_rocksdb_plugin::impl::importData(unsigned int blockLimit)
}
auto impacted = getImpactedAccounts( op );
if( impacted.empty() )
return true;
supplement_operation( op, _mainDb );
rocksdb_operation_object obj;
obj.trx_id = tx.id();
obj.block = blockNo;
......@@ -1489,10 +1561,11 @@ void account_history_rocksdb_plugin::impl::on_post_apply_operation(const operati
}
auto impacted = getImpactedAccounts(n.op);
if( impacted.empty() )
return; // Ignore operations not impacting any account (according to original implementation)
supplement_operation( n.op, _mainDb );
if( _reindexing )
{
rocksdb_operation_object obj;
......
......@@ -158,6 +158,8 @@ namespace hive { namespace protocol {
uint64_t weight = 0; ///< defines the score this vote receives, used by vote payout calc. 0 if a negative vote or changed votes.
int64_t rshares = 0; ///< The number of rshares this vote is responsible for
int16_t vote_percent = 0;
//potential payout of related comment at the moment of this vote
asset pending_payout = asset( 0, HBD_SYMBOL ); //supplemented by account history RocksDB plugin (needed by HiveMind)
};
struct return_vesting_delegation_operation : public virtual_operation
......
......@@ -10,6 +10,7 @@
#include <hive/chain/util/delayed_voting.hpp>
#include <hive/plugins/account_history/account_history_plugin.hpp>
#include <hive/plugins/account_history_rocksdb/account_history_rocksdb_plugin.hpp>
#include <hive/plugins/chain/chain_plugin.hpp>
#include <hive/plugins/rc/rc_plugin.hpp>
#include <hive/plugins/webserver/webserver_plugin.hpp>
......@@ -39,6 +40,9 @@ using hive::plugins::condenser_api::condenser_api_plugin;
namespace hive { namespace chain {
typedef hive::plugins::account_history::account_history_plugin ah_plugin;
//typedef hive::plugins::account_history_rocksdb::account_history_rocksdb_plugin ah_plugin;
using std::cout;
using std::cerr;
......@@ -56,14 +60,14 @@ clean_database_fixture::clean_database_fixture( uint16_t shared_file_size_in_mb
std::cout << "running test " << boost::unit_test::framework::current_test_case().p_name << std::endl;
}
appbase::app().register_plugin< hive::plugins::account_history::account_history_plugin >();
appbase::app().register_plugin< ah_plugin >();
db_plugin = &appbase::app().register_plugin< hive::plugins::debug_node::debug_node_plugin >();
appbase::app().register_plugin< hive::plugins::rc::rc_plugin >();
appbase::app().register_plugin< hive::plugins::witness::witness_plugin >();
db_plugin->logging = false;
appbase::app().initialize<
hive::plugins::account_history::account_history_plugin,
ah_plugin,
hive::plugins::debug_node::debug_node_plugin,
hive::plugins::rc::rc_plugin,
hive::plugins::witness::witness_plugin
......@@ -186,10 +190,8 @@ live_database_fixture::live_database_fixture()
_chain_dir = fc::current_path() / "test_blockchain";
FC_ASSERT( fc::exists( _chain_dir ), "Requires blockchain to test on in ./test_blockchain" );
appbase::app().register_plugin< hive::plugins::account_history::account_history_plugin >();
appbase::app().initialize<
hive::plugins::account_history::account_history_plugin
>( argc, argv );
appbase::app().register_plugin< ah_plugin >();
appbase::app().initialize< ah_plugin >( argc, argv );
db = &appbase::app().get_plugin< hive::plugins::chain::chain_plugin >().db();
BOOST_REQUIRE( db );
......@@ -1322,7 +1324,7 @@ json_rpc_database_fixture::json_rpc_database_fixture()
std::cout << "running test " << boost::unit_test::framework::current_test_case().p_name << std::endl;
}
appbase::app().register_plugin< hive::plugins::account_history::account_history_plugin >();
appbase::app().register_plugin< ah_plugin >();
db_plugin = &appbase::app().register_plugin< hive::plugins::debug_node::debug_node_plugin >();
appbase::app().register_plugin< hive::plugins::witness::witness_plugin >();
rpc_plugin = &appbase::app().register_plugin< hive::plugins::json_rpc::json_rpc_plugin >();
......@@ -1332,7 +1334,7 @@ json_rpc_database_fixture::json_rpc_database_fixture()
db_plugin->logging = false;
appbase::app().initialize<
hive::plugins::account_history::account_history_plugin,
ah_plugin,
hive::plugins::debug_node::debug_node_plugin,
hive::plugins::json_rpc::json_rpc_plugin,
hive::plugins::block_api::block_api_plugin,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment