Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PReq for #1670: Make chain_parameters::current_fees const #1678

Merged
merged 5 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace detail {
auto nathan_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan")));
dlog("Allocating all stake to ${key}", ("key", utilities::key_to_wif(nathan_key)));
graphene::chain::genesis_state_type initial_state;
initial_state.initial_parameters.current_fees = std::make_shared<fee_schedule>(fee_schedule::get_default());
initial_state.initial_parameters.get_mutable_fees() = fee_schedule::get_default();
initial_state.initial_active_witnesses = GRAPHENE_DEFAULT_MIN_WITNESS_COUNT;
initial_state.initial_timestamp = time_point_sec(time_point::now().sec_since_epoch() /
initial_state.initial_parameters.block_interval *
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/account_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ object_id_type account_create_evaluator::do_apply( const account_create_operatio
&& global_properties.parameters.account_fee_scale_bitshifts != 0 )
{
d.modify(global_properties, [](global_property_object& p) {
p.parameters.current_fees->get<account_create_operation>().basic_fee <<= p.parameters.account_fee_scale_bitshifts;
p.parameters.get_mutable_fees().get<account_create_operation>().basic_fee <<= p.parameters.account_fee_scale_bitshifts;
});
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/db_getter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const dynamic_global_property_object& database::get_dynamic_global_properties()

const fee_schedule& database::current_fee_schedule()const
{
return *get_global_properties().parameters.current_fees;
return get_global_properties().parameters.get_current_fees();
}

time_point_sec database::head_block_time()const
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/db_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ void database::init_genesis(const genesis_state_type& genesis_state)
p.parameters = genesis_state.initial_parameters;
// Set fees to zero initially, so that genesis initialization needs not pay them
// We'll fix it at the end of the function
p.parameters.current_fees->zero_all_fees();
p.parameters.get_mutable_fees().zero_all_fees();

});
_p_dyn_global_prop_obj = & create<dynamic_global_property_object>([&genesis_state](dynamic_global_property_object& p) {
Expand Down Expand Up @@ -692,7 +692,7 @@ void database::init_genesis(const genesis_state_type& genesis_state)

// Enable fees
modify(get_global_properties(), [&genesis_state](global_property_object& p) {
p.parameters.current_fees = genesis_state.initial_parameters.current_fees;
p.parameters.get_mutable_fees() = genesis_state.initial_parameters.get_current_fees();
});

// Create witness scheduler
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/db_maint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g

modify(gpo, [&dgpo](global_property_object& p) {
// Remove scaling of account registration fee
p.parameters.current_fees->get<account_create_operation>().basic_fee >>= p.parameters.account_fee_scale_bitshifts *
p.parameters.get_mutable_fees().get<account_create_operation>().basic_fee >>= p.parameters.account_fee_scale_bitshifts *
(dgpo.accounts_registered_this_interval / p.parameters.accounts_per_fee_scale);

if( p.pending_parameters )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ namespace graphene { namespace chain {
uint32_t max_preimage_size;
};

struct fee_schedule;

struct chain_parameters
{
/** using a shared_ptr breaks the circular dependency created between operations and the fee schedule */
std::shared_ptr<fee_schedule> current_fees; ///< current schedule of fees
std::shared_ptr<const fee_schedule> current_fees; ///< current schedule of fees
const fee_schedule& get_current_fees() const { FC_ASSERT(current_fees); return *current_fees; }
fee_schedule& get_mutable_fees() { FC_ASSERT(current_fees); return const_cast<fee_schedule&>(*current_fees); }

uint8_t block_interval = GRAPHENE_DEFAULT_BLOCK_INTERVAL; ///< interval in seconds between blocks
uint32_t maintenance_interval = GRAPHENE_DEFAULT_MAINTENANCE_INTERVAL; ///< interval in sections between blockchain maintenance events
uint8_t maintenance_skip_slots = GRAPHENE_DEFAULT_MAINTENANCE_SKIP_SLOTS; ///< number of block_intervals to skip at maintenance time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,5 @@ namespace graphene { namespace chain {

} } // graphene::chain

namespace fc {
template<> struct get_typename<std::shared_ptr<graphene::chain::fee_schedule>> { static const char* name() { return "shared_ptr<fee_schedule>"; } };
}

FC_REFLECT_TYPENAME( graphene::chain::fee_parameters )
FC_REFLECT( graphene::chain::fee_schedule, (parameters)(scale) )
17 changes: 17 additions & 0 deletions libraries/chain/include/graphene/chain/protocol/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ namespace graphene { namespace chain {
friend bool operator == ( const extended_private_key_type& p1, const extended_private_key_type& p2);
friend bool operator != ( const extended_private_key_type& p1, const extended_private_key_type& p2);
};

// Forward-declare fee_schedule to allow typename reflection below
struct fee_schedule;
} } // graphene::chain

namespace fc
Expand All @@ -344,7 +347,21 @@ namespace fc
void from_variant( const fc::variant& var, graphene::chain::extended_public_key_type& vo, uint32_t max_depth = 2 );
void to_variant( const graphene::chain::extended_private_key_type& var, fc::variant& vo, uint32_t max_depth = 2 );
void from_variant( const fc::variant& var, graphene::chain::extended_private_key_type& vo, uint32_t max_depth = 2 );

// Define typename reflectors for shared_ptr<fee_schedule> here, so they're available everywhere that needs them
// (Cannot be done in fee_schedule.hpp because chain_parameters.hpp forward declares fee_schedule to make a shared_ptr to one)
template<> struct get_typename<std::shared_ptr<const graphene::chain::fee_schedule>> { static const char* name() {
return "shared_ptr<const fee_schedule>";
} };
template<> struct get_typename<std::shared_ptr<graphene::chain::fee_schedule>> { static const char* name() {
return "shared_ptr<fee_schedule>";
} };
void from_variant( const fc::variant& var, std::shared_ptr<const graphene::chain::fee_schedule>& vo,
uint32_t max_depth = 2 );
}
namespace fc {
}


FC_REFLECT( graphene::chain::public_key_type, (key_data) )
FC_REFLECT( graphene::chain::public_key_type::binary_key, (data)(check) )
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/protocol/fee_schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace graphene { namespace chain {

void chain_parameters::validate()const
{
current_fees->validate();
get_current_fees().validate();
FC_ASSERT( reserve_percent_of_fee <= GRAPHENE_100_PERCENT );
FC_ASSERT( network_percent_of_fee <= GRAPHENE_100_PERCENT );
FC_ASSERT( lifetime_referrer_percent_of_fee <= GRAPHENE_100_PERCENT );
Expand Down
10 changes: 10 additions & 0 deletions libraries/chain/protocol/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
#include <graphene/chain/config.hpp>
#include <graphene/chain/protocol/types.hpp>
#include <graphene/chain/protocol/fee_schedule.hpp>

#include <fc/crypto/base58.hpp>
#include <fc/crypto/ripemd160.hpp>
Expand Down Expand Up @@ -229,4 +230,13 @@ namespace fc
{
vo = graphene::chain::extended_private_key_type( var.as_string() );
}

void from_variant( const fc::variant& var, std::shared_ptr<const graphene::chain::fee_schedule>& vo,
uint32_t max_depth ) {
// If it's null, just make a new one
if (!vo) vo = std::make_shared<const graphene::chain::fee_schedule>();
// Convert the non-const shared_ptr<const fee_schedule> to a non-const fee_schedule& so we can write it
// Don't decrement max_depth since we're not actually deserializing at this step
from_variant(var, const_cast<graphene::chain::fee_schedule&>(*vo), max_depth);
}
} // fc
4 changes: 2 additions & 2 deletions libraries/egenesis/embed_genesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void load_genesis(
}

int main( int argc, char** argv )
{
{ try {
int main_return = 0;
boost::program_options::options_description cli_options("Graphene Chain Identifier");
cli_options.add_options()
Expand Down Expand Up @@ -285,4 +285,4 @@ int main( int argc, char** argv )
}

return main_return;
}
} FC_LOG_AND_RETHROW() }
3 changes: 3 additions & 0 deletions libraries/net/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
#include <graphene/net/exceptions.hpp>

#include <graphene/chain/config.hpp>
// Nasty hack: A circular dependency around fee_schedule is resolved by fwd-declaring it and using a shared_ptr
// to it in chain_parameters, which is used in an operation and thus must be serialized by the net library.
// Resolving that forward declaration doesn't happen until now:
#include <graphene/chain/protocol/fee_schedule.hpp>

#include <fc/git_revision.hpp>
Expand Down
Loading