[−][src]Module grin_core::consensus
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
HeaderInfo |
Minimal header information required for the Difficulty calculation to take place |
Enums
Error |
Consensus errors |
Constants
BASE_EDGE_BITS |
Original reference edge_bits to compute difficulty factors for higher Cuckoo graph sizes, changing this would hard fork |
BLOCK_INPUT_WEIGHT |
Weight of an input when counted against the max block weight capacity |
BLOCK_KERNEL_WEIGHT |
Weight of a kernel when counted against the max block weight capacity |
BLOCK_OUTPUT_WEIGHT |
Weight of an output when counted against the max block weight capacity |
BLOCK_TIME_SEC |
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). |
BLOCK_TIME_WINDOW |
Average time span of the difficulty adjustment window |
CLAMP_FACTOR |
Clamp factor to use for difficulty adjustment Limit value to within this factor of goal |
COINBASE_MATURITY |
Number of blocks before a coinbase matures and can be spent |
CUT_THROUGH_HORIZON |
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. |
DAMP_FACTOR |
Dampening factor to use for difficulty adjustment |
DAY_HEIGHT |
A day is 1440 blocks |
DEFAULT_MIN_EDGE_BITS |
Default Cuckoo Cycle edge_bits, used for mining and validating. |
DIFFICULTY_ADJUST_WINDOW |
Number of blocks used to calculate difficulty adjustments |
GRIN_BASE |
A grin is divisible to 10^9, following the SI prefixes |
HARD_FORK_INTERVAL |
Fork every 6 months. |
HOUR_HEIGHT |
Nominal height for standard time intervals, hour is 60 blocks |
INITIAL_DIFFICULTY |
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) FOR MAINNET, use pub const INITIAL_DIFFICULTY: u64 = 1_000_000 * MIN_DIFFICULTY; Pick MUCH more modest value for TESTNET4: |
MAX_BLOCK_WEIGHT |
Total maximum block weight. At current sizes, this means a maximum theoretical size of: |
MAX_SECONDARY_SCALING |
Maximum scaling factor for secondary pow, enforced in diff retargetting increasing scaling factor increases frequency of secondary blocks ONLY IN TESTNET4 LIMITED TO ABOUT 8 TIMES THE NATURAL SCALE |
MICRO_GRIN |
Microgrin, a thousand of a milligrin |
MILLI_GRIN |
Milligrin, a thousand of a grin |
MIN_DIFFICULTY |
minimum possible difficulty equal to graph_weight(SECOND_POW_EDGE_BITS) |
NANO_GRIN |
Nanogrin, smallest unit, takes a billion to make a grin |
PROOFSIZE |
Cuckoo-cycle proof size (cycle length) |
REWARD |
The block subsidy amount, one grin per second on average |
SECOND_POW_EDGE_BITS |
Secondary proof-of-work edge_bits, meant to be ASIC resistant. |
WEEK_HEIGHT |
A week is 10_080 blocks |
YEAR_HEIGHT |
A year is 524_160 blocks |
Traits
VerifySortOrder |
Consensus rule that collections of items are sorted lexicographically. |
Functions
clamp |
TODO: Doc |
damp |
TODO: Doc |
graph_weight |
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 |
next_difficulty |
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). |
reward |
Actual block reward for a given total fee amount |
secondary_pow_ratio |
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. |
secondary_pow_scaling |
Factor by which the secondary proof of work difficulty will be adjusted |
valid_header_version |
Check whether the block version is valid at a given height, implements 6 months interval scheduled hard forks for the first 2 years. |