Skip to content

Commit 8a85c7f

Browse files
authored
Merge pull request #428 from ainblockchain/release/v0.7.6
Merge Release/v0.7.6 into master
2 parents 843363e + f15ea3a commit 8a85c7f

Some content is hidden

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

41 files changed

+3527
-935
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ MIN_NUM_VALIDATORS=3 ACCOUNT_INDEX=2 DEBUG=false STAKE=250 CONSOLE_LOG=true ENAB
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:
106106
```
107-
rm -rf chains logs
107+
rm -rf /path/to/data/dir logs
108108
```
109+
The default blockchain data directory is ~/ain_blockchain_data (e.g. chain data will be at ~/ain_blockchain_data/chains). You can use a different directory by specifying the `BLOCKCHAIN_DATA_DIR` environment variable.
110+
109111
The default minimum size of the validator whitelist is 3. Change MIN_NUM_VALIDATORS parameter in
110112
the genesis-configs/base/genesis.json to change this value. You may also need to modify the GENESIS_WHITELIST and GENESIS_VALIDATORS accordingly.
111113
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:

client/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const process = require('process');
43
const express = require('express');
54
const jayson = require('jayson');
65
const _ = require('lodash');

client/protocol_versions.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,14 @@
3434
},
3535
"0.7.3": {
3636
"min": "0.7.0"
37+
},
38+
"0.7.4": {
39+
"min": "0.7.0"
40+
},
41+
"0.7.5": {
42+
"min": "0.7.0"
43+
},
44+
"0.7.6": {
45+
"min": "0.7.0"
3746
}
3847
}

