fee_schedule.cpp: Use relaxation to set fee #435

This commit is contained in:
theoreticalbts 2015-11-05 14:56:59 -05:00
parent 09855166a2
commit a96fd62d03

View file

@ -31,6 +31,8 @@ namespace fc
//template const graphene::chain::fee_schedule& smart_ref<graphene::chain::fee_schedule>::operator*() const;
}
#define MAX_FEE_STABILIZATION_ITERATION 4
namespace graphene { namespace chain {
typedef fc::smart_ref<fee_schedule> smart_fee_schedule;
@ -138,8 +140,23 @@ namespace graphene { namespace chain {
asset fee_schedule::set_fee( operation& op, const price& core_exchange_rate )const
{
auto f = calculate_fee( op, core_exchange_rate );
op.visit( set_fee_visitor( f ) );
return f;
auto f_max = f;
for( int i=0; i<MAX_FEE_STABILIZATION_ITERATION; i++ )
{
op.visit( set_fee_visitor( f_max ) );
auto f2 = calculate_fee( op, core_exchange_rate );
if( f == f2 )
break;
f_max = std::max( f_max, f2 );
f = f2;
if( i == 0 )
{
// no need for warnings on later iterations
wlog( "set_fee requires multiple iterations to stabilize with core_exchange_rate ${p} on operation ${op}",
("p", core_exchange_rate) ("op", op) );
}
}
return f_max;
}
void chain_parameters::validate()const