Skip to content

Commit

Permalink
Merge pull request #556 from ainblockchain/release/v0.9.1
Browse files Browse the repository at this point in the history
Merge Release/v0.9.1 into master branch
  • Loading branch information
minsulee2 authored Sep 3, 2021
2 parents a392a8b + c3b5014 commit 8042cda
Show file tree
Hide file tree
Showing 96 changed files with 9,967 additions and 2,096 deletions.
23 changes: 17 additions & 6 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ on:
types: [opened, synchronize, reopened, closed]
jobs:
build_and_test:
if: ${{ github.event_name == 'pull_request' && github.event.action == 'opened' }}
if: ${{ github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'edited') }}
runs-on: macos-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
# Setup node environment for testing
- uses: actions/setup-node@v2
with:
Expand All @@ -30,9 +28,22 @@ jobs:
run: yarn install
- name: run unittest
run: yarn run test_unit
- name: run integration test
if: github.event.pull_request.base.ref == 'master' # integration test only run when master merging
run: yarn run test_integration
# integration test only run when master merging
- name: run blockchain integration test
if: github.event.action == 'opened' && github.event.pull_request.base.ref == 'master'
run: yarn run test_integration_blockchain
- name: run consensus integration test
if: github.event.action == 'opened' && github.event.pull_request.base.ref == 'master'
run: yarn run test_integration_consensus
- name: run dapp integration test
if: github.event.action == 'opened' && github.event.pull_request.base.ref == 'master'
run: yarn run test_integration_dapp
- name: run node integration test
if: github.event.action == 'opened' && github.event.pull_request.base.ref == 'master'
run: yarn run test_integration_node
- name: run sharding integration test
if: github.event.action == 'opened' && github.event.pull_request.base.ref == 'master'
run: yarn run test_integration_sharding
check_protocol_version:
if: ${{ github.event_name == 'push' }}
runs-on: macos-latest
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ You can override default port numbering system by setting `PORT` and `P2P_PORT`
```
gcloud init
# For one-off deploy
sh deploy_blockchain_gcp.sh {dev|spring|summer} <YOUR_GCP_USER_NAME> <NUMBER_OF_SHARDS> [--setup]
bash deploy_blockchain_gcp.sh {dev|spring|summer} <YOUR_GCP_USER_NAME> <NUMBER_OF_SHARDS> [--setup]
# For incremental deploy
sh deploy_blockchain_incremental_gcp.sh {dev|staging|spring|summer} <YOUR_GCP_USER_NAME> <NUMBER_OF_SHARDS> [--setup]
bash deploy_blockchain_incremental_gcp.sh {dev|staging|spring|summer} <YOUR_GCP_USER_NAME> <NUMBER_OF_SHARDS> [--setup]
```
- Set up Ubuntu machine (if it's on a new VM)
```
sh setup_blockchain_ubuntu.sh
bash setup_blockchain_ubuntu.sh
```
- Copy files to a sharable folder & install yarn packages
```
Expand All @@ -49,7 +49,7 @@ source setup_tracker_gcp.sh
- Start tracker server job
```
cd ain-blockchain/
sh start_tracker_genesis_gcp.sh
bash start_tracker_genesis_gcp.sh
```

<!--
Expand Down Expand Up @@ -97,9 +97,9 @@ yarn install
```
- Run blockchain nodes
```
MIN_NUM_VALIDATORS=3 ACCOUNT_INDEX=0 DEBUG=false STAKE=250 CONSOLE_LOG=true ENABLE_DEV_SET_CLIENT_API=true ENABLE_GAS_FEE_WORKAROUND=true node client/index.js
MIN_NUM_VALIDATORS=3 ACCOUNT_INDEX=1 DEBUG=false STAKE=250 CONSOLE_LOG=true ENABLE_DEV_SET_CLIENT_API=true ENABLE_GAS_FEE_WORKAROUND=true node client/index.js
MIN_NUM_VALIDATORS=3 ACCOUNT_INDEX=2 DEBUG=false STAKE=250 CONSOLE_LOG=true ENABLE_DEV_SET_CLIENT_API=true ENABLE_GAS_FEE_WORKAROUND=true node client/index.js
MIN_NUM_VALIDATORS=3 ACCOUNT_INDEX=0 DEBUG=false STAKE=100000 CONSOLE_LOG=true ENABLE_DEV_SET_CLIENT_API=true ENABLE_GAS_FEE_WORKAROUND=true node client/index.js
MIN_NUM_VALIDATORS=3 ACCOUNT_INDEX=1 DEBUG=false STAKE=100000 CONSOLE_LOG=true ENABLE_DEV_SET_CLIENT_API=true ENABLE_GAS_FEE_WORKAROUND=true node client/index.js
MIN_NUM_VALIDATORS=3 ACCOUNT_INDEX=2 DEBUG=false STAKE=100000 CONSOLE_LOG=true ENABLE_DEV_SET_CLIENT_API=true ENABLE_GAS_FEE_WORKAROUND=true node client/index.js
```
You can override default port numbering system by setting `PORT` and `P2P_PORT` environment variables.
Before starting node jobs, remove existing blockchain files and logs if necessary:
Expand All @@ -112,7 +112,7 @@ The default minimum size of the validator whitelist is 3. Change MIN_NUM_VALIDAT
the genesis-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 `genesis-configs/base` by default and it can be altered using `GENESIS_CONFIGS_DIR` env variable. For example, afan shard cluster can use the following command line:
```
GENESIS_CONFIGS_DIR=genesis-configs/afan-shard MIN_NUM_VALIDATORS=1 ACCOUNT_INDEX=0 DEBUG=false STAKE=250 CONSOLE_LOG=true ENABLE_DEV_SET_CLIENT_API=true ENABLE_GAS_FEE_WORKAROUND=true node client/index.js
GENESIS_CONFIGS_DIR=genesis-configs/afan-shard MIN_NUM_VALIDATORS=1 ACCOUNT_INDEX=0 DEBUG=false STAKE=100000 CONSOLE_LOG=true ENABLE_DEV_SET_CLIENT_API=true ENABLE_GAS_FEE_WORKAROUND=true node client/index.js
```

#### On Google Cloud Platform (GCP)
Expand All @@ -122,21 +122,21 @@ GENESIS_CONFIGS_DIR=genesis-configs/afan-shard MIN_NUM_VALIDATORS=1 ACCOUNT_INDE
```
gcloud init
# For one-off deploy
sh deploy_blockchain_gcp.sh {dev|spring|summer} <YOUR_GCP_USER_NAME> <NUMBER_OF_SHARDS> [--setup]
bash deploy_blockchain_gcp.sh {dev|spring|summer} <YOUR_GCP_USER_NAME> <NUMBER_OF_SHARDS> [--setup]
# For incremental deploy
sh deploy_blockchain_incremental_gcp.sh {dev|staging|spring|summer} <YOUR_GCP_USER_NAME> <NUMBER_OF_SHARDS> [--setup]
bash deploy_blockchain_incremental_gcp.sh {dev|staging|spring|summer} <YOUR_GCP_USER_NAME> <NUMBER_OF_SHARDS> [--setup]
```
- Set up Ubuntu machine (if it's on a new VM)
```
sh setup_blockchain_ubuntu.sh
bash setup_blockchain_ubuntu.sh
```
- Copy files to a sharable folder & install yarn packages
```
source setup_node_gcp.sh
```
- Start Node server job (set shard index to 0 if you're running a root chain node)
```
sh start_node_genesis_gcp.sh {dev|spring|summer} <SHARD_INDEX> <SERVER_INDEX>
bash start_node_genesis_gcp.sh {dev|spring|summer} <SHARD_INDEX> <SERVER_INDEX>
```

<!--
Expand Down Expand Up @@ -303,11 +303,11 @@ POST http://<ip_address>:8080/batch with json_body {"tx_list": [{"operation": {"

Four Node server with a Tracker server can be started all at once using `start_servers.sh` like:
```
sh start_servers.sh
bash start_servers.sh
```
and can be stopped all at once using `stop_servers.sh` like:
```
sh stop_servers.sh
bash stop_servers.sh
```

## Versions
Expand Down
41 changes: 26 additions & 15 deletions blockchain/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ const {
const PathUtil = require('../common/path-util');

class Block {
constructor(lastHash, lastVotes, transactions, number, epoch, timestamp,
constructor(lastHash, lastVotes, evidence, transactions, number, epoch, timestamp,
stateProofHash, proposer, validators, gasAmountTotal, gasCostTotal) {
this.last_votes = lastVotes;
this.evidence = evidence;
this.transactions = Block.sanitizeTransactions(transactions);
// Block's header
this.last_hash = lastHash;
this.last_votes_hash = CommonUtil.hashString(stringify(lastVotes));
this.evidence_hash = CommonUtil.hashString(stringify(this.evidence));
this.transactions_hash = CommonUtil.hashString(stringify(this.transactions));
this.number = number;
this.epoch = epoch;
Expand All @@ -48,6 +50,7 @@ class Block {
last_hash: this.last_hash,
last_votes_hash: this.last_votes_hash,
transactions_hash: this.transactions_hash,
evidence_hash: this.evidence_hash,
number: this.number,
epoch: this.epoch,
timestamp: this.timestamp,
Expand All @@ -62,6 +65,7 @@ class Block {
get body() {
return {
last_votes: this.last_votes,
evidence: this.evidence,
transactions: this.transactions,
};
}
Expand All @@ -88,25 +92,26 @@ class Block {
return sizeof({...block.header, ...block.body});
}

static create(lastHash, lastVotes, transactions, number, epoch,
stateProofHash, proposer, validators, gasAmountTotal, gasCostTotal) {
return new Block(lastHash, lastVotes, transactions, number, epoch, Date.now(),
stateProofHash, proposer, validators, gasAmountTotal, gasCostTotal);
static create(lastHash, lastVotes, evidence, transactions, number, epoch,
stateProofHash, proposer, validators, gasAmountTotal, gasCostTotal, timestamp) {
return new Block(lastHash, lastVotes, evidence, transactions, number, epoch,
timestamp ? timestamp : Date.now(), stateProofHash, proposer, validators, gasAmountTotal,
gasCostTotal);
}

static parse(blockInfo) {
if (!Block.hasRequiredFields(blockInfo)) return null;
if (blockInfo instanceof Block) return blockInfo;
return new Block(blockInfo.last_hash, blockInfo.last_votes,
return new Block(blockInfo.last_hash, blockInfo.last_votes, blockInfo.evidence,
blockInfo.transactions, blockInfo.number, blockInfo.epoch, blockInfo.timestamp,
blockInfo.state_proof_hash, blockInfo.proposer, blockInfo.validators,
blockInfo.gas_amount_total, blockInfo.gas_cost_total);
}

static hasRequiredFields(block) {
return (block && block.last_hash !== undefined && block.last_votes !== undefined &&
block.transactions !== undefined && block.number !== undefined &&
block.epoch !== undefined && block.timestamp !== undefined &&
block.evidence !== undefined && block.transactions !== undefined &&
block.number !== undefined && block.epoch !== undefined && block.timestamp !== undefined &&
block.state_proof_hash !== undefined && block.proposer !== undefined &&
block.validators !== undefined && block.gas_amount_total !== undefined &&
block.gas_cost_total !== undefined);
Expand All @@ -129,6 +134,11 @@ class Block {
`[${LOG_HEADER}] Last votes or last_votes_hash is incorrect for block ${block.hash}`);
return false;
}
if (block.evidence_hash !== CommonUtil.hashString(stringify(block.evidence))) {
logger.error(
`[${LOG_HEADER}] Evidence or evidence_hash is incorrect for block ${block.hash}`);
return false;
}
return true;
}

Expand All @@ -138,8 +148,8 @@ class Block {
if (!CommonUtil.isCksumAddr(address)) {
return false;
}
if (!CommonUtil.isDict(info) || !CommonUtil.isNumber(info[PredefinedDbPaths.STAKE]) ||
!CommonUtil.isBool(info[PredefinedDbPaths.PROPOSAL_RIGHT])) {
if (!CommonUtil.isDict(info) || !CommonUtil.isNumber(info[PredefinedDbPaths.CONSENSUS_STAKE]) ||
!CommonUtil.isBool(info[PredefinedDbPaths.CONSENSUS_PROPOSAL_RIGHT])) {
return false;
}
}
Expand Down Expand Up @@ -292,7 +302,7 @@ class Block {
operation: {
type: 'SET_VALUE',
ref: PathUtil.getStakingStakeRecordValuePath(PredefinedDbPaths.CONSENSUS, address, 0, timestamp),
value: info[PredefinedDbPaths.STAKE]
value: info[PredefinedDbPaths.CONSENSUS_STAKE]
}
};
txs.push(Transaction.fromTxBody(txBody, privateKey));
Expand All @@ -315,13 +325,13 @@ class Block {
return [firstTx, secondTx, thirdTx, ...stakingTxs];
}

static executeGenesisTxsAndGetData(genesisTxs) {
static executeGenesisTxsAndGetData(genesisTxs, genesisTime) {
const tempGenesisDb = new DB(
new StateNode(StateVersions.EMPTY), StateVersions.EMPTY, null, null, false, -1, null);
tempGenesisDb.initDbStates();
const resList = [];
for (const tx of genesisTxs) {
const res = tempGenesisDb.executeTransaction(Transaction.toExecutable(tx), true);
const res = tempGenesisDb.executeTransaction(Transaction.toExecutable(tx), true, false, 0, genesisTime);
if (CommonUtil.isFailedTx(res)) {
logger.error(`Genesis transaction failed:\n${JSON.stringify(tx, null, 2)}` +
`\nRESULT: ${JSON.stringify(res)}`)
Expand All @@ -345,13 +355,14 @@ class Block {
const genesisTime = GenesisAccounts[AccountProperties.TIMESTAMP];
const lastHash = '';
const lastVotes = [];
const evidence = {};
const transactions = Block.getGenesisBlockTxs(genesisTime);
const number = 0;
const epoch = 0;
const proposer = ownerAddress;
const validators = GENESIS_VALIDATORS;
const { stateProofHash, gasAmountTotal, gasCostTotal } = Block.executeGenesisTxsAndGetData(transactions);
return new Block(lastHash, lastVotes, transactions, number, epoch, genesisTime,
const { stateProofHash, gasAmountTotal, gasCostTotal } = Block.executeGenesisTxsAndGetData(transactions, genesisTime);
return new Block(lastHash, lastVotes, evidence, transactions, number, epoch, genesisTime,
stateProofHash, proposer, validators, gasAmountTotal, gasCostTotal);
}
}
Expand Down
Loading

0 comments on commit 8042cda

Please sign in to comment.