Module stack_test_epic_core::consensus
source · [−]Expand description
All the rules required for a cryptocurrency to have reach consensus across the whole network are complex and hard to completely isolate. Some can be simple parameters (like block reward), others complex algorithms (like Merkle sum trees or reorg rules). However, as long as they’re simple enough, consensus-relevant constants and short functions should be kept here.
Structs
Minimal header information required for the Difficulty calculation to take place
Constants
Dampening factor to use for AR scale calculation.
Set the height (and its multiples) where the foundation coinbase will be added to the block. Used in automated tests.
Original reference edge_bits to compute difficulty factors for higher Cuckoo graph sizes, changing this would hard fork
Block Reward that will be assigned after we change from era 5 to era 6.
Progpow Minimum difficulty (used for saturation)
RandomX Minimum difficulty (used for saturation)
Height of the first epic block emission era (1440*334) = 480.960
Height of the second epic block emission era (480960 + (1440*470)) = 1.157.760
Height of the third epic block emission era (1157760 + (1440*601)) = 2.023.200
Height of the fourth epic block emission era
Height of the fifth epic block emission era
After the epic block emission era 6, each era will last 4 years (approximately 1460 days)
Weight of an input when counted against the max block weight capacity
Weight of a kernel when counted against the max block weight capacity
Weight of an output when counted against the max block weight capacity
Block interval, in seconds, the network will tune its next_target for. Note that we may reduce this value in the future as we get more data on mining with Cuckoo Cycle, networks improve and block propagation is optimized (adjusting the reward accordingly).
Average time span of the difficulty adjustment window
Clamp factor to use for difficulty adjustment Limit value to within this factor of goal
Number of blocks before a coinbase matures and can be spent
Default number of blocks in the past when cross-block cut-through will start happening. Needs to be long enough to not overlap with a long reorg. Rational behind the value is the longest bitcoin fork was about 30 blocks, so 5h. We add an order of magnitude to be safe and round to 7x24h of blocks to make it easier to reason about.
A day is 1440 blocks
Default Cuckatoo Cycle edge_bits, used for mining and validating.
Number of blocks used to calculate difficulty adjustments
Dampening factor to use for difficulty adjustment
A epic is divisible to 10^8 like bitcoin
Floonet: Height of the first epic block emission era
defines the block height at wich the difficulty adjustment era changes for floonet
Floonet first hard fork height
Set the height (and its multiples) where the foundation coinbase will be added to the block. Used in the Floonet.
Duration in height of the first foundation levy era NOTE_L: Adjust this before the official launch
After the first foundation levy era, we decrease the foundation levy each year
The foundation levy in each era
Freeman, smallest unit, takes a hundred million to make a epic
Nominal height for standard time intervals, hour is 60 blocks
The initial difficulty at launch. This should be over-estimated and difficulty should come down at launch rather than up Currently grossly over-estimated at 10% of current ethereum GPUs (assuming 1GPU can solve a block at diff 1 in one block interval)
defines the block height at wich the difficulty adjustment era changes
Mainnet first hard fork height Doubled from the previous hard coded value 1300000 We might need to change this later for final release
Set the height (and its multiples) where the foundation coinbase will be added to the block. This variable will sparse the blocks that receive the foundation coinbase.
Total maximum block weight. At current sizes, this means a maximum theoretical size of:
Microepic, a thousand of a milliepic
Milliepic, a thousand of a epic
Minimum scaling factor for AR pow, enforced in diff retargetting avoids getting stuck when trying to increase ar_scale subject to dampening
Minimum difficulty, enforced in diff retargetting avoids getting stuck when trying to increase difficulty subject to dampening
Progpow Minimum difficulty (used for saturation)
RandomX Minimum difficulty (used for saturation)
Progpow Minimum difficulty until fork (used for saturation)
RandomX Minimum difficulty until fork (used for saturation)
Clamp factor to use for difficulty adjustment Limit value to within this factor of goal
Dampening factor to use for difficulty adjustment
Cuckoo-cycle proof size (cycle length)
Clamp factor to use for difficulty adjustment Limit value to within this factor of goal
Dampening factor to use for difficulty adjustment
Cuckaroo proof-of-work edge_bits, meant to be ASIC resistant.
Default number of blocks in the past to determine the height where we request a txhashset (and full blocks from). Needs to be long enough to not overlap with a long reorg. Rational behind the value is the longest bitcoin fork was about 30 blocks, so 5h. We add an order of magnitude to be safe and round to 2x24h of blocks to make it easier to reason about.
defines the block height at wich the difficulty adjustment era changes for testing
AutomatedTesting and UserTesting first hard fork height.
unit difficulty, equal to graph_weight(SECOND_POW_EDGE_BITS)
A week is 10_080 blocks
A year is 524_160 blocks
Functions
Check if the current height is a foundation height, if it’s, the function returns the cumulative foundation reward value for one DAY_HEIGHT. Otherwise, the function returns 0.
Count, in units of 1/100 (a percent), the number of “secondary” (AR) blocks in the provided window of blocks.
Compute the total reward generated by each block in a given height.
limit value to be within some factor from a goal
Sum all the foundation reward, to send one
Move value linearly toward a goal
Get the height where the difficulty patch will be added.
Get the height of the first epic hard fork
Floonet: Compute the total reward generated by each block in a given height.
Get the height where the foundation coinbase will be added to the block.
Get the current position of the foundation coinbase in the file foundation.json
based on the block’s height
Compute weight of a graph as number of siphash bits defining the graph Must be made dependent on height to phase out smaller size over the years This can wait until end of 2019 at latest
Compute possible block version at a given height
Check if the given height is a foundation height. A foundation height is a height where we add the foundation levy. To be a foundation height the height has to be multiple of the foundation height and we have to have a foundation levy (following the schedule) different from zero for that height.
Mainnet: Compute the total reward generated by each block in a given height.
Computes the proof-of-work difficulty that the next block should comply with. Takes an iterator over past block headers information, from latest (highest height) to oldest (lowest height).
changes the header info with new difficulty era1 for the block to mine
calculates the next difficulty level for progpow and randomx
Get the total mining reward (with fee) based on the height
Get the mining reward at current height
Get the current value of the mining reward + foundation levy for a given height
Compute the foundation levy for each block.
Ratio the secondary proof of work should take over the primary, as a function of block height (time). Starts at 90% losing a percent approximately every week. Represented as an integer between 0 and 100.
Factor by which the secondary proof of work difficulty will be adjusted
returns the median timestamp from last 6 mined blocks
The total overage at a given height. Variable due to changing rewards TODOBG: Make this more efficient by hardcoding reward schedule times
Check whether the block version is valid at a given height, implements 6 months interval scheduled hard forks for the first 2 years.