Skip to content

Commit

Permalink
Merge branch 'hf1' into 'dev'
Browse files Browse the repository at this point in the history
Hf1

See merge request blurt/blurt!49
  • Loading branch information
baabeetaa committed Jul 9, 2020
2 parents ed8e88e + cc9f2d0 commit 3403e4d
Show file tree
Hide file tree
Showing 32 changed files with 172 additions and 7 deletions.
57 changes: 57 additions & 0 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2858,6 +2858,7 @@ void database::_apply_block( const signed_block& next_block )

notify_changed_objects();


// This moves newly irreversible blocks from the fork db to the block log
// and commits irreversible state to the database. This should always be the
// last call of applying a block because it is the only thing that is not
Expand Down Expand Up @@ -2992,6 +2993,12 @@ void database::_apply_transaction(const signed_transaction& trx)
});
}


// processing simple fee system here!
process_tx_fee( trx );



notify_pre_apply_transaction( note );

//Finally process the operations
Expand All @@ -3008,6 +3015,43 @@ void database::_apply_transaction(const signed_transaction& trx)

} FC_CAPTURE_AND_RETHROW( (trx) ) }

/**
* simple fee system:
* fee = flat_fee + bandwidth_fee
*
* flat_fee: fixed fee for each operation in the tx, eg., 0.05 BLURT
* bandwidth_fee: eg., 0.01 BLURT / Kbytes
*
* fee goes to BLURT_TREASURY_ACCOUNT
*/
void database::process_tx_fee( const signed_transaction& trx ) {
try {
if (!has_hardfork(BLURT_HARDFORK_0_1)) return;

// figuring out the fee
auto operation_flat_fee = get_witness_schedule_object().median_props.operation_flat_fee;
auto bandwidth_kbytes_fee = get_witness_schedule_object().median_props.bandwidth_kbytes_fee;
int64_t flat_fee_amount = operation_flat_fee.amount.value * trx.operations.size();
auto flat_fee = asset(std::max(flat_fee_amount, int64_t(1)), BLURT_SYMBOL);

auto trx_size = fc::raw::pack_size(trx);
int64_t bw_fee_amount = (trx_size * bandwidth_kbytes_fee.amount.value)/1024;
auto bw_fee = asset(std::max(bw_fee_amount, int64_t(1)), BLURT_SYMBOL);
auto fee = flat_fee + bw_fee;

flat_set< account_name_type > required;
vector<authority> other;
trx.get_required_authorities( required, required, required, other );
for( const auto& auth : required ) {
const auto& acnt = get_account( auth );
FC_ASSERT( acnt.balance >= fee, "Account does not have sufficient funds for transaction fee.", ("balance", acnt.balance)("fee", fee) );

adjust_balance( acnt, -fee );
adjust_balance( get_account( BLURT_TREASURY_ACCOUNT ), fee );
}
} FC_CAPTURE_AND_RETHROW( (trx) )
}

