Coder Social home page Coder Social logo

node's Introduction

BNB Beacon Chain

BNB Beacon Chain is a blockchain with a flexible set of native assets and pluggable modules. It uses tendermint for consensus and app logic is written in golang. It targets fast block times, a native dApp layer and multi-token support with no smart contract VM.

Reference Discord

Beacon Chain has the basic features of most blockchains:

  • Sending and receiving BNB and digital assets
  • Issuing new digital assets (we have a standard called BEP-2)
  • Mint/burn, freeze/unfreeze, lock/unlock of digital assets

Besides, it has many other rich features:

  • Staking/governance for both Beacon Chain and BNB Smart Chain.
  • Cross chain communication.
  • Atomic swap support.
  • Support hot sync and state sync.

Overview

  • This uses BFT consensus so up to 1/3 of all validator nodes can be rogue or bad.
  • Validator nodes are part of the "validator set" so they are known, trusted and controlled by the network.
  • Full nodes are not validator nodes, but anyone can get a copy of the whole blockchain and validate it.
  • No PoW means block times are very fast.
  • UXTO/account does not matter as we just use the cosmos bank.
  • Features like the DEX (deprecated now) will run directly on the node as apps written in golang. Read more about Tendermint and ABCI.

Getting Started

Environment setup

Requirement

Go version above 1.19 is required.

Please install it or use brew on macOS: brew install go.

Build from Source

$ git clone [email protected]:bnb-chain/node.git 
$ cd node && make build

If you get such error when running the node with self built binary:

Caught SIGILL in blst_cgo_init, consult <blst>/bindinds/go/README.md.

please try to add the following environment variables and build again:

export CGO_CFLAGS="-O -D__BLST_PORTABLE__"
export CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__"

To test that installation worked, try to run the cli tool:

$./build/bnbchaind version

Start the blockchain

This command will generate a keypair for your node and create the genesis block config:

$ ./build/bnbchaind init --moniker testnode
$ cat ~/.bnbchaind/config/genesis.json

You may want to check the Issuing assets section below before you start, but this is how to start the node and begin generating blocks:

$ ./build/bnbchaind start --moniker testnode

If everything worked you will see blocks being generated around every 1s in your console, like

I[2023-01-05|20:39:46.960] Starting ABCI with Tendermint                module=main 
I[2023-01-05|20:39:47.016] Loading order book snapshot from last breathe block module=main blockHeight=0
I[2023-01-05|20:39:47.016] No breathe block is ever saved. just created match engines for all the pairs. module=main 
I[2023-01-05|20:39:47.017] get last breathe block height                module=main height=0
I[2023-01-05|20:39:48.194] Executed block                               module=state height=1 validTxs=0 invalidTxs=0
I[2023-01-05|20:39:48.200] Committed state                              module=state height=1 txs=0 appHash=45AE480E42446C584BEFF2162941F4A76C542E96E44F878B21546DCC7E79DCE5
I[2023-01-05|20:39:49.194] Executed block                               module=state height=2 validTxs=0 invalidTxs=0
I[2023-01-05|20:39:49.198] Committed state                              module=state height=2 txs=0 appHash=6903AA785839B393C7E252C74185F42297E38ADD9804D8EE0AF08A3EF9D99080
I[2023-01-05|20:39:50.215] Executed block                               module=state height=3 validTxs=0 invalidTxs=0

Reset

When you make a change you probably want to reset your chain, remember to kill the node first.

$ ./build/bnbchaind unsafe-reset-all

Join mainnet/testnet

Please refer to the document for joining mainnet or testnnet.

Assets

Issuing assets

Assets may be issued through bnbcli while the blockchain is running; see here for an example:

$ chainId=`cat ~/.bnbchaind/config/genesis.json | jq .chain_id --raw-output`
# Input password "12345678"
$ ./build/bnbcli token issue --trust-node --symbol FBTC --token-name FunBitCoin  --total-supply  10000000000  --from testnode  --chain-id ${chainId}

This will post a transaction with an IssueMsg to the blockchain, which contains the data needed for token issuance.

Checking a balance

Start your node, then list your keys as below:

$ ./build/bnbcli keys list 

NAME:   TYPE:   ADDRESS:                                                PUBKEY:
testnode        local   bnb1elavnu4uyzt43hw380vhw0m2zl7djz0xeac60t      bnbp1addwnpepqva5fmn4r4hc66fpqafwwdf20nq8xjpr3kezkclpmluufxdk5x4gw9xsln5

Check a balance with this command, e.g.:

$  ./build/bnbcli account bnb1elavnu4uyzt43hw380vhw0m2zl7djz0xeac60t --chain-id ${chainId} | jq

Sending assets

You have to send a transaction to send assets to another address, which is possible with the cli tool:

Make sure chain-id is set correctly; you can find it in your genesis.json.

$ ./build/bnbcli send --to bnb1u5mvgkqt9rmj4fut60rnpqfv0a865pwnn90v9q --amount 100:FBTC-4C9  --from testnode  --chain-id ${chainId}

