From 0ccc6bb4d751de145f32d70c086b4b4799440711 Mon Sep 17 00:00:00 2001 From: yangsai Date: Sat, 28 Mar 2020 21:46:18 +0800 Subject: [PATCH] enhance delegate stability --- .../libraries/blockchain/ChainInterface.cpp | 28 +++++++++++-------- .../libraries/include/blockchain/Config.hpp | 3 ++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Chain/libraries/blockchain/ChainInterface.cpp b/src/Chain/libraries/blockchain/ChainInterface.cpp index 44121cf8..3f25af88 100644 --- a/src/Chain/libraries/blockchain/ChainInterface.cpp +++ b/src/Chain/libraries/blockchain/ChainInterface.cpp @@ -85,18 +85,24 @@ namespace thinkyoung { // just like in Bitcoin ShareType ChainInterface::get_max_delegate_pay_issued_per_block()const { + static const ShareType delegate_pay_inc[] = { 1500000, 1650000, 1815000, 1996000, 2196000, + 2415000, 2657000, 2923000, 3215000, 3536000, 4000000}; + static const uint32_t delegate_pay_inc_times = 11; + ShareType pay_per_block = ALP_MAX_DELEGATE_PAY_PER_BLOCK; - // static const time_point_sec start_timestamp = get_genesis_timestamp(); - // static const uint32_t seconds_per_period = fc::days( 4 * 365 ).to_seconds(); // Ignore leap years, leap seconds, etc. - // - // const time_point_sec now = this->now(); - // if( now >= start_timestamp ) - // { - // const uint32_t elapsed_time = (now - start_timestamp).to_seconds(); - // const uint32_t num_full_periods = elapsed_time / seconds_per_period; - // for( uint32_t i = 0; i < num_full_periods; ++i ) - // pay_per_block /= 2; - // } + uint32_t head_block_num = get_head_block_num(); + uint32_t inc_times = 0; + + //if head_block_num is ALP_DELEGATE_PAY_BLOCK_NUM, switch to new pay + if (head_block_num >= ALP_DELEGATE_PAY_BLOCK_NUM) + { + inc_times = (head_block_num - ALP_DELEGATE_PAY_BLOCK_NUM) / ALP_DELEGATE_PAY_INC_NUM; + //get the pos of delegate_pay_inc + uint32_t pos = inc_times >= delegate_pay_inc_times ? (delegate_pay_inc_times - 1):inc_times; + + //set the value + pay_per_block = delegate_pay_inc[pos]; + } return pay_per_block; } diff --git a/src/Chain/libraries/include/blockchain/Config.hpp b/src/Chain/libraries/include/blockchain/Config.hpp index ce34aa8a..ac3ad07f 100644 --- a/src/Chain/libraries/include/blockchain/Config.hpp +++ b/src/Chain/libraries/include/blockchain/Config.hpp @@ -131,3 +131,6 @@ #define ALP_BLOCKCHAIN_EXTRA_SIGNATURE_FEE 1000 #define ALP_BLOCKCHAIN_TRANSACTION_MAX_DEPOSIT_NUM 100 +//for delegate pay +#define ALP_DELEGATE_PAY_BLOCK_NUM 8524000 +#define ALP_DELEGATE_PAY_INC_NUM 3150000