Giter Club home page Giter Club logo

efsn's Introduction

Go eFSN

FUSION would like to extend its gratitude to the Ethereum Foundation. FUSION has used the official open-source golang implementation of the Ethereum protocol.

Automatic node setup

The fastest way to get a node up and running and to start staking automatically is by using the FUSION Node Manager script.
Just execute the following command on Ubuntu 18.04 (or newer), press 1 and answer the questions:

bash -c "$(curl -fsSL https://raw.githubusercontent.com/FUSIONFoundation/efsn/master/QuickNodeSetup/fsnNode.sh)"

The Node Manager script and an example video can also be found under this link: Quick Setup
The video shows how to quickly setup a staking node.

Manual node setup

How to run a Miner

Change the parameter YOURDIRECTORY to your local directory

Install Docker first, e.g. on Ubuntu do sudo apt-get install docker.io

Pull Miner image from repository

docker pull fusionnetwork/efsn:latest

Run a Miner from the image

  1. With ticket auto-buy disabled

docker run -it -p 40408:40408 -v YOURDIRECTORY:/fusion-node fusionnetwork/efsn -u <account to unlock> -e MyFusionMiner

  1. With ticket auto-buy enabled

docker run -it -p 40408:40408 -v YOURDIRECTORY:/fusion-node fusionnetwork/efsn -u <account to unlock> -e MyFusionMiner -a

Build your own Miner image (optional)

docker build --file Dockerfile -t YOUR-DOCKER-HUB-ID/efsn .

Run a Miner using your image

docker run -it -p 40408:40408 -v YOURDIRECTORY:/fusion-node fusionnetwork/efsn -u <account to unlock> -e MyFusionMiner -a

Remember to:

  1. Replace YOUR-DOCKER-HUB-ID with your valid Docker Hub id.

  2. Save the keystore file as YOURDIRECTORY/UTC...

  3. Save the password.txt as YOURDIRECTORY/password.txt

  4. (Optional) Add flag "-a" or "--autobt" to enable ticket auto-buy.

  5. (Optional) Add flag "-tn" or "--testnet" to connect to the public testnet.

Note: The password file must be named password.txt and the keystore file name must start with UTC...

How to run a Gateway

Change the parameter YOURDIRECTORY to your local directory

Install Docker first, e.g. on Ubuntu do sudo apt-get install docker.io

Pull Gateway image from repository

docker pull fusionnetwork/gateway:latest

Run a Gateway from the image

  1. Connect to mainnet

docker run -it -p 9000:9000 -p 9001:9001 -p 40408:40408 -v YOURDIRECTORY:/fusion-node fusionnetwork/gateway

  1. Connect to testnet

docker run -it -p 9000:9000 -p 9001:9001 -p 40408:40408 -v YOURDIRECTORY:/fusion-node fusionnetwork/gateway -tn

Build your own Gateway image (optional)

docker build --file Dockerfile.gtw -t YOUR-DOCKER-HUB-ID/gateway .

Run a Gateway using your image

docker run -it -p 9000:9000 -p 9001:9001 -p 40408:40408 -v YOURDIRECTORY:/fusion-node YOUR-DOCKER-HUB-ID/gateway

Remember to replace YOUR-DOCKER-HUB-ID with your valid Docker Hub id.

You can now connect to the websocket API via ws://localhost:9001

Note that this creates a public gateway, unless the system is protected by an external firewall. Additional configuration steps should be taken to ensure the security and integrity of the API communication, like setting up encryption (e.g. via an nginx proxy). To run a purely local gateway for testing, use:

docker run -it -p 127.0.0.1:9000:9000 -p 127.0.0.1:9001:9001 -p 40408:40408 -v YOURDIRECTORY:/fusion-node YOUR-DOCKER-HUB-ID/gateway

How to run a MinerAndLocalGateway

Change the parameter YOURDIRECTORY to your local directory

Install Docker first, e.g. on Ubuntu do sudo apt-get install docker.io

Pull MinerAndLocalGateway image from repository

docker pull fusionnetwork/minerandlocalgateway:latest

Run a MinerAndLocalGateway from the image

  1. With ticket auto-buy disabled

docker run -it -p 127.0.0.1:9000:9000 -p 127.0.0.1:9001:9001 -p 40408:40408 -v YOURDIRECTORY:/fusion-node fusionnetwork/minerandlocalgateway -u <account to unlock> -e MyFusionMinerAndLocalGateway

  1. With ticket auto-buy enabled