Password to sign with 'you': 12345678
Committed at block 833 (tx hash: 40C2B27B056A63DFE5BCE32709F160F53633C0EBEBBD05E1AC26419D35303765, response: {Code:0 Data:[] Log:Msg 0:  Info: GasWanted:0 GasUsed:0 Events:[{Type: Attributes:[{Key:[115 101 110 100 101 114] Value:[98 110 98 49 101 108 97 118 110 117 52 117 121 122 116 52 51 104 119 51 56 48 118 104 119 48 109 50 122 108 55 100 106 122 48 120 101 97 99 54 48 116] XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0} {Key:[114 101 99 105 112 105 101 110 116] Value:[98 110 98 49 117 53 109 118 103 107 113 116 57 114 109 106 52 102 117 116 54 48 114 110 112 113 102 118 48 97 56 54 53 112 119 110 110 57 48 118 57 113] XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0} {Key:[97 99 116 105 111 110] Value:[115 101 110 100] XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0}] XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0}] Codespace: XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0})

You can look at the contents of the tx, use the tx hash above:

$  ./build/bnbcli tx 40C2B27B056A63DFE5BCE32709F160F53633C0EBEBBD05E1AC26419D35303765 --chain-id ${chainId} 

Then you can check the balance of pepe's key to see that he now has 100 satoshi units of FBTC-4C9:

$ ./build/bnbcli account bnb1u5mvgkqt9rmj4fut60rnpqfv0a865pwnn90v9q  --chain-id ${chainId} | jq
{
  "type": "bnbchain/Account",
  "value": {
    "base": {
      "address": "bnb1u5mvgkqt9rmj4fut60rnpqfv0a865pwnn90v9q",
      "coins": [
        {
          "denom": "FBTC-4C9",
          "amount": "100"
        }
      ],
      ...
    },
    ...
  }
}

Amounts are represented as ints, and all coins have a fixed scale of 8. This means that if a balance of 100000000 were to be shown here, that would represent a balance of 1 coin.

Contribution

It is welcomed to contribute to this repo from everyone. If you'd like to contribute, please fork, fix, commit and submit a pull request to review and merge into the main code base. Please make sure your contributions adhere to our coding guidelines:

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

node's People

Contributors

ackratos avatar chainwhisper avatar darren-liu avatar emailtovamos avatar endercrypto avatar fletcher142 avatar forcodedancing avatar j75689 avatar nathanbsc avatar notatestuser avatar owen-reorg avatar pythonberg1997 avatar qinglin89 avatar randyahx avatar rickyyangz avatar sokkary avatar unclezoro avatar xiangdotli avatar yutianwu 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node's Issues

Access Point for REST API

Function Wish List:

  1. fast
  2. validate the basics of the transactions: decode, valid tx type. valid fields.
  3. batch the requests
  4. flow control in order not to overflow the validator
  5. client metrics to reject/ban vicious number of requests

reduce initial config.toml timeouts

Block time has increased with the tendermint upgrade because default commit timeout set in config.toml has increased as below:

# All timeouts are in milliseconds¬
timeout_propose = 1000¬
timeout_propose_delta = 500¬
timeout_prevote = 500¬
timeout_prevote_delta = 500¬
timeout_precommit = 1000¬
timeout_precommit_delta = 500¬
timeout_commit = 3000¬

We should reduce the defaults down (i.e. timeout_commit should have a value of 1000) in the config.toml generated by bnbchaind init

Fee Collection/Distribution

  • daily transaction would be sent to block proposer;
  • token creatation/listing/ICO would be distributed across validator (by voting power?)

where we want to override cosmos-sdk

  1. drop GAS
  2. drop BigInt
  3. merge fronzen/locked coin onto the same account
  4. logger to be async
  5. Query Interface for CLI
  6. Cache should not be cleared for checkState/DeliverState

Bug: Consensus failure on node restart

Stack trace on subsequent startup:

