Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Log2 Ancestors Module #2053

@rphmeier

Description

@rphmeier

The idea behind log2 ancestors is to keep a record of some block hashes in the history of the chain.

decl_storage! {
    Ancestors: map BlockNumber => (BlockNumber, Hash);
}
fn initialise() {
    let number = current_number() - 1;
    let parent_hash = parent_hash();

    let mut index = 0;
    let mut working_number = number;
    while index < 32 {
        Ancestors::put(index, (number, parent_hash)); // storage
        if working_number % 2 != 0 { break }
        working_number /= 2;
        index += 1;
    }

    // post-condition: Ancestors(index) stores the hash and
    // number of the last block whose number was divisible by 2^index.
}

We can use this module to safely skip backwards in the finalized chain, so long ancestry proofs become shorter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    I9-optimisationAn enhancement to provide better overall performance in terms of time-to-completion for a task.Z1-easyCan be fixed primarily by duplicating and adapting code by an intermediate coderZ6-mentorAn easy task where a mentor is available. Please indicate in the issue who the mentor could be.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions