Skip to content

Commit

Permalink
Merge pull request #1193 from ainblockchain/release/v1.1.0
Browse files Browse the repository at this point in the history
Release/v1.1.0
  • Loading branch information
platfowner committed Jul 18, 2023
2 parents 6ec7f92 + 9b33b82 commit 0638959
Show file tree
Hide file tree
Showing 35 changed files with 1,208 additions and 235 deletions.
8 changes: 8 additions & 0 deletions blockchain-configs/base/timer_flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,13 @@
"update_min_gc_num_siblings_deleted": {
"enabled_block": 2,
"has_bandage": true
},
"update_min_gc_num_siblings_deleted2": {
"enabled_block": 2,
"has_bandage": true
},
"tweak_transfer_gc_rule": {
"enabled_block": 2,
"has_bandage": true
}
}
8 changes: 8 additions & 0 deletions blockchain-configs/mainnet-prod/timer_flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,13 @@
"update_min_gc_num_siblings_deleted": {
"enabled_block": 1414800,
"has_bandage": true
},
"update_min_gc_num_siblings_deleted2": {
"enabled_block": 2430100,
"has_bandage": true
},
"tweak_transfer_gc_rule": {
"enabled_block": 2430100,
"has_bandage": true
}
}
50 changes: 0 additions & 50 deletions blockchain-configs/testnet-dev/timer_flags.json

This file was deleted.

