当前位置: 首页 > 软件库 > Web3 > 区块链 >

go-spacemesh

授权协议 MIT License
开发语言 Google Go
所属分类 Web3、 区块链
软件类型 开源软件
地区 不详
投 递 者 越望
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

 

A Programmable Cryptocurrency

Bors enabled

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.15 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.

Using go build and go test without make

To build code without using make the CGO_LDFLAGS environment variable must be setappropriately. The required value can be obtained by running make print-ldflags ormake print-test-ldflags.

This can be done in 3 ways:

  1. Setting the variable in the shell environment (e.g., in bash run CGO_LDFLAGS=$(make print-ldflags)).
  2. Prefixing the key and value to the go command (e.g., CGO_LDFLAGS=$(make print-ldflags) go build).
  3. Using go env -w CGO_LDFLAGS=$(make print-ldflags), which persistently adds this value to Go'senvironment for any future runs.

There's a handy shortcut for the 3rd method: make go-env or make go-env-test.


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 7513 and UDP port 7513 for p2p connections:

./go-spacemesh --tcp-port 7513 --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 7513 --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

Find the latest Testnet release in the releases and download the precompiled binary for your platform of choice (or you can compile go-spacemesh yourself, from source, using the release tag). The release notes contain a link to a config.json file that you'll need to join the testnet.