void database::apply_operation(const operation& op)
{
operation_notification note = create_operation_notification( op );
Expand Down Expand Up @@ -3578,6 +3622,10 @@ void database::init_hardforks()
_hardfork_versions.times[ 0 ] = fc::time_point_sec( BLURT_GENESIS_TIME );
_hardfork_versions.versions[ 0 ] = hardfork_version( 0, 0 );

FC_ASSERT( BLURT_HARDFORK_0_1 == 1, "Invalid hardfork configuration" );
_hardfork_versions.times[ BLURT_HARDFORK_0_1 ] = fc::time_point_sec( BLURT_HARDFORK_0_1_TIME );
_hardfork_versions.versions[ BLURT_HARDFORK_0_1 ] = BLURT_HARDFORK_0_1_VERSION;

const auto& hardforks = get_hardfork_property_object();
FC_ASSERT( hardforks.last_hardfork <= BLURT_NUM_HARDFORKS, "Chain knows of more hardforks than configuration", ("hardforks.last_hardfork",hardforks.last_hardfork)("BLURT_NUM_HARDFORKS",BLURT_NUM_HARDFORKS) );
FC_ASSERT( _hardfork_versions.versions[ hardforks.last_hardfork ] <= BLURT_BLOCKCHAIN_VERSION, "Blockchain version is older than last applied hardfork" );
Expand Down Expand Up @@ -3644,6 +3692,15 @@ void database::apply_hardfork( uint32_t hardfork )

switch( hardfork )
{
case BLURT_HARDFORK_0_1:
{
modify( get< reward_fund_object, by_name >( BLURT_POST_REWARD_FUND_NAME ), [&]( reward_fund_object& rfo ) {
#ifndef IS_TEST_NET
rfo.recent_claims = BLURT_HARDFORK_0_1_RECENT_CLAIMS;
#endif
});
}
break;
default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/include/blurt/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ namespace blurt { namespace chain {
void _apply_transaction( const signed_transaction& trx );
void apply_operation( const operation& op );

void process_tx_fee( const signed_transaction& trx );

///Steps involved in applying a new block
///@{

Expand Down
12 changes: 12 additions & 0 deletions libraries/chain/include/blurt/chain/witness_objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ namespace blurt { namespace chain {
* expiring.
*/
uint32_t account_subsidy_decay = BLURT_DEFAULT_ACCOUNT_SUBSIDY_DECAY;

/**
* fixed fee for each operation in the tx, default 0.05 BLURT per operation
*/
asset operation_flat_fee = asset( 50, BLURT_SYMBOL );

/**
* bandwidth fee per KBytes (not bytes), default 0.01 BLURT per KBytes
*/
asset bandwidth_kbytes_fee = asset( 10, BLURT_SYMBOL );
};

/**
Expand Down Expand Up @@ -272,6 +282,8 @@ FC_REFLECT( blurt::chain::chain_properties,
(maximum_block_size)
(account_subsidy_budget)
(account_subsidy_decay)
(operation_flat_fee)
(bandwidth_kbytes_fee)
)

FC_REFLECT( blurt::chain::witness_object,
Expand Down
30 changes: 28 additions & 2 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ struct witness_properties_change_flags
uint32_t account_subsidy_decay_changed : 1;
uint32_t key_changed : 1;
uint32_t url_changed : 1;
uint32_t reserve_1 : 1;
uint32_t reserve_2 : 1;
uint32_t operation_flat_fee_changed : 1;
uint32_t bandwidth_kbytes_fee_changed : 1;
};

void witness_set_properties_evaluator::do_apply( const witness_set_properties_operation& o )
Expand Down Expand Up @@ -186,6 +186,24 @@ void witness_set_properties_evaluator::do_apply( const witness_set_properties_op
fc::raw::unpack_from_vector< std::string >( itr->second, url );
}

itr = o.props.find( "operation_flat_fee" );
flags.operation_flat_fee_changed = itr != o.props.end();
if( flags.operation_flat_fee_changed )
{
fc::raw::unpack_from_vector( itr->second, props.operation_flat_fee );

FC_ASSERT( props.operation_flat_fee.amount <= 100000, "operation_flat_fee too high!" );
}

itr = o.props.find( "bandwidth_kbytes_fee" );
flags.bandwidth_kbytes_fee_changed = itr != o.props.end();
if( flags.bandwidth_kbytes_fee_changed )
{
fc::raw::unpack_from_vector( itr->second, props.bandwidth_kbytes_fee );

FC_ASSERT( props.bandwidth_kbytes_fee.amount <= 100000, "bandwidth_kbytes_fee too high!" );
}

_db.modify( witness, [&]( witness_object& w )
{
if( flags.account_creation_changed )
Expand Down Expand Up @@ -217,6 +235,14 @@ void witness_set_properties_evaluator::do_apply( const witness_set_properties_op
{
from_string( w.url, url );
}

if( flags.operation_flat_fee_changed ) {
w.props.operation_flat_fee = props.operation_flat_fee;
}

if( flags.bandwidth_kbytes_fee_changed ) {
w.props.bandwidth_kbytes_fee = props.bandwidth_kbytes_fee;
}
});
}

Expand Down
18 changes: 17 additions & 1 deletion libraries/chain/witness_schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,21 @@ void update_median_witness_props( database& db )
});
uint32_t median_account_subsidy_decay = active[active.size()/2]->props.account_subsidy_decay;

// sort them by pool level
/// sort them by operation_flat_fee
std::sort( active.begin(), active.end(), [&]( const witness_object* a, const witness_object* b )
{
return a->props.operation_flat_fee.amount < b->props.operation_flat_fee.amount;
} );
asset median_operation_flat_fee = active[active.size()/2]->props.operation_flat_fee;

/// sort them by bandwidth_kbytes_fee
std::sort( active.begin(), active.end(), [&]( const witness_object* a, const witness_object* b )
{
return a->props.bandwidth_kbytes_fee.amount < b->props.bandwidth_kbytes_fee.amount;
} );
asset median_bandwidth_kbytes_fee = active[active.size()/2]->props.bandwidth_kbytes_fee;

/// sort them by pool level
std::sort( active.begin(), active.end(), [&]( const witness_object* a, const witness_object* b )
{
return a->available_witness_account_subsidies < b->available_witness_account_subsidies;
Expand Down Expand Up @@ -107,6 +121,8 @@ void update_median_witness_props( database& db )
_wso.median_props.maximum_block_size = median_maximum_block_size;
_wso.median_props.account_subsidy_budget = median_account_subsidy_budget;
_wso.median_props.account_subsidy_decay = median_account_subsidy_decay;
_wso.median_props.operation_flat_fee = median_operation_flat_fee;
_wso.median_props.bandwidth_kbytes_fee = median_bandwidth_kbytes_fee;

rd_setup_dynamics_params( account_subsidy_user_params, account_subsidy_system_params, _wso.account_subsidy_rd );
rd_setup_dynamics_params( account_subsidy_per_witness_user_params, account_subsidy_system_params, _wso.account_subsidy_witness_rd );
Expand Down
2 changes: 2 additions & 0 deletions libraries/plugins/account_history/account_history_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ void account_history_plugin::set_program_options(

void account_history_plugin::plugin_initialize( const boost::program_options::variables_map& options )
{
ilog( "Initializing account_history_plugin" );

my = std::make_unique< detail::account_history_plugin_impl >();

my->_pre_apply_operation_conn = my->_db.add_pre_apply_operation_handler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,8 @@ void account_history_rocksdb_plugin::set_program_options(

void account_history_rocksdb_plugin::plugin_initialize(const boost::program_options::variables_map& options)
{
ilog( "Initializing account_history_rocksdb_plugin" );

if(options.count("account-history-rocksdb-stop-import-at-block"))
_blockLimit = options.at("account-history-rocksdb-stop-import-at-block").as<uint32_t>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void account_by_key_api_plugin::set_program_options( options_description& cli, o

void account_by_key_api_plugin::plugin_initialize( const variables_map& options )
{
ilog( "Initializing account_by_key_api_plugin" );
api = std::make_shared< account_by_key_api >();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void account_history_api_plugin::set_program_options( options_description& cli,

void account_history_api_plugin::plugin_initialize( const variables_map& options )
{
ilog( "Initializing account_history_api_plugin" );
api = std::make_shared< account_history_api >();
}

Expand Down
1 change: 1 addition & 0 deletions libraries/plugins/apis/block_api/block_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void block_api_plugin::set_program_options(

void block_api_plugin::plugin_initialize( const variables_map& options )
{
ilog( "Initializing block_api_plugin" );
api = std::make_shared< block_api >();
}

Expand Down
1 change: 1 addition & 0 deletions libraries/plugins/apis/chain_api/chain_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void chain_api_plugin::set_program_options( options_description& cli, options_de

void chain_api_plugin::plugin_initialize( const variables_map& options )
{
ilog( "Initializing chain_api_plugin" );
api = std::make_shared< chain_api >();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void condenser_api_plugin::set_program_options( options_description& cli, option

void condenser_api_plugin::plugin_initialize( const variables_map& options )
{
ilog( "Initializing condenser_api_plugin" );
api = std::make_shared< condenser_api >();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void database_api_plugin::set_program_options(

void database_api_plugin::plugin_initialize( const variables_map& options )
{
ilog( "Initializing database_api_plugin" );
api = std::make_shared< database_api >();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void debug_node_api_plugin::set_program_options( options_description& cli, optio

void debug_node_api_plugin::plugin_initialize( const variables_map& options )
{
ilog( "Initializing debug_node_api_plugin" );
api = std::make_shared< debug_node_api >();
}

Expand Down
1 change: 1 addition & 0 deletions libraries/plugins/apis/follow_api/follow_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void follow_api_plugin::set_program_options( options_description& cli, options_d

void follow_api_plugin::plugin_initialize( const variables_map& options )
{
ilog( "Initializing follow_api_plugin" );
api = std::make_shared< follow_api >();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ void network_broadcast_api_plugin::set_program_options( options_description& cli

void network_broadcast_api_plugin::plugin_initialize( const variables_map& options )
{
ilog( "Initializing network_broadcast_api_plugin" );

api = std::make_shared< network_broadcast_api >();
FC_ASSERT( !appbase::app().get_plugin< rc::rc_plugin >().get_rc_plugin_skip_flags().skip_reject_not_enough_rc,
"rc-skip-reject-not-enough-rc=false is required to broadcast transactions" );
Expand Down
1 change: 1 addition & 0 deletions libraries/plugins/apis/rc_api/rc_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void rc_api_plugin::set_program_options( options_description& cli, options_descr

void rc_api_plugin::plugin_initialize( const variables_map& options )
{
ilog( "Initializing rc_api_plugin" );
api = std::make_shared< rc_api >();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void reputation_api_plugin::set_program_options( options_description& cli, optio

void reputation_api_plugin::plugin_initialize( const variables_map& options )
{
ilog( "Initializing reputation_api_plugin" );
api = std::make_shared< reputation_api >();
}

Expand Down
1 change: 1 addition & 0 deletions libraries/plugins/apis/rewards_api/rewards_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ void rewards_api_plugin::set_program_options( boost::program_options::options_de

void rewards_api_plugin::plugin_initialize( const boost::program_options::variables_map& options )
{
ilog( "Initializing rewards_api_plugin" );
api = std::make_unique< rewards_api >();
}

Expand Down
1 change: 1 addition & 0 deletions libraries/plugins/apis/tags_api/tags_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void tags_api_plugin::set_program_options( options_description& cli, options_des

void tags_api_plugin::plugin_initialize( const variables_map& options )
{
ilog( "Initializing tags_api_plugin" );
api = std::make_shared< tags_api >();
}

Expand Down
1 change: 1 addition & 0 deletions libraries/plugins/apis/test_api/test_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ test_api_plugin::~test_api_plugin() {}

void test_api_plugin::plugin_initialize( const variables_map& options )
{
ilog( "Initializing test_api_plugin" );
JSON_RPC_REGISTER_API( name() );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ void transaction_status_api_plugin::set_program_options( boost::program_options:

void transaction_status_api_plugin::plugin_initialize( const boost::program_options::variables_map& options )
{
ilog( "Initializing transaction_status_api_plugin" );
api = std::make_unique< transaction_status_api >();
}

Expand Down
1 change: 1 addition & 0 deletions libraries/plugins/chain/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip
}

void chain_plugin::plugin_initialize(const variables_map& options) {
ilog( "Initializing chain_plugin" );
my->shared_memory_dir = app().data_dir() / "blockchain";

if( options.count("shared-file-dir") )
Expand Down
1 change: 1 addition & 0 deletions libraries/plugins/debug_node/debug_node_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void debug_node_plugin::set_program_options(

void debug_node_plugin::plugin_initialize( const variables_map& options )
{
ilog( "Initializing debug_node_plugin" );
my = std::make_shared< detail::debug_node_plugin_impl >();

if( options.count( "debug-node-edit-script" ) > 0 )
Expand Down
1 change: 1 addition & 0 deletions libraries/plugins/json_rpc/json_rpc_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ void json_rpc_plugin::set_program_options( options_description& , options_descri

void json_rpc_plugin::plugin_initialize( const variables_map& options )
{
ilog( "Initializing json_rpc_plugin" );
my->initialize();

if( options.count( "log-json-rpc" ) )
Expand Down
1 change: 1 addition & 0 deletions libraries/plugins/p2p/p2p_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ void p2p_plugin::set_program_options( bpo::options_description& cli, bpo::option

void p2p_plugin::plugin_initialize(const boost::program_options::variables_map& options)
{
ilog( "Initializing p2p_plugin" );
my = std::make_unique< detail::p2p_plugin_impl >( appbase::app().get_plugin< plugins::chain::chain_plugin >() );

if( options.count( "p2p-endpoint" ) )
Expand Down
1 change: 1 addition & 0 deletions libraries/plugins/statsd/statsd_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ void statsd_plugin::set_program_options( options_description& cli, options_descr

void statsd_plugin::plugin_initialize( const boost::program_options::variables_map& options )
{
ilog( "Initializing statsd_plugin" );
if( options.count( "statsd-endpoint" ) )
{
auto statsd_endpoint = options.at( "statsd-endpoint" ).as< string >();
Expand Down
2 changes: 2 additions & 0 deletions libraries/plugins/webserver/webserver_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ void webserver_plugin::set_program_options( options_description&, options_descri

void webserver_plugin::plugin_initialize( const variables_map& options )
{
ilog( "Initializing webserver_plugin" );

auto thread_pool_size = options.at("webserver-thread-pool-size").as<thread_pool_size_t>();
FC_ASSERT(thread_pool_size > 0, "webserver-thread-pool-size must be greater than 0");
ilog("configured with ${tps} thread pool size", ("tps", thread_pool_size));
Expand Down
Loading

0 comments on commit 3403e4d

Please sign in to comment.