Skip to content

Commit

Permalink
Merge pull request #1186 from ainblockchain/bugfix/platfowner/bugfix
Browse files Browse the repository at this point in the history
Fix invalid receipts error with rest function call
  • Loading branch information
platfowner committed Jul 12, 2023
2 parents 2fba3d6 + 52416cf commit cd85d20
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 96 deletions.
50 changes: 0 additions & 50 deletions blockchain-configs/testnet-dev/timer_flags.json

This file was deleted.

2 changes: 1 addition & 1 deletion 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
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
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
2 changes: 1 addition & 1 deletion start_local_blockchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ printf "\n[[[[[ start_local_blockchain.sh ]]]]]\n\n"
printf "\nStarting tracker..\n"
PORT=8080 \
P2P_PORT=5000 \
CONSOLE_LOG=true \
CONSOLE_LOG=false \
node ./tracker-server/index.js &
printf "\nDone\n\n"
sleep 5
Expand Down
4 changes: 2 additions & 2 deletions start_local_blockchain_afan_shard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ printf "\n[[[[[ start_local_blockchain_afan_shard.sh ]]]]]\n\n"
printf "\nStarting parent tracker..\n"
PORT=8080 \
P2P_PORT=5000 \
CONSOLE_LOG=true \
CONSOLE_LOG=false \
node ./tracker-server/index.js &
printf "\nDone\n\n"
sleep 5
Expand Down Expand Up @@ -60,7 +60,7 @@ printf "\nStarting afan child chain tracker..\n"
BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/afan-shard \
PORT=9000 \
P2P_PORT=6000 \
CONSOLE_LOG=true \
CONSOLE_LOG=false \
node ./tracker-server/index.js &
printf "\nDone\n\n"
sleep 5
Expand Down
4 changes: 3 additions & 1 deletion start_local_blockchain_multi_shards.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ printf "\n[[[[[ start_local_blockchain_multi_shards.sh ]]]]]\n\n"
printf "\nStarting parent tracker..\n"
PORT=8080 \
P2P_PORT=5000 \
CONSOLE_LOG=true \
CONSOLE_LOG=false \
node ./tracker-server/index.js &
printf "\nDone\n\n"
sleep 5
Expand Down Expand Up @@ -64,6 +64,7 @@ printf "\nStarting child chain 1 tracker..\n"
BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/afan-shard \
PORT=9000 \
P2P_PORT=6000 \
CONSOLE_LOG=false \
node ./tracker-server/index.js &
printf "\nDone\n\n"
sleep 10
Expand Down Expand Up @@ -131,6 +132,7 @@ printf "\nStarting child chain 2 tracker..\n"
BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/sim-shard \
PORT=9010 \
P2P_PORT=6010 \
CONSOLE_LOG=false \
node ./tracker-server/index.js &
printf "\nDone\n\n"
sleep 10
Expand Down
2 changes: 1 addition & 1 deletion test/unit/functions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2723,7 +2723,7 @@ describe("Functions", () => {
return triggerRes.func_promises.then((resp) => {
assert.deepEqual(resp, {
func_count: 1,
trigger_count: 0,
trigger_count: 1,
fail_count: 0,
});
});
Expand Down

0 comments on commit cd85d20

Please sign in to comment.