Skip to content

Commit

Permalink
Merge pull request #6 from ECO-chain/develop
Browse files Browse the repository at this point in the history
Themis Hardfork
  • Loading branch information
bilalws authored Sep 3, 2020
2 parents 6cb1486 + b7125c6 commit 973d16d
Show file tree
Hide file tree
Showing 13 changed files with 590 additions and 444 deletions.
21 changes: 21 additions & 0 deletions ThemisHardfork.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Themis Hardfork

## Purpose
The purpose of this hardfork is to sanitize the reward system.
***
## Description

The hardfork will take effect from block 870,000

Changes:
- Coinstake will be reduced to 5 ECOC
- New max cap is 300 million ECOC
- Each epoch changes every 1 million blocks (approximately one year)
- Each epoch the coinstake will be reduced by 1 ECOC until it reaches 1 ECOC. So each epochs coinstake will be 5-4-3-2-1 ECOC
- After that point the coinstake will be stable at 1 ECOC until it reaches the cap (300 million ECOC)
- Last rewarl block is **47,870,000**. After that point the only reward for stakers will be the transaction fees.
- Multisigners are reduced to 5. The basic reason about this is to reduce the future chaindata size.
***
## Upgrade instructions

Nothing special is needed. The steps are taking backup of the wallet, download the binaries and execute the. In case of compiling from source code the process is the same as the previous versions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 1)
define(_CLIENT_VERSION_MINOR, 3)
define(_CLIENT_VERSION_MINOR, 4)
define(_CLIENT_VERSION_REVISION, 0)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
Expand Down
6 changes: 5 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ BITCOIN_CORE_H = \
zmq/zmqpublishnotifier.h \
aal/qtumstate.h \
aal/qtumtransaction.h \
aal/storageresults.h
aal/storageresults.h \
ecoc/ecoc.h


obj/build.h: FORCE
Expand Down Expand Up @@ -223,6 +224,7 @@ libbitcoin_server_a_SOURCES = \
aal/qtumtransaction.cpp \
consensus/consensus.cpp \
aal/storageresults.cpp \
ecoc/ecoc.cpp \
$(BITCOIN_CORE_H)

if ENABLE_ZMQ
Expand Down Expand Up @@ -516,6 +518,8 @@ libbitcoin_common_a_SOURCES = \
cpp-ethereum/utils/json_spirit/json_spirit_value.h \
cpp-ethereum/utils/json_spirit/json_spirit_writer.h \
cpp-ethereum/utils/json_spirit/json_spirit_writer_template.h \
ecoc/ecoc.h \
ecoc/ecoc.cpp \
$(BITCOIN_CORE_H)

#only added json_spirit so that `make dist` works properly
Expand Down
151 changes: 79 additions & 72 deletions src/chainparams.cpp

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ struct Params {
int BIP65Height;
/** Block height at which BIP66 becomes active */
int BIP66Height;
/* Themis Height hardfork*/
int ThemisHeight;
/* nLastPoWBlock + lastPoSBlock is the block height that gives the last reward (300 million coins cap reached) */
int lastPOSBlock;
/**
* Minimum blocks including miner confirmation of the total of 2016 blocks in a retargeting period,
* (nPowTargetTimespan / nPowTargetSpacing) which is also used for BIP9 deployments.
Expand All @@ -65,10 +69,12 @@ struct Params {
int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; }
uint256 nMinimumChainWork;
uint256 defaultAssumeValid;

int nLastPOWBlock;
int nFirstMPoSBlock;
int nMPoSRewardRecipients;
int nFixUTXOCacheHFHeight;
int nOriginalMPoSRewardRecipients;
int nThemisMPoSRewardRecipients;
};
} // namespace Consensus

Expand Down
106 changes: 102 additions & 4 deletions src/ecoc/ecoc.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,108 @@
// Copyright (c) 2018 The Eco Chain team
// Distributed under the GPLv3 software license, check
// https://www.gnu.org/licenses/gpl-3.0.en.html for details
// https://www.gnu.org/licenses/gpl-3.0.en.html for details

/*
#include "ecoc.h"
#include "chainparams.h"

namespace ecoc {
namespace ecoc
{
int getMultisigners(int height) {
const Consensus::Params& params = Params().GetConsensus();
const int ThemisHeight = params.ThemisHeight;

if (height < ThemisHeight + 1) {
return params.nOriginalMPoSRewardRecipients;
}

return params.nThemisMPoSRewardRecipients;
}

int getPoSReward(int height, const Consensus::Params& params)
{
const int ThemisHeight = params.ThemisHeight;
const int lastRewardBlock = lastPoWBlock + params.lastPOSBlock;
const int lastEpoch = ThemisHeight + (4 * rewardSession);
const int ThemisBlockReward = 5;

/* redundant check */
if (height > lastRewardBlock) {
return 0;
}

if (height < ThemisHeight + 1) {
return 50;
}

if (height > lastEpoch) {
return 1;
}

int rewardReduction = int((height - (ThemisHeight + 1)) / rewardSession);
return ThemisBlockReward - rewardReduction;
}

