Skip to content

Commit

Permalink
add: example for block producer
Browse files Browse the repository at this point in the history
  • Loading branch information
nitinmittal23 committed Aug 5, 2023
1 parent c9489b4 commit 0e14417
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 10 deletions.
8 changes: 0 additions & 8 deletions CONTRIBUTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ The end goal of review is to suggest useful improvements to the author. Reviews

Read more in [Review Guidelines](./REVIEW.md).

### Releases

1. All releases should be proposed in a PR and subject to community review for a minimum of one week.
1. During release review, the code is frozen unless new changes are proposed, approved and merged.
1. A release PR must be approved at least by two known contributors of the chainflow project.

Read more in [Release Guidelines](./RELEASE.md).

### Emergencies

Emergency releases are allowed to shorten waiting periods depending on the severity of the issue.
1 change: 1 addition & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Chainflow Example
12 changes: 12 additions & 0 deletions example/producer/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
RPC_WS_ENDPOINT_URL_LIST=
START_BLOCK=
KAFKA_CONNECTION_URL=
MONGO_URL=
PRODUCER_TOPIC=polygon.1.blocks

#LOGGER_ENV
SENTRY_DSN=
SENTRY_ENVIRONMENT=
DATADOG_API_KEY=
DATADOG_APP_KEY=

19 changes: 19 additions & 0 deletions example/producer/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
env: {
es2021: true,
node: true,
},
extends: [
'airbnb-base',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: [
'@typescript-eslint',
],
rules: {
},
};
File renamed without changes.
32 changes: 32 additions & 0 deletions example/producer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "ethereum-producer",
"version": "1.0.0",
"description": "",
"exports": "./dist/",
"type": "module",
"scripts": {
"tests": "echo here will be Unit test run",
"tests:integration": "echo 'Hello integration tests'",
"lint": "eslint src/**/*.ts",
"lint:fix": "eslint --fix ./src/**/*.ts",
"build": "tsup",
"start": "node --experimental-import-meta-resolve --trace-warnings dist/index.js",
"link:lib": "npm link @maticnetwork/chainflow",
"link:lib:build": "npm run link:lib && npm run build"
},
"author": "nitinmittal23",
"license": "ISC",
"dependencies": {
"dotenv": "^16.0.1",
"@maticnetwork/chainflow": "^1.0.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
"eslint": "^8.20.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"tsup": "^6.2.3",
"typescript": "^4.8.2"
}
}
37 changes: 37 additions & 0 deletions example/producer/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { produceBlocks } from "@maticnetwork/chainflow/block_producers/produce_blocks";
import { Logger } from "@maticnetwork/chainflow/logger";
import dotenv from 'dotenv';

dotenv.config();
Logger.create({
sentry: {
dsn: process.env.SENTRY_DSN,
level: 'error'
},
datadog: {
api_key: process.env.DATADOG_API_KEY,
service_name: process.env.DATADOG_APP_KEY
},
console: {
level: "debug"
}
});

const producer = produceBlocks({
startBlock: parseInt(process.env.START_BLOCK as string),
rpcWsEndpoints: process.env.RPC_WS_ENDPOINT_URL_LIST?.split(','),
topic: process.env.PRODUCER_TOPIC || "polygon.1.blocks",
maxReOrgDepth: 96,
maxRetries: 5,
mongoUrl: process.env.MONGO_URL,
blockSubscriptionTimeout: 120000,
"bootstrap.servers": process.env.KAFKA_CONNECTION_URL || "localhost:9092",
"security.protocol": "plaintext",
type: "erigon"
})

producer.on("blockProducer.fatalError", (error: any) => {
Logger.error(`Block producer exited. ${error.message}`);

process.exit(1); //Exiting process on fatal error. Process manager needs to restart the process.
});
14 changes: 14 additions & 0 deletions example/producer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "NodeNext",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"target": "esnext",
"moduleResolution": "nodenext",
"sourceMap": true,
"outDir": "dist",
"declaration": true,
"alwaysStrict": true,
"strict": true
}
}
14 changes: 14 additions & 0 deletions example/producer/tsup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: [
'./src/index.ts'
],
splitting: false,
sourcemap: true,
clean: true,
format: 'esm',
bundle: false,
platform: 'node',
dts: true
});
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
"bootstrap": "npx lerna bootstrap",
"prepublish": "yarn build",
"build": "tsc && tsc-alias",
"build:link": "npm run build && npm link",
"lint": "npx eslint \"./internal/**/*.ts\" \"./public/**/*.ts\"",
"lint:fix": "npx eslint --fix \"./internal/**/*.ts\" \"./public/**/*.ts\"",
"lint-tests:fix": "npx eslint --fix \"./tests/**/*.ts\"",
"publish:ci": "lerna publish from-package --yes",
"version:ci": "lerna version --yes --no-private --conventional-commits --create-release github --message 'chore(release): publish'"
"publish:ci": "npm publish from-package --yes",
"version:ci": "npm version --yes --no-private --conventional-commits --create-release github --message 'chore(release): publish'"
},
"author": "nitinmittal23",
"license": "UNLICENSED",
Expand Down

0 comments on commit 0e14417

Please sign in to comment.