Fabcoin Core  0.16.2
P2P Digital Currency
Functions
internal.c File Reference
#include <assert.h>
#include <inttypes.h>
#include <stddef.h>
#include <errno.h>
#include <math.h>
#include "mmap.h"
#include "ethash.h"
#include "fnv.h"
#include "endian.h"
#include "internal.h"
#include "data_sizes.h"
#include "io.h"
#include "sha3.h"
Include dependency graph for internal.c:

Go to the source code of this file.

Functions

uint64_t ethash_get_datasize (uint64_t const block_number)
 
uint64_t ethash_get_cachesize (uint64_t const block_number)
 
void ethash_calculate_dag_item (node *const ret, uint32_t node_index, ethash_light_t const light)
 
bool ethash_compute_full_data (void *mem, uint64_t full_size, ethash_light_t const light, ethash_callback_t callback)
 Compute the memory data for a full node's memory. More...
 
void ethash_quick_hash (ethash_h256_t *return_hash, ethash_h256_t const *header_hash, uint64_t const nonce, ethash_h256_t const *mix_hash)
 
ethash_h256_t ethash_get_seedhash (uint64_t block_number)
 Calculate the seedhash for a given block number. More...
 
bool ethash_quick_check_difficulty (ethash_h256_t const *header_hash, uint64_t const nonce, ethash_h256_t const *mix_hash, ethash_h256_t const *boundary)
 Difficulty quick check for POW preverification. More...
 
ethash_light_t ethash_light_new_internal (uint64_t cache_size, ethash_h256_t const *seed)
 Allocate and initialize a new ethash_light handler. More...
 
ethash_light_t ethash_light_new (uint64_t block_number)
 Allocate and initialize a new ethash_light handler. More...
 
void ethash_light_delete (ethash_light_t light)
 Frees a previously allocated ethash_light handler. More...
 
ethash_return_value_t ethash_light_compute_internal (ethash_light_t light, uint64_t full_size, ethash_h256_t const header_hash, uint64_t nonce)
 Calculate the light client data. More...
 
ethash_return_value_t ethash_light_compute (ethash_light_t light, ethash_h256_t const header_hash, uint64_t nonce)
 Calculate the light client data. More...
 
ethash_full_t ethash_full_new_internal (char const *dirname, ethash_h256_t const seed_hash, uint64_t full_size, ethash_light_t const light, ethash_callback_t callback)
 Allocate and initialize a new ethash_full handler. More...
 
ethash_full_t ethash_full_new (ethash_light_t light, ethash_callback_t callback)
 Allocate and initialize a new ethash_full handler. More...
 
void ethash_full_delete (ethash_full_t full)
 Frees a previously allocated ethash_full handler. More...
 
ethash_return_value_t ethash_full_compute (ethash_full_t full, ethash_h256_t const header_hash, uint64_t nonce)
 Calculate the full client data. More...
 
void const * ethash_full_dag (ethash_full_t full)
 Get a pointer to the full DAG data. More...
 
uint64_t ethash_full_dag_size (ethash_full_t full)
 Get the size of the DAG data. More...
 

Detailed Description

Author
Tim Hughes tim@t.nosp@m.wist.nosp@m.edfur.nosp@m.y.co.nosp@m.m
Matthew Wampler-Doty
Date
2015

Definition in file internal.c.

Function Documentation

void ethash_calculate_dag_item ( node *const  ret,
uint32_t  node_index,
ethash_light_t const  light 
)

Definition at line 125 of file internal.c.

Here is the call graph for this function:

Here is the caller graph for this function:

bool ethash_compute_full_data ( void *  mem,
uint64_t  full_size,
ethash_light_t const  light,
ethash_callback_t  callback 
)

Compute the memory data for a full node's memory.

Parameters
memA pointer to an ethash full's memory
full_sizeThe size of the full data in bytes
cacheA cache object to use in the calculation
callbackThe callback function. Check ethash_full_new() for details.
Returns
true if all went fine and false for invalid parameters

Definition at line 188 of file internal.c.

Here is the call graph for this function:

Here is the caller graph for this function:

ethash_return_value_t ethash_full_compute ( ethash_full_t  full,
ethash_h256_t const  header_hash,
uint64_t  nonce 
)

Calculate the full client data.

Parameters
fullThe full client handler
header_hashThe header hash to pack into the mix
nonceThe nonce to pack into the mix
Returns
An object of ethash_return_value to hold the return value

Definition at line 575 of file internal.c.

Here is the caller graph for this function:

void const* ethash_full_dag ( ethash_full_t  full)

Get a pointer to the full DAG data.

Definition at line 595 of file internal.c.

Here is the caller graph for this function:

uint64_t ethash_full_dag_size ( ethash_full_t  full)

Get the size of the DAG data.

Definition at line 600 of file internal.c.

Here is the caller graph for this function:

void ethash_full_delete ( ethash_full_t  full)

Frees a previously allocated ethash_full handler.

Parameters
fullThe light handler to free

Definition at line 565 of file internal.c.

Here is the caller graph for this function:

ethash_full_t ethash_full_new ( ethash_light_t  light,
ethash_callback_t  callback 
)

Allocate and initialize a new ethash_full handler.

