ainblockchain / ain-blockchain

Official Javascript implementation of AI Network Blockchain.
https://www.ainetwork.ai/
MIT License
68 stars 27 forks source link

AI Network Blockchain

AI Network | Whitepaper | Documentation

Official Javascript implementation of AI Network Blockchain.

JSON-RPC API

For accessing AIN Blockchain nodes, see JSON_RPC_API.md.

Install Environment (Last update at 6th of Dec 2021)

OS

NodeJs version

Tracker

Tracker server is required by new peers who wish to join the AIN network. Each peer is sent the ip address of 2 other nodes in the network. These nodes then gossip information through the network of all transactions and blocks.

NOTE: Tracker Server must be started first before starting any blockchain node instances.

Running Tracker without Docker

Local

On Google Coud Platform (GCP)

Tracker Client API for development and testing purposes

Tracker protocol version check & health check

GET http://:8080/

Network status check

GET http://:8080/network_status

Blockchain Node

Operates a single peer node instance of the AIN blockchain. A single blockchain node instance processes incoming transaction requests and maintains a local copy of the entire blockchain. The blockchain node first queries the tracker-server for ip addresses of other peers, and then syncs its local blockchain to the network consensus blockchain. If a node is included in the whitelist and has staked appropriate amount of AIN, it will then take part in the consensus protocol.

Running Blockchain Node without Docker

Local

The default minimum size of the validator whitelist is 3. Change MIN_NUM_VALIDATORS parameter in the blockchain-configs/base/genesis.json to change this value. You may also need to modify the GENESIS_WHITELIST and GENESIS_VALIDATORS accordingly. The genesis configs directory used is blockchain-configs/base by default and it can be altered using BLOCKCHAIN_CONFIGS_DIR env variable. For example, afan shard cluster can use the following command line:

BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/afan-shard MIN_NUM_VALIDATORS=1 DEBUG=false STAKE=100000 CONSOLE_LOG=true ENABLE_GAS_FEE_WORKAROUND=true node client/index.js

On Google Cloud Platform (GCP)

Running Blockchain Node with Docker

Testing How-Tos

How to run unit test and integration test all around.

yarn run test_unit
yarn run test_integration

Some individual tests already definded in the package.json.

yarn run test_unit_block_pool
yarn run test_unit_blockchain
yarn run test_unit_common_util
yarn run test_unit_consensus
yarn run test_unit_db
yarn run test_unit_event_handler
yarn run test_unit_functions
yarn run test_unit_object_util
yarn run test_unit_p2p
yarn run test_unit_p2p_util
yarn run test_unit_radix_node
yarn run test_unit_radix_tree
yarn run test_unit_rule_util
yarn run test_unit_state_manager
yarn run test_unit_state_node
yarn run test_unit_state_util
yarn run test_unit_traffic_db
yarn run test_unit_traffic_sm
yarn run test_unit_tx
yarn run test_unit_tx_pool
yarn run test_integration_dapp
yarn run test_integration_blockchain
yarn run test_integration_consensus
yarn run test_integration_event_handler
yarn run test_integration_function
yarn run test_integration_node
yarn run test_integration_he_protocol
yarn run test_integration_he_sharding
yarn run test_integration_sharding

The load test is also supported.

yarn run loadtest

Blockchain Node Client API for development and testing purposes

Node protocol version check

GET http://:8080/

Node health check

GET http://:8080/health_check

Fetch latest blocks in the blockchain (up to 20 blocks)

GET http://:8080/blocks

Fetch specific list of blocks from the blockchain

GET http://:8080/blocks?from=1&to=100

Fetch transactions in the transaction pool

GET http://:8080/tx_pool

Fetch transaction status in the transaction tracker

GET http://:8080/tx_tracker

Fetch nonce status in the committed nonce tracker

GET http://:8080/committed_nonce_tracker

Fetch nonce status in the pending nonce tracker

GET http://:8080/pending_nonce_tracker

Fetch value

GET http://:8080/get_value?ref=/db/path/to/fetch

Fetch rule

GET http://:8080/get_rule?ref=/db/path/to/fetch

Fetch function

GET http://:8080/get_function?ref=/db/path/to/fetch

Fetch owner

GET http://:8080/get_owner?ref=/db/path/to/fetch

Match rule with database value location

GET http://:8080/match_rule?ref=/db/path/to/match

Match function with database value location

GET http://:8080/match_function?ref=/db/path/to/match

Match owner with database rule/function/owner location

GET http://:8080/match_owner?ref=/db/path/to/match

Evaluate rule

POST http://:8080/eval_rule with json_body {"ref": "/db/path/to/eval", "value": "some value", "address": "0xABCD...Z", "timestamp": "1234567890"}

Evaluate owner

POST http://:8080/eval_owner with json_body {"ref": "/db/path/to/eval", "permission": "write_rule", "address": "0xABCD...Z"}

Perform multiple get operations

POST http://:8080/get with json_body {"op_list": [{"type": "GET_VALUE", "ref": "/db/path/to/fetch"}, {"type": "GET_RULE", "ref": "/db/path/to/fetch2"}]}

Set value

POST http://:8080/set_value with json_body {"ref": "/db/path/to/set", "value": "some value"}

Increase value

POST http://:8080/inc_value with json_body {"ref": "/db/path/to/increase", "value": 10}

Decrease value

POST http://:8080/dec_value with json_body {"ref": "/db/path/to/decrease", "value": 10}

Set rule

POST http://:8080/set_rule with json_body {"ref": "/db/path/to/set", "value": "some rule config"}

Set function

POST http://:8080/set_function with json_body {"ref": "/db/path/to/set", "value": "some function config"}

Set owner

POST http://:8080/set_owner with json_body {"ref": "/db/path/to/set", "value": "some owner config"}

Perform multiple set operations

POST http://:8080/set with json_body {"op_list": [{"type": "SET_VALUE", "ref": "/db/path/to/set", "value": "some value}, {"type": "SET_RULE", "ref": "/db/path/to/set2", "value": "some rule"}]}

Perform multiple transactions

POST http://:8080/batch with json_body {"tx_list": [{"operation": {"type": "SET_VALUE", "ref": "/db/path/to/set", "value": "testme"}}, {"operation": {"type": "SET_RULE", "ref": "/db/path/to/set2", "value": "some rule"}}]}

Utility scripts

Four Node server with a Tracker server can be started all at once using start_local_blockchain.sh like:

bash start_local_blockchain.sh

and can be stopped all at once using stop_local_blockchain.sh like:

bash stop_local_blockchain.sh

Versions

Please check the latest versions below:

Contribution

Please read the CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

License

This project is licensed under the MIT License - see the LICENSE file for details.