E[07-27|08:46:22.118] CONSENSUS FAILURE!!! module=consensus err="runtime error: invalid memory address or nil pointer dereference" stack="goroutine 110 [running]:\nruntime/debug.Stack(0xc431af8108, 0x188a7a0, 0x2072ad0)\n\t/usr/local/Cellar/go/1.10.2/libexec/src/runtime/debug/stack.go:24 +0xa7\ngithub.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine.func1(0xc420120f00)\n\t/Users/luke/go/src/github.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus/state.go:558 +0x57\npanic(0x188a7a0, 0x2072ad0)\n\t/usr/local/Cellar/go/1.10.2/libexec/src/runtime/panic.go:502 +0x229\ngithub.com/BiJie/BinanceChain/app.(*BinanceChain).EndBlocker(0xc420a71ef0, 0x1b809a0, 0xc431b5a9f0, 0xc42003f740, 0x9, 0x155, 0x0, 0x0, 0x0, 0x0, ...)\n\t/Users/luke/go/src/github.com/BiJie/BinanceChain/app/app.go:152 +0x6b\ngithub.com/BiJie/BinanceChain/app.(*BinanceChain).EndBlocker-fm(0x1b809a0, 0xc431b5a9f0, 0xc42003f740, 0x9, 0x155, 0x0, 0x0, 0x0, 0x0, 0x0, ...)\n\t/Users/luke/go/src/github.com/BiJie/BinanceChain/app/app.go:73 +0xa4\ngithub.com/BiJie/BinanceChain/app.(*BaseApp).EndBlock(0xc420a48240, 0x155, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)\n\t/Users/luke/go/src/github.com/BiJie/BinanceChain/app/baseapp.go:658 +0xc6\ngithub.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/abci/client.(*localClient).EndBlockSync(0xc420b22540, 0x155, 0xc431b36e20, 0x0, 0x0)\n\t/Users/luke/go/src/github.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/abci/client/local_client.go:213 +0x85\ngithub.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/proxy.(*appConnConsensus).EndBlockSync(0xc420aa8fb0, 0x155, 0x14, 0x20, 0xc431a9d200)\n\t/Users/luke/go/src/github.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/proxy/app_conn.go:77 +0x3d\ngithub.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/state.execBlockOnProxyApp(0x1b80f60, 0xc420b21f40, 0x1b855e0, 0xc420aa8fb0, 0xc4209c5810, 0xc431b5a000, 0x1b89760, 0xc4200de4d0, 0x1, 0xc420a245a0, ...)\n\t/Users/luke/go/src/github.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/state/execution.go:210 +0x7b5\ngithub.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/state.(*BlockExecutor).ApplyBlock(0xc420b22a80, 0xc420a24540, 0x11, 0x154, 0x0, 0xc420a24560, 0x14, 0x14, 0x1, 0xc420a245a0, ...)\n\t/Users/luke/go/src/github.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/state/execution.go:76 +0x12f\ngithub.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).finalizeCommit(0xc420120f00, 0x155)\n\t/Users/luke/go/src/github.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus/state.go:1289 +0xbb2\ngithub.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).tryFinalizeCommit(0xc420120f00, 0x155)\n\t/Users/luke/go/src/github.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus/state.go:1220 +0x468\ngithub.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).enterCommit.func1(0xc420120f00, 0x0, 0x155)\n\t/Users/luke/go/src/github.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus/state.go:1168 +0x98\ngithub.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).enterCommit(0xc420120f00, 0x155, 0x0)\n\t/Users/luke/go/src/github.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus/state.go:1197 +0x802\ngithub.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote(0xc420120f00, 0xc431ae25a0, 0x0, 0x0, 0xc420046f00, 0xc42003e118, 0xc42003e120)\n\t/Users/luke/go/src/github.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus/state.go:1600 +0xbb4\ngithub.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote(0xc420120f00, 0xc431ae25a0, 0x0, 0x0, 0xc431af9b38, 0xc431af9b58)\n\t/Users/luke/go/src/github.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus/state.go:1458 +0x56\ngithub.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg(0xc420120f00, 0x1871cc0, 0xc431aca0b0, 0x0, 0x0)\n\t/Users/luke/go/src/github.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus/state.go:628 +0x64f\ngithub.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine(0xc420120f00, 0x0)\n\t/Users/luke/go/src/github.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus/state.go:584 +0x5c5\ncreated by github.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).OnStart\n\t/Users/luke/go/src/github.com/BiJie/BinanceChain/vendor/github.com/tendermint/tendermint/consensus/state.go:295 +0x140\n"

easy script wrapper for cli commands

To hide passphrase entry and make interaction with the bnbcli easier, make a wrapper to call the cli commands

e.g. ./send.sh --from=luke --to=bnbxyz --amount=100 --token=bnb

reduce fees

Current gas price to send coins is quite expensive

handle the exchange error after block confirmation

After consensus is reached, even though the order (and other transaction, such as ICO) is checked in the checkTx(), there is still chance that the final execution failed. In such case, the troubled transaction and necessary context should be saved into the recoverable backlog. When the issue is recovered either manually or even through a binary upgrade, the backlog would be rerun and recovered to the proper state.

Binary transaction sig format

There's a ton of json marshalling and unmarshalling going on in the incoming tx lifecycle. We could speed things up greatly by giving transaction msgs known fixed sizes in binary.

This relates to the fact that the sig is generated by StdSignDoc, which is signed in JSON format.

Handle small residual

small residual may be left on order and balance due to decimal computation. A mechnism is reuqired to clear it out.

Fee Calculation

  1. cancel
  2. execution
  3. transfer
  4. burn
  5. freeze
  6. create token
  7. list
  8. expire
  9. ICO

Do not produce empty blocks?

There is a config option create_empty_blocks that is set to true by default. Having this flipped to false seems to work in dev but I wanted to know if anyone had any concerns about consensus in production.

make market data available via websocket

WebSockets are similar to network sockets but are consumable by modern networking libraries and browsers. WebSockets could be implemented as an alternative to LCD's REST interface for piping market data to clients.

Scope: Market data could go through the Frontier and be redistributed via Kafka/similar or be served over a direct link to the node; the actual implementation should be flexible enough to allow for either option.

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.