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

chore: merge 1.5.1-rc2 into main #464

Merged
merged 15 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/godwoken-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ jobs:
MANUAL_BUILD_WEB3_INDEXER=true
WEB3_GIT_URL=https://github.com/${{ github.repository }}
WEB3_GIT_CHECKOUT=${{ github.ref }}
GODWOKEN_TESTS_REF=refs/pull/155/head
GODWOKEN_PREBUILD_IMAGE_NAME=ghcr.io/nervosnetwork/godwoken-prebuilds:1.4-rc-202207180528
GODWOKEN_PREBUILD_IMAGE_NAME=ghcr.io/nervosnetwork/godwoken-prebuilds:1.4.2-rc2-202207211420
11 changes: 9 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ jobs:
- uses: actions/checkout@v3
with:
repository: RetricSu/godwoken-kicker
ref: 'compatibility-changes'
ref: 'master'
- name: Kicker init
run: ./kicker init
- name: Kicker start
run: ./kicker start
run: |
# Temporary workaround unreliable web3 health check
(echo " == kicker start attempt: 1 == " && ./kicker start) || \
(echo " == kicker start attempt: 2 == " && ./kicker stop && ./kicker start) || \
(echo " == kicker start failed == " && docker-compose --file docker/docker-compose.yml logs --tail 6 && exit 1)
docker-compose --file docker/docker-compose.yml logs --tail 6
# FIXME: Sometimes, Godwoken service is not running
# https://github.com/Flouse/godwoken/runs/3639382192?check_suite_focus=true#step:8:667
- name: Kicker ps
run: sleep 60 && ./kicker ps && ./kicker logs web3
- name: Store kicker network information as environment variables
Expand Down
7 changes: 5 additions & 2 deletions crates/indexer/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,14 @@ impl Transaction {
s.append(&vec![0u8; 0]);
}
};
// r & s should be integer format in RLP
let r_num = U256::from(&self.r);
let s_num = U256::from(&self.s);
s.append(&self.value)
.append(&self.data)
.append(&self.add_chain_replay_protection())
.append(&self.r.to_vec())
.append(&self.s.to_vec());
.append(&r_num)
.append(&s_num);
s.finalize_unbounded_list();
s.out().freeze().to_vec()
}
Expand Down
2 changes: 1 addition & 1 deletion docker/indexer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN cargo install moleculec --version 0.7.2
COPY . /godwoken-web3
RUN cd /godwoken-web3 && rustup component add rustfmt && cargo build --release

FROM ubuntu:21.04
FROM ubuntu:focal

RUN apt-get update \
&& apt-get dist-upgrade -y \
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"eslint": "^8.5.0",
"prettier": "^2.2.1"
},
"version": "1.5.0-rc1",
"version": "1.5.1-rc2",
"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.5.0-rc1",
"version": "1.5.1-rc2",
"private": true,
"scripts": {
"start": "concurrently \"tsc -w\" \"nodemon ./bin/cluster\"",
Expand Down Expand Up @@ -31,7 +31,7 @@
"dependencies": {
"@ckb-lumos/base": "0.18.0-rc6",
"@ckb-lumos/toolkit": "0.18.0-rc6",
"@godwoken-web3/godwoken": "1.5.0-rc1",
"@godwoken-web3/godwoken": "1.5.1-rc2",
"@newrelic/native-metrics": "^7.0.1",
"@sentry/node": "^6.11.0",
"blake2b": "2.1.3",
Expand Down
40 changes: 27 additions & 13 deletions packages/api-server/src/convert-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ export function decodeRawTransactionData(

const [nonce, gasPrice, gasLimit, to, value, data, v, r, s] = resultHex;

// r & s is integer in RLP, convert to 32-byte hex string (add leading zeros)
const rWithLeadingZeros: HexString = "0x" + r.slice(2).padStart(64, "0");
const sWithLeadingZeros: HexString = "0x" + s.slice(2).padStart(64, "0");
const tx: PolyjuiceTransaction = {
nonce,
gasPrice,
Expand All @@ -116,13 +119,18 @@ export function decodeRawTransactionData(
value,
data,
v,
r,
s,
r: rWithLeadingZeros,
s: sWithLeadingZeros,
};

return tx;
}

export function getSignature(tx: PolyjuiceTransaction): HexString {
const realVWithoutPrefix = +tx.v % 2 === 0 ? "01" : "00";
return "0x" + tx.r.slice(2) + tx.s.slice(2) + realVWithoutPrefix;
}

function numberToRlpEncode(num: HexString): HexString {
if (num === "0x0" || num === "0x") {
return "0x";
Expand Down Expand Up @@ -166,10 +174,24 @@ function calcMessage(tx: PolyjuiceTransaction): HexString {
return message;
}

function toRlpNumber(num: HexNumber): bigint {
return num === "0x" ? 0n : BigInt(num);
}

function encodePolyjuiceTransaction(tx: PolyjuiceTransaction) {
const { nonce, gasPrice, gasLimit, to, value, data, v, r, s } = tx;

const beforeEncode = [nonce, gasPrice, gasLimit, to, value, data, v, r, s];
const beforeEncode = [
toRlpNumber(nonce),
toRlpNumber(gasPrice),
toRlpNumber(gasLimit),
to,
toRlpNumber(value),
data,
toRlpNumber(v),
toRlpNumber(r),
toRlpNumber(s),
];

const result = rlp.encode(beforeEncode);
return "0x" + result.toString("hex");
Expand All @@ -180,7 +202,7 @@ export async function parseRawTransactionData(
rpc: GodwokenClient,
polyjuiceRawTx: HexString
): Promise<[L2Transaction, [string, string] | undefined]> {
const { nonce, gasPrice, gasLimit, to, value, data, v, r: rA, s: sA } = rawTx;
const { nonce, gasPrice, gasLimit, to, value, data } = rawTx;

// Reject transactions with too large size
const rlpEncoded = encodePolyjuiceTransaction(rawTx);
Expand All @@ -205,15 +227,7 @@ export async function parseRawTransactionData(
);
}

const r = "0x" + rA.slice(2).padStart(64, "0");
const s = "0x" + sA.slice(2).padStart(64, "0");

let real_v = "0x00";
if (+v % 2 === 0) {
real_v = "0x01";
}

const signature = r + s.slice(2) + real_v.slice(2);
const signature: HexString = getSignature(rawTx);

const message = calcMessage(rawTx);

Expand Down
4 changes: 2 additions & 2 deletions packages/api-server/src/methods/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import {
calcEthTxHash,
decodeRawTransactionData,
generateRawTransaction,
getSignature,
parseRawTransactionData,
polyjuiceRawTransactionToApiTransaction,
PolyjuiceTransaction,
Expand Down Expand Up @@ -1253,8 +1254,7 @@ export class Eth {
fromAddress: HexString
): Promise<boolean> {
const tx: PolyjuiceTransaction = decodeRawTransactionData(rawTx);
const real_v = +tx.v % 2 === 0 ? "0x01" : "0x00";
const signature: HexString = tx.r + tx.s.slice(2) + real_v.slice(2);
const signature: HexString = getSignature(tx);
const signatureHash: Hash = utils
.ckbHash(new Reader(signature).toArrayBuffer())
.serializeJson();
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.5.0-rc1",
"version": "1.5.1-rc2",
"private": true,
"main": "lib/index.js",
"scripts": {
Expand Down