common/constants.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const os = require('os');
12
const fs = require('fs');
23
const path = require('path');
34
const semver = require('semver');
@@ -63,7 +64,11 @@ if (!semver.valid(CONSENSUS_PROTOCOL_VERSION)) {
6364
throw Error('Wrong data version format is specified for CONSENSUS_PROTOCOL_VERSION');
6465
}
6566
const LOGS_DIR = path.resolve(__dirname, '../logs');
66-
const CHAINS_DIR = path.resolve(__dirname, '../chains');
67+
const BLOCKCHAIN_DATA_DIR = process.env.BLOCKCHAIN_DATA_DIR || path.resolve(__dirname, '../ain_blockchain_data');
68+
if (!fs.existsSync(BLOCKCHAIN_DATA_DIR)) {
69+
fs.mkdirSync(BLOCKCHAIN_DATA_DIR, { recursive: true });
70+
}
71+
const CHAINS_DIR = path.resolve(BLOCKCHAIN_DATA_DIR, 'chains');
6772
const CHAINS_N2B_DIR_NAME = 'n2b'; // NOTE: Block number to block.
6873
const CHAINS_H2N_DIR_NAME = 'h2n'; // NOTE: Block hash to block number.
6974
const HASH_DELIMITER = '#';
@@ -237,6 +242,7 @@ const AccountProperties = {
237242
const OwnerProperties = {
238243
ANYONE: '*',
239244
BRANCH_OWNER: 'branch_owner',
245+
FID_PREFIX: 'fid:',
240246
OWNER: '.owner',
241247
OWNERS: 'owners',
242248
WRITE_FUNCTION: 'write_function',
@@ -312,6 +318,7 @@ const NativeFunctionIds = {
312318
PAY: '_pay',
313319
RELEASE: '_release',
314320
SAVE_LAST_TX: '_saveLastTx',
321+
SET_OWNER_CONFIG: '_setOwnerConfig',
315322
STAKE: '_stake',
316323
TRANSFER: '_transfer',
317324
UNSTAKE: '_unstake',
@@ -645,6 +652,10 @@ function buildOwnerPermissions(branchOwner, writeFunction, writeOwner, writeRule
645652
};
646653
}
647654

655+
function buildRulePermission(rule) {
656+
return { [RuleProperties.WRITE]: rule };
657+
}
658+
648659
module.exports = {
649660
FeatureFlags,
650661
CURRENT_PROTOCOL_VERSION,
@@ -700,6 +711,7 @@ module.exports = {
700711
GenesisOwners,
701712
GasFeeConstants,
702713
buildOwnerPermissions,
714+
buildRulePermission,
703715
...GenesisParams.blockchain,
704716
...GenesisParams.consensus,
705717
...GenesisParams.resource,

common/network-util.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
const _ = require('lodash');
2+
const axios = require('axios');
3+
const logger = require('../logger')('NETWORK-UTIL');
4+
const {
5+
CURRENT_PROTOCOL_VERSION
6+
} = require('../common/constants');
7+
const ChainUtil = require('../common/chain-util');
8+
9+
10+
async function _waitUntilTxFinalize(endpoint, txHash) {
11+
while (true) {
12+
const confirmed = await sendGetRequest(
13+
endpoint,
14+
'ain_getTransactionByHash',
15+
{ hash: txHash }
16+
)
17+
.then((resp) => {
18+
return (_.get(resp, 'data.result.result.is_finalized', false) === true);
19+
})
20+
.catch((err) => {
21+
logger.error(`Failed to confirm transaction: ${err}`);
22+
return false;
23+
});
24+
if (confirmed) {
25+
return true;
26+
}
27+
await ChainUtil.sleep(1000);
28+
}
29+
}
30+
31+
async function sendTxAndWaitForFinalization(endpoint, tx, privateKey) {
32+
const res = await signAndSendTx(endpoint, tx, privateKey);
33+
if (_.get(res, 'errMsg', false) || !_.get(res, 'success', false)) {
34+
throw Error(`Failed to sign and send tx: ${res.errMsg}`);
35+
}
36+
if (!(await _waitUntilTxFinalize(endpoint, _.get(res, 'txHash', null)))) {
37+
throw Error('Transaction did not finalize in time.' +
38+
'Try selecting a different parent_chain_poc.');
39+
}
40+
}
41+
42+
async function sendSignedTx(endpoint, params) {
43+
return await axios.post(
44+
endpoint,
45+
{
46+
method: 'ain_sendSignedTransaction',
47+
params,
48+
jsonrpc: '2.0',
49+
id: 0
50+
}
51+
).then((resp) => {
52+
const result = _.get(resp, 'data.result.result.result', {});
53+
const success = !ChainUtil.isFailedTx(result);
54+
return { success, errMsg: result.error_message };
55+
}).catch((err) => {
56+
logger.error(`Failed to send transaction: ${err}`);
57+
return { success: false, errMsg: err.message };
58+
});
59+
}
60+
61+
// FIXME(minsulee2): this is duplicated function see: ./tools/util.js
62+
async function signAndSendTx(endpoint, tx, privateKey) {
63+
const { txHash, signedTx } = ChainUtil.signTransaction(tx, privateKey);
64+
const result = await sendSignedTx(endpoint, signedTx);
65+
return Object.assign(result, { txHash });
66+
}
67+
68+
function sendGetRequest(endpoint, method, params) {
69+
// NOTE(platfowner): .then() was used here to avoid some unexpected behavior of axios.post()
70+
// (see https://github.com/ainblockchain/ain-blockchain/issues/101)
71+
return axios.post(
72+
endpoint,
73+
{
74+
method,
75+
params: Object.assign(params, { protoVer: CURRENT_PROTOCOL_VERSION }),
76+
jsonrpc: '2.0',
77+
id: 0
78+
}
79+
).then((resp) => {
80+
return resp;
81+
}).catch((err) => {
82+
logger.error(`Failed to send get request: ${err}`);
83+
return null;
84+
});
85+
}
86+
87+
module.exports = {
88+
sendTxAndWaitForFinalization,
89+
sendSignedTx,
90+
signAndSendTx,
91+
sendGetRequest
92+
};

common/path-util.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ class PathUtil {
5454
return ChainUtil.formatPath([PredefinedDbPaths.MANAGE_APP, appName, PredefinedDbPaths.MANAGE_APP_CONFIG]);
5555
}
5656

57+
static getAppPath(appName) {
58+
return ChainUtil.formatPath([PredefinedDbPaths.APPS, appName]);
59+
}
60+
5761
static getAppAdminPathFromServiceAccountName(accountName) {
5862
return ruleUtil.getAppAdminPath(accountName);
5963
}

common/version-util.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ const {
44
} = require('../common/constants');
55

66
class VersionUtil {
7+
static isValidProtocolVersion(version) {
8+
if (!version || !semver.valid(version)) {
9+
return false;
10+
} else {
11+
return true;
12+
}
13+
}
14+
715
static isValidVersionMatch(ver) {
816
return ver && semver.valid(semver.coerce(ver.min)) &&
917
(!ver.max || semver.valid(semver.coerce(ver.max)));

consensus/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const {
3434
const {
3535
signAndSendTx,
3636
sendGetRequest
37-
} = require('../p2p/util');
37+
} = require('../common/network-util');
3838
const PathUtil = require('../common/path-util');
3939
const DB = require('../db');
4040
const VersionUtil = require('../common/version-util');

0 commit comments

Comments
 (0)