Parameters
lightThe light handler containing the cache.
callbackA callback function with signature of ethash_callback_t It accepts an unsigned with which a progress of DAG calculation can be displayed. If all goes well the callback should return 0. If a non-zero value is returned then DAG generation will stop. Be advised. A progress value of 100 means that DAG creation is almost complete and that this function will soon return succesfully. It does not mean that the function has already had a succesfull return.
Returns
Newly allocated ethash_full handler or NULL in case of ERRNOMEM or invalid parameters used for ethash_compute_full_data()

Definition at line 554 of file internal.c.

Here is the call graph for this function:

Here is the caller graph for this function:

ethash_full_t ethash_full_new_internal ( char const *  dirname,
ethash_h256_t const  seed_hash,
uint64_t  full_size,
ethash_light_t const  light,
ethash_callback_t  callback 
)

Allocate and initialize a new ethash_full handler.

Internal version.

Parameters
dirnameThe directory in which to put the DAG file.
seedhashThe seed hash of the block. Used in the DAG file naming.
full_sizeThe size of the full data in bytes.
cacheA cache object to use that was allocated with ethash_cache_new(). Iff this function succeeds the ethash_full_t will take memory memory ownership of the cache and free it at deletion. If not then the user still has to handle freeing of the cache himself.
callbackA callback function with signature of ethash_callback_t It accepts an unsigned with which a progress of DAG calculation can be displayed. If all goes well the callback should return 0. If a non-zero value is returned then DAG generation will stop.
Returns
Newly allocated ethash_full handler or NULL in case of ERRNOMEM or invalid parameters used for ethash_compute_full_data()

Definition at line 466 of file internal.c.

Here is the call graph for this function:

Here is the caller graph for this function:

uint64_t ethash_get_cachesize ( uint64_t const  block_number)

Definition at line 82 of file internal.c.

Here is the call graph for this function:

Here is the caller graph for this function:

uint64_t ethash_get_datasize ( uint64_t const  block_number)

Definition at line 76 of file internal.c.

Here is the call graph for this function:

Here is the caller graph for this function:

ethash_h256_t ethash_get_seedhash ( uint64_t  block_number)

Calculate the seedhash for a given block number.

Definition at line 344 of file internal.c.

Here is the caller graph for this function:

ethash_return_value_t ethash_light_compute ( ethash_light_t  light,
ethash_h256_t const  header_hash,
uint64_t  nonce 
)

Calculate the light client data.

Parameters
lightThe light client handler
header_hashThe header hash to pack into the mix
nonceThe nonce to pack into the mix
Returns
an object of ethash_return_value_t holding the return values

Definition at line 432 of file internal.c.

Here is the call graph for this function:

Here is the caller graph for this function:

ethash_return_value_t ethash_light_compute_internal ( ethash_light_t  light,
uint64_t  full_size,
ethash_h256_t const  header_hash,
uint64_t  nonce 
)

Calculate the light client data.

Internal version.

Parameters
lightThe light client handler
full_sizeThe size of the full data in bytes.
header_hashThe header hash to pack into the mix
nonceThe nonce to pack into the mix
Returns
The resulting hash.

Definition at line 417 of file internal.c.

Here is the caller graph for this function:

void ethash_light_delete ( ethash_light_t  light)

Frees a previously allocated ethash_light handler.

Parameters
lightThe light handler to free

Definition at line 409 of file internal.c.

Here is the caller graph for this function:

ethash_light_t ethash_light_new ( uint64_t  block_number)

Allocate and initialize a new ethash_light handler.

Parameters
block_numberThe block number for which to create the handler
Returns
Newly allocated ethash_light handler or NULL in case of ERRNOMEM or invalid parameters used for ethash_compute_cache_nodes()

Definition at line 400 of file internal.c.

Here is the call graph for this function:

Here is the caller graph for this function:

ethash_light_t ethash_light_new_internal ( uint64_t  cache_size,
ethash_h256_t const *  seed 
)

Allocate and initialize a new ethash_light handler.

Internal version

Parameters
cache_sizeThe size of the cache in bytes
seedBlock seedhash to be used during the computation of the cache nodes
Returns
Newly allocated ethash_light handler or NULL in case of ERRNOMEM or invalid parameters used for ethash_compute_cache_nodes()

Definition at line 367 of file internal.c.

Here is the call graph for this function:

Here is the caller graph for this function:

bool ethash_quick_check_difficulty ( ethash_h256_t const *  header_hash,
uint64_t const  nonce,
ethash_h256_t const *  mix_hash,
ethash_h256_t const *  boundary 
)

Difficulty quick check for POW preverification.

Parameters
header_hashThe hash of the header
nonceThe block's nonce
mix_hashThe mix digest hash
boundaryThe boundary is defined as (2^256 / difficulty)
Returns
true for succesful pre-verification and false otherwise

Definition at line 354 of file internal.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void ethash_quick_hash ( ethash_h256_t return_hash,
ethash_h256_t const *  header_hash,
uint64_t const  nonce,
ethash_h256_t const *  mix_hash 
)

Definition at line 328 of file internal.c.

Here is the call graph for this function:

Here is the caller graph for this function: