Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #492 from nervosnetwork/1.6-rc
Browse files Browse the repository at this point in the history
chore: merge 1.6.1-rc1 into main
  • Loading branch information
RetricSu committed Aug 15, 2022
2 parents 17672b2 + b2eb5fc commit 702500b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 20 deletions.
46 changes: 33 additions & 13 deletions crates/indexer/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,19 +519,39 @@ impl Web3Indexer {
let tx_hash = ckb_types::H256::from_slice(gw_tx_hash.as_slice())?;
let tx_hash_hex = hex(tx_hash.as_bytes())
.unwrap_or_else(|_| format!("convert tx hash: {:?} to hex format failed", tx_hash));
let tx_receipt: TxReceipt = self
.godwoken_rpc_client
.get_transaction_receipt(&tx_hash)?
.ok_or_else(|| {
anyhow!(
"tx receipt not found by tx_hash: ({}) of block: {}, index: {}",
tx_hash_hex,
block_number,
tx_index
)
})?
.into();
Ok(tx_receipt)

let get_receipt = || -> Result<TxReceipt> {
let tx_receipt: TxReceipt = self
.godwoken_rpc_client
.get_transaction_receipt(&tx_hash)?
.ok_or_else(|| {
anyhow!(
"tx receipt not found by tx_hash: ({}) of block: {}, index: {}",
tx_hash_hex,
block_number,
tx_index
)
})?
.into();
Ok(tx_receipt)
};

let max_retry = 10;
let mut retry_times = 0;
while retry_times < max_retry {
let receipt = get_receipt();
match receipt {
Ok(tx_receipt) => return Ok(tx_receipt),
Err(err) => {
log::error!("{}", err);
retry_times += 1;
// sleep and retry
let sleep_time = std::time::Duration::from_secs(retry_times);
std::thread::sleep(sleep_time);
}
}
}
get_receipt()
}

async fn build_web3_block(
Expand Down
1 change: 1 addition & 0 deletions docker/indexer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ FROM ubuntu:focal
RUN apt-get update \
&& apt-get dist-upgrade -y \
&& apt-get install -y openssl \
&& apt-get install -y libcurl4 \
&& apt-get clean \
&& echo 'Finished installing OS updates'

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"eslint": "^8.5.0",
"prettier": "^2.2.1"
},
"version": "1.6.0-rc1",
"version": "1.6.1-rc1",
"author": "hupeng <bitrocks.hu@gmail.com>"
}
4 changes: 2 additions & 2 deletions packages/api-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@godwoken-web3/api-server",
"version": "1.6.0-rc1",
"version": "1.6.1-rc1",
"private": true,
"scripts": {
"start": "concurrently \"tsc -w\" \"nodemon ./bin/cluster\"",
Expand Down Expand Up @@ -32,7 +32,7 @@
"dependencies": {
"@ckb-lumos/base": "0.18.0-rc6",
"@ckb-lumos/toolkit": "0.18.0-rc6",
"@godwoken-web3/godwoken": "1.6.0-rc1",
"@godwoken-web3/godwoken": "1.6.1-rc1",
"@newrelic/native-metrics": "^7.0.1",
"@sentry/node": "^6.11.0",
"blake2b": "2.1.3",
Expand Down
21 changes: 18 additions & 3 deletions packages/api-server/src/methods/gw-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import { LogItem, PolyjuiceSystemLog } from "./types";
import { HexNumber, HexString } from "@ckb-lumos/base";
import { logger } from "../base/logger";

const gwVmMaxCycleExitCode = "0xff";
const gwVmMaxCycleErrMsg = "VM max cycle exceeded";
// we use 3(OUT_OF_GAS in evmcCodeTypeMapping) as vm_max_cycle_exceeded status code
const gwVmMaxCycleStatusCode = 3;

export const evmcCodeTypeMapping: {
[key: string]: string;
} = {
Expand Down Expand Up @@ -183,15 +188,25 @@ export function parseGwError(error: any): GwErrorDetail {
}

const returnData = err.data.return_data;
const statusReason: string = parseReturnData(returnData);

// when tx reach vm max cycles, evm status code is success
// but godwoken return err.data.exit_code = 0xff, we should handle such case
const statusReason: string =
err.data.exit_code === gwVmMaxCycleExitCode
? gwVmMaxCycleErrMsg
: parseReturnData(returnData);
const statusCode =
err.data.exit_code === gwVmMaxCycleExitCode
? gwVmMaxCycleStatusCode
: polyjuiceSystemLog?.statusCode;

return {
code: err.code,
message: err.message,
data: err.data,
polyjuiceSystemLog,
statusCode: polyjuiceSystemLog?.statusCode,
statusReason: statusReason,
statusCode,
statusReason,
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/godwoken/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@godwoken-web3/godwoken",
"version": "1.6.0-rc1",
"version": "1.6.1-rc1",
"private": true,
"main": "lib/index.js",
"scripts": {
Expand Down

0 comments on commit 702500b

Please sign in to comment.