Note that you must download (or build) precisely this version (latest Testnet release) of go-spacemesh, and the compatible config file, in order to join the current testnet. Older versions of the code may be incompatible with this testnet, and a different config file will not work.


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?

  • golang 正常的 struct 就是普通的一个内存块,必定是占用一小块内存的,并且结构体的大小是要经过边界,长度的对齐的,但是“空结构体”是不占内存的,size 为 0; 本质上来讲,使用空结构体的初衷只有一个:节省内存,但是更多的情况,节省的内存其实很有限,这种情况使用空结构体的考量其实是:根本不关心结构体变量的值。 特殊变量:zerobase 空结构体是没有内存大小的结构体。这句话是没有错

  • Map Map是一个拥有key value对的元素的无序集合,key的值是唯一的 Go里面的Map就是Hash Table的引用,是引用类型,类似Pointer和Slice 一、声明和初始化 // 这样初始化默认是一个nil类型,没有引用任何散列表 var m map[string]int fmt.Println(m == nil) // true // 这样赋值就会出错 m["a"] = 1

  • 复制一个map,最快的方法是定制化创建一个新的map,类型相同,然后通过loop将k,v赋予新的map; package main import ( "fmt" ) func main() { map_origin := map[string]int{ "x":1, "y":2, } map_copy := map[string]

  • 指针 Go 拥有指针。指针保存了值的内存地址。 类型 *T 是指向 T 类型值的指针。其零值为 nil。 var p *int & 操作符会生成一个指向其操作数的指针。 i := 42 p = &i * 操作符表示指针指向的底层值。 fmt.Println(*p) // 通过指针 p 读取 i *p = 21 // 通过指针 p 设置 i 这也就是通常所说的“间接引用”或“重

  • slice 切片 引用类型         //直接声明 + 初始化         var slice1 []string         slice1 = make([]string, 10 ,10)         //基于数组  、基于切片         *** 基于数组、切片、由于切片使用的是地址引用 在 容量 cap 不变的情况下,改变值 原变量 与 新变量 值都会改变 在容量 ca

  • 介绍 本文详细介绍——空结构体 struct{}: type Q struct{} var q struct{} 但是如果一个结构体没有任何字段,不包含任何数据,那么它有什么用处呢?我们如何利用空结构体?   宽度 在深入研究空结构体之前,我想先简短介绍一下关于宽度的知识。 宽度这个术语来自于gc编译器,但是他的词源可以追溯到几十年以前。 宽度描述了一个数据类型实例需要占用的字节数,由于进程的内存

  • 概述 golang 官方的包管理从 1.11 版本就开始支持了, 之前尝试了几次, 效果都不理想, 就一直用 dep 来管理 package. 最近 1.13 版本发布了, 使用 go module 的官方管理方式越来越多, dep 也早就不在继续开发了. 鉴于此, 是时候把 golang 的包管理方式迁移到 go module 上来了. 我一直是用 spacemacs 来开发各种应用, 所以本文

  • go map map 是在 Go 中将值(value)与键(key)关联的内置类型。通过相应的键可以获取到值(字典类型)2value值可以任意,但是go中value值必须都一致,key值只能用数字,字符串,布尔,key值也固定。 map的定义 var m map[string]int //map[key值类型]value类型 fmt.Println(m) // map[] 只定义,没有初始化,

  • 空结构体占用空间为0 可以使用 unsafe.Sizeof 计算出一个数据类型实例需要占用的字节数。 package main import ( "fmt" "unsafe" ) func main() { fmt.Println(unsafe.Sizeof(struct{}{})) } 输出为0 即空结构体 struct{} 实例不占据任何的内存空间。 空结构体的场景

  • go map类似python字典 map是引用类型因此使用的时候需要先定义,比如用make 开辟一段空间。 map并发读写是存在问题的,就是我正在读的元素可能正在被修改那抹我读的就是错的,因此在map读写的时候需要加锁。 不加锁报错 package main import ( "fmt" "sync" ) var Mutex sync.Mutex var Map = make(map[s

  • 总结 空结构体也是结构体,只是 size 为 0 的类型而已; 所有的空结构体都有一个共同的地址:zerobase 的地址; 空结构体可以作为 receiver ,receiver 是空结构体作为值的时候,编译器其实直接忽略了第一个参数的传递,编译器在编译期间就能确认生成对应的代码; map 和 struct{} 结合使用常常用来节省一点点内存,使用的场景一般用来判断 key 存在于 map; c

  • golang中的map默认为nil package main func main() { var m map[string]int m["1"] = 1 } 运行报错:panic: assignment to entry in nil map 需要对map进行初始化:m = make(map[string]string)     

 相关资料
  • Go!

    Go! 是一个 PHP 5.4 库,让 PHP 支持 AOP 面向方面编程方法,无需 PECL 扩展、Runkit、evals 或者 DI 容器支持。可使用 XDebug 轻松调试。 示例代码: // Aspect/MonitorAspect.phpnamespace Aspect;use Go\Aop\Aspect;use Go\Aop\Intercept\FieldAccess;use Go\

  • 命令go vet是一个用于检查Go语言源码中静态错误的简单工具。与大多数Go命令一样,go vet命令可以接受-n标记和-x标记。-n标记用于只打印流程中执行的命令而不真正执行它们。-n标记也用于打印流程中执行的命令,但不会取消这些命令的执行。示例如下: hc@ubt:~$ go vet -n pkgtool /usr/local/go/pkg/tool/linux_386/vet golang/

  • 命令go fix会把指定代码包的所有Go语言源码文件中的旧版本代码修正为新版本的代码。这里所说的版本即Go语言的版本。代码包的所有Go语言源码文件不包括其子代码包(如果有的话)中的文件。修正操作包括把对旧程序调用的代码更换为对新程序调用的代码、把旧的语法更换为新的语法,等等。 这个工具其实非常有用。在编程语言的升级和演进的过程中,难免会对过时的和不够优秀的语法及标准库进行改进。这样的改进对于编程语

  • Pact Go的版本目前支持Pact v2规范,访问网站开始学习。 Go-Kit例子 Pact Go代码库中有一个详细的Go Kit 例子,介绍如何使用Pact去测试Go Kit微服务。 原生Go实现 还有一个Go版本的Pact(兼容pact v1.1),不需要运行一个守护进程。如果你不需要v2+的匹配以及运行守护进程,可以考虑使用或者为Pact Go贡献。

  • Panic表示的意思就是有些意想不到的错误发生了。通常我们用来表示程序正常运行过程中不应该出现的,或者我们没有处理好的错误。 package main import "os" func main() { // 我们使用panic来检查预期不到的错误 panic("a problem") // Panic的通常使用方法就是如果一个函数 // 返回一个我们不知道怎么处理

  • 使用os.Exit可以给定一个状态,然后立刻退出程序运行。 package main import "fmt" import "os" func main() { // 当使用`os.Exit`的时候defer操作不会被运行, // 所以这里的``fmt.Println`将不会被调用 defer fmt.Println("!") // 退出程序并设置退出状态值