docker run -it -p 127.0.0.1:9000:9000 -p 127.0.0.1:9001:9001 -p 40408:40408 -v YOURDIRECTORY:/fusion-node fusionnetwork/minerandlocalgateway -u <account to unlock> -e MyFusionMinerAndLocalGateway -a

Build your own MinerAndLocalGateway image (optional)

docker build --file Dockerfile.minerLocalGtw -t YOUR-DOCKER-HUB-ID/minerandlocalgateway .

Run a MinerAndLocalGateway using your image

docker run -it -p 127.0.0.1:9000:9000 -p 127.0.0.1:9001:9001 -p 40408:40408 -v YOURDIRECTORY:/fusion-node YOUR-DOCKER-HUB-ID/minerandlocalgateway -u <account to unlock> -e MyFusionMinerAndLocalGateway

Remember to:

  1. Replace YOUR-DOCKER-HUB-ID with your valid Docker Hub id.

  2. Save the keystore file as YOURDIRECTORY/UTC...

  3. Save the password.txt as YOURDIRECTORY/password.txt

  4. (Optional) Add flag "-a" or "--autobt" to enabled ticket auto-buy.

Note: The password file must be named password.txt and the keystore file name must start with UTC...

You can now connect to the websocket API via ws://localhost:9001

API Reference

The API reference can be found here

Building from source

Building efsn requires both a Go (version 1.11 or later) and a C compiler.
You can install them using your favourite package manager.

On Ubuntu 18.04, run these commands to build efsn:

add-apt-repository ppa:longsleep/golang-backports
apt-get update
apt-get install golang-go build-essential
git clone https://github.com/FUSIONFoundation/efsn.git
cd efsn
make efsn

Executables

The FUSION project comes with a wrapper/executable found in the cmd directory.

Command Description
efsn Our main FUSION CLI client. It is the entry point into the FUSION network (main-, test- or private net), capable of running as a full node (default) or archive node (retaining all historical state). It can be used by other processes as a gateway into the FUSION network via JSON RPC endpoints exposed on top of HTTP, WebSocket and/or IPC transports. See efsn --help for command line options.

Running FUSION

Going through all the possible command line flags is out of scope here (please see efsn --help), but we've enumerated a few common parameter combos to get you up to speed quickly on how you can run your own efsn instance.

Interacting with the FUSION network

By far the most common scenario is people wanting to simply interact with the FUSION network: create swaps, transfer time-locked assets; deploy and interact with contracts. To do so run

$ efsn console

This command will start up efsn's built-in interactive JavaScript console, through which you can invoke all official web3 methods as well as FUSION's own APIs.
This tool is optional; if you leave it out you can always attach to an already running efsn instance with efsn attach.

Programmatically interfacing with FUSION

As a developer, sooner rather than later you'll want to start interacting with efsn and the FUSION network via your own programs and not manually through the console. To aid this, efsn has built-in support for JSON-RPC based APIs (standard APIs and FUSION RPC APIs). These can be exposed via HTTP, WebSockets and IPC (unix sockets on unix based platforms).

The IPC interface is enabled by default and exposes all APIs supported by efsn, whereas the HTTP and WS interfaces need to be manually enabled and only expose a subset of the APIs due to security reasons. These can be turned on/off and configured as you'd expect.

HTTP based JSON-RPC API options:

  • --http Enable the HTTP-RPC server
  • --http.addr HTTP-RPC server listening interface (default: localhost)
  • --http.port HTTP-RPC server listening port (default: 8545)
  • --http.api API's offered over the HTTP-RPC interface (default: eth,net,web3)
  • --http.corsdomain Comma separated list of domains from which to accept cross origin requests (browser enforced)
  • --ws Enable the WS-RPC server
  • --ws.addr WS-RPC server listening interface (default: localhost)
  • --ws.port WS-RPC server listening port (default: 8546)
  • --ws.api API's offered over the WS-RPC interface (default: eth,net,web3)
  • --ws.origins Origins from which to accept websockets requests
  • --ipcdisable Disable the IPC-RPC server
  • --ipcapi API's offered over the IPC-RPC interface (default: admin,debug,eth,miner,net,personal,txpool,web3)
  • --ipcpath Filename for IPC socket/pipe within the datadir (explicit paths escape it)

You'll need to use your own programming environments' capabilities (libraries, tools, etc) to connect via HTTP, WS or IPC to an efsn node configured with the above flags, and you'll need to speak JSON-RPC on all transports. You can reuse the same connection for multiple requests!

