Elixium Core v0.6.3 Elixium.Block View Source

Provides functions for creating blocks and mining new ones

Link to this section Summary

Functions

Calculates the block reward for a given block index, following our weighted smooth emission algorithm

Calculates the difficulty for a block using the WWHM difficulty algorithm described at https://getmasari.org/research-papers/wwhm.pdf

The target is a number based off of the block difficulty. The higher the block difficulty, the lower the target. When a block is being mined, the goal is to find a hash that is lower in numerical value than the target. The maximum target (when the difficulty is 0) is 115792089237316195423570985008687907853269984665640564039457584007913129639935, which means any hash is valid

Return a list of keys that differ between two given block headers

Because the hash is a Base16 string, and not an integer, we must first convert the hash to an integer, and afterwards compare it to the target

Retrieves a block header from a given block

When the first node on the Elixium network spins up, there won’t be any blocks in the chain. In order to create a base from which all nodes can agree, we create a block called a genesis block. This block has the data structure that a block would have, but has hard-coded values. This block never needs to be verified by nodes, as it doesn’t contain any actual data. The block mined after the genesis block must reference the hash of the genesis block as its previous_hash to be valid

Takes the previous block as an argument (This is the way we create every block except the genesis block)

The process of mining consists of hashing the index of the block, the hash of the previous block (thus linking the current and previous block), the timestamp at which the block was generated, the merkle root of the transactions within the block, and a random nonce. We then check to see whether the number represented by the hash is lower than the mining difficulty. If the value of the hash is lower, it is a valid block, and we can broadcast the block to other nodes on the network

Takes in a block received from a peer which may have malicious or extra attributes attached. Removes all extra parameters which are not defined explicitly by the block struct

Link to this section Functions

Link to this function calculate_block_hash(block) View Source
calculate_block_hash(Elixium.Block) :: String.t()
Link to this function calculate_block_reward(block_index) View Source
calculate_block_reward(number()) :: integer()

Calculates the block reward for a given block index, following our weighted smooth emission algorithm.

Where x is total token supply, t is block at full emission, i is block index, and s is the sigma of the total_token_supply, the Smooth emission algorithm is as follows: Round(((x 10,000,000) max{0, t - i}) / s) (+1 if i % 172 = 0)

Link to this function calculate_difficulty(block) View Source
calculate_difficulty(Elixium.Block) :: number()

Calculates the difficulty for a block using the WWHM difficulty algorithm described at https://getmasari.org/research-papers/wwhm.pdf

Link to this function calculate_difficulty(block, blocks_to_weight) View Source
Link to this function calculate_target(difficulty) View Source
calculate_target(float()) :: number()

The target is a number based off of the block difficulty. The higher the block difficulty, the lower the target. When a block is being mined, the goal is to find a hash that is lower in numerical value than the target. The maximum target (when the difficulty is 0) is 115792089237316195423570985008687907853269984665640564039457584007913129639935, which means any hash is valid.

Link to this function diff_header(block1, block2) View Source
diff_header(Elixium.Block, Elixium.Block) :: list()

Return a list of keys that differ between two given block headers.

Link to this function hash_beat_target?(map) View Source
hash_beat_target?(Elixium.Block) :: boolean()

Because the hash is a Base16 string, and not an integer, we must first convert the hash to an integer, and afterwards compare it to the target

Link to this function header(block) View Source
header(Elixium.Block) :: map()

Retrieves a block header from a given block

Link to this function initialize() View Source
initialize() :: Elixium.Block

When the first node on the Elixium network spins up, there won’t be any blocks in the chain. In order to create a base from which all nodes can agree, we create a block called a genesis block. This block has the data structure that a block would have, but has hard-coded values. This block never needs to be verified by nodes, as it doesn’t contain any actual data. The block mined after the genesis block must reference the hash of the genesis block as its previous_hash to be valid

Link to this function initialize(map) View Source
initialize(Elixium.Block) :: Elixium.Block

Takes the previous block as an argument (This is the way we create every block except the genesis block)

Link to this function mine(block, nonce_range \\ 0..18446744073709551615, cpu_num \\ 0, hashes \\ 0, last_hashrate_check \\ time_unix()) View Source
mine(Elixium.Block, Range.t(), number(), number(), number()) ::
  Elixium.Block | :not_in_range

The process of mining consists of hashing the index of the block, the hash of the previous block (thus linking the current and previous block), the timestamp at which the block was generated, the merkle root of the transactions within the block, and a random nonce. We then check to see whether the number represented by the hash is lower than the mining difficulty. If the value of the hash is lower, it is a valid block, and we can broadcast the block to other nodes on the network.

Link to this function sanitize(unsanitized_block) View Source
sanitize(Elixium.Block) :: Elixium.Block

Takes in a block received from a peer which may have malicious or extra attributes attached. Removes all extra parameters which are not defined explicitly by the block struct.

Link to this function total_block_fees(transactions) View Source
total_block_fees(list()) :: integer()
Link to this function weight_solvetimes_and_sum_difficulties(blocks) View Source