Struct PreImageCycle
Combines two PreImageCache, allowing for faster lookup
struct PreImageCycle
;
Nodes generate a large amount of pre-images on startup, then will seek to
a certain position in their pre-image chain and use the values sequentially.
In order to reduce the space usage of nodes, while ensuring they don't
get random delays while seeking pre-images, this struct holds two caches.
The seeds
are sparse values spawing the whole pre-image chain, while the
preimages
are consecutive values for the current cycle.
Constructors
Name | Description |
---|---|
this
()
|
Make sure we get initialized by disabling the default ctor |
this
(secret, cycle_length, preimage_count, initial_seek)
|
Construct an instance based on a secret |
this
(from, at, cycle_length, initial_seek)
|
Construct an instance based on a pre-image at a given height |
Fields
Name | Type | Description |
---|---|---|
cycles
|
ulong | The number of cycles for a bulk of pre-images |
index
|
uint | The index of the enrollment within the current cycle |
PreImageCount
|
immutable(ulong) | The total number of pre-images |
preimages
|
PreImageCache | Currently active list of pre-images |
seeds
|
PreImageCache | Seed for all enrollments for the current cycle |
Methods
Name | Description |
---|---|
opIndex
(height)
|
Get a pre-image at the specified height. |
Example
const cycle_length = 2;
const number_of_cycles = 10;
testPreImageCycle(cycle_length, number_of_cycles);
Example
const cycle_length = 3;
const number_of_cycles = 12;
testPreImageCycle(cycle_length, number_of_cycles);
Example
Test for the getCycleSeed
function
import agora .utils .WellKnownKeys;
import std .exception;
Hash seed;
Height seed_height;
getCycleSeed(NODE5, 20, seed, seed_height);
assert(seed != Hash .init);
assert(seed_height != Height(0));
getCycleSeed(NODE5, 1008, seed, seed_height);
assert(seed != Hash .init);
assert(seed_height != Height(0));