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

Commit

Permalink
Merge branch 'main' into merge-1.9-rc
Browse files Browse the repository at this point in the history
  • Loading branch information
RetricSu committed Nov 30, 2022
2 parents 4a147c8 + a811315 commit a11c94b
Show file tree
Hide file tree
Showing 5 changed files with 513 additions and 9 deletions.
12 changes: 6 additions & 6 deletions docs/addtional-feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

## Instant Finality

Ethereum require a transaction to be on-chain(meaning the transaction is included in the latest block) before returning a final status(aka. transaction receipt) to users so they can know whether the transaction is success or not.
Ethereum requires a transaction to be on-chain (meaning the transaction is included in the latest block) before returning a transaction receipt with final status to users, so they know whether the transaction is success or not.

Godwoken provide a quicker way to confirm transaction. Once the transaction is validated in mempool, users can get instant transaction receipt. This feature is called Instant Finality.
Godwoken provide a faster way to confirm transaction. Once a transaction is verified in the mempool, the instant transaction receipt will be generated immediately. This feature is called `Instant Finality`.

If your want to build a low latency user experience for on-chain interaction in your dapp, you can turn on such feature by using the RPC with additional path or query parameter:
If you want to build a low latency user experience for on-chain interactions in your dApp, you could turn on `Instant Finality` feature by using the RPC **with additional path or query parameter**:

```sh
```bash
# http
https://example_web3_rpc_url?instant-finality-hack=true
https://example_web3_rpc_url/instant-finality-hack
Expand All @@ -17,6 +17,6 @@ https://example_web3_rpc_url/instant-finality-hack
ws://example_web3_rpc_url/ws?instant-finality-hack=true
```

Environment like [Hardhat](https://github.com/NomicFoundation/hardhat) will swallow the http url's query parameter, so you might want to use the `/instant-finality-hack` path to overcome that.
**Note**: Environments like [Hardhat](https://github.com/NomicFoundation/hardhat) will swallow the http url's query parameter, so you might want to use the `/instant-finality-hack` path to overcome that.

Also notice that under such mode, there might have some [compatibility issue](https://github.com/godwokenrises/godwoken-web3/issues/283) with Ethereum toolchain like `ether.js`. If you care more about the compatibility, please use the bare RPC url `https://example_web3_rpc_url`, which is consider to be most compatible with Ethereum.
Also notice that under `instant-finality-hack` mode, there might be some [compatibility issue](https://github.com/godwokenrises/godwoken-web3/issues/283) with Ethereum toolchain like `ether.js`. If you care more about the compatibility, please use the bare RPC url `https://example_web3_rpc_url`, which is considered to be most compatible with Ethereum.
9 changes: 9 additions & 0 deletions packages/api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
"@godwoken-web3/godwoken": "1.9.0",
"@ethersproject/bignumber": "^5.7.0",
"@newrelic/native-metrics": "^7.0.1",
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/exporter-jaeger": "^1.8.0",
"@opentelemetry/instrumentation-express": "^0.32.0",
"@opentelemetry/instrumentation-http": "^0.34.0",
"@opentelemetry/instrumentation-knex": "^0.31.0",
"@opentelemetry/instrumentation-redis-4": "^0.34.0",
"@opentelemetry/instrumentation-winston": "^0.31.0",
"@opentelemetry/propagator-jaeger": "^1.8.0",
"@opentelemetry/sdk-node": "^0.34.0",
"@sentry/node": "^6.11.0",
"axios": "^0.27.2",
"blake2b": "2.1.3",
Expand Down
3 changes: 3 additions & 0 deletions packages/api-server/src/app/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import { logger } from "../base/logger";
import { BlockEmitter } from "../block-emitter";
import { CKBPriceOracle } from "../price-oracle";
import { initSentry } from "../sentry";
import { startOpentelemetry } from "../opentelemetry";

const numCPUs = cpus().length;
const clusterCount = +(envConfig.clusterCount || 0);
const numOfCluster = clusterCount || numCPUs;

startOpentelemetry();

if (cluster.isMaster) {
logger.info(`Master ${process.pid} is running`);

Expand Down
62 changes: 62 additions & 0 deletions packages/api-server/src/opentelemetry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import process from "process";

import * as opentelemetry from "@opentelemetry/sdk-node";

import { ExpressInstrumentation } from "@opentelemetry/instrumentation-express";
import { HttpInstrumentation } from "@opentelemetry/instrumentation-http";
import { KnexInstrumentation } from "@opentelemetry/instrumentation-knex";
import { RedisInstrumentation } from "@opentelemetry/instrumentation-redis-4";
import { WinstonInstrumentation } from "@opentelemetry/instrumentation-winston";

import { JaegerExporter } from "@opentelemetry/exporter-jaeger";
import { JaegerPropagator } from "@opentelemetry/propagator-jaeger";

// TODO: We can remove this after upgrade sdk-node to 0.34
// Reference: https://github.com/open-telemetry/opentelemetry-js/pull/3388
const jaegerExporter = new JaegerExporter();
const jaegerPropagator = new JaegerPropagator();

// Configuration (sdk 0.34 or later):
// Disable:
// OTEL_TRACES_EXPORTER: none
//
// Example(jaeger):
// LOG_FORMAT: json (add trace id to log)
// OTEL_TRACES_EXPORTER: jaeger
// OTEL_PROPAGATORS: jaeger
// OTEL_EXPORTER_OTLP_PROTOCOL: grpc (default is http/protobuf)
// OTEL_EXPORTER_JAEGER_ENDPOINT: http://jaeger:14250
// OTEL_RESOURCE_ATTRIBUTES: service.name=web3-readonly1
//
// Reference: https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-sdk-node/README.md
const sdk = new opentelemetry.NodeSDK({
traceExporter: jaegerExporter,
textMapPropagator: jaegerPropagator,
instrumentations: [
new HttpInstrumentation(),
new RedisInstrumentation(),
new ExpressInstrumentation(),
new KnexInstrumentation(),
// Add trace_id, span_id and trace_flags to log entry
new WinstonInstrumentation(),
],
});

export function startOpentelemetry() {
sdk
.start()
.then(() => console.log("Opentelemetry tracing initialized"))
.catch((error) =>
console.log("Error initializing opentelemetry tracing", error)
);

process.on("SIGTERM", () => {
sdk
.shutdown()
.then(() => console.log("Opentelemetry Tracing terminated"))
.catch((error) =>
console.log("Error terminating opentelemetry tracing", error)
)
.finally(() => process.exit(0));
});
}
Loading

0 comments on commit a11c94b

Please sign in to comment.