Code Monkey home page Code Monkey logo

Comments (8)

joelreymont avatar joelreymont commented on May 19, 2024

Let's make sure we can mine in parallel with everything else.

from aeternity.

akorosmezey avatar akorosmezey commented on May 19, 2024

I am extracting code from the the main miner in the Cuckoo Cycle code of John Tomp (https://github.com/tromp/cuckoo) and build an Erlang interface using NIFs.

from aeternity.

akorosmezey avatar akorosmezey commented on May 19, 2024

Cuckoo Cycle takes a string (which can be the hash of the block) and a nonce and creates a pair of siphash keys. These, together with the nonce, are used to create paths. The algorithm looks for 42-long cycles in these paths.

An attempt with a specific nonce value takes roughly 6 seconds on my laptop and it succeeds with a 2.2% chance. It results in an array of 42 integers representing the cycle found. Tromp suggested adding a difficulty by calculating the SHA265 hash of the solution and discarding the solution unless the hash is below the difficulty, just like with SHA256 PoW. (N. B. the success rate can be tuned by changing the node/edge ratio (1/2 in the suggested implementation) but this is nonlinear).

There are two methods verifying a solution:

  • We can redo the calculation from the block hash and nonce. This takes about 6 seconds as it includes re-generating the original solution.
  • Using the actual solution (array of 42 numbers) we can verify the solution by simple checking if it forms a cycle, this takes only 50-100 microseconds on my laptop. Though this is much faster, it requires storing the solution for aiding later verification.

from aeternity.

joelreymont avatar joelreymont commented on May 19, 2024

Do you mean storing the solution in the block header, together with the hash and nonce? @sennui

from aeternity.

sennui avatar sennui commented on May 19, 2024

I think, that storing the solution was one of the ideas behind democratizing miners and giving a slack to cheap mobile phones. (Jumping 42 pointers is way cheaper even than computing sha256)

@wagerlabs Yes, I would add it to the block and respectively include it in a header.
It would be an equivalent of current solution for, say, bitcoin: hash is a solution and its public.

If we want to make it fixed 42 numbers, we can drive the difficulty in a way mentioned by @akorosmezey (or we can assume from the very beginning that the length of the array can grow, which is fine too)

from aeternity.

joelreymont avatar joelreymont commented on May 19, 2024

from aeternity.

akorosmezey avatar akorosmezey commented on May 19, 2024

@sennui raised the question where the output of printf calls in the NIF goes. Unfortunately it goes to the console. I can remove most of them (the ones from my code) but there are still others from the original code. In order to remove them I need to fork the repo or just include the sources.

(A simple solution would be to redirect stdout to /dev/null for the duration of the call but this may affect other processes running parallel and in case of a crash we do not have the chance of undo the redirection.)

from aeternity.

akorosmezey avatar akorosmezey commented on May 19, 2024

PR #84 created that adds a call with default values to the API. @wagerlabs supported this idea.

from aeternity.

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.