go-spacemesh

command module
v0.1.19-ntpfix Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2020 License: MIT Imports: 4 Imported by: 0

README

Spacemesh logo  

A Programmable Cryptocurrency

Go Report Card Bors enabled CI

Browse Gitcoin Bounties

go-spacemesh

💾⏰💪 Thanks for your interest in this open source project. This repo is the go implementation of the Spacemesh p2p full node software.

Spacemesh is a decentralized blockchain computer using a new race-free consensus protocol that doesn't involve energy-wasteful proof of work.

We aim to create a secure and scalable decentralized computer formed by a large number of desktop PCs at home.

We are designing and coding a modern blockchain platform from the ground up for scale, security and speed based on the learnings of the achievements and mistakes of previous projects in this space.

To learn more about Spacemesh head over to https://spacemesh.io.

To learn more about the Spacemesh protocol watch this video.

Motivation

Spacemesh is designed to create a decentralized blockchain smart contracts computer and a cryptocurrency that is formed by connecting the home PCs of people from around the world into one virtual computer without incurring massive energy waste and mining pools issues that are inherent in other blockchain computers, and provide a provably-secure and incentive-compatible smart contracts execution environment.

Spacemesh is designed to be ASIC-resistant and in a way that doesn’t give an unfair advantage to rich parties who can afford setting up dedicated computers on the network. We achieve this by using a novel consensus protocol and optimize the software to be most effectively be used on home PCs that are also used for interactive apps.

What is this good for?

Provide dapp and app developers with a robust way to add value exchange and other value related features to their apps at scale. Our goal is to create a truly decentralized cryptocurrency that fulfills the original vision behind bitcoin to become a secure trustless store of value as well as a transactional currency with extremely low transaction fees.

Target Users

go-spacemesh is designed to be installed and operated on users' home PCs to form one decentralized computer. It is going to be distributed in the Spacemesh App but people can also build and run it from source code.

Project Status

We are working hard towards our first major milestone - a public permissionless testnet running the Spacemesh consensus protocol.

Contributing

Thank you for considering to contribute to the go-spacemesh open source project!

We welcome contributions large and small and we actively accept contributions.

Diggin' Deeper

Please read the Spacemesh full FAQ.

go-spacemesh Architecture

High Level Design

Client Software Architecture

Getting

git clone git@github.com:spacemeshos/go-spacemesh.git

-- or --

Fork the project from https://github.com/spacemeshos/go-spacemesh

Since the project uses Go Modules it is best to place the code outside your $GOPATH. Read this for alternatives.

Setting Up Local Dev Environment

Building is supported on OS X, Linux, FreeBSD, and Windows.

Install Go 1.14 or later for your platform, if you haven't already.

