diff --git a/README.md b/README.md
index 5e7516cd..5f3c609b 100644
--- a/README.md
+++ b/README.md
@@ -2,13 +2,16 @@
# NKN Full Node
-### *Official Go implementation of NKN full node.*
+### _Official Go implementation of NKN full node._
+
[![GitHub license](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE) [![Go Report Card](https://goreportcard.com/badge/github.com/nknorg/nkn)](https://goreportcard.com/report/github.com/nknorg/nkn) [![Build Status](https://github.com/nknorg/nkn/actions/workflows/build-ubuntu.yml/badge.svg)](https://github.com/nknorg/nkn/actions/workflows/build-ubuntu.yml) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](#contributing)
### Dev Status: V2 line, Production (Stable and Feature-Complete)
+
---
+
> NKN, short for New Kind of Network, is a project aiming to rebuild the
@@ -21,9 +24,9 @@ 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:
-* [nkn-sdk-go](https://github.com/nknorg/nkn-sdk-go)
-* [nkn-sdk-js](https://github.com/nknorg/nkn-sdk-js)
-* [nkn-java-sdk](https://github.com/nknorg/nkn-java-sdk)
+- [nkn-sdk-go](https://github.com/nknorg/nkn-sdk-go)
+- [nkn-sdk-js](https://github.com/nknorg/nkn-sdk-js)
+- [nkn-java-sdk](https://github.com/nknorg/nkn-java-sdk)
## Introduction
@@ -50,13 +53,13 @@ More details can be found in [our wiki](https://github.com/nknorg/nkn/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.
+- 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
@@ -68,7 +71,7 @@ a node.
### Use pre-built Docker image
-*Prerequirement*: Have working docker software installed. For help with that
+_Prerequirement_: Have working docker software installed. For help with that
visit [official docker
docs](https://docs.docker.com/install/#supported-platforms)
@@ -85,7 +88,7 @@ a node.
### Building using Docker
-*Prerequirement*: Have working docker software installed. For help with that
+_Prerequirement_: Have working docker software installed. For help with that
visit [official docker
docs](https://docs.docker.com/install/#supported-platforms)
@@ -111,6 +114,7 @@ $ make
```
Run Unit Tests
+
```sh
# run all tests
$ go test -v ./...
@@ -121,8 +125,8 @@ 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
+- `nknd`: the nkn node program
+- `nknc`: command line tool for nkn node control
Now you can see [configuration](#configuration) for how to configure and run a
node.
@@ -152,9 +156,8 @@ be specified by passing arguments to `nknd` or in `config.json`, run `nknd
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
+- `config.mainnet.json`: join the mainnet
+- `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.
@@ -162,6 +165,8 @@ 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.
+If config file is not provided, node will join the mainnet by default.
+
#### `wallet.json`:
Before starting the node, you need to create a new wallet first. Wallet
@@ -169,7 +174,7 @@ 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!
-``` shell
+```shell
$ ./nknc wallet -c
Password:
Re-enter Password:
@@ -191,11 +196,7 @@ 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.
+`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.staticdns{1,2,3}.io` domain name which `x-x-x-x` is your ipv4 address, replace dot with dash. **The default cert domain is deprecated and will be removed in the future version. Please provide your own domain or cert if you need to use tls.**
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.
@@ -204,7 +205,6 @@ If you already have certificate and want to use it in `nknd`, you can put it in
`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
@@ -212,9 +212,7 @@ 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-mainnet), [join the
-testnet](#join-the-testnet) or [create a private
-chain](https://github.com/nknorg/nkn/wiki/Create-a-Private-Chain).
+Now you can [join the mainnet](#join-the-mainnet) or [create a private chain](https://github.com/nknorg/nkn/wiki/Create-a-Private-Chain).
### Join the MainNet
@@ -261,12 +259,12 @@ wrong. If the problem still persists, [create an
issue](https://github.com/nknorg/nkn/issues/new) or ask us in our [Discord
group](#community).
-### [Recommended] Using BeneficiaryAddr
+### [Recommended] Using Beneficiary Address
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
+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
@@ -275,16 +273,7 @@ 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.
+By default, `nknd` will try to detect if your node is behind a router and 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 earn mining rewards 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
@@ -297,13 +286,6 @@ 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?**
@@ -330,8 +312,8 @@ git commit -s
## Community
-* [Forum](https://forum.nkn.org/)
-* [Discord](https://discord.gg/c7mTynX)
-* [Telegram](https://t.me/nknorg)
-* [Reddit](https://www.reddit.com/r/nknblockchain/)
-* [Twitter](https://twitter.com/NKN_ORG)
+- [Forum](https://forum.nkn.org/)
+- [Discord](https://discord.gg/c7mTynX)
+- [Telegram](https://t.me/nknorg)
+- [Reddit](https://www.reddit.com/r/nknblockchain/)
+- [Twitter](https://twitter.com/NKN_ORG)
diff --git a/api/httpjson/RPCserver.go b/api/httpjson/RPCserver.go
index 217b4cbd..5754f654 100644
--- a/api/httpjson/RPCserver.go
+++ b/api/httpjson/RPCserver.go
@@ -182,7 +182,8 @@ func (s *RPCServer) Handle(w http.ResponseWriter, r *http.Request) {
err := recover()
if err != nil {
var code errcode.ErrCode
- if _, err = chain.GetDefaultLedger(); err != nil {
+ if _, e := chain.GetDefaultLedger(); e != nil {
+ err = e
code = errcode.ErrNullDB
} else if s.GetNetNode() == nil {
code = errcode.ErrNullID
diff --git a/api/websocket/server/server.go b/api/websocket/server/server.go
index 2e56998a..9181ca62 100644
--- a/api/websocket/server/server.go
+++ b/api/websocket/server/server.go
@@ -9,6 +9,7 @@ import (
"crypto/tls"
"encoding/hex"
"encoding/json"
+ "errors"
"fmt"
"io"
"net"
@@ -159,7 +160,7 @@ func (ms *MsgServer) registryMethod() {
if okSig && okSalt { // if client send ClientSalt and Signature, then check it
strSignature, typeOk := signature.(string) // interface type assertion
if !typeOk {
- return api.RespPacking(err.Error(), errcode.INVALID_PARAMS)
+ return api.RespPacking(errors.New("invalid signature"), errcode.INVALID_PARAMS)
}
byteSignature, err := hex.DecodeString(strSignature)
if err != nil {
@@ -168,7 +169,7 @@ func (ms *MsgServer) registryMethod() {
strClientSalt, typeOk := clientSalt.(string) // interface type assertion
if !typeOk {
- return api.RespPacking(err.Error(), errcode.INVALID_PARAMS)
+ return api.RespPacking(errors.New("invalid salt"), errcode.INVALID_PARAMS)
}
byteClientSalt, err := hex.DecodeString(strClientSalt)
if err != nil {
@@ -562,7 +563,7 @@ func (ms *MsgServer) newConnection(conn session.Conn, r *http.Request) {
for {
messageType, bysMsg, err := conn.ReadMessage()
if err != nil {
- log.Errorf("websocket read message error: %v", err)
+ log.Debugf("websocket read message error: %v", err)
break
}
conn.SetReadDeadline(time.Now().Add(pongTimeout))
diff --git a/config.local.json b/config.local.json
index 3500ac22..41e7eb13 100644
--- a/config.local.json
+++ b/config.local.json
@@ -1,15 +1,6 @@
-{
- "NAT": false,
- "HttpWsPort": 30002,
- "HttpJsonPort": 30003,
- "Hostname": "127.0.0.1",
- "SeedList": [
- "http://127.0.0.1:30003"
- ],
- "StunList": [
- "stun:stun.l.google.com:19302",
- "stun:stun.cloudflare.com:3478",
- "stun:stunserver.stunprotocol.org:3478"
- ],
- "GenesisBlockProposer": ""
+{
+ "nat": false,
+ "hostname": "127.0.0.1",
+ "seedList": ["http://127.0.0.1:30003"],
+ "genesisBlockProposer": ""
}
diff --git a/config.mainnet.json b/config.mainnet.json
index 8468c5ca..ab3a8ccb 100644
--- a/config.mainnet.json
+++ b/config.mainnet.json
@@ -1,55 +1,3 @@
-{
- "BeneficiaryAddr": "",
- "SeedList": [
- "http://mainnet-seed-0001.nkn.org:30003",
- "http://mainnet-seed-0002.nkn.org:30003",
- "http://mainnet-seed-0003.nkn.org:30003",
- "http://mainnet-seed-0004.nkn.org:30003",
- "http://mainnet-seed-0005.nkn.org:30003",
- "http://mainnet-seed-0006.nkn.org:30003",
- "http://mainnet-seed-0007.nkn.org:30003",
- "http://mainnet-seed-0008.nkn.org:30003",
- "http://mainnet-seed-0009.nkn.org:30003",
- "http://mainnet-seed-0010.nkn.org:30003",
- "http://mainnet-seed-0011.nkn.org:30003",
- "http://mainnet-seed-0012.nkn.org:30003",
- "http://mainnet-seed-0013.nkn.org:30003",
- "http://mainnet-seed-0014.nkn.org:30003",
- "http://mainnet-seed-0015.nkn.org:30003",
- "http://mainnet-seed-0016.nkn.org:30003",
- "http://mainnet-seed-0017.nkn.org:30003",
- "http://mainnet-seed-0018.nkn.org:30003",
- "http://mainnet-seed-0019.nkn.org:30003",
- "http://mainnet-seed-0020.nkn.org:30003",
- "http://mainnet-seed-0021.nkn.org:30003",
- "http://mainnet-seed-0022.nkn.org:30003",
- "http://mainnet-seed-0023.nkn.org:30003",
- "http://mainnet-seed-0024.nkn.org:30003",
- "http://mainnet-seed-0025.nkn.org:30003",
- "http://mainnet-seed-0026.nkn.org:30003",
- "http://mainnet-seed-0027.nkn.org:30003",
- "http://mainnet-seed-0028.nkn.org:30003",
- "http://mainnet-seed-0029.nkn.org:30003",
- "http://mainnet-seed-0030.nkn.org:30003",
- "http://mainnet-seed-0031.nkn.org:30003",
- "http://mainnet-seed-0032.nkn.org:30003",
- "http://mainnet-seed-0033.nkn.org:30003",
- "http://mainnet-seed-0034.nkn.org:30003",
- "http://mainnet-seed-0035.nkn.org:30003",
- "http://mainnet-seed-0036.nkn.org:30003",
- "http://mainnet-seed-0037.nkn.org:30003",
- "http://mainnet-seed-0038.nkn.org:30003",
- "http://mainnet-seed-0039.nkn.org:30003",
- "http://mainnet-seed-0040.nkn.org:30003",
- "http://mainnet-seed-0041.nkn.org:30003",
- "http://mainnet-seed-0042.nkn.org:30003",
- "http://mainnet-seed-0043.nkn.org:30003",
- "http://mainnet-seed-0044.nkn.org:30003"
- ],
- "StunList": [
- "stun:stun.l.google.com:19302",
- "stun:stun.cloudflare.com:3478",
- "stun:stunserver.stunprotocol.org:3478"
- ],
- "GenesisBlockProposer": "a0309f8280ca86687a30ca86556113a253762e40eb884fc6063cad2b1ebd7de5"
+{
+ "beneficiaryAddr": ""
}
diff --git a/config.testnet.json b/config.testnet.json
deleted file mode 100644
index c1d6fa9b..00000000
--- a/config.testnet.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "HttpWsPort": 30002,
- "HttpJsonPort": 30003,
- "SeedList": [
- "http://devnet-seed-0001.nkn.org:30003",
- "http://devnet-seed-0002.nkn.org:30003",
- "http://devnet-seed-0003.nkn.org:30003",
- "http://devnet-seed-0004.nkn.org:30003"
- ],
- "StunList": [
- "stun:stun.l.google.com:19302",
- "stun:stun.cloudflare.com:3478",
- "stun:stunserver.stunprotocol.org:3478"
- ],
- "GenesisBlockProposer": "0149c42944eea91f094c16538eff0449d4d1e236f31c8c706b2e40e98402984c",
- "BeneficiaryAddr": ""
-}
diff --git a/config/config.go b/config/config.go
index e184f21e..9c27bc7d 100644
--- a/config/config.go
+++ b/config/config.go
@@ -326,7 +326,23 @@ var (
SyncBlockRateBurst: 1024,
SyncMode: "full",
MaxRollbackBlocks: 180,
- ClientMsgCacheSize: 0, // client relay messag cache mega bytes
+ ClientMsgCacheSize: 0,
+ GenesisBlockProposer: "a0309f8280ca86687a30ca86556113a253762e40eb884fc6063cad2b1ebd7de5",
+ SeedList: []string{
+ "http://mainnet-seed-0001.nkn.org:30003",
+ "http://mainnet-seed-0002.nkn.org:30003",
+ "http://mainnet-seed-0003.nkn.org:30003",
+ "http://mainnet-seed-0004.nkn.org:30003",
+ "http://mainnet-seed-0005.nkn.org:30003",
+ "http://mainnet-seed-0006.nkn.org:30003",
+ "http://mainnet-seed-0007.nkn.org:30003",
+ "http://mainnet-seed-0008.nkn.org:30003",
+ },
+ StunList: []string{
+ "stun:stun.l.google.com:19302",
+ "stun:stun.cloudflare.com:3478",
+ "stun:stunserver.stunprotocol.org:3478",
+ },
}
)