uint64_t getActualSupply(int height)
{
const Consensus::Params& params = Params().GetConsensus();
const int ThemisHeight = params.ThemisHeight;
int epochPeriod = rewardSession;
uint64_t actualSupply;

if (height <= lastPoWBlock) {
actualSupply = height * PoWReward;
}
else if (height <= ThemisHeight) {
actualSupply = lastPoWBlock * PoWReward + (height - lastPoWBlock) * 50;
}
else if (height > ThemisHeight && height <= lastPoWBlock + params.lastPOSBlock) {
actualSupply = lastPoWBlock * PoWReward + (ThemisHeight - lastPoWBlock) * 50; /* actualy supply at themis height*/
for (int epoch = 1; epoch <= 5; epoch++) {
if (epoch == 5) {
epochPeriod = lastPoWBlock + params.lastPOSBlock - ThemisHeight - 4 * epochPeriod;
}
actualSupply += std::max(0, (6 - epoch) * std::min(epochPeriod, height - ThemisHeight - (epoch - 1) * rewardSession));
}
}
else {
actualSupply = 300 * 1000 * 1000;
}

return actualSupply;
}

void ecocLog(const std::string message)
{
if (debug) {
LogPrintf("ecoc: %s\n", message);
}
}

void ecocLogNL(const std::string message)
{
if (debug) {
LogPrintf("ecoc: %s", message);
}
}

void ecocLogNL(int i)
{
if (debug) {
LogPrintf("ecoc: %d", i);
}
}

void ecocLog(int i)
{
if (debug) {
LogPrintf("ecoc: %d\n", i);
}
}

void ecocLogFun(const std::string message)
{
if (debug) {
LogPrintf("ecoc: Entering function %s\n", message);
}
}
*/
} // namespace ecoc
94 changes: 37 additions & 57 deletions src/ecoc/ecoc.h
Original file line number Diff line number Diff line change
@@ -1,66 +1,46 @@
// Copyright (c) 2018 The Eco Chain team
// Distributed under the GPLv3 software license, check
// https://www.gnu.org/licenses/gpl-3.0.en.html for details
// https://www.gnu.org/licenses/gpl-3.0.en.html for details

#ifndef ECOC_H
#define ECOC_H

#include "util.h"
//#include "libethcore/SealEngine.cpp"
#include "chainparams.h"