On Windows you need to install make via msys2, MingGW-w64 or [mingw] (https://chocolatey.org/packages/mingw)

Ensure that $GOPATH is set correctly and that the $GOPATH/bin directory appears in $PATH.

Before building we need to set up the golang environment. Do this by running:

make install

This will invoke setup_env.sh which supports Linux and MacOS. On other platforms it should be straightforward to follow the steps in this script manually.

Building

To build go-spacemesh for your current system architecture, from the project root directory, use:

make build

(On FreeBSD, you should instead use gmake build. You can install gmake with pkg install gmake if it isn't already installed.)

This will build the go-spacemesh binary, saving it in the build/ directory.

To build a binary for a specific architecture directory use:

make darwin | linux | freebsd | windows

Platform-specific binaries are saved to the /build directory.


Running

go-spacemesh is p2p software which is designed to form a decentralized network by connecting to other instances of go-spacemesh running on remote computers.

To run go-spacemesh you need to specify the parameters shared between all instances on a specific network.

You specify these parameters by providing go-spacemesh with a json config file. Other CLI flags control local node behavior and override default values.

Joining a Testnet (without mining)
  1. Build go-spacemesh from source code.
  2. Download the testnet's json config file. Make sure your local config file suffix is .json.
  3. Start go-spacemesh with the following arguments:
./go-spacemesh --tcp-port [a_port] --config [configFileLocation] -d [nodeDataFilesPath]
Example

Assuming tn1.json is a testnet config file saved in the same directory as go-spacemesh, use the following command to join the testnet. The data folder will be created in the same directory as go-spacemesh. The node will use TCP port 7152 and UDP port 7152 for p2p connections:

./go-spacemesh --tcp-port 7152 --config ./tn1.json -d ./sm_data
  1. Build the CLI Wallet from source code and run it:

  2. Use the CLI Wallet commands to setup accounts, start smeshing and execute transactions.

./cli_wallet
Joining a Testnet (with mining)
  1. Run go-spacemesh to join a testnet without mining (see above).
  2. Run the CLI Wallet to create a coinbase account. Save your coinbase account public address - you'll need it later.
  3. Stop go-spacemesh and start it with the following params:
./go-spacemesh --tcp-port [a_port] --config [configFileLocation] -d [nodeDataFilesPath] --coinbase [coinbase_account] --start-mining --post-datadir [dir_for_post_data]
Example
./go-spacemesh --tcp-port 7152 --config ./tn1.json -d ./sm_data --coinbase 0x36168c60e06abbb4f5df6d1dd6a1b15655d71e75 --start-mining --post-datadir ./post_data
  1. Use the CLI wallet to check your coinbase account balance and to transact
Joining Spacemesh (TweedleDee) Testnet (net id 118)
  1. Build go-spacemesh source code from this github release: go-spacemesh 0.1.14.
  2. Follow the instructions on how to join a testnet with mining (above) and use TweedleDee net id 118 config file as your node's config file.

Testing

NOTE: if tests are hanging try running ulimit -n 400. some tests require that to work.

make test

or

make cover

Continuous Integration

We've enabled continuous integration on this repository in GitHub. You can read more about our CI workflows.

Docker

A Dockerfile is included in the project allowing anyone to build and run a docker image:

docker build -t spacemesh .
docker run -d --name=spacemesh spacemesh

Windows

On Windows you will need the following prerequisites:

  • Powershell - included by in Windows by default since Windows 7 and Windows Server 2008 R2
  • Git for Windows - after installation remove C:\Program Files\Git\bin from System PATH (if present) and add C:\Program Files\Git\cmd to System PATH (if not already present)
  • Make - after installation add C:\Program Files (x86)\GnuWin32\bin to System PATH
  • Golang
  • GCC. There are several ways to install gcc on Windows, including Cygwin. Instead, we recommend tdm-gcc which we've tested.

Close and reopen powershell to load the new PATH. You can then run the command make install followed by make build as on UNIX-based systems.

Running a Local Testnet

  • You can run a local Spacemesh Testnet with 6 full nodes, 6 user accounts, and 1 POET support service on your computer using docker.
  • The local testnet full nodes are built from this repo.
  • This is a great way to get a feel for the protocol and the platform and to start hacking on Spacemesh.
  • Follow the steps in our Local Testnet Guide
Next Steps...

Got Questions?

Documentation

Overview

go-spacemesh is a golang implementation of the Spacemesh node. See - https://spacemesh.io

Directories

Path Synopsis
Package activation is responsible for creating activation transactions and running the mining flow, coordinating PoST building, sending proofs to PoET and building NIPoST structs.
Package activation is responsible for creating activation transactions and running the mining flow, coordinating PoST building, sending proofs to PoET and building NIPoST structs.
api
config
Package config provides configuration for GRPC and HTTP api servers
Package config provides configuration for GRPC and HTTP api servers
cmd
Package cmd is the base package for various sets of builds and executables created from go-spacemesh
Package cmd is the base package for various sets of builds and executables created from go-spacemesh
hare
package hare is the tester executable running instances of hare consensus algorithm
package hare is the tester executable running instances of hare consensus algorithm
integration
Package integration provides RPC testing harness for executing and interacting with full node
Package integration provides RPC testing harness for executing and interacting with full node
multi_node_sim
package multi_node_sim is an implementation of a framework running multiple nodes in same executable with fast hare implementation.
package multi_node_sim is an implementation of a framework running multiple nodes in same executable with fast hare implementation.
node
Package node contains the main executable for go-spacemesh node
Package node contains the main executable for go-spacemesh node
p2p
package p2p cmd is the main executable for running p2p tests and simulations
package p2p cmd is the main executable for running p2p tests and simulations
Package collector implements event collecting from pubsub
Package collector implements event collecting from pubsub
common
types
Package types defines the types used by go-spacemesh consensus algorithms and structs
Package types defines the types used by go-spacemesh consensus algorithms and structs
util
Package util provides common utility functions.
Package util provides common utility functions.
Package config contains go-spacemesh node configuration definitions
Package config contains go-spacemesh node configuration definitions
Package crypto provides funcs and types used by other packages to perform crypto related ops
Package crypto provides funcs and types used by other packages to perform crypto related ops
sha3
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
Package database defines interfaces to key value type databases used by various components in go-spacemesh node
Package database defines interfaces to key value type databases used by various components in go-spacemesh node
Package eligibility defines fixed size oracle used for node testing
Package eligibility defines fixed size oracle used for node testing
Package events defines events published by go-spacemsh node using nodes pubsub
Package events defines events published by go-spacemsh node using nodes pubsub
Package fetch contains mechanism to fetch data from remote peers
Package fetch contains mechanism to fetch data from remote peers
Package filesystem provides functionality for interacting with directories and files in a cross-platform manner.
Package filesystem provides functionality for interacting with directories and files in a cross-platform manner.
Package hare implements the Hare Protocol.
Package hare implements the Hare Protocol.
Package layerfetcher fetches layers from remote peers
Package layerfetcher fetches layers from remote peers
Package log provides the both file and console (general) logging capabilities to spacemesh modules such as app and identity.
Package log provides the both file and console (general) logging capabilities to spacemesh modules such as app and identity.
Package mesh defines the main store point for all the block-mesh objects such as blocks, transactions and global state
Package mesh defines the main store point for all the block-mesh objects such as blocks, transactions and global state
Package metrics defines telemetry primitives to be used across components.
Package metrics defines telemetry primitives to be used across components.
Package miner is responsible for creating valid blocks that contain valid activation transactions and transactions
Package miner is responsible for creating valid blocks that contain valid activation transactions and transactions
Package nattraversal provides tools for acquiring ports on a Network Address Translator (NAT).
Package nattraversal provides tools for acquiring ports on a Network Address Translator (NAT).
upnp
Package upnp provides a simple and opinionated interface to UPnP-enabled routers, allowing users to forward ports and discover their external IP address.
Package upnp provides a simple and opinionated interface to UPnP-enabled routers, allowing users to forward ports and discover their external IP address.
p2p
Package p2p provides a networking api for creating p2p protocols by enabling sending direct messages to a set of provided neighbors or broadcasting a message to all of them.
Package p2p provides a networking api for creating p2p protocols by enabling sending direct messages to a set of provided neighbors or broadcasting a message to all of them.
config
Package config defines configuration used in the p2p package
Package config defines configuration used in the p2p package
connectionpool
Package connectionpool functions as a connection cache that takes care of connecting and reusing connected sockets.
Package connectionpool functions as a connection cache that takes care of connecting and reusing connected sockets.
discovery
Package discovery implements uses bitcoin-based addrbook to store network addresses and collects them by crawling the network using a simple protocol.
Package discovery implements uses bitcoin-based addrbook to store network addresses and collects them by crawling the network using a simple protocol.
gossip
Package gossip implements simple protocol to send new validated messages to all peers and ignore old or not valid messages.
Package gossip implements simple protocol to send new validated messages to all peers and ignore old or not valid messages.
metrics
Package metrics defines metric reporting for the p2p component.
Package metrics defines metric reporting for the p2p component.
net
Package net manages the accepting network connections/messages and routing the data upward for the protocols to consume.
Package net manages the accepting network connections/messages and routing the data upward for the protocols to consume.
net/wire/delimited
Package delimited implements a reader and writer for simple streams of length-delimited byte records.
Package delimited implements a reader and writer for simple streams of length-delimited byte records.
node
Package node defines simple data structures to represent p2p node identities.
Package node defines simple data structures to represent p2p node identities.
p2pcrypto
Package p2pcrypto defines the cryptographic primitives used to communicate and identify in the p2p network, it uses go stdlib's NaCL box implementation.
Package p2pcrypto defines the cryptographic primitives used to communicate and identify in the p2p network, it uses go stdlib's NaCL box implementation.
server
Package server is used to wrap the p2p services to define multiple req-res messages under one protocol.
Package server is used to wrap the p2p services to define multiple req-res messages under one protocol.
service
Package service defines basic interfaces to for protocols to consume p2p functionality.
Package service defines basic interfaces to for protocols to consume p2p functionality.
version
Package version includes methods to compare versions between nodes.
Package version includes methods to compare versions between nodes.
Package pendingtxs exposes the AccountPendingTxs type, which keeps track of transactions that haven't been applied to global state yet.
Package pendingtxs exposes the AccountPendingTxs type, which keeps track of transactions that haven't been applied to global state yet.
Package rlp implements the RLP serialization format.
Package rlp implements the RLP serialization format.
systest module
Package timesync is used to check system time reliability by communicating with NTP time servers.
Package timesync is used to check system time reliability by communicating with NTP time servers.
Package trie implements Merkle Patricia Tries.
Package trie implements Merkle Patricia Tries.
Package turbohare is a component returning block ids for layer as seen by this miner, without running any consensus process
Package turbohare is a component returning block ids for layer as seen by this miner, without running any consensus process

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL