Giter Site home page Giter Site logo

Comments (4)

davecgh avatar davecgh commented on May 27, 2024

I would guess that there probably isn't a way. I know that the upstream project upon which this one is based doesn't have a way to generate one because there are already existing Bitcoin tools for it.

However, given this is a new currency and there are no tools for it, I agree that it would be a good idea to have a tool to generate the linear, no-fork version of the block chain the addblock utility requires.

from dcrd.

jcvernaleo avatar jcvernaleo commented on May 27, 2024

@jpbriquet what I would probably do in your case is start the node, let it sync, stop the node, drop any blocks later than what you want to be at with https://github.com/decred/dcrd/tree/master/cmd/dropafter and then restart with no peers (--connect=localhost or something like that),

I also agree that a tool to generate a bootstrap.dat like file (up to a specified block) would be nice. showblock might be a good starting point for such a thing.

from dcrd.

jpbriquet avatar jpbriquet commented on May 27, 2024

Thanks @davecgh @jcvernaleo for your answers

I agree too that a new tool to dump to bootstrap.dat file would be good, and I understand that it was not needed with btcd, as it was already provided by the Bitcoin project.

At the moment, I think that I will keep a reference node synchronised. This node will be periodically stop while its database files are saved as blockchain database snapshot.
I will push this database to new nodes in their data directory when they are started, and I hope that it will prevent the full synchronisation. (I've not tried this principle yet).

In my spare time, I may take a look about the tool.
As I'm not yet familiar with the dcrd codebase, in addition of showblock is there other related things or places where I should dig?

from dcrd.

davecgh avatar davecgh commented on May 27, 2024

So, you would start by using addblock as a skeleton for the new app linearize in order to get the standard config pieces and database setup.

Once that is in place, essentially you would just need to loop through all of the blocks in order and dump them out using the correct serialization format.

I just took a look and the readBlock function in addblock to see the serialization format for the boostrap.data file and it has the following comment:

    // The block file format is:
    //  <network> <block length> <serialized block>

So, putting it all together, you would basically just need a nicer version of the following:

    // You'd probably actually need to take the height as a parameter
    // and error check it here since bootstrap.dat usually coincides with
    // checkpoints.
    _, bestHeight, err := db.NewestSha()
    if err != nil {
        log.Errorf("Failed to retrieve latest hash: %v", err)
        return err
    }

    for i := int32(0); i < bestHeight; i++ {
        // Get the block hash for the current height.
        blockHash, err := db.FetchBlockShaByHeight(i)
        if err != nil {
            // log it...
            return err
        }

        // Load the block for the current height.
        block, err := db.FetchBlockBySha(blockHash)
        if err != nil {
            // log it...
            return err
        }

        // Serialize the block.
        serializedBlock, err := block.Bytes()
        if err != nil {
            // log it...
            return err
        }

        // Write out the serialized block to the file with the expected
        // header format.
        err = binary.Write(fi, binary.LittleEndian, uint32(activeNetParams.Net))
        if err != nil {
            // log it...
            return err
        }
        err = binary.Write(fi, binary.LittleEndian, uint32(len(serializedBlock)))
        if err != nil {
            // log it...
            return err
        }
        _, err = fi.Write(serializedBlock)
        if err != nil {
            // log it...
            return err
        }
    }

from dcrd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.