8 changes: 8 additions & 0 deletions blockchain-configs/testnet-prod/timer_flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,13 @@
"update_min_gc_num_siblings_deleted": {
"enabled_block": 1411300,
"has_bandage": true
},
"update_min_gc_num_siblings_deleted2": {
"enabled_block": 2429500,
"has_bandage": true
},
"tweak_transfer_gc_rule": {
"enabled_block": 2429500,
"has_bandage": true
}
}
3 changes: 2 additions & 1 deletion client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,8 @@ app.get('/get_config', (req, res) => {
/**
* Dev Client SET APIs (available to whitelisted IPs, if ENABLE_DEV_CLIENT_SET_API == true)
*/

// TODO(platfowner): Deprecate Dev Client SET APIs once the related test cases are migrated to
// json rpc APIs.
if (NodeConfigs.ENABLE_DEV_CLIENT_SET_API) {
app.post('/set_value', (req, res, next) => {
const beginTime = Date.now();
Expand Down
3 changes: 3 additions & 0 deletions client/protocol_versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,8 @@
},
"1.0.15": {
"min": "1.0.0"
},
"1.1.0": {
"min": "1.0.0"
}
}
14 changes: 10 additions & 4 deletions common/common-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ class CommonUtil {
// TODO(platfowner): Consider some code (e.g. IN_LOCKUP_PERIOD, INSUFFICIENT_BALANCE) no failure
// so that their transactions are not reverted.
static isFailedFuncResultCode(code) {
return code !== FunctionResultCode.SUCCESS;
return code !== FunctionResultCode.SUCCESS && code !== FunctionResultCode.SKIP;
}

static isAppPath(parsedPath) {
Expand Down Expand Up @@ -1057,15 +1057,19 @@ class CommonUtil {
static createTimerFlagEnabledBandageMap(timerFlags) {
const LOG_HEADER = 'createTimerFlagEnabledBandageMap';
const map = new Map();
console.log(`[${LOG_HEADER}] Registering bandage files:`);
if (process.env.LOG_BANDAGE_INFO) {
console.log(`[${LOG_HEADER}] Registering bandage files:`);
}
const flagNameList = Object.keys(timerFlags);
for (let i = 0; i < flagNameList.length; i++) {
const flagName = flagNameList[i];
const flag = timerFlags[flagName];
const enabledBlockNumber = CommonUtil.getEnabledBlockNumberFromTimerFlag(flag);
if (CommonUtil.isNumber(enabledBlockNumber) && flag['has_bandage'] === true) {
const bandageFilePath = path.resolve(__dirname, '../db/bandage-files', `${flagName}.js`);
console.log(`[${LOG_HEADER}] [${i}] Registering ${bandageFilePath}`);
if (process.env.LOG_BANDAGE_INFO) {
console.log(`[${LOG_HEADER}] [${i}] Registering ${bandageFilePath}`);
}
if (!fs.existsSync(bandageFilePath)) {
throw Error(`Missing bandage file: ${bandageFilePath}`);
}
Expand All @@ -1074,7 +1078,9 @@ class CommonUtil {
}
map.get(enabledBlockNumber).push(flagName);
} else {
console.log(`[${LOG_HEADER}] [${i}] Skipping for timer flag: ${flagName}`);
if (process.env.LOG_BANDAGE_INFO) {
console.log(`[${LOG_HEADER}] [${i}] Skipping for timer flag: ${flagName}`);
}
}
}
return map;
Expand Down
13 changes: 7 additions & 6 deletions common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,18 @@ function setNodeConfigs() {
NodeConfigs[param] = valFromNodeParams;
}
}
if (!fs.existsSync(NodeConfigs.BLOCKCHAIN_DATA_DIR)) {
const blockchainDataDirPath = path.resolve(__dirname, '..', NodeConfigs.BLOCKCHAIN_DATA_DIR);
if (!fs.existsSync(blockchainDataDirPath)) {
try {
fs.mkdirSync(NodeConfigs.BLOCKCHAIN_DATA_DIR, { recursive: true });
fs.mkdirSync(blockchainDataDirPath, { recursive: true });
} catch (e) {
console.log(e)
}
}
NodeConfigs.LOGS_DIR = path.resolve(NodeConfigs.BLOCKCHAIN_DATA_DIR, 'logs');
NodeConfigs.CHAINS_DIR = path.resolve(NodeConfigs.BLOCKCHAIN_DATA_DIR, 'chains');
NodeConfigs.SNAPSHOTS_ROOT_DIR = path.resolve(NodeConfigs.BLOCKCHAIN_DATA_DIR, 'snapshots');
NodeConfigs.KEYS_ROOT_DIR = path.resolve(NodeConfigs.BLOCKCHAIN_DATA_DIR, 'keys');
NodeConfigs.LOGS_DIR = path.resolve(blockchainDataDirPath, 'logs');
NodeConfigs.CHAINS_DIR = path.resolve(blockchainDataDirPath, 'chains');
NodeConfigs.SNAPSHOTS_ROOT_DIR = path.resolve(blockchainDataDirPath, 'snapshots');
NodeConfigs.KEYS_ROOT_DIR = path.resolve(blockchainDataDirPath, 'keys');
}
setNodeConfigs();

Expand Down
1 change: 1 addition & 0 deletions common/result-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const FailedTxPrecheckCodeSet = new Set([
// If they are altered and deployed, the full sync of the blockchain nodes can fail.
const FunctionResultCode = {
SUCCESS: 0,
SKIP: 20000, // Normal skip
FAILURE: 20001, // Normal failure
INTERNAL_ERROR: 20002, // Something went wrong but don't know why
// Transfer
Expand Down
2 changes: 1 addition & 1 deletion db/bandage-files/allow_non_negative_transfer_value_only.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
"write": "(auth.addr === $from || auth.fid === '_stake' || auth.fid === '_unstake' || auth.fid === '_pay' || auth.fid === '_claim' || auth.fid === '_hold' || auth.fid === '_release' || auth.fid === '_collectFee' || auth.fid === '_claimReward' || auth.fid === '_openCheckout' || auth.fid === '_closeCheckout' || auth.fid === '_closeCheckin') && !getValue('transfer/' + $from + '/' + $to + '/' + $key) && (util.isServAcntName($from, blockNumber) || util.isCksumAddr($from)) && (util.isServAcntName($to, blockNumber) || util.isCksumAddr($to)) && $from !== $to && util.isNumber(newData) && newData > 0 && util.getBalance($from, getValue) >= newData"
}
},
// From allow_lower_case_app_names_only bandage file.
// From allow_lower_case_app_names_only.js bandage file.
prevValue: {
".rule": {
"write": "(auth.addr === $from || auth.fid === '_stake' || auth.fid === '_unstake' || auth.fid === '_pay' || auth.fid === '_claim' || auth.fid === '_hold' || auth.fid === '_release' || auth.fid === '_collectFee' || auth.fid === '_claimReward' || auth.fid === '_openCheckout' || auth.fid === '_closeCheckout' || auth.fid === '_closeCheckin') && !getValue('transfer/' + $from + '/' + $to + '/' + $key) && (util.isServAcntName($from, blockNumber) || util.isCksumAddr($from)) && (util.isServAcntName($to, blockNumber) || util.isCksumAddr($to)) && $from !== $to && util.isNumber(newData) && util.getBalance($from, getValue) >= newData"
Expand Down
19 changes: 19 additions & 0 deletions db/bandage-files/tweak_transfer_gc_rule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
data: [
{
path: ['rules', 'transfer', '$from', '$to', '$key', '.rule' ],
value: {
"state": {
"gc_max_siblings": 10,
"gc_num_siblings_deleted": 10
}
},
prevValue: {
"state": {
"gc_max_siblings": 200,
"gc_num_siblings_deleted": 100
}
}
}
]
};
10 changes: 10 additions & 0 deletions db/bandage-files/update_min_gc_num_siblings_deleted2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
data: [
{
path: ['values', 'blockchain_params', 'resource', 'min_gc_num_siblings_deleted'],
value: 10,
// From update_min_gc_num_siblings_deleted.js bandage file.
prevValue: 20
}
]
};
86 changes: 46 additions & 40 deletions db/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,7 @@ class Functions {
}
} else if (functionEntry.function_type === FunctionTypes.REST) {
// NOTE: Skipped when the event source is null.
if (NodeConfigs.ENABLE_REST_FUNCTION_CALL &&
eventSource !== null &&
functionEntry.function_url) {
if (functionEntry.function_url) {
const restFunctionUrlWhitelist = this.db.getRestFunctionsUrlWhitelist();
if (!CommonUtil.isWhitelistedUrl(functionEntry.function_url, restFunctionUrlWhitelist)) {
// NOTE: Skipped when the function url is not in the whitelist.
Expand All @@ -255,43 +253,51 @@ class Functions {
`function_url '${functionEntry.function_url}' with:\n` +
formattedParams);
}
const newAuth = Object.assign(
{}, auth, { fid: functionEntry.function_id, fids: this.getFids() });
promises.push(axios.post(functionEntry.function_url, {
fid: functionEntry.function_id,
function: functionEntry,
valuePath,
functionPath,
value,
prevValue,
params,
timestamp,
executedAt,
transaction,
blockNumber,
blockTime,
options,
eventSource,
auth: newAuth,
chainId: blockchainParams.chainId,
networkId: blockchainParams.networkId,
}, {
timeout: NodeConfigs.REST_FUNCTION_CALL_TIMEOUT_MS
}).catch((error) => {
if (DevFlags.enableRichFunctionLogging) {
logger.error(
`Failed to trigger REST function [[ ${functionEntry.function_id} ]] of ` +
`function_url '${functionEntry.function_url}' with error: \n` +
`${JSON.stringify(error)}` +
formattedParams);
}
failCount++;
return true;
}));
funcResults[functionEntry.function_id] = {
code: FunctionResultCode.SUCCESS,
bandwidth_gas_amount: blockchainParams.restFunctionCallGasAmount,
};
if (NodeConfigs.ENABLE_REST_FUNCTION_CALL && eventSource !== null) {
const newAuth = Object.assign(
{}, auth, { fid: functionEntry.function_id, fids: this.getFids() });
promises.push(axios.post(functionEntry.function_url, {
fid: functionEntry.function_id,
function: functionEntry,
valuePath,
functionPath,
value,
prevValue,
params,
timestamp,
executedAt,
transaction,
blockNumber,
blockTime,
options,
eventSource,
auth: newAuth,
chainId: blockchainParams.chainId,
networkId: blockchainParams.networkId,
}, {
timeout: NodeConfigs.REST_FUNCTION_CALL_TIMEOUT_MS
}).catch((error) => {
if (DevFlags.enableRichFunctionLogging) {
logger.error(
`Failed to trigger REST function [[ ${functionEntry.function_id} ]] of ` +
`function_url '${functionEntry.function_url}' with error: \n` +
`${JSON.stringify(error)}` +
formattedParams);
}
failCount++;
return true;
}));
funcResults[functionEntry.function_id] = {
code: FunctionResultCode.SUCCESS,
bandwidth_gas_amount: blockchainParams.restFunctionCallGasAmount,
};
} else {
// Rest function trigger is skipped.
funcResults[functionEntry.function_id] = {
code: FunctionResultCode.SKIP,
bandwidth_gas_amount: blockchainParams.restFunctionCallGasAmount,
};
}
triggerCount++;
}
}
Expand Down
Loading

0 comments on commit 0638959

Please sign in to comment.