Skip to content

Commit 8042cda

Browse files
authored
Merge pull request #556 from ainblockchain/release/v0.9.1
Merge Release/v0.9.1 into master branch
2 parents a392a8b + c3b5014 commit 8042cda

File tree

96 files changed

+9967
-2096
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+9967
-2096
lines changed

.github/workflows/github-actions.yml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ on:
1414
types: [opened, synchronize, reopened, closed]
1515
jobs:
1616
build_and_test:
17-
if: ${{ github.event_name == 'pull_request' && github.event.action == 'opened' }}
17+
if: ${{ github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'edited') }}
1818
runs-on: macos-latest
1919
steps:
2020
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
2121
- uses: actions/checkout@v2
22-
with:
23-
ref: ${{ github.event.pull_request.head.sha }}
2422
# Setup node environment for testing
2523
- uses: actions/setup-node@v2
2624
with:
@@ -30,9 +28,22 @@ jobs:
3028
run: yarn install
3129
- name: run unittest
3230
run: yarn run test_unit
33-
- name: run integration test
34-
if: github.event.pull_request.base.ref == 'master' # integration test only run when master merging
35-
run: yarn run test_integration
31+
# integration test only run when master merging
32+
- name: run blockchain integration test
33+
if: github.event.action == 'opened' && github.event.pull_request.base.ref == 'master'
34+
run: yarn run test_integration_blockchain
35+
- name: run consensus integration test
36+
if: github.event.action == 'opened' && github.event.pull_request.base.ref == 'master'
37+
run: yarn run test_integration_consensus
38+
- name: run dapp integration test
39+
if: github.event.action == 'opened' && github.event.pull_request.base.ref == 'master'
40+
run: yarn run test_integration_dapp
41+
- name: run node integration test
42+
if: github.event.action == 'opened' && github.event.pull_request.base.ref == 'master'
43+
run: yarn run test_integration_node
44+
- name: run sharding integration test
45+
if: github.event.action == 'opened' && github.event.pull_request.base.ref == 'master'
46+
run: yarn run test_integration_sharding
3647
check_protocol_version:
3748
if: ${{ github.event_name == 'push' }}
3849
runs-on: macos-latest

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ You can override default port numbering system by setting `PORT` and `P2P_PORT`
3434
```
3535
gcloud init
3636
# For one-off deploy
37-
sh deploy_blockchain_gcp.sh {dev|spring|summer} <YOUR_GCP_USER_NAME> <NUMBER_OF_SHARDS> [--setup]
37+
bash deploy_blockchain_gcp.sh {dev|spring|summer} <YOUR_GCP_USER_NAME> <NUMBER_OF_SHARDS> [--setup]
3838
# For incremental deploy
39-
sh deploy_blockchain_incremental_gcp.sh {dev|staging|spring|summer} <YOUR_GCP_USER_NAME> <NUMBER_OF_SHARDS> [--setup]
39+
bash deploy_blockchain_incremental_gcp.sh {dev|staging|spring|summer} <YOUR_GCP_USER_NAME> <NUMBER_OF_SHARDS> [--setup]
4040
```
4141
- Set up Ubuntu machine (if it's on a new VM)
4242
```
43-
sh setup_blockchain_ubuntu.sh
43+
bash setup_blockchain_ubuntu.sh
4444
```
4545
- Copy files to a sharable folder & install yarn packages
4646
```
@@ -49,7 +49,7 @@ source setup_tracker_gcp.sh
4949
- Start tracker server job
5050
```
5151
cd ain-blockchain/
52-
sh start_tracker_genesis_gcp.sh
52+
bash start_tracker_genesis_gcp.sh
5353
```
5454

5555
<!--
@@ -97,9 +97,9 @@ yarn install
9797
```
9898
- Run blockchain nodes
9999
```
100-
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
101-
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
102-
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
100+
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
101+
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
102+
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
103103
```
104104
You can override default port numbering system by setting `PORT` and `P2P_PORT` environment variables.
105105
Before starting node jobs, remove existing blockchain files and logs if necessary:
@@ -112,7 +112,7 @@ The default minimum size of the validator whitelist is 3. Change MIN_NUM_VALIDAT
112112
the genesis-configs/base/genesis.json to change this value. You may also need to modify the GENESIS_WHITELIST and GENESIS_VALIDATORS accordingly.
113113
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:
114114
```
115-
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
115+
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
116116
```
117117

118118
#### On Google Cloud Platform (GCP)
@@ -122,21 +122,21 @@ GENESIS_CONFIGS_DIR=genesis-configs/afan-shard MIN_NUM_VALIDATORS=1 ACCOUNT_INDE
122122
```
123123
gcloud init
124124
# For one-off deploy
125-
sh deploy_blockchain_gcp.sh {dev|spring|summer} <YOUR_GCP_USER_NAME> <NUMBER_OF_SHARDS> [--setup]
125+
bash deploy_blockchain_gcp.sh {dev|spring|summer} <YOUR_GCP_USER_NAME> <NUMBER_OF_SHARDS> [--setup]
126126
# For incremental deploy
127-
sh deploy_blockchain_incremental_gcp.sh {dev|staging|spring|summer} <YOUR_GCP_USER_NAME> <NUMBER_OF_SHARDS> [--setup]
127+
bash deploy_blockchain_incremental_gcp.sh {dev|staging|spring|summer} <YOUR_GCP_USER_NAME> <NUMBER_OF_SHARDS> [--setup]
128128
```
129129
- Set up Ubuntu machine (if it's on a new VM)
130130
```
131-
sh setup_blockchain_ubuntu.sh
131+
bash setup_blockchain_ubuntu.sh
132132
```
133133
- Copy files to a sharable folder & install yarn packages
134134
```
135135
source setup_node_gcp.sh
136136
```
137137
- Start Node server job (set shard index to 0 if you're running a root chain node)
138138
```
139-
sh start_node_genesis_gcp.sh {dev|spring|summer} <SHARD_INDEX> <SERVER_INDEX>
139+
bash start_node_genesis_gcp.sh {dev|spring|summer} <SHARD_INDEX> <SERVER_INDEX>
140140
```
141141

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

304304
Four Node server with a Tracker server can be started all at once using `start_servers.sh` like:
305305
```
306-
sh start_servers.sh
306+
bash start_servers.sh
307307
```
308308
and can be stopped all at once using `stop_servers.sh` like:
309309
```
310-
sh stop_servers.sh
310+
bash stop_servers.sh
311311
```
312312

313313
## Versions

blockchain/block.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ const {
2222
const PathUtil = require('../common/path-util');
2323

2424
class Block {
25-
constructor(lastHash, lastVotes, transactions, number, epoch, timestamp,
25+
constructor(lastHash, lastVotes, evidence, transactions, number, epoch, timestamp,
2626
stateProofHash, proposer, validators, gasAmountTotal, gasCostTotal) {
2727
this.last_votes = lastVotes;
28+
this.evidence = evidence;
2829
this.transactions = Block.sanitizeTransactions(transactions);
2930
// Block's header
3031
this.last_hash = lastHash;
3132
this.last_votes_hash = CommonUtil.hashString(stringify(lastVotes));
33+
this.evidence_hash = CommonUtil.hashString(stringify(this.evidence));
3234
this.transactions_hash = CommonUtil.hashString(stringify(this.transactions));
3335
this.number = number;
3436
this.epoch = epoch;
@@ -48,6 +50,7 @@ class Block {
4850
last_hash: this.last_hash,
4951
last_votes_hash: this.last_votes_hash,
5052
transactions_hash: this.transactions_hash,
53+
evidence_hash: this.evidence_hash,
5154
number: this.number,
5255
epoch: this.epoch,
5356
timestamp: this.timestamp,
@@ -62,6 +65,7 @@ class Block {
6265
get body() {
6366
return {
6467
last_votes: this.last_votes,
68+
evidence: this.evidence,
6569
transactions: this.transactions,
6670
};
6771
}
@@ -88,25 +92,26 @@ class Block {
8892
return sizeof({...block.header, ...block.body});
8993
}
9094

91-
static create(lastHash, lastVotes, transactions, number, epoch,
92-
stateProofHash, proposer, validators, gasAmountTotal, gasCostTotal) {
93-
return new Block(lastHash, lastVotes, transactions, number, epoch, Date.now(),
94-
stateProofHash, proposer, validators, gasAmountTotal, gasCostTotal);
95+
static create(lastHash, lastVotes, evidence, transactions, number, epoch,
96+
stateProofHash, proposer, validators, gasAmountTotal, gasCostTotal, timestamp) {
97+
return new Block(lastHash, lastVotes, evidence, transactions, number, epoch,
98+
timestamp ? timestamp : Date.now(), stateProofHash, proposer, validators, gasAmountTotal,
99+
gasCostTotal);
95100
}
96101

97102
static parse(blockInfo) {
98103
if (!Block.hasRequiredFields(blockInfo)) return null;
99104
if (blockInfo instanceof Block) return blockInfo;
100-
return new Block(blockInfo.last_hash, blockInfo.last_votes,
105+
return new Block(blockInfo.last_hash, blockInfo.last_votes, blockInfo.evidence,
101106
blockInfo.transactions, blockInfo.number, blockInfo.epoch, blockInfo.timestamp,
102107
blockInfo.state_proof_hash, blockInfo.proposer, blockInfo.validators,
103108
blockInfo.gas_amount_total, blockInfo.gas_cost_total);
104109
}
105110

106111
static hasRequiredFields(block) {
107112
return (block && block.last_hash !== undefined && block.last_votes !== undefined &&
108-
block.transactions !== undefined && block.number !== undefined &&
109-
block.epoch !== undefined && block.timestamp !== undefined &&
113+
block.evidence !== undefined && block.transactions !== undefined &&
114+
block.number !== undefined && block.epoch !== undefined && block.timestamp !== undefined &&
110115
block.state_proof_hash !== undefined && block.proposer !== undefined &&
111116
block.validators !== undefined && block.gas_amount_total !== undefined &&
112117
block.gas_cost_total !== undefined);
@@ -129,6 +134,11 @@ class Block {
129134
`[${LOG_HEADER}] Last votes or last_votes_hash is incorrect for block ${block.hash}`);
130135
return false;
131136
}
137+
if (block.evidence_hash !== CommonUtil.hashString(stringify(block.evidence))) {
138+
logger.error(
139+
`[${LOG_HEADER}] Evidence or evidence_hash is incorrect for block ${block.hash}`);
140+
return false;
141+
}
132142
return true;
133143
}
134144

@@ -138,8 +148,8 @@ class Block {
138148
if (!CommonUtil.isCksumAddr(address)) {
139149
return false;
140150
}
141-
if (!CommonUtil.isDict(info) || !CommonUtil.isNumber(info[PredefinedDbPaths.STAKE]) ||
142-
!CommonUtil.isBool(info[PredefinedDbPaths.PROPOSAL_RIGHT])) {
151+
if (!CommonUtil.isDict(info) || !CommonUtil.isNumber(info[PredefinedDbPaths.CONSENSUS_STAKE]) ||
152+
!CommonUtil.isBool(info[PredefinedDbPaths.CONSENSUS_PROPOSAL_RIGHT])) {
143153
return false;
144154
}
145155
}
@@ -292,7 +302,7 @@ class Block {
292302
operation: {
293303
type: 'SET_VALUE',
294304
ref: PathUtil.getStakingStakeRecordValuePath(PredefinedDbPaths.CONSENSUS, address, 0, timestamp),
295-
value: info[PredefinedDbPaths.STAKE]
305+
value: info[PredefinedDbPaths.CONSENSUS_STAKE]
296306
}
297307
};
298308
txs.push(Transaction.fromTxBody(txBody, privateKey));
@@ -315,13 +325,13 @@ class Block {
315325
return [firstTx, secondTx, thirdTx, ...stakingTxs];
316326
}
317327

318-
static executeGenesisTxsAndGetData(genesisTxs) {
328+
static executeGenesisTxsAndGetData(genesisTxs, genesisTime) {
319329
const tempGenesisDb = new DB(
320330
new StateNode(StateVersions.EMPTY), StateVersions.EMPTY, null, null, false, -1, null);
321331
tempGenesisDb.initDbStates();
322332
const resList = [];
323333
for (const tx of genesisTxs) {
324-
const res = tempGenesisDb.executeTransaction(Transaction.toExecutable(tx), true);
334+
const res = tempGenesisDb.executeTransaction(Transaction.toExecutable(tx), true, false, 0, genesisTime);
325335
if (CommonUtil.isFailedTx(res)) {
326336
logger.error(`Genesis transaction failed:\n${JSON.stringify(tx, null, 2)}` +
327337
`\nRESULT: ${JSON.stringify(res)}`)
@@ -345,13 +355,14 @@ class Block {
345355
const genesisTime = GenesisAccounts[AccountProperties.TIMESTAMP];
346356
const lastHash = '';
347357
const lastVotes = [];
358+
const evidence = {};
348359
const transactions = Block.getGenesisBlockTxs(genesisTime);
349360
const number = 0;
350361
const epoch = 0;
351362
const proposer = ownerAddress;
352363
const validators = GENESIS_VALIDATORS;
353-
const { stateProofHash, gasAmountTotal, gasCostTotal } = Block.executeGenesisTxsAndGetData(transactions);
354-
return new Block(lastHash, lastVotes, transactions, number, epoch, genesisTime,
364+
const { stateProofHash, gasAmountTotal, gasCostTotal } = Block.executeGenesisTxsAndGetData(transactions, genesisTime);
365+
return new Block(lastHash, lastVotes, evidence, transactions, number, epoch, genesisTime,
355366
stateProofHash, proposer, validators, gasAmountTotal, gasCostTotal);
356367
}
357368
}

0 commit comments

Comments
 (0)