Skip to content

Commit 51be207

Browse files
authored
Merge pull request #9 from kryptokrauts/feat/1.0.11-add-sync-message-block-interval-param
feat: added params for sync message interval and block finality
2 parents 5aa1fb1 + 6d29d8e commit 51be207

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

.env_template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
LOG_LEVEL=info
2+
SYNC_MESSAGE_BLOCK_INTERVAL=60
23

34
# node API endpoint (http(s)://...)
45
EOSIO_NODE_API=
@@ -15,6 +16,8 @@ EOSIO_FETCH_BLOCK=true
1516
EOSIO_FETCH_TRACES=true
1617
# fetch deltas true/false
1718
EOSIO_FETCH_DELTAS=true
19+
# number of blocks until tx is final
20+
EOSIO_NUM_BLOCKS_TO_FINALITY=180
1821

1922
# unique client_id for interacting with Kafka
2023
KAFKA_CLIENT_ID=

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kryptokrauts/event-processor-node-lib",
3-
"version": "1.0.10",
3+
"version": "1.0.11",
44
"description": "Wrapper for ease listening on antelope blockchain based on @blockmatic/antelope-ship-reader",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -11,6 +11,8 @@
1111
"scripts": {
1212
"dev-aa": "env-cmd -f ./.env_local tsnd examples/atomicassets.ts | npx pino-pretty --colorize",
1313
"dev-am": "env-cmd -f ./.env_local_am tsnd examples/atomicmarket.ts | npx pino-pretty --colorize",
14+
"dev-service": "env-cmd -f ./.env_local_service tsnd examples/service.ts | npx pino-pretty --colorize",
15+
"dev-audit": "env-cmd -f ./.env_local_audit tsnd examples/audit.ts | npx pino-pretty --colorize",
1416
"lint": "eslint --ignore-path .eslintignore \"**/*.+(js|ts|tsx)\"",
1517
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|json|ts|tsx)\"",
1618
"format:check": "prettier -c .",

src/common/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Logger, pino } from 'pino';
55
dotenv.config();
66

77
export const control_api_port = process.env.PORT || 8000;
8+
export const sync_message_block_interval = Number(process.env.SYNC_MESSAGE_BLOCK_INTERVAL || 60);
89

910
export const EOSIO_CONFIG = {
1011
start_block: Number(process.env.EOSIO_START_BLOCK),
@@ -15,6 +16,7 @@ export const EOSIO_CONFIG = {
1516
fetch_block: process.env.EOSIO_FETCH_BLOCK !== 'false',
1617
fetch_traces: process.env.EOSIO_FETCH_TRACES !== 'false',
1718
fetch_deltas: process.env.EOSIO_FETCH_DELTAS !== 'false',
19+
num_blocks_to_finality: Number(process.env.EOSIO_NUM_BLOCKS_TO_FINALITY || 180),
1820
};
1921

2022
export const KAFKA_CONFIG: KafkaConfig = {

src/eosio/ship-reader-wrapper.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import {
55
EosioReaderConfig,
66
} from '@blockmatic/eosio-ship-reader';
77
import { takeWhile } from 'rxjs/operators';
8-
import { EOSIO_CONFIG, getLogger, KAFKA_CONFIG, KAFKA_TOPIC_CONFIG } from '../common/config';
8+
import {
9+
EOSIO_CONFIG,
10+
getLogger,
11+
KAFKA_CONFIG,
12+
KAFKA_TOPIC_CONFIG,
13+
sync_message_block_interval,
14+
} from '../common/config';
915
import {
1016
ActionHandlerResult,
1117
delta_whitelist,
@@ -21,9 +27,6 @@ const logger = getLogger('ship-reader-wrapper');
2127
const signal_traps = ['SIGTERM', 'SIGINT', 'SIGUSR2'];
2228
const error_types = ['unhandledRejection', 'uncaughtException'];
2329

24-
//current finality is 3 minutes, with a new block every 0.5s -> 360 blocks
25-
const num_blocks_to_finality = 3 * 60 * 2;
26-
2730
export class ShipReaderWrapper {
2831
config: ShipReaderWrapperConfig = undefined;
2932
forked: boolean = false;
@@ -155,9 +158,9 @@ export class ShipReaderWrapper {
155158
logger.trace(`Current block ${this.current_block}`);
156159

157160
// since replaying blocks is much faster, check within greater block-span
158-
let syncStateCheckInterval: number = 10 * num_blocks_to_finality;
161+
let syncStateCheckInterval: number = 10 * sync_message_block_interval;
159162
if (logger.isLevelEnabled('trace') || this.reader_in_sync) {
160-
syncStateCheckInterval = num_blocks_to_finality;
163+
syncStateCheckInterval = sync_message_block_interval;
161164
}
162165

163166
if (block.block_num % syncStateCheckInterval === 0) {
@@ -219,7 +222,7 @@ export class ShipReaderWrapper {
219222
): Promise<void> {
220223
const head_block = Number(await getHeadBlockNum());
221224
const head_diff = head_block - current_block;
222-
this.reader_in_sync = head_diff - num_blocks_to_finality <= 0;
225+
this.reader_in_sync = head_diff - EOSIO_CONFIG.num_blocks_to_finality <= 0;
223226

224227
if (this.reader_in_sync) {
225228
logger.info('Reader is in sync with current block height');

0 commit comments

Comments
 (0)