Note: Please understand the security implications of opening up an HTTP/WS based transport before doing so! Hackers on the internet are actively trying to subvert FUSION nodes with exposed APIs! Further, all browser tabs can access locally running webservers, so malicious webpages could try to subvert locally available APIs!

Operating a private network

Maintaining your own private network is more complicated as a lot of configurations taken for granted in the official networks need to be set up manually.

Defining the private genesis state

First, you'll need to create the genesis state of your network, which all nodes need to be aware of and agree upon. This consists of a small JSON file (e.g. call it genesis.json):

{
  "config": {
        "chainId": 0,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
  "alloc"      : {},
  "coinbase"   : "0x0000000000000000000000000000000000000000",
  "difficulty" : "0x20000",
  "extraData"  : "",
  "gasLimit"   : "0x2fefd8",
  "nonce"      : "0x0000000000000042",
  "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp"  : "0x00"
}

The above fields should be fine for most purposes, although we'd recommend changing the nonce to some random value so you prevent unknown remote nodes from being able to connect to you. If you'd like to pre-fund some accounts for easier testing, you can populate the alloc field with account configs:

"alloc": {
  "0x0000000000000000000000000000000000000001": {"balance": "111111111"},
  "0x0000000000000000000000000000000000000002": {"balance": "222222222"}
}

With the genesis state defined in the above JSON file, you'll need to initialize every efsn node with it prior to starting it up to ensure all blockchain parameters are correctly set:

$ efsn init path/to/genesis.json

Creating the rendezvous point

With all nodes that you want to run initialized to the desired genesis state, you'll need to start a bootstrap node (bootnode) that others can use to find each other in your network and/or over the internet. The clean way is to configure and run a dedicated bootnode:

$ bootnode --genkey=boot.key
$ bootnode --nodekey=boot.key

With the bootnode online, it will display an enode URL that other nodes can use to connect to it and exchange peer information. Make sure to replace the displayed IP address information (most probably [::]) with your externally accessible IP address to get the actual enode URL.

Note: You could also use a full fledged efsn node as a bootnode, but that is not the recommended way.

Starting up your member nodes

With the bootnode operational and externally reachable (you can try telnet <ip> <port> to ensure it's indeed reachable), start every subsequent efsn node pointed to the bootnode for peer discovery via the --bootnodes flag. It will probably also be desirable to keep the data directory of your private network separated, so do also specify a custom --datadir flag.

$ efsn --datadir=path/to/custom/data/folder --bootnodes=<bootnode-enode-url-from-above>

Note: Since your network will be completely cut off from the main and test networks, you'll also need to configure a miner to process transactions and create new blocks for you.

Contribution

Thank you for considering to help out with the source code! We welcome contributions from anyone on the internet, and are grateful for even the smallest of fixes!

If you'd like to contribute to FUSION, please fork, fix, commit and send a pull request for the maintainers to review and merge into the main code base. If you wish to submit more complex changes though, please check up with the core devs first on our Telegram channel to ensure those changes are in line with the general philosophy of the project and/or get some early feedback which can make both your efforts much lighter as well as our review and merge procedures quick and simple.

Please make sure your contributions adhere to our coding guidelines:

  • Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
  • Code must be documented adhering to the official Go commentary guidelines.
  • Pull requests need to be based on and opened against the master branch.

License

The efsn and go-ethereum libraries (i.e. all code outside of the cmd directory) are licensed under the GNU Lesser General Public License v3.0, also included in our repository in the COPYING.LESSER file.

The efsn and go-ethereum binaries (i.e. all code inside of the cmd directory) are licensed under the GNU General Public License v3.0, also included in our repository in the COPYING file.

efsn's People

Contributors

andrzej-fusion avatar ben0z avatar bin0j avatar bret-fusion avatar cross-chain avatar fanbsb avatar fjl avatar iruwen avatar joeykhd avatar khaneight avatar netlogic avatar weijun-sh avatar ymtprogrammingking avatar zhaojun-sh avatar zhiqiangxu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

efsn's Issues

Custodial Account for asset cannot makeSwap

MakeSwap cannot have a swap created on an assets custodial account.
This could cause a double spend race condition

I register a makeSwap. Someone does takeSwap but balance request is on custodial asset account and custodial asset account decreases its balance for whatever reason. System gets hosed. Custodial Accounts for Assets have the only magic wand for increase/decrease balance so they should not be able to makeSwap on that account.

Ticket retreated for no reason

I just had a ticket retreated for absolutely no reason. The node said "mining too far in the future" at the time.

Ticket id: 0x027411e798a112c55698a7ef758cc2fe6ea2ce68ee1b5e2e8207cbc7913c26c4
Purchased in block: 2653202
Retreated in block: 2657537.

image

The node was connected and mining normally the whole time as per my external monitoring.

No deviation from the expected height:

image

Not fallen behind (eth.syncing was never true):

image

Number of tickets drops:

image

Tickets slashing mechanism

1. How to know which blocks retreated tickets?

Run this cmd to grep the imported blocks info from efsn node running log:
grep Imported nohup.out | grep "order=1"

INFO [07-17|15:52:35.196] Imported new chain segment blocks=1 txs=0 mgas=0.000 elapsed=22.048ms mgasps=0.000 order=1 number=113519 hash=eaacb0…761839 difficulty=1926 miner=0xe1E31933F1eb215421040998Dc6Ff2C0629a42eF root=f62768…120358 parentHash=bd399e…af6614 time=1563378755 cache=9.63mB

The imported block which order=1 means that this block was mined by second miner, the order=0 node miss minning this block. Check this block in chaindb:
./efsn attach ./data/efsn.ipc --exec "eth.getBlock(113519)"

In this block, nonce: "0x0000000000000001" same as order=1

{
difficulty: 1926,
extraData: "0xd883013e91846566736e88676f312e31322e36856c696e75780000000000000000000a633b08330b3665d03a83d9f69c2131b30f11516e69dc34d7614bdd3f97e220dc33018b70d45ea4294f8f3680a0cee322e8c34ce13e1bb9953761b33275e892fd17e7027f2f547170fb5577656ef0e9912a5d841f92b80fddce0e33b067bd5d4a2659925c705e0c7e4018d9349cca74303856056fed6a13a3514c4c110cde5c02b704b47200",
gasLimit: 8000000,
gasUsed: 0,
hash: "0xeaacb0943abaeedc48405575432ed7055923a72ecca6cb425e85ea5857761839",
logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
miner: "0xe1e31933f1eb215421040998dc6ff2c0629a42ef",
mixHash: "0x0c92fc1e7313715e83227cde7e803dc427bfc54c66e5f943f9efc042aa6ef8d1",
nonce: "0x0000000000000001",
number: 113519,
parentHash: "0xbd399e7a45232eabafdca3cfe546bb4a6bf7ba2f503b9d4b988eba84e5af6614",
receiptsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
size: 682,
stateRoot: "0xf62768f7e01fae783bcb0d5770e7f9bdadaaebdf6c0cecd49525aad60b120358",
timestamp: 1563378755,
totalDifficulty: 288113211,
transactions: [],
transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
uncles: []
}

nonce: "0x0000000000000001" means that this block was mined by second miner, and the order=0 node miss minning this block then it's ticket will be retreated.

./efsn attach ./data/efsn.ipc --exec "fsn.getSnapshot(web3.toHex("113519"))"

{
retreat: ["0x8b70d45ea4294f8f3680a0cee322e8c34ce13e1bb9953761b33275e892fd17e7"],
selected: "0x3b08330b3665d03a83d9f69c2131b30f11516e69dc34d7614bdd3f97e220dc33",
ticketNumber: 2659
}

2. How to know chain forked happened?

Run this cmd to grep the imported blocks info from efsn node running log:
cat efsnnode.log | grep Imported | grep -Eo "order=0 *number=[0-9]*" | uniq -d | xargs -I{} grep "Imported.*{}" efsnnode.log | tee chainforked.txt

INFO [07-17|04:53:01.339] Imported new chain segment blocks=1 txs=1 mgas=0.022 elapsed=22.682ms mgasps=0.968 order=0 number=110495 hash=559dc3…0c8b76 difficulty=2926 miner=0x3bfA2C1...778E7F6 root=a17c0e…33ca37 parentHash=32fb1c…9d6cc7 time=1563339168 cache=9.75mB
INFO [07-17|04:53:02.468] Imported new chain segment blocks=1 txs=0 mgas=0.000 elapsed=21.586ms mgasps=0.000 order=0 number=110495 hash=0a96ad…562c24 difficulty=2926 miner=0x3bfA2C1...778E7F6 root=afcc7d…80c2bd parentHash=32fb1c…9d6cc7 time=1563339169 cache=9.81mB

The same node miner=0x3bfA2C1...778E7F6,
the same blocknumber number=110495
the same parentHash=32fb1c…9d6cc7.
The three points mean that the miner run two nodes with one wallet, and make the chain forked.

3. What is the consensus about Tickets retreated?

The "Tickets Slashing" consensus mechanism improve the stability of the fusion network and prevent attacks.

  • Node missed minning block time period, usually the node not online, mined with forked chain, the program interrupted, or the network problem, etc. The ticket will be retreated.(deployed)
  • "double-blocking": Miner run more than one node with one wallet address and broadcast more than one block at the same block height. The node will be slashed at least two tickets, depending on how many blocks are duplicated.(next update)

Nodes in the network can report the "double-blocking" behavior, submit a special transaction which list the evidence, and the "Ticket Slashing" consensus mechanism will punish the attack node, slash at least two tickets.

Decide on main boot nodes

// MainnetBootnodes are the enode URLs of the P2P bootstrap nodes running on
// the main Ethereum network.
var MainnetBootnodes = []string{
}

var PSNBootnodes = []string{}

/

Discover port for fsn?

Discover port for ethereum is 30303
Has this been changed for efsn?
Need to know for firewall configuration docs.

High number of transactions causing node outages and network reorgs/stalls

A very high amount of transactions leads to the occasional network stalling we see, eventually due to efsn oom crashes or maybe there's some other issue involved causing problems with the ticket selection.

Wedefi started its daily mass txs with block 2627672 tonight, at 01:34 UTC:

https://fsnex.com/block/2627672

This is what my system monitoring shows starting at that time - notice the increasing memory usage, suddenly hitting a cliff:

image

My node struggles with sharply increasing memory and CPU usage as Wedefi keeps pushing, but eventually keeps working until it finally dies at ~02:05 UTC, followed by a manual reboot.

Here's some relevant excerpts from my logs:

01:34 UTC:

image

01:39 UTC:

image

01:43 UTC:

image

01:47 UTC:

image

01:48 UTC, the network just keeps degrading:

image

Starting 02:02 UTC, my node capitulates and my monitoring triggers a critical alert:

image

image

Around the same time, Krypton noticed in the dev channel that the network is in a degraded state. It started recovering after, with a few nodes failing to catch up until some time later.

Crypto Go :we are a research group to help developers build secure applications.

Hi, we are a research group to help developers build secure applications. We designed a cryptographic misuse detector (i.e., CryptoGo) on Go language. We found your great public repository from Github, and several security issues detected by CryptoGo are shown in the following.
Note that the cryptographic algorithms are categorized with two aspects: security strength and security vulnerability based on NIST Special Publication 800-57 and other public publications. Moreover, CryptoGo defined certain rules derived from the APIs of Go cryptographic library and other popular cryptographic misuse detectors. The specific security issues we found are as follows:
(1) Location: accounts/keystore/keystore_passphrase.go:330
Broken rule: the salt of scrypt is not random;
(2) Location: accounts/keystore/presale.go:77
Broken rule: the salt of pbkdf2 is constant;
(3) Location: crypto/ecies/ecies.go:204
Broken rule: R-04: Not unique IV in CTR;
(4) Location: signer/storage/aes_gcm_storage.go:133
Broken rule: Constant key in AES;
We wish the above security issues could truly help you to build a secure application. If you have any concern or suggestion, please feel free to contact us, we are looking forward to your reply. Thanks.

[BUG]UDP package reflection vulnerability in p2p/discover/udp.go

Brief introduction:
In p2p/discover/udp.go, there is is a well-known vulnerability from Etheruem. As you are using the code from Ethereum and haven't updated the code, your code has the same problem here. The problem is in the function func (t *udp) loop().
In the case case r := <-t.gotreply:, the code is
if p.callback(r.data) { p.errc <- nil plist.Remove(el) }
Here, even the p.callback has something wrong , it won't change the matched flag. The matched flag is used to contain the hash of the previous ping package. This means even if the hash doesn't match, it won't give the error and will always accept the connection. If you guys know the protocol, you will know I can give you the target node ip, and require the "find neighbors" and the reflect all the traffic to the target node. This can lead to a serious DDOS attack.

Expected behaviour/How to patch

You can check the code of here ,
https://github.com/simplechain-org/simplechain/blob/master/p2p/discover/udp.go#L453
This project use the same code but update the corresponding codes. You need do change the matched flag if the hash won't match. You can sync the code of the corresponding version of etherum.

By the way, if you can read chinese, in order to make your life easier, this link will be helpful in helping you understanding the harm of this vulnerability.
https://bcsec.org/index/detail/tag/2/id/489

step to reproduce the behavior

  1. get a fake udp source address
    2.send a ping to udp port with the fake ip
  2. send a pong to the udp port with empty hash
  3. send findnode pacakge to reflect 5 times traffic

As I said , you can always check the link above to see the harm. They have pictures there.

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.