namespace ecoc {
const bool debug = false;
const int LastPoWBlock = 10000 ; // turning block from PoW to PoS
const int BlockTime= 32 ; // block time creation target
const int granularity = 7;
const int consensusMultisigners = 10;
const int coinbaseMaturity = (600*100)/(BlockTime); //600*100/BlockTime = 1875 ; (formula proportional to bitcoin who has 600 secs and 100 blocks maturity)
const std::string ecoUnit = "ECOC";
const int MinerSleepInSecs = 60; // delay the block creation for a minute
const int StakerPollingPeriod = 5000; //STAKER_POLLING_PERIOD in miliseconds
const int PoWReward = 20000 ; // reward of coins for each block at first phase (PoW)
const int PoSReward = 50 ; // PoS reward, doubling every epoch. After LastPoSBlock blocks reward is zero.
const int maxHalvings = 4 ;// 4 POS epochs(sessions) , doubling until cap. Variable name (maxHalvings) stays unmodified for historical reasons (tribute to bitcoin)
const int rewardSession= 2500000 ; // how many blocks for doubling the PoS reward , about two and a half years
const int LastPoSBlock = 9812500 ; // LastPoWBlock + LastPoSBlock is the block height that gives the last reward (2 billion coins cap reached)
const int blockSizeLimit = 4*1000*1000 ; // blocksize limit 4M
const int blockGasLimit= 20 * blockSizeLimit; // maximum gas per block , set it proportionally to blockSizeLimit
const int minTxGas = 40;

const std::string genesisBlockMainNet = "0000009cbd44612c6e231a74c6d5ae65dcc4a55fa728cc5aa55f0558bdcc7268";
const std::string genesisBlockTestNet = "0000005d73ef7042858df0f7fca1459d519ae0a209d68c9bf5701e61dd97fb42";
const std::string genesisBlockRegTest = "52b4ddc1be5a40a1c5cf3ad2280baa8e7a25b5e3fe02b9d229c476bd0830c8d6";
const std::string genesisMerkleRoot = "441bfed54efa3a027363d44aa74751180147bbad7e4a55f30213735b83a7d078";

inline void ecocLog(const std::string message) {
if (debug) {
LogPrintf("ecoc: %s\n", message);
}
}

inline void ecocLogNL(const std::string message) {
if (debug) {
LogPrintf("ecoc: %s", message);
}
}

inline void ecocLogNL(int i) {
if (debug) {
LogPrintf("ecoc: %d", i);
}
}

inline void ecocLog(int i) {
if (debug) {
LogPrintf("ecoc: %d\n", i);
}
}

inline void ecocLogFun(const std::string message) {
if (debug) {
LogPrintf("ecoc: Entering function %s\n", message);
}
}
}

#endif // ECOC_H
const bool debug = true;

const int lastPoWBlock = 10000; // turning block from PoW to PoS
const int blockTime = 32; // block time creation target
const int granularity = 7;
// const int consensusMultisigners = 10;
const int coinbaseMaturity = (600 * 100) / (blockTime); //600*100/blockTime = 1875 ; (formula proportional to bitcoin who has 600 secs and 100 blocks maturity)
const std::string ecoUnit = "ECOC";
const int minerSleepInSecs = 60; // delay the block creation for a minute
const int stakerPollingPeriod = 5000; // STAKER_POLLING_PERIOD in miliseconds
const int PoWReward = 20000; // reward of coins for each block at first phase (PoW)
// const int PoSReward = 50; // PoS reward, replaced with GetPosReward(height) at Themis hardfork
// const int maxHalvings = 4; // Number of doubling epochs, removes at Themis hardfork
const int rewardSession = 1 * 1000 * 1000; // how many blocks for reward reduction , about a year
const int blockSizeLimit = 4 * 1000 * 1000; // blocksize limit 4M
const int blockGasLimit = 20 * blockSizeLimit; // maximum gas per block , set it proportionally to blockSizeLimit
const int minTxGas = 40;

const std::string genesisBlockMainNet = "0000009cbd44612c6e231a74c6d5ae65dcc4a55fa728cc5aa55f0558bdcc7268";
const std::string genesisBlockTestNet = "0000005d73ef7042858df0f7fca1459d519ae0a209d68c9bf5701e61dd97fb42";
const std::string genesisBlockRegTest = "52b4ddc1be5a40a1c5cf3ad2280baa8e7a25b5e3fe02b9d229c476bd0830c8d6";
const std::string genesisMerkleRoot = "441bfed54efa3a027363d44aa74751180147bbad7e4a55f30213735b83a7d078";

void ecocLog(const std::string message);
void ecocLogNL(const std::string message);
void ecocLogNL(int i);
void ecocLog(int i);
void ecocLogFun(const std::string message);

int getPoSReward(int height, const Consensus::Params& params);
int getMultisigners(int height);
uint64_t getActualSupply(int height);
} // namespace ecoc

#endif // ECOC_H
Loading

0 comments on commit 973d16d

Please sign in to comment.