Giter VIP home page Giter VIP logo

nanochain's Introduction

Nanochain

A minimal viable blockchain to demonstrate simple blockchain principles.

Project goals:

  • Well-documented.
  • Low-line count.
  • Low-dependencies.
  • Using classic proof-of-work.
  • Basic P2P using UDP chatter.
  • Supports chain reconfiguration.
  • No encryption or accounts.
  • In-memory.

Enabling Multicast

Nanochain uses a UDP multicast gossip protocol for P2P networking. Before running the program, make sure your localhost network interface has multicast enabled. The simplest way to do this on Unix-like systems is:

$ sudo ifconfig lo multicast

Otherwise, the program with fail with addMembership: failed (Unknown error -1) error from the Multicast module when attempting to add the node to the multicast group.

Usually, lo is the name of the local loopback (localhost) network interface on modern Linux machines, but could differ depending on your machine and/or OS. To check what your localhost network interface is, type ifconfig; The interface prefixed by lo, e.g. lo0 is usually the interface of interest. Simply replace lo with the name of your localhost network interface in the command above.

Running the Demo

Install the Stack build system:

$ stack setup
$ stack build
$ stack exec nanochain

Ports 3000, 3001, and 3002 are opened for the initial nodes. In the browser go to:

localhost:3000/blocks

To mine blocks query:

localhost:3001/mineBlock

To see the current chain query:

localhost:3000/blocks

To add a new peer, use the addPeer endpoint followed by any open port:

localhost:3000/addPeer/3003

to add localhost:3003 as a peer.

Consensus (Proof Of Work)

Nanochain uses a simple proof of work (PoW) approach to chain concensus: To mine a block on the chain, a node must compute a nonce such that that resulting hash of the block being mined begins with a number of 0's equal to round(ln(n)) where n is the length of the current chain. For this PoW implementation the average nonce computed is 16^n, so when the length of the chain surpasses 12 (round(ln(n)) == 4) it begins to take several seconds to mine each block. As n surpasses 23, mining a block could take well over 10 minutes.

License

Copyright 2017 Adjoint Inc

Released under Apache 2.0.

nanochain's People

Contributors

sdiehl avatar

Watchers

libby kent avatar James Cloos avatar

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.