From a8c4211bfabb4e8adc072c31f87d0b91ae3d9078 Mon Sep 17 00:00:00 2001 From: Vardan Nadkarni Date: Mon, 14 Aug 2023 17:59:44 +0530 Subject: [PATCH 1/7] :bug: Fixed deleted block logic and incorrect totalCommision --- services/blockchain-connector/methods/pos.js | 10 +--- .../blockchain-connector/shared/sdk/pos.js | 11 ++-- .../shared/database/schema/accountBalances.js | 2 +- .../shared/database/schema/blocks.js | 2 +- .../shared/database/schema/ccu.js | 3 +- .../shared/database/schema/eventTopics.js | 3 +- .../shared/database/schema/multisignature.js | 1 - .../shared/database/schema/transactions.js | 12 ++--- .../shared/database/schema/validators.js | 2 +- .../shared/indexer/blockchainIndex.js | 50 ++++++++++++++++++- .../shared/indexer/indexStatus.js | 2 +- .../pos/registerValidator.js | 24 +++++++++ .../shared/indexer/utils/events.js | 1 - .../shared/indexer/validatorIndex.js | 6 +-- 14 files changed, 98 insertions(+), 31 deletions(-) diff --git a/services/blockchain-connector/methods/pos.js b/services/blockchain-connector/methods/pos.js index e16079356d..4601bdf72a 100644 --- a/services/blockchain-connector/methods/pos.js +++ b/services/blockchain-connector/methods/pos.js @@ -82,16 +82,10 @@ module.exports = [ }, { name: 'getPoSGenesisStakers', - controller: async ({ height }) => getPoSGenesisStakers(height), - params: { - height: { optional: false, type: 'number' }, - }, + controller: async () => getPoSGenesisStakers(), }, { name: 'getPoSGenesisValidators', - controller: async ({ height }) => getPoSGenesisValidators(height), - params: { - height: { optional: false, type: 'number' }, - }, + controller: async () => getPoSGenesisValidators(), }, ]; diff --git a/services/blockchain-connector/shared/sdk/pos.js b/services/blockchain-connector/shared/sdk/pos.js index 369631917c..5bbec49a76 100644 --- a/services/blockchain-connector/shared/sdk/pos.js +++ b/services/blockchain-connector/shared/sdk/pos.js @@ -22,6 +22,7 @@ const { timeoutMessage, invokeEndpoint } = require('./client'); const { MODULE_NAME_POS } = require('./constants/names'); const { getBlockByHeight } = require('./blocks'); const regex = require('../utils/regex'); +const { getGenesisHeight } = require('./genesisBlock'); const logger = Logger(); @@ -138,9 +139,10 @@ const getPosLockedReward = async ({ address, tokenID }) => { } }; -const getPoSGenesisStakers = async (height) => { +const getPoSGenesisStakers = async () => { try { - const block = await getBlockByHeight(height, true); + const genesisHeight = await getGenesisHeight(); + const block = await getBlockByHeight(genesisHeight, true); const { stakers = [] } = (block.assets .find(asset => asset.module === MODULE_NAME_POS)).data; return stakers; @@ -152,9 +154,10 @@ const getPoSGenesisStakers = async (height) => { } }; -const getPoSGenesisValidators = async (height) => { +const getPoSGenesisValidators = async () => { try { - const block = await getBlockByHeight(height, true); + const genesisHeight = await getGenesisHeight(); + const block = await getBlockByHeight(genesisHeight, true); const { validators = [] } = (block.assets .find(asset => asset.module === MODULE_NAME_POS)).data; return validators; diff --git a/services/blockchain-indexer/shared/database/schema/accountBalances.js b/services/blockchain-indexer/shared/database/schema/accountBalances.js index 4fc3af6139..40c06ad889 100644 --- a/services/blockchain-indexer/shared/database/schema/accountBalances.js +++ b/services/blockchain-indexer/shared/database/schema/accountBalances.js @@ -19,7 +19,7 @@ module.exports = { schema: { address: { type: 'string', null: false }, tokenID: { type: 'string', null: false }, - balance: { type: 'bigInteger', null: false, default: BigInt('0') }, + balance: { type: 'bigInteger', null: false, defaultValue: BigInt('0') }, }, indexes: { address: { type: 'key' }, diff --git a/services/blockchain-indexer/shared/database/schema/blocks.js b/services/blockchain-indexer/shared/database/schema/blocks.js index 0a8b3de94c..568692406e 100644 --- a/services/blockchain-indexer/shared/database/schema/blocks.js +++ b/services/blockchain-indexer/shared/database/schema/blocks.js @@ -24,7 +24,7 @@ module.exports = { size: { type: 'integer' }, isFinal: { type: 'boolean', defaultValue: false }, assetsModules: { type: 'json' }, - numberOfEvents: { type: 'integer' }, + numberOfEvents: { type: 'integer', defaultValue: 0 }, reward: { type: 'bigInteger' }, }, indexes: { diff --git a/services/blockchain-indexer/shared/database/schema/ccu.js b/services/blockchain-indexer/shared/database/schema/ccu.js index c3ad39c2d1..ef66352218 100644 --- a/services/blockchain-indexer/shared/database/schema/ccu.js +++ b/services/blockchain-indexer/shared/database/schema/ccu.js @@ -13,13 +13,14 @@ * Removal or modification of this copyright notice is prohibited. * */ + module.exports = { tableName: 'ccu', primaryKey: 'transactionID', schema: { transactionID: { type: 'string', null: false }, height: { type: 'integer', null: false }, - sendingChainID: { type: 'string', null: true, default: null }, + sendingChainID: { type: 'string', null: true, defaultValue: null }, }, indexes: { height: { type: 'range' }, diff --git a/services/blockchain-indexer/shared/database/schema/eventTopics.js b/services/blockchain-indexer/shared/database/schema/eventTopics.js index e2c73d2f35..c04bd7ec83 100644 --- a/services/blockchain-indexer/shared/database/schema/eventTopics.js +++ b/services/blockchain-indexer/shared/database/schema/eventTopics.js @@ -15,9 +15,8 @@ */ module.exports = { tableName: 'event_topics', - primaryKey: 'tempID', + primaryKey: ['eventID', 'topic'], schema: { - tempID: { type: 'string' }, eventID: { type: 'string' }, topic: { type: 'string' }, height: { type: 'integer' }, diff --git a/services/blockchain-indexer/shared/database/schema/multisignature.js b/services/blockchain-indexer/shared/database/schema/multisignature.js index 3d565d585f..ca1528924b 100644 --- a/services/blockchain-indexer/shared/database/schema/multisignature.js +++ b/services/blockchain-indexer/shared/database/schema/multisignature.js @@ -22,7 +22,6 @@ module.exports = { memberAddress: { type: 'string' }, }, indexes: { - id: { type: 'key' }, groupAddress: { type: 'key' }, memberAddress: { type: 'key' }, }, diff --git a/services/blockchain-indexer/shared/database/schema/transactions.js b/services/blockchain-indexer/shared/database/schema/transactions.js index d2c4ccf5f0..f3dc4b6d9f 100644 --- a/services/blockchain-indexer/shared/database/schema/transactions.js +++ b/services/blockchain-indexer/shared/database/schema/transactions.js @@ -25,12 +25,12 @@ module.exports = { blockID: { type: 'string', null: false }, timestamp: { type: 'integer', null: false }, senderAddress: { type: 'string', null: false }, - recipientAddress: { type: 'string', null: true, default: null }, - tokenID: { type: 'string', null: true, default: null }, - amount: { type: 'bigInteger', null: true, default: null }, - receivingChainID: { type: 'string', null: true, default: null }, - messageFee: { type: 'bigInteger', null: true, default: null }, - data: { type: 'string', null: true, default: null }, + recipientAddress: { type: 'string', null: true, defaultValue: null }, + tokenID: { type: 'string', null: true, defaultValue: null }, + amount: { type: 'bigInteger', null: true, defaultValue: null }, + receivingChainID: { type: 'string', null: true, defaultValue: null }, + messageFee: { type: 'bigInteger', null: true, defaultValue: null }, + data: { type: 'string', null: true, defaultValue: null }, size: { type: 'integer', null: false }, fee: { type: 'bigInteger', null: false }, minFee: { type: 'bigInteger', null: false }, diff --git a/services/blockchain-indexer/shared/database/schema/validators.js b/services/blockchain-indexer/shared/database/schema/validators.js index dcae3b85c3..5e577c19a2 100644 --- a/services/blockchain-indexer/shared/database/schema/validators.js +++ b/services/blockchain-indexer/shared/database/schema/validators.js @@ -18,7 +18,7 @@ module.exports = { primaryKey: 'address', schema: { address: { type: 'string' }, - name: { type: 'string', null: true }, + name: { type: 'string' }, blsKey: { type: 'string', null: true }, proofOfPossession: { type: 'string', null: true }, generatorKey: { type: 'string', null: true }, diff --git a/services/blockchain-indexer/shared/indexer/blockchainIndex.js b/services/blockchain-indexer/shared/indexer/blockchainIndex.js index c75763cb57..08a9614fee 100644 --- a/services/blockchain-indexer/shared/indexer/blockchainIndex.js +++ b/services/blockchain-indexer/shared/indexer/blockchainIndex.js @@ -174,10 +174,12 @@ const indexBlock = async job => { block.generatorAddress, blockReward, commissionAmount, ); + logger.trace(`Incrementing validator commission with address ${block.generatorAddress} by ${commissionAmount}.`); await validatorsTable.increment({ increment: { totalCommission: BigInt(commissionAmount) }, where: { address: block.generatorAddress }, }, dbTrx); + logger.trace(`Incrementing validator self stake rewards with address ${block.generatorAddress} by ${selfStakeReward}.`); await validatorsTable.increment({ increment: { totalSelfStakeRewards: BigInt(selfStakeReward) }, where: { address: block.generatorAddress }, @@ -247,10 +249,16 @@ const deleteIndexedBlocks = async job => { const connection = await getDBConnection(MYSQL_ENDPOINT); const dbTrx = await startDBTransaction(connection); logger.trace(`Created new MySQL transaction to delete block(s) with ID(s): ${blockIDs}.`); + + let blockReward = BigInt('0'); + try { await BluebirdPromise.map( blocks, async block => { + const retrivedBlock = await getBlockByHeight(block.height); + if (retrivedBlock.id === block.id) return; + let { data: forkedTransactions } = await getTransactionsByBlockID(block.id); const transactionsTable = await getTransactionsTable(); const events = await getEventsByBlockID(block.id); @@ -285,6 +293,44 @@ const deleteIndexedBlocks = async job => { // Calculate locked amount change from events and update in key_value_store table if (events.length) { + const eventsTable = await getEventsTable(); + const eventTopicsTable = await getEventTopicsTable(); + + const { eventsInfo, eventTopicsInfo } = await getEventsInfoToIndex(block, events); + await eventsTable.delete(eventsInfo, dbTrx); + await eventTopicsTable.delete(eventTopicsInfo, dbTrx); + + // Update the generator's rewards + const blockRewardEvent = events.find( + e => [MODULE.REWARD, MODULE.DYNAMIC_REWARD].includes(e.module) + && e.name === EVENT.REWARD_MINTED, + ); + if (blockRewardEvent) { + blockReward = BigInt(blockRewardEvent.data.amount || '0'); + + if (blockReward !== BigInt('0')) { + const commissionAmount = await calcCommissionAmount( + block.generatorAddress, block.height, blockReward, + ); + const selfStakeReward = await calcSelfStakeReward( + block.generatorAddress, blockReward, commissionAmount, + ); + + const validatorsTable = await getValidatorsTable(); + logger.trace(`Decrementing validator commission with address ${block.generatorAddress} by ${commissionAmount}.`); + await validatorsTable.decrement({ + increment: { totalCommission: BigInt(commissionAmount) }, + where: { address: block.generatorAddress }, + }, dbTrx); + logger.trace(`Decrementing validator self stake rewards with address ${block.generatorAddress} by ${selfStakeReward}.`); + await validatorsTable.decrement({ + increment: { totalSelfStakeRewards: BigInt(selfStakeReward) }, + where: { address: block.generatorAddress }, + }, dbTrx); + } + } + + // Calculate locked amount change and update in key_value_store table for affected tokens const tokenIDLockedAmountChangeMap = {}; events.forEach(event => { const { data: eventData } = event; @@ -310,7 +356,9 @@ const deleteIndexedBlocks = async job => { // Invalidate cached events for this block // This must be done after processing all event related calculations await deleteEventsFromCache(block.height); - }); + }, + { concurrency: 1 }, + ); await blocksTable.deleteByPrimaryKey(blockIDs); await commitDBTransaction(dbTrx); diff --git a/services/blockchain-indexer/shared/indexer/indexStatus.js b/services/blockchain-indexer/shared/indexer/indexStatus.js index 1c0c204851..3a51dc3cda 100644 --- a/services/blockchain-indexer/shared/indexer/indexStatus.js +++ b/services/blockchain-indexer/shared/indexer/indexStatus.js @@ -119,7 +119,7 @@ const init = async () => { // Index stakers and commission information available in genesis block await indexValidatorCommissionInfo(genesisBlock); - await indexStakersInfo(genesisBlock); + await indexStakersInfo(); }; module.exports = { diff --git a/services/blockchain-indexer/shared/indexer/transactionProcessor/pos/registerValidator.js b/services/blockchain-indexer/shared/indexer/transactionProcessor/pos/registerValidator.js index c0f4e92d27..5d35828426 100644 --- a/services/blockchain-indexer/shared/indexer/transactionProcessor/pos/registerValidator.js +++ b/services/blockchain-indexer/shared/indexer/transactionProcessor/pos/registerValidator.js @@ -30,6 +30,7 @@ const MYSQL_ENDPOINT = config.endpoints.mysql; const accountsTableSchema = require('../../../database/schema/accounts'); const transactionsTableSchema = require('../../../database/schema/transactions'); const validatorsTableSchema = require('../../../database/schema/validators'); +const commissionsTableSchema = require('../../../database/schema/commissions'); const { getPosConstants } = require('../../../dataService'); const { requestConnector } = require('../../../utils/request'); @@ -37,10 +38,21 @@ const { requestConnector } = require('../../../utils/request'); const getAccountsTable = () => getTableInstance(accountsTableSchema, MYSQL_ENDPOINT); const getTransactionsTable = () => getTableInstance(transactionsTableSchema, MYSQL_ENDPOINT); const getValidatorsTable = () => getTableInstance(validatorsTableSchema, MYSQL_ENDPOINT); +const getCommissionsTable = () => getTableInstance(commissionsTableSchema, MYSQL_ENDPOINT); // Command specific constants const COMMAND_NAME = 'registerValidator'; +const getCommissionIndexingInfo = (blockHeader, tx) => { + const newCommissionEntry = { + address: getLisk32AddressFromPublicKey(tx.senderPublicKey), + commission: 10000, + height: blockHeader.height, + }; + + return newCommissionEntry; +}; + // eslint-disable-next-line no-unused-vars const applyTransaction = async (blockHeader, tx, events, dbTrx) => { if (tx.executionStatus !== TRANSACTION_STATUS.SUCCESS) return; @@ -48,6 +60,7 @@ const applyTransaction = async (blockHeader, tx, events, dbTrx) => { const accountsTable = await getAccountsTable(); const transactionsTable = await getTransactionsTable(); const validatorsTable = await getValidatorsTable(); + const commissionsTable = await getCommissionsTable(); const account = { address: getLisk32AddressFromPublicKey(tx.senderPublicKey), @@ -77,6 +90,11 @@ const applyTransaction = async (blockHeader, tx, events, dbTrx) => { logger.trace(`Indexing transaction ${tx.id} contained in block at height ${tx.height}.`); await transactionsTable.upsert(tx, dbTrx); logger.debug(`Indexed transaction ${tx.id} contained in block at height ${tx.height}.`); + + const commissionInfo = getCommissionIndexingInfo(blockHeader, tx); + logger.trace(`Indexing commission update for address ${commissionInfo.address} at height ${commissionInfo.height}.`); + await commissionsTable.upsert(commissionInfo, dbTrx); + logger.debug(`Indexed commission update for address ${commissionInfo.address} at height ${commissionInfo.height}.`); }; // eslint-disable-next-line no-unused-vars @@ -85,6 +103,7 @@ const revertTransaction = async (blockHeader, tx, events, dbTrx) => { const accountsTable = await getAccountsTable(); const validatorsTable = await getValidatorsTable(); + const commissionsTable = await getCommissionsTable(); // Remove the validator details from the table on transaction reversal const account = { @@ -105,6 +124,11 @@ const revertTransaction = async (blockHeader, tx, events, dbTrx) => { const validatorPK = account[validatorsTableSchema.primaryKey]; await validatorsTable.deleteByPrimaryKey(validatorPK, dbTrx); logger.debug(`Removed validator entry for address ${account.address}.`); + + const commissionInfo = getCommissionIndexingInfo(blockHeader, tx); + logger.trace(`Deleting commission entry for address ${commissionInfo.address} at height ${commissionInfo.height}.`); + await commissionsTable.delete(commissionInfo, dbTrx); + logger.debug(`Deleted commission entry for address ${commissionInfo.address} at height ${commissionInfo.height}.`); }; module.exports = { diff --git a/services/blockchain-indexer/shared/indexer/utils/events.js b/services/blockchain-indexer/shared/indexer/utils/events.js index 9b5e6886d5..d738c6d60f 100644 --- a/services/blockchain-indexer/shared/indexer/utils/events.js +++ b/services/blockchain-indexer/shared/indexer/utils/events.js @@ -70,7 +70,6 @@ const getEventsInfoToIndex = async (block, events) => { event.topics.forEach(topic => { const eventTopicInfo = { - tempID: event.id.concat(topic), eventID: event.id, height: block.height, name: event.name, diff --git a/services/blockchain-indexer/shared/indexer/validatorIndex.js b/services/blockchain-indexer/shared/indexer/validatorIndex.js index 53135a51ce..ca459b66c3 100644 --- a/services/blockchain-indexer/shared/indexer/validatorIndex.js +++ b/services/blockchain-indexer/shared/indexer/validatorIndex.js @@ -30,7 +30,7 @@ const getStakesTable = () => getTableInstance(stakesTableSchema, MYSQL_ENDPOINT) const indexValidatorCommissionInfo = async (genesisBlock) => { const commissionsTable = await getCommissionsTable(); - const validators = await requestConnector('getPoSGenesisValidators', { height: genesisBlock.height }); + const validators = await requestConnector('getPoSGenesisValidators'); const commissionInfo = validators.map(validator => ({ address: validator.address, height: genesisBlock.height, @@ -39,9 +39,9 @@ const indexValidatorCommissionInfo = async (genesisBlock) => { if (commissionInfo.length) await commissionsTable.upsert(commissionInfo); }; -const indexStakersInfo = async (genesisBlock) => { +const indexStakersInfo = async () => { const stakesTable = await getStakesTable(); - const stakers = await requestConnector('getPoSGenesisStakers', { height: genesisBlock.height }); + const stakers = await requestConnector('getPoSGenesisStakers'); const stakestoIndex = []; await stakers.forEach(async staker => staker.stakes.forEach(stake => { stakestoIndex.push({ From 7038b18732ce08f00af4a322a78075ca81206d86 Mon Sep 17 00:00:00 2001 From: Vardan Nadkarni Date: Mon, 14 Aug 2023 19:52:49 +0530 Subject: [PATCH 2/7] =?UTF-8?q?=E2=9A=99=20Updated=20default=20configurati?= =?UTF-8?q?on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/example.env | 8 +-- ecosystem.config.js | 111 ++++++++++++++++++------------------ ecosystem.jenkins.config.js | 30 +++++----- 3 files changed, 74 insertions(+), 75 deletions(-) diff --git a/docker/example.env b/docker/example.env index 2d6a7c8225..8e89666123 100644 --- a/docker/example.env +++ b/docker/example.env @@ -169,10 +169,10 @@ EXCHANGERATESAPI_IO_API_KEY= # EXPORT_S3_BUCKET_NAME_EXPORTS='exports' # SERVICE_BROKER_TIMEOUT=10 # SERVICE_LOG_LEVEL='info' -# SERVICE_LOG_CONSOLE='false' -# SERVICE_LOG_STDOUT='true' -# SERVICE_LOG_GELF='false' -# SERVICE_LOG_FILE='false' +# SERVICE_LOG_CONSOLE=false +# SERVICE_LOG_STDOUT=true +# SERVICE_LOG_GELF=false +# SERVICE_LOG_FILE=false # DOCKER_HOST='local' # EXPORT_S3_ENDPOINT='s3.amazonaws.com' # EXPORT_S3_ACCESS_KEY= diff --git a/ecosystem.config.js b/ecosystem.config.js index 3077c37fb6..1b98f94844 100644 --- a/ecosystem.config.js +++ b/ecosystem.config.js @@ -29,37 +29,36 @@ module.exports = { max_memory_restart: '300M', autorestart: true, env: { - PORT: '9901', + PORT: 9901, // --- Remember to set the properties below SERVICE_BROKER: 'redis://localhost:6379/0', SERVICE_GATEWAY_REDIS_VOLATILE: 'redis://localhost:6379/5', ENABLE_HTTP_API: 'http-status,http-version3,http-exports', ENABLE_WS_API: 'blockchain,rpc-v3', GATEWAY_DEPENDENCIES: 'indexer,connector', - WS_RATE_LIMIT_ENABLE: 'false', + WS_RATE_LIMIT_ENABLE: false, WS_RATE_LIMIT_CONNECTIONS: 5, WS_RATE_LIMIT_DURATION: 1, // in seconds - ENABLE_REQUEST_CACHING: 'true', - JSON_RPC_STRICT_MODE: 'false', - HTTP_RATE_LIMIT_ENABLE: 'false', + ENABLE_REQUEST_CACHING: true, + JSON_RPC_STRICT_MODE: false, + HTTP_RATE_LIMIT_ENABLE: false, HTTP_RATE_LIMIT_CONNECTIONS: 200, HTTP_RATE_LIMIT_WINDOW: 10, // in seconds HTTP_CACHE_CONTROL_DIRECTIVES: 'public, max-age=10', - ENABLE_HTTP_CACHE_CONTROL: 'true', - HTTP_RATE_LIMIT_ENABLE_X_FORWARDED_FOR: 'false', + ENABLE_HTTP_CACHE_CONTROL: true, + HTTP_RATE_LIMIT_ENABLE_X_FORWARDED_FOR: false, HTTP_RATE_LIMIT_NUM_KNOWN_PROXIES: 0, - // ENABLE_REVERSE_PROXY_TIMEOUT_SETTINGS: 'true' + // ENABLE_REVERSE_PROXY_TIMEOUT_SETTINGS: true, // HTTP_KEEP_ALIVE_TIMEOUT: 65000, // HTTP_HEADERS_TIMEOUT: 66000, // CORS_ALLOWED_ORIGIN: '*', - // PORT: 9901, // HOST: '0.0.0.0', // SERVICE_BROKER_TIMEOUT: 10, // SERVICE_LOG_LEVEL: 'info', - // SERVICE_LOG_CONSOLE: 'false', - // SERVICE_LOG_STDOUT: 'true', - // SERVICE_LOG_GELF: 'false', - // SERVICE_LOG_FILE: 'false', + // SERVICE_LOG_CONSOLE: false, + // SERVICE_LOG_STDOUT: true, + // SERVICE_LOG_GELF: false, + // SERVICE_LOG_FILE: false, // DOCKER_HOST: 'local', // JOB_INTERVAL_UPDATE_READINESS_STATUS: 0, // JOB_SCHEDULE_UPDATE_READINESS_STATUS: '* * * * *', @@ -81,13 +80,13 @@ module.exports = { // --- Remember to set the properties below SERVICE_BROKER: 'redis://localhost:6379/0', SERVICE_APP_REGISTRY_MYSQL: 'mysql://lisk:password@127.0.0.1:3306/lisk', - ENABLE_REBUILD_INDEX_AT_INIT: 'false', + ENABLE_REBUILD_INDEX_AT_INIT: false, // SERVICE_BROKER_TIMEOUT: 10, // SERVICE_LOG_LEVEL: 'info', - // SERVICE_LOG_CONSOLE: 'false', - // SERVICE_LOG_STDOUT: 'true', - // SERVICE_LOG_GELF: 'false', - // SERVICE_LOG_FILE: 'false', + // SERVICE_LOG_CONSOLE: false, + // SERVICE_LOG_STDOUT: true, + // SERVICE_LOG_GELF: false, + // SERVICE_LOG_FILE: false, // DOCKER_HOST: 'local', // GITHUB_APP_REGISTRY_REPO: 'https://github.com/LiskHQ/app-registry', // GITHUB_APP_REGISTRY_REPO_BRANCH: 'main', @@ -116,15 +115,15 @@ module.exports = { GEOIP_JSON: 'https://geoip.lisk.com/json', // ENABLE_BLOCK_CACHING: true, // EXPIRY_IN_HOURS: 12, - // USE_LISK_IPC_CLIENT: 'true', + // USE_LISK_IPC_CLIENT: true, // LISK_APP_DATA_PATH: '~/.lisk/lisk-core', - // ENABLE_TESTING_MODE: 'false', + // ENABLE_TESTING_MODE: false, // SERVICE_BROKER_TIMEOUT: 10, // SERVICE_LOG_LEVEL: 'info', - // SERVICE_LOG_CONSOLE: 'false', - // SERVICE_LOG_STDOUT: 'true', - // SERVICE_LOG_GELF: 'false', - // SERVICE_LOG_FILE: 'false', + // SERVICE_LOG_CONSOLE: false, + // SERVICE_LOG_STDOUT: true, + // SERVICE_LOG_GELF: false, + // SERVICE_LOG_FILE: false, // DOCKER_HOST: 'local', // GENESIS_BLOCK_URL: 'https://downloads.lisk.com/lisk/mainnet/genesis_block.json.tar.gz', // JOB_INTERVAL_CACHE_CLEANUP: 0, @@ -152,19 +151,19 @@ module.exports = { SERVICE_INDEXER_REDIS_VOLATILE: 'redis://localhost:6379/2', SERVICE_MESSAGE_QUEUE_REDIS: 'redis://localhost:6379/3', SERVICE_INDEXER_MYSQL: 'mysql://lisk:password@127.0.0.1:3306/lisk', - ENABLE_DATA_RETRIEVAL_MODE: 'true', - ENABLE_INDEXING_MODE: 'true', - ENABLE_PERSIST_EVENTS: 'false', - // ENABLE_APPLY_SNAPSHOT: 'false', + ENABLE_DATA_RETRIEVAL_MODE: true, + ENABLE_INDEXING_MODE: true, + ENABLE_PERSIST_EVENTS: false, + // ENABLE_APPLY_SNAPSHOT: false, // INDEX_SNAPSHOT_URL: '', - // ENABLE_SNAPSHOT_ALLOW_INSECURE_HTTP: 'true', + // ENABLE_SNAPSHOT_ALLOW_INSECURE_HTTP: true, // SERVICE_INDEXER_MYSQL_READ_REPLICA: 'mysql://lisk:password@127.0.0.1:3306/lisk', // SERVICE_BROKER_TIMEOUT: 10, // SERVICE_LOG_LEVEL: 'info', - // SERVICE_LOG_CONSOLE: 'false', - // SERVICE_LOG_STDOUT: 'true', - // SERVICE_LOG_GELF: 'false', - // SERVICE_LOG_FILE: 'false', + // SERVICE_LOG_CONSOLE: false, + // SERVICE_LOG_STDOUT: true, + // SERVICE_LOG_GELF: false, + // SERVICE_LOG_FILE: false, // DOCKER_HOST: 'local', // MAINCHAIN_SERVICE_URL: 'https://service.lisk.com', // LISK_STATIC: 'https://static-data.lisk.com', @@ -206,10 +205,10 @@ module.exports = { SERVICE_MESSAGE_QUEUE_REDIS: 'redis://localhost:6379/3', // SERVICE_BROKER_TIMEOUT: 10, // SERVICE_LOG_LEVEL: 'info', - // SERVICE_LOG_CONSOLE: 'false', - // SERVICE_LOG_STDOUT: 'true', - // SERVICE_LOG_GELF: 'false', - // SERVICE_LOG_FILE: 'false', + // SERVICE_LOG_CONSOLE: false, + // SERVICE_LOG_STDOUT: true, + // SERVICE_LOG_GELF: false, + // SERVICE_LOG_FILE: false, // DOCKER_HOST: 'local', // JOB_INTERVAL_INDEX_MISSING_BLOCKS: 0, // JOB_SCHEDULE_INDEX_MISSING_BLOCKS: '*/15 * * * *', @@ -231,8 +230,8 @@ module.exports = { // --- Remember to set the properties below SERVICE_BROKER: 'redis://localhost:6379/0', SERVICE_FEE_ESTIMATOR_CACHE: 'redis://localhost:6379/1', - ENABLE_FEE_ESTIMATOR_QUICK: 'true', - ENABLE_FEE_ESTIMATOR_FULL: 'false', + ENABLE_FEE_ESTIMATOR_QUICK: true, + ENABLE_FEE_ESTIMATOR_FULL: false, // FEE_EST_COLD_START_BATCH_SIZE: 1, // FEE_EST_DEFAULT_START_BLOCK_HEIGHT: 1, // FEE_EST_EMA_BATCH_SIZE: 20, @@ -240,10 +239,10 @@ module.exports = { // FEE_EST_WAVG_DECAY_PERCENTAGE: 10, // SERVICE_BROKER_TIMEOUT: 10, // SERVICE_LOG_LEVEL: 'info', - // SERVICE_LOG_CONSOLE: 'false', - // SERVICE_LOG_STDOUT: 'true', - // SERVICE_LOG_GELF: 'false', - // SERVICE_LOG_FILE: 'false', + // SERVICE_LOG_CONSOLE: false, + // SERVICE_LOG_STDOUT: true, + // SERVICE_LOG_GELF: false, + // SERVICE_LOG_FILE: false, // DOCKER_HOST: 'local', }, @@ -265,14 +264,14 @@ module.exports = { SERVICE_BROKER: 'redis://localhost:6379/0', SERVICE_STATISTICS_REDIS: 'redis://localhost:6379/1', SERVICE_STATISTICS_MYSQL: 'mysql://lisk:password@127.0.0.1:3306/lisk', - TRANSACTION_STATS_HISTORY_LENGTH_DAYS: '366', + TRANSACTION_STATS_HISTORY_LENGTH_DAYS: 366, // SERVICE_STATISTICS_MYSQL_READ_REPLICA: 'mysql://reader:password@127.0.0.1:3307/lisk', // SERVICE_BROKER_TIMEOUT: 10, // SERVICE_LOG_LEVEL: 'info', - // SERVICE_LOG_CONSOLE: 'false', - // SERVICE_LOG_STDOUT: 'true', - // SERVICE_LOG_GELF: 'false', - // SERVICE_LOG_FILE: 'false', + // SERVICE_LOG_CONSOLE: false, + // SERVICE_LOG_STDOUT: true, + // SERVICE_LOG_GELF: false, + // SERVICE_LOG_FILE: false, // DOCKER_HOST: 'local', // JOB_INTERVAL_REFRESH_TRANSACTION_STATS: 0, // JOB_SCHEDULE_REFRESH_TRANSACTION_STATS: '*/30 * * * *', @@ -301,10 +300,10 @@ module.exports = { // EXCHANGERATESAPI_IO_API_KEY: '' // SERVICE_BROKER_TIMEOUT: 10, // SERVICE_LOG_LEVEL: 'info', - // SERVICE_LOG_CONSOLE: 'false', - // SERVICE_LOG_STDOUT: 'true', - // SERVICE_LOG_GELF: 'false', - // SERVICE_LOG_FILE: 'false', + // SERVICE_LOG_CONSOLE: false, + // SERVICE_LOG_STDOUT: true, + // SERVICE_LOG_GELF: false, + // SERVICE_LOG_FILE: false, // DOCKER_HOST: 'local', // JOB_INTERVAL_REFRESH_PRICES_BINANCE: 0, // JOB_SCHEDULE_REFRESH_PRICES_BINANCE: '* * * * *', @@ -340,10 +339,10 @@ module.exports = { // EXPORT_S3_BUCKET_NAME_EXPORTS: 'exports', // SERVICE_BROKER_TIMEOUT: 10, // SERVICE_LOG_LEVEL: 'info', - // SERVICE_LOG_CONSOLE: 'false', - // SERVICE_LOG_STDOUT: 'true', - // SERVICE_LOG_GELF: 'false', - // SERVICE_LOG_FILE: 'false', + // SERVICE_LOG_CONSOLE: false, + // SERVICE_LOG_STDOUT: true, + // SERVICE_LOG_GELF: false, + // SERVICE_LOG_FILE: false, // DOCKER_HOST: 'local', // EXPORT_S3_ENDPOINT: 's3.amazonaws.com', // EXPORT_S3_ACCESS_KEY: '', diff --git a/ecosystem.jenkins.config.js b/ecosystem.jenkins.config.js index c51074e877..65fb10acc3 100644 --- a/ecosystem.jenkins.config.js +++ b/ecosystem.jenkins.config.js @@ -29,22 +29,22 @@ module.exports = { max_memory_restart: '300M', autorestart: true, env: { - PORT: '9901', + PORT: 9901, SERVICE_BROKER: 'redis://localhost:6379/0', SERVICE_GATEWAY_REDIS_VOLATILE: 'redis://localhost:6379/3', ENABLE_HTTP_API: 'http-status,http-version3,http-exports', ENABLE_WS_API: 'blockchain,rpc-v3', GATEWAY_DEPENDENCIES: 'indexer,connector', - WS_RATE_LIMIT_ENABLE: 'false', + WS_RATE_LIMIT_ENABLE: false, WS_RATE_LIMIT_CONNECTIONS: 5, WS_RATE_LIMIT_DURATION: 1, // in seconds - ENABLE_REQUEST_CACHING: 'true', - JSON_RPC_STRICT_MODE: 'false', - HTTP_RATE_LIMIT_ENABLE: 'false', + ENABLE_REQUEST_CACHING: true, + JSON_RPC_STRICT_MODE: false, + HTTP_RATE_LIMIT_ENABLE: false, HTTP_RATE_LIMIT_CONNECTIONS: 200, HTTP_RATE_LIMIT_WINDOW: 10, // in seconds HTTP_CACHE_CONTROL_DIRECTIVES: 'public, max-age=10', - ENABLE_HTTP_CACHE_CONTROL: 'true', + ENABLE_HTTP_CACHE_CONTROL: true, }, }, { @@ -63,7 +63,7 @@ module.exports = { // --- Remember to set the properties below SERVICE_BROKER: 'redis://localhost:6379/0', SERVICE_APP_REGISTRY_MYSQL: 'mysql://lisk:password@127.0.0.1:3306/lisk', - ENABLE_REBUILD_INDEX_AT_INIT: 'false', + ENABLE_REBUILD_INDEX_AT_INIT: false, }, }, { @@ -83,9 +83,9 @@ module.exports = { SERVICE_BROKER: 'redis://localhost:6379/0', LISK_APP_WS: 'ws://localhost:7887', GEOIP_JSON: 'https://geoip.lisk.com/json', - // USE_LISK_IPC_CLIENT: 'true', + // USE_LISK_IPC_CLIENT: true, // LISK_APP_DATA_PATH: '~/.lisk/lisk-core', - ENABLE_TESTING_MODE: 'true', + ENABLE_TESTING_MODE: true, }, }, { @@ -107,9 +107,9 @@ module.exports = { SERVICE_INDEXER_REDIS_VOLATILE: 'redis://localhost:6379/2', SERVICE_MESSAGE_QUEUE_REDIS: 'redis://localhost:6379/3', SERVICE_INDEXER_MYSQL: 'mysql://lisk:password@127.0.0.1:3306/lisk', - ENABLE_DATA_RETRIEVAL_MODE: 'true', - ENABLE_INDEXING_MODE: 'true', - ENABLE_PERSIST_EVENTS: 'false', + ENABLE_DATA_RETRIEVAL_MODE: true, + ENABLE_INDEXING_MODE: true, + ENABLE_PERSIST_EVENTS: false, }, }, { @@ -146,8 +146,8 @@ module.exports = { // --- Remember to set the properties below SERVICE_BROKER: 'redis://localhost:6379/0', SERVICE_FEE_ESTIMATOR_CACHE: 'redis://localhost:6379/1', - ENABLE_FEE_ESTIMATOR_QUICK: 'true', - ENABLE_FEE_ESTIMATOR_FULL: 'false', + ENABLE_FEE_ESTIMATOR_QUICK: true, + ENABLE_FEE_ESTIMATOR_FULL: false, }, }, { @@ -167,7 +167,7 @@ module.exports = { SERVICE_BROKER: 'redis://localhost:6379/0', SERVICE_STATISTICS_REDIS: 'redis://localhost:6379/1', SERVICE_STATISTICS_MYSQL: 'mysql://lisk:password@127.0.0.1:3306/lisk', - TRANSACTION_STATS_HISTORY_LENGTH_DAYS: '366', + TRANSACTION_STATS_HISTORY_LENGTH_DAYS: 366, }, }, { From 07b2fb044c833abb8af658706ea5831fb50672a3 Mon Sep 17 00:00:00 2001 From: Vardan Nadkarni Date: Tue, 15 Aug 2023 21:56:13 +0530 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=94=A8=20Corrected=20variable=20names?= =?UTF-8?q?=20and=20added=20logs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecosystem.config.js | 3 ++- services/blockchain-connector/methods/pos.js | 2 ++ .../shared/database/schema/blocks.js | 2 +- .../shared/database/schema/ccu.js | 1 - .../shared/indexer/blockchainIndex.js | 14 +++++++++----- .../shared/indexer/indexStatus.js | 8 +------- .../transactionProcessor/pos/registerValidator.js | 1 + .../shared/indexer/validatorIndex.js | 14 ++++++++++---- 8 files changed, 26 insertions(+), 19 deletions(-) diff --git a/ecosystem.config.js b/ecosystem.config.js index 1b98f94844..6266e2870e 100644 --- a/ecosystem.config.js +++ b/ecosystem.config.js @@ -29,7 +29,6 @@ module.exports = { max_memory_restart: '300M', autorestart: true, env: { - PORT: 9901, // --- Remember to set the properties below SERVICE_BROKER: 'redis://localhost:6379/0', SERVICE_GATEWAY_REDIS_VOLATILE: 'redis://localhost:6379/5', @@ -54,6 +53,8 @@ module.exports = { // CORS_ALLOWED_ORIGIN: '*', // HOST: '0.0.0.0', // SERVICE_BROKER_TIMEOUT: 10, + // HOST: '0.0.0.0', + // PORT: 9901, // SERVICE_LOG_LEVEL: 'info', // SERVICE_LOG_CONSOLE: false, // SERVICE_LOG_STDOUT: true, diff --git a/services/blockchain-connector/methods/pos.js b/services/blockchain-connector/methods/pos.js index 4601bdf72a..53d2f3c577 100644 --- a/services/blockchain-connector/methods/pos.js +++ b/services/blockchain-connector/methods/pos.js @@ -83,9 +83,11 @@ module.exports = [ { name: 'getPoSGenesisStakers', controller: async () => getPoSGenesisStakers(), + params: {}, }, { name: 'getPoSGenesisValidators', controller: async () => getPoSGenesisValidators(), + params: {}, }, ]; diff --git a/services/blockchain-indexer/shared/database/schema/blocks.js b/services/blockchain-indexer/shared/database/schema/blocks.js index 568692406e..a84234a70d 100644 --- a/services/blockchain-indexer/shared/database/schema/blocks.js +++ b/services/blockchain-indexer/shared/database/schema/blocks.js @@ -25,7 +25,7 @@ module.exports = { isFinal: { type: 'boolean', defaultValue: false }, assetsModules: { type: 'json' }, numberOfEvents: { type: 'integer', defaultValue: 0 }, - reward: { type: 'bigInteger' }, + reward: { type: 'bigInteger', defaultValue: BigInt('0') }, }, indexes: { id: { type: 'key' }, diff --git a/services/blockchain-indexer/shared/database/schema/ccu.js b/services/blockchain-indexer/shared/database/schema/ccu.js index ef66352218..7fd308ba67 100644 --- a/services/blockchain-indexer/shared/database/schema/ccu.js +++ b/services/blockchain-indexer/shared/database/schema/ccu.js @@ -13,7 +13,6 @@ * Removal or modification of this copyright notice is prohibited. * */ - module.exports = { tableName: 'ccu', primaryKey: 'transactionID', diff --git a/services/blockchain-indexer/shared/indexer/blockchainIndex.js b/services/blockchain-indexer/shared/indexer/blockchainIndex.js index 08a9614fee..0cd8e73082 100644 --- a/services/blockchain-indexer/shared/indexer/blockchainIndex.js +++ b/services/blockchain-indexer/shared/indexer/blockchainIndex.js @@ -174,16 +174,18 @@ const indexBlock = async job => { block.generatorAddress, blockReward, commissionAmount, ); - logger.trace(`Incrementing validator commission with address ${block.generatorAddress} by ${commissionAmount}.`); + logger.trace(`Increasing commission for validator ${block.generatorAddress} by ${commissionAmount}.`); await validatorsTable.increment({ increment: { totalCommission: BigInt(commissionAmount) }, where: { address: block.generatorAddress }, }, dbTrx); - logger.trace(`Incrementing validator self stake rewards with address ${block.generatorAddress} by ${selfStakeReward}.`); + logger.debug(`Increased commission for validator ${block.generatorAddress} by ${commissionAmount}.`); + logger.trace(`Increasing self-stake rewards for validator ${block.generatorAddress} by ${commissionAmount}.`); await validatorsTable.increment({ increment: { totalSelfStakeRewards: BigInt(selfStakeReward) }, where: { address: block.generatorAddress }, }, dbTrx); + logger.debug(`Increased self-stake rewards for validator ${block.generatorAddress} by ${commissionAmount}.`); } } @@ -218,7 +220,7 @@ const indexBlock = async job => { await blocksTable.upsert(blockToIndex, dbTrx); await commitDBTransaction(dbTrx); - logger.debug(`Committed MySQL transaction to index block ${block.id} at height ${block.height}.`); + logger.info(`Committed MySQL transaction to index block ${block.id} at height ${block.height}.`); } catch (error) { await rollbackDBTransaction(dbTrx); logger.debug(`Rolled back MySQL transaction to index block ${block.id} at height ${block.height}.`); @@ -317,16 +319,18 @@ const deleteIndexedBlocks = async job => { ); const validatorsTable = await getValidatorsTable(); - logger.trace(`Decrementing validator commission with address ${block.generatorAddress} by ${commissionAmount}.`); + logger.trace(`Decreasing commission for validator ${block.generatorAddress} by ${commissionAmount}.`); await validatorsTable.decrement({ increment: { totalCommission: BigInt(commissionAmount) }, where: { address: block.generatorAddress }, }, dbTrx); - logger.trace(`Decrementing validator self stake rewards with address ${block.generatorAddress} by ${selfStakeReward}.`); + logger.debug(`Decreased commission for validator ${block.generatorAddress} by ${commissionAmount}.`); + logger.trace(`Decreasing self-stake rewards for validator ${block.generatorAddress} by ${selfStakeReward}.`); await validatorsTable.decrement({ increment: { totalSelfStakeRewards: BigInt(selfStakeReward) }, where: { address: block.generatorAddress }, }, dbTrx); + logger.debug(`Decreased self-stake rewards for validator ${block.generatorAddress} by ${selfStakeReward}.`); } } diff --git a/services/blockchain-indexer/shared/indexer/indexStatus.js b/services/blockchain-indexer/shared/indexer/indexStatus.js index 3a51dc3cda..db4b168ee2 100644 --- a/services/blockchain-indexer/shared/indexer/indexStatus.js +++ b/services/blockchain-indexer/shared/indexer/indexStatus.js @@ -30,10 +30,6 @@ const { updateFinalizedHeight, } = require('../constants'); -const { - getBlockByHeight, -} = require('../dataService'); - const logger = Logger(); const blocksTableSchema = require('../database/schema/blocks'); @@ -115,10 +111,8 @@ const init = async () => { Signals.get('newBlock').add(checkIndexReadiness); Signals.get('chainNewBlock').add(updateFinalizedHeight); - const genesisBlock = await getBlockByHeight(await getGenesisHeight()); - // Index stakers and commission information available in genesis block - await indexValidatorCommissionInfo(genesisBlock); + await indexValidatorCommissionInfo(); await indexStakersInfo(); }; diff --git a/services/blockchain-indexer/shared/indexer/transactionProcessor/pos/registerValidator.js b/services/blockchain-indexer/shared/indexer/transactionProcessor/pos/registerValidator.js index 5d35828426..3d44cfc38a 100644 --- a/services/blockchain-indexer/shared/indexer/transactionProcessor/pos/registerValidator.js +++ b/services/blockchain-indexer/shared/indexer/transactionProcessor/pos/registerValidator.js @@ -44,6 +44,7 @@ const getCommissionsTable = () => getTableInstance(commissionsTableSchema, MYSQL const COMMAND_NAME = 'registerValidator'; const getCommissionIndexingInfo = (blockHeader, tx) => { + // TODO: Fetch default commission value from node. const newCommissionEntry = { address: getLisk32AddressFromPublicKey(tx.senderPublicKey), commission: 10000, diff --git a/services/blockchain-indexer/shared/indexer/validatorIndex.js b/services/blockchain-indexer/shared/indexer/validatorIndex.js index ca459b66c3..e8cd46416a 100644 --- a/services/blockchain-indexer/shared/indexer/validatorIndex.js +++ b/services/blockchain-indexer/shared/indexer/validatorIndex.js @@ -21,6 +21,11 @@ const { requestConnector } = require('../utils/request'); const commissionsTableSchema = require('../database/schema/commissions'); const stakesTableSchema = require('../database/schema/stakes'); +const { + getBlockByHeight, +} = require('../dataService'); +const { getGenesisHeight } = require('../constants'); + const config = require('../../config'); const MYSQL_ENDPOINT = config.endpoints.mysql; @@ -28,7 +33,8 @@ const MYSQL_ENDPOINT = config.endpoints.mysql; const getCommissionsTable = () => getTableInstance(commissionsTableSchema, MYSQL_ENDPOINT); const getStakesTable = () => getTableInstance(stakesTableSchema, MYSQL_ENDPOINT); -const indexValidatorCommissionInfo = async (genesisBlock) => { +const indexValidatorCommissionInfo = async () => { + const genesisBlock = await getBlockByHeight(await getGenesisHeight()); const commissionsTable = await getCommissionsTable(); const validators = await requestConnector('getPoSGenesisValidators'); const commissionInfo = validators.map(validator => ({ @@ -42,16 +48,16 @@ const indexValidatorCommissionInfo = async (genesisBlock) => { const indexStakersInfo = async () => { const stakesTable = await getStakesTable(); const stakers = await requestConnector('getPoSGenesisStakers'); - const stakestoIndex = []; + const stakesToIndex = []; await stakers.forEach(async staker => staker.stakes.forEach(stake => { - stakestoIndex.push({ + stakesToIndex.push({ stakerAddress: staker.address, validatorAddress: stake.validatorAddress, amount: stake.amount, }); })); - if (stakestoIndex.length) await stakesTable.upsert(stakestoIndex); + if (stakesToIndex.length) await stakesTable.upsert(stakesToIndex); }; module.exports = { From 113095c30fb03b7ee0796a126cfc1d3864d7e67a Mon Sep 17 00:00:00 2001 From: Sameer Kumar Subudhi Date: Tue, 15 Aug 2023 19:51:25 +0200 Subject: [PATCH 4/7] Update services/blockchain-indexer/shared/indexer/blockchainIndex.js --- services/blockchain-indexer/shared/indexer/blockchainIndex.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/blockchain-indexer/shared/indexer/blockchainIndex.js b/services/blockchain-indexer/shared/indexer/blockchainIndex.js index 0cd8e73082..a0866ecd1b 100644 --- a/services/blockchain-indexer/shared/indexer/blockchainIndex.js +++ b/services/blockchain-indexer/shared/indexer/blockchainIndex.js @@ -220,7 +220,7 @@ const indexBlock = async job => { await blocksTable.upsert(blockToIndex, dbTrx); await commitDBTransaction(dbTrx); - logger.info(`Committed MySQL transaction to index block ${block.id} at height ${block.height}.`); + logger.debug(`Committed MySQL transaction to index block ${block.id} at height ${block.height}.`); } catch (error) { await rollbackDBTransaction(dbTrx); logger.debug(`Rolled back MySQL transaction to index block ${block.id} at height ${block.height}.`); From f0d5a82eed5922d4a5cf724b4da76ae882ee84f3 Mon Sep 17 00:00:00 2001 From: Vardan Nadkarni Date: Wed, 16 Aug 2023 15:05:12 +0530 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=93=9D=20Updated=20todo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../transactionProcessor/pos/registerValidator.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/services/blockchain-indexer/shared/indexer/transactionProcessor/pos/registerValidator.js b/services/blockchain-indexer/shared/indexer/transactionProcessor/pos/registerValidator.js index 3d44cfc38a..59c27b19e8 100644 --- a/services/blockchain-indexer/shared/indexer/transactionProcessor/pos/registerValidator.js +++ b/services/blockchain-indexer/shared/indexer/transactionProcessor/pos/registerValidator.js @@ -43,8 +43,11 @@ const getCommissionsTable = () => getTableInstance(commissionsTableSchema, MYSQL // Command specific constants const COMMAND_NAME = 'registerValidator'; -const getCommissionIndexingInfo = (blockHeader, tx) => { - // TODO: Fetch default commission value from node. +const getCommissionIndexingInfo = async (blockHeader, tx) => { + // TODO: Enable this to fetch default commission value from node once SDK fixes https://github.com/LiskHQ/lisk-sdk/issues/8856 + // const posConstants = await getPosConstants(); + // const defaultComission = posConstants.defaultCommission; + const newCommissionEntry = { address: getLisk32AddressFromPublicKey(tx.senderPublicKey), commission: 10000, @@ -92,7 +95,7 @@ const applyTransaction = async (blockHeader, tx, events, dbTrx) => { await transactionsTable.upsert(tx, dbTrx); logger.debug(`Indexed transaction ${tx.id} contained in block at height ${tx.height}.`); - const commissionInfo = getCommissionIndexingInfo(blockHeader, tx); + const commissionInfo = await getCommissionIndexingInfo(blockHeader, tx); logger.trace(`Indexing commission update for address ${commissionInfo.address} at height ${commissionInfo.height}.`); await commissionsTable.upsert(commissionInfo, dbTrx); logger.debug(`Indexed commission update for address ${commissionInfo.address} at height ${commissionInfo.height}.`); @@ -126,7 +129,7 @@ const revertTransaction = async (blockHeader, tx, events, dbTrx) => { await validatorsTable.deleteByPrimaryKey(validatorPK, dbTrx); logger.debug(`Removed validator entry for address ${account.address}.`); - const commissionInfo = getCommissionIndexingInfo(blockHeader, tx); + const commissionInfo = await getCommissionIndexingInfo(blockHeader, tx); logger.trace(`Deleting commission entry for address ${commissionInfo.address} at height ${commissionInfo.height}.`); await commissionsTable.delete(commissionInfo, dbTrx); logger.debug(`Deleted commission entry for address ${commissionInfo.address} at height ${commissionInfo.height}.`); From 951b070bdfd3eae6f23bf57eef56e85622f5c9da Mon Sep 17 00:00:00 2001 From: Vardan Nadkarni Date: Wed, 16 Aug 2023 18:37:26 +0530 Subject: [PATCH 6/7] =?UTF-8?q?=F0=9F=90=9B=20Corrected=20logs=20and=20val?= =?UTF-8?q?idator=20table=20update=20after=20delete=20of=20block?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blockchain-indexer/shared/indexer/blockchainIndex.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/blockchain-indexer/shared/indexer/blockchainIndex.js b/services/blockchain-indexer/shared/indexer/blockchainIndex.js index a0866ecd1b..9842042be7 100644 --- a/services/blockchain-indexer/shared/indexer/blockchainIndex.js +++ b/services/blockchain-indexer/shared/indexer/blockchainIndex.js @@ -180,12 +180,12 @@ const indexBlock = async job => { where: { address: block.generatorAddress }, }, dbTrx); logger.debug(`Increased commission for validator ${block.generatorAddress} by ${commissionAmount}.`); - logger.trace(`Increasing self-stake rewards for validator ${block.generatorAddress} by ${commissionAmount}.`); + logger.trace(`Increasing self-stake rewards for validator ${block.generatorAddress} by ${selfStakeReward}.`); await validatorsTable.increment({ increment: { totalSelfStakeRewards: BigInt(selfStakeReward) }, where: { address: block.generatorAddress }, }, dbTrx); - logger.debug(`Increased self-stake rewards for validator ${block.generatorAddress} by ${commissionAmount}.`); + logger.debug(`Increased self-stake rewards for validator ${block.generatorAddress} by ${selfStakeReward}.`); } } @@ -321,13 +321,13 @@ const deleteIndexedBlocks = async job => { const validatorsTable = await getValidatorsTable(); logger.trace(`Decreasing commission for validator ${block.generatorAddress} by ${commissionAmount}.`); await validatorsTable.decrement({ - increment: { totalCommission: BigInt(commissionAmount) }, + decrement: { totalCommission: BigInt(commissionAmount) }, where: { address: block.generatorAddress }, }, dbTrx); logger.debug(`Decreased commission for validator ${block.generatorAddress} by ${commissionAmount}.`); logger.trace(`Decreasing self-stake rewards for validator ${block.generatorAddress} by ${selfStakeReward}.`); await validatorsTable.decrement({ - increment: { totalSelfStakeRewards: BigInt(selfStakeReward) }, + decrement: { totalSelfStakeRewards: BigInt(selfStakeReward) }, where: { address: block.generatorAddress }, }, dbTrx); logger.debug(`Decreased self-stake rewards for validator ${block.generatorAddress} by ${selfStakeReward}.`); From 52580dd6b80ae08a9439e02147a957aa69ba9c92 Mon Sep 17 00:00:00 2001 From: Vardan Nadkarni Date: Wed, 16 Aug 2023 21:24:29 +0530 Subject: [PATCH 7/7] =?UTF-8?q?=F0=9F=94=84=20Optimized=20to=20fetch=20add?= =?UTF-8?q?ress=20from=20transaction=20instead=20of=20generating=20from=20?= =?UTF-8?q?pubkey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../indexer/transactionProcessor/pos/registerValidator.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/services/blockchain-indexer/shared/indexer/transactionProcessor/pos/registerValidator.js b/services/blockchain-indexer/shared/indexer/transactionProcessor/pos/registerValidator.js index 59c27b19e8..51da78ea89 100644 --- a/services/blockchain-indexer/shared/indexer/transactionProcessor/pos/registerValidator.js +++ b/services/blockchain-indexer/shared/indexer/transactionProcessor/pos/registerValidator.js @@ -18,8 +18,6 @@ const { DB: { MySQL: { getTableInstance } }, } = require('lisk-service-framework'); -const { getLisk32AddressFromPublicKey } = require('../../../utils/account'); - const config = require('../../../../config'); const { TRANSACTION_STATUS } = require('../../../constants'); @@ -49,7 +47,7 @@ const getCommissionIndexingInfo = async (blockHeader, tx) => { // const defaultComission = posConstants.defaultCommission; const newCommissionEntry = { - address: getLisk32AddressFromPublicKey(tx.senderPublicKey), + address: tx.senderAddress, commission: 10000, height: blockHeader.height, }; @@ -67,7 +65,7 @@ const applyTransaction = async (blockHeader, tx, events, dbTrx) => { const commissionsTable = await getCommissionsTable(); const account = { - address: getLisk32AddressFromPublicKey(tx.senderPublicKey), + address: tx.senderAddress, publicKey: tx.senderPublicKey, name: tx.params.name, isValidator: true, @@ -111,7 +109,7 @@ const revertTransaction = async (blockHeader, tx, events, dbTrx) => { // Remove the validator details from the table on transaction reversal const account = { - address: getLisk32AddressFromPublicKey(tx.senderPublicKey), + address: tx.senderAddress, publicKey: tx.senderPublicKey, name: null, isValidator: false,