Skip to content

Commit

Permalink
Merge pull request #9 from kryptokrauts/feat/1.0.11-add-sync-message-…
Browse files Browse the repository at this point in the history
…block-interval-param

feat: added params for sync message interval and block finality
  • Loading branch information
mitch-lbw authored Apr 9, 2024
2 parents 5aa1fb1 + 6d29d8e commit 51be207
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .env_template
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
LOG_LEVEL=info
SYNC_MESSAGE_BLOCK_INTERVAL=60

# node API endpoint (http(s)://...)
EOSIO_NODE_API=
Expand All @@ -15,6 +16,8 @@ EOSIO_FETCH_BLOCK=true
EOSIO_FETCH_TRACES=true
# fetch deltas true/false
EOSIO_FETCH_DELTAS=true
# number of blocks until tx is final
EOSIO_NUM_BLOCKS_TO_FINALITY=180

# unique client_id for interacting with Kafka
KAFKA_CLIENT_ID=
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kryptokrauts/event-processor-node-lib",
"version": "1.0.10",
"version": "1.0.11",
"description": "Wrapper for ease listening on antelope blockchain based on @blockmatic/antelope-ship-reader",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -11,6 +11,8 @@
"scripts": {
"dev-aa": "env-cmd -f ./.env_local tsnd examples/atomicassets.ts | npx pino-pretty --colorize",
"dev-am": "env-cmd -f ./.env_local_am tsnd examples/atomicmarket.ts | npx pino-pretty --colorize",
"dev-service": "env-cmd -f ./.env_local_service tsnd examples/service.ts | npx pino-pretty --colorize",
"dev-audit": "env-cmd -f ./.env_local_audit tsnd examples/audit.ts | npx pino-pretty --colorize",
"lint": "eslint --ignore-path .eslintignore \"**/*.+(js|ts|tsx)\"",
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|json|ts|tsx)\"",
"format:check": "prettier -c .",
Expand Down
2 changes: 2 additions & 0 deletions src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Logger, pino } from 'pino';
dotenv.config();

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

export const EOSIO_CONFIG = {
start_block: Number(process.env.EOSIO_START_BLOCK),
Expand All @@ -15,6 +16,7 @@ export const EOSIO_CONFIG = {
fetch_block: process.env.EOSIO_FETCH_BLOCK !== 'false',
fetch_traces: process.env.EOSIO_FETCH_TRACES !== 'false',
fetch_deltas: process.env.EOSIO_FETCH_DELTAS !== 'false',
num_blocks_to_finality: Number(process.env.EOSIO_NUM_BLOCKS_TO_FINALITY || 180),
};

export const KAFKA_CONFIG: KafkaConfig = {
Expand Down
17 changes: 10 additions & 7 deletions src/eosio/ship-reader-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import {
EosioReaderConfig,
} from '@blockmatic/eosio-ship-reader';
import { takeWhile } from 'rxjs/operators';
import { EOSIO_CONFIG, getLogger, KAFKA_CONFIG, KAFKA_TOPIC_CONFIG } from '../common/config';
import {
EOSIO_CONFIG,
getLogger,
KAFKA_CONFIG,
KAFKA_TOPIC_CONFIG,
sync_message_block_interval,
} from '../common/config';
import {
ActionHandlerResult,
delta_whitelist,
Expand All @@ -21,9 +27,6 @@ const logger = getLogger('ship-reader-wrapper');
const signal_traps = ['SIGTERM', 'SIGINT', 'SIGUSR2'];
const error_types = ['unhandledRejection', 'uncaughtException'];

//current finality is 3 minutes, with a new block every 0.5s -> 360 blocks
const num_blocks_to_finality = 3 * 60 * 2;

export class ShipReaderWrapper {
config: ShipReaderWrapperConfig = undefined;
forked: boolean = false;
Expand Down Expand Up @@ -155,9 +158,9 @@ export class ShipReaderWrapper {
logger.trace(`Current block ${this.current_block}`);

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

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

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

0 comments on commit 51be207

Please sign in to comment.