• Stars
    star
    472
  • Rank 93,034 (Top 2 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created almost 7 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Official Go implementation of NKN full node.

NKN

NKN Full Node

Official Go implementation of NKN full node.


GitHub license Go Report Card Build Status PRs Welcome

Dev Status: V2 line, Production (Stable and Feature-Complete)



NKN, short for New Kind of Network, is a project aiming to rebuild the Internet that will be truly open, decentralized, dynamic, safe, shared and owned by the community.

Official website: https://nkn.org/

Note: This is the official full node implementation of the NKN protocol, which relays data for clients and earn mining rewards. For client implementation which can send and receive data, please refer to:

Introduction

The core of the NKN network consists of many connected nodes distributed globally. Every node is only connected to and aware of a few other nodes called neighbors. Packets can be transmitted from any node to any other node in an efficient and verifiable route. Data can be sent to any clients without public or static IP address using their permanent NKN address with end-to-end encryption. The network stack of NKN network is open source at another repo called nnet that can be used to build other decentralized/distributed systems.

The relay workload can be verified using our Proof of Relay (PoR) algorithm. A small and fixed portion of the packets will be randomly selected as proof. The random selection can be verified and cannot be predicted or controlled. Proof will be sent to other nodes for payment and rewards.

A node in our network is both relayer and consensus participant. Consensus among massive nodes can be reached efficiently by only communicating with neighbors using our consensus algorithm based on Cellular Automata. Consensus is reached for every block to prevent fork.

More details can be found in our wiki.

Technical Highlights

  • Transmit any data to any node/client without any centralized server.
  • Proof-of-Relay, a useful proof of work: mining is relaying data.
  • Extremely scalable consensus algorithm (billions of nodes within seconds).
  • Strong consistency rather than eventual consistency.
  • Dynamic, large-scale network.
  • Verifiable topology and routes.
  • Secure address scheme with public key embedded.

Use pre-built binaries

You just need to download and decompress the correct version matching your OS and architecture from github releases.

Now you can jump to configuration for how to configure and run a node.

Use pre-built Docker image

Prerequirement: Have working docker software installed. For help with that visit official docker docs

We host latest Docker image (the same as you build with docker) on our official Docker Hub account. You can get it by

$ docker pull nknorg/nkn

Now you can jump to configuration for how to configure and run a node.

Building using Docker

Prerequirement: Have working docker software installed. For help with that visit official docker docs

Build and tag Docker image

$ docker build -f docker/Dockerfile -t nknorg/nkn .

This command should be run once every time you update the code base.

Building from source

To build from source, you need a properly configured Go environment (lookup the required version within go.mod, and see Go Official Installation Documentation for install instructions).

Build the source code with make

$ git clone https://github.com/nknorg/nkn.git
$ cd nkn
$ make

Run Unit Tests

# run all tests
$ go test -v ./...

# run only specific tests
go test -v ./chain/store

After building is successful, you should see two executables:

  • nknd: the nkn node program
  • nknc: command line tool for nkn node control

Now you can see configuration for how to configure and run a node.

You can also build binaries for other architectures by executing make all. The resulting binaries are stored in build directory.

Configuration

When starting a NKN node (i.e. running nknd), it will reads a few configurable files: config.json for configuration, wallet.json for wallet, and certs/* for certificates. Additionally, it will read directory web for web GUI interface static assets. By default nknd assumes they are located in the current working directory.

For Docker, a directory containing config.json, wallet.json (if exists) and certs/ should be mapped to /nkn/data directory in the container. If not provided, the default config and certs will be copied to /nkn/data/, and a wallet and random password will be generated and saved to /nkn/data/ on nknd launch.

The path of config file, wallet file, database directory and log directory can be specified by passing arguments to nknd or in config.json, run nknd --help for more information.

config.json:

We provide a few sample config.json:

  • config.mainnet.json: join the mainnet
  • config.testnet.json: join the testnet
  • config.local.json: create and join a private chain on your localhost

You can copy the one you want to config.json or write your own.

For convenience, we ship a copy of config.mainnet.json in release version (as default.json) and in docker image (under /nkn/). The docker container will copy this default one to /nkn/data/config.json if not exists on nknd launch.

wallet.json:

Before starting the node, you need to create a new wallet first. Wallet information will be saved at wallet.json and it's encrypted with the password you provided when creating the wallet. So please make sure you pick a strong password and remember it!

$ ./nknc wallet -c
Password:
Re-enter Password:
Address                                Public Key
-------                                ----------
NKNRQxosmUixL8bvLAS5G79m1XNx3YqPsFPW   35db285ea2f91499164cd3e19203ab5e525df6216d1eba3ac6bcef00503407ce

[IMPORTANT] Each node needs to use a unique wallet. If you use share wallet among multiple nodes, only one of them will be able to join the network!

If you are using Docker, it should be docker run -it -v ${PWD}:/nkn/data nknorg/nkn nknc wallet -c instead, assuming you want to store the wallet.json in your current working directory. If you want it to be saved to another directory, you need to change ${PWD} to that directory.

The docker container will create a wallet saved to /nkn/data/wallet.json and a random password saved to /nkn/data/wallet.pswd if not exists on nknd launch.

certs/

nknd uses Let's Encrypt to apply and renew TLS certificate and put in into cert/ directory.

By default nknd will generate certificate with x-x-x-x.ipv4.nknlabs.io domain name which x-x-x-x is your ipv4 address, replace dot with dash.

If you would like to use your own domain name, simply set CertDomainName with your domain name in config.json, nknd will automatically apply or renew certificate from Let's Encrypt and deploy it.

If you already have certificate and want to use it in nknd, you can put it in the certs directory then set HttpsJsonDomain HttpWssDomain with your domain name, HttpsJsonCert HttpsJsonKey HttpWssCert HttpWssKey with your certificate full chain file and private key file.

Data and Logs

After nknd starts, it will creates two directories: ChainDB to store blockchain data, and Log to store logs. By default nknd will creates these directories in the current working directory, but it can be changed by passing --chaindb and --log arguments to nknd or specify in config.json.

Now you can join the mainnet, join the testnet or create a private chain.

Join the MainNet

[IMPORTANT] In order to join the MainNet, you need to have a public IP address, or set up port forwarding on your router properly so that other people can establish connection to you.

If you have done the previous steps correctly (config.json, create wallet, public IP or port forwarding), joining the MainNet is as simple as running:

$ ./nknd

If you are using Docker then you should run the following command instead:

$ docker run -p 30001-30005:30001-30005 -v ${PWD}:/nkn/data --name nkn --rm -it nknorg/nkn

If you would like to enable web GUI interface from outside of the container, you need to replace -p 30001-30005:30001-30005 with -p 30000-30005:30000-30005.

If you get an error saying docker: Error response from daemon: Conflict. The container name "/nkn" is already in use by container ..., you should run docker rm nkn first to remove the old container.

If everything goes well, you should be part of the MainNet after a few minutes! You can query your wallet balance (which includes the NKN token you've mined) by:

$ ./nknc wallet -l balance

or if you are using Docker:

$ docker exec -it nkn nknc wallet -l balance

If there is a problem, you may want to check if any of the previous steps went wrong. If the problem still persists, create an issue or ask us in our Discord group.

[Recommended] Using BeneficiaryAddr

By default, token mined by your node will be sent to the wallet your node is using, which is NOT as safe as you might think. The recommended way is to use another cold wallet (that is saved and backed up well) to store your token. You can use your code wallet address as BeneficiaryAddr in config.json such that token mined by your node will be sent directly to that beneficiary address. This is safer and more convenient because: 1. even if your node is hacked, or your node wallet is leaked, you will not lose any token; 2. if you run multiple nodes, it's the only way that all their mining rewards will go to the same address.

NAT traversal and port forwarding

Most likely your node is behind a router and does not have a public IP address. By default, nknd will try to detect if your router supports UPnP or NAT-PMP protocol, and if success, it will try to set up port forwarding automatically. You can add --no-nat flag when starting nknd OR add "NAT": false in config.json to disable automatic port forwarding. If your router does not support such protocol, you have to setup port forwarding on your router for port 30001 as well as all other ports specified in config.json (30001-30005 by default), otherwise other nodes cannot establish connections to you and you will NOT be able to mine token even though your node can still run and sync blocks.

When setting up port forwarding, public port needs to be the same as private port mapped to your node. For example, you should map port 30001 on your router's public IP address to port 30001 on your node's internal IP address.

The specific steps to setup port forwarding depends on your router. But in general, you need to log in to the admin interface of your router (typically in a web browser), then navigate to the port forwarding section, and create several mappings, one for each port. One of the easiest way to find out how to setup port forwarding on your router is to search "how to setup port forwarding" + your router model or name online.

Join the TestNet

Joining the TestNet is the same as joining MainNet, except for using config.testnet.json as your config file instead of config.mainnet.json. Note that TestNet token is for testing purpose only (thus do not have value), and may be cleared at any time when TestNet upgrades.

Contributing

Can I submit a bug, suggestion or feature request?

Yes. Please open an issue for that.

Can I contribute patches to NKN project?

Yes, we appreciate your help! To make contributions, please fork the repo, push your changes to the forked repo with signed-off commits, and open a pull request here.

Please follow our Golang Style Guide for coding style.

Please sign off your commit. This means adding a line "Signed-off-by: Name " at the end of each commit, indicating that you wrote the code and have the right to pass it on as an open source patch. This can be done automatically by adding -s when committing:

git commit -s

Community

More Repositories

1

nnet

nnet: a fast, scalable, and developer-friendly p2p overlay network stack
Go
118
star
2

nkn-tunnel

Tunnel tcp through NKN client.
Go
115
star
3

nconnect

Securely connect to remote machines without the need of any server, public IP address, or publicly exposed ports.
Go
106
star
4

nkn-sdk-go

Go implementation of NKN client and wallet
Go
58
star
5

nkn-client-js

[Deprecated, use nkn-sdk-js instead] JavaScript implementation of NKN client
JavaScript
55
star
6

nMobile

The world's most secure private and group messenger
Dart
47
star
7

encrypted-stream

A Golang library that transforms any net.Conn or io.ReadWriter stream to an encrypted and/or authenticated stream
Go
46
star
8

nkn-sdk-js

JavaScript Implementation of NKN Client and Wallet SDK
JavaScript
43
star
9

nkn-shell-daemon

NKN shell daemon
JavaScript
30
star
10

tuna

A free market to use service by paying NKN or host service to earn NKN
Go
20
star
11

nkn-simulation

NetLogo
18
star
12

nkn-wallet-js

[Deprecated, use nkn-sdk-js instead] JavaScript implementation of NKN wallet
JavaScript
16
star
13

nkn-java-sdk

JVM sdk for nkn.org, written in Java
Java
13
star
14

nkn-file-transfer

Decentralized file transfer app using NKN client
Go
13
star
15

nkn-sdk-py3

Python3 implementation of NKN SDK
Python
9
star
16

ncp-go

Go implementation of NCP (NKN Control Protocol), a ARQ protocol for NKN network.
Go
9
star
17

nkn-sdk-flutter

Objective-C
9
star
18

nkn-tuna-session

An overlay peer to peer connection based on multiple concurrent tuna connections and ncp protocol.
Go
7
star
19

fortunetree

Front-end for Fortune Tree which is a token incentive forum
JavaScript
6
star
20

nkn-cloud-image

Scripts to automatically build image running NKN node
Makefile
6
star
21

nkn-db-tool

Golang tool to export NKN blockchain database
Go
5
star
22

nkn-multiclient-js

[Deprecated, use nkn-sdk-js instead] A high-level library uses multiple concurrent nkn-client-js
JavaScript
5
star
23

nBounty

NKN bounty program
5
star
24

nftp-js

Source code of of https://nftp.nkn.org
JavaScript
4
star
25

documentations

NKN documentations
HTML
4
star
26

nkn-sdk-cpp

NKN SDK for C/C++
C++
4
star
27

nkn-crawler

nkn-crawler: A python crawler for NKN Network
Python
4
star
28

ncp-js

JavaScript
3
star
29

nshell-chrome-extension

Vue
2
star
30

goproxy

A simple http/https proxy that protects proxy's local/internal network by disallowing local/internal network address as destination.
Go
2
star
31

crypto

Crypto for NKN
Go
2
star
32

eth-resolver-go

Go
2
star
33

nkn-protocols

Documentation and discussion of NKN protocols, including NKN node and NKN client
2
star
34

ip-range-to-cidr

Go
2
star
35

tuna-proxy-speedtest

Test tuna proxy speed using fast.com
Go
2
star
36

mockconn-go

Mocked network connection with customized latency, throughput, loss and buffer size
Go
2
star
37

nkn-node-sampler

NKN node crawler using random sampling
Go
2
star
38

nMobile-legacy

NKN mobile App which include wallet, news, d-chat and IOT devices communication functions
1
star
39

nkn-dashboard

Vue
1
star
40

nkn-utility

Go
1
star
41

portchecker-server

Go
1
star
42

portchecker

Go
1
star
43

nkngomobile

nkngomobile
Go
1
star
44

nkn-shell-client-xterm

A NKN shell client using xterm.js
HTML
1
star
45

portmapper

Go
1
star
46

NKNDataPump

Go
1
star
47

nkn-sdk-android

NKN wallet and data transmission SDK for Android
Kotlin
1
star
48

ncp-go-graph

Go
1
star