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
calculate_block_hash(Elixium.Block) :: String.t()
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)
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
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.
diff_header(Elixium.Block, Elixium.Block) :: list()
Return a list of keys that differ between two given block headers.
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
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.
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.