Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions packages/js-drive/lib/abci/handlers/extendVoteHandlerFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ const {
function extendVoteHandlerFactory(proposalBlockExecutionContext) {
/**
* @typedef extendVoteHandler
* @param {Object} request
* @param {number} request.round
* @return {Promise<abci.ResponseExtendVote>}
*/
async function extendVoteHandler() {
const consensusLogger = proposalBlockExecutionContext.getConsensusLogger()
.child({
abciMethod: 'extendVote',
});

consensusLogger.debug('ExtendVote ABCI method requested');

const unsignedWithdrawalTransactionsMap = proposalBlockExecutionContext
.getWithdrawalTransactionsMap();

Expand All @@ -32,6 +37,25 @@ function extendVoteHandlerFactory(proposalBlockExecutionContext) {
extension: Buffer.from(txHashHex, 'hex'),
}));

const voteExtensionTypeName = {
[VoteExtensionType.DEFAULT]: 'default',
[VoteExtensionType.THRESHOLD_RECOVER]: 'threshold recovery',
};

voteExtensions.forEach(({ extension, type }) => {
const extensionString = extension.toString('hex');

const extensionTruncatedString = extensionString.substring(
0,
Math.min(30, extensionString.length),
);

consensusLogger.debug({
type,
extension: extensionString,
}, `Vote extended to obtain ${voteExtensionTypeName} signature for ${extensionTruncatedString}... payload`);
});

return new ResponseExtendVote({
voteExtensions,
});
Expand Down
34 changes: 22 additions & 12 deletions packages/js-drive/lib/abci/handlers/finalizeBlockHandlerFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const {
tendermint: {
abci: {
ResponseFinalizeBlock,
RequestProcessProposal,
},
},
} = require('@dashevo/abci/types');
Expand All @@ -11,13 +12,12 @@ const {
* @return {finalizeBlockHandler}
* @param {GroveDBStore} groveDBStore
* @param {BlockExecutionContextRepository} blockExecutionContextRepository
* @param {LRUCache} dataContractCache
* @param {CoreRpcClient} coreRpcClient
* @param {BaseLogger} logger
* @param {ExecutionTimer} executionTimer
* @param {BlockExecutionContext} latestBlockExecutionContext
* @param {BlockExecutionContext} proposalBlockExecutionContext
* @param {processProposalHandler} processProposalHandler
* @param {processProposal} processProposal
*/
function finalizeBlockHandlerFactory(
groveDBStore,
Expand All @@ -27,7 +27,7 @@ function finalizeBlockHandlerFactory(
executionTimer,
latestBlockExecutionContext,
proposalBlockExecutionContext,
processProposalHandler,
processProposal,
) {
/**
* @typedef finalizeBlockHandler
Expand All @@ -44,16 +44,20 @@ function finalizeBlockHandlerFactory(

const consensusLogger = logger.child({
height: height.toString(),
round,
abciMethod: 'finalizeBlock',
});

consensusLogger.debug('FinalizeBlock ABCI method requested');
consensusLogger.trace({ abciRequest: request });

if (proposalBlockExecutionContext.getRound() !== round) {
consensusLogger.warn(
`Finalizing previously executed round ${round} instead of the last known ${proposalBlockExecutionContext.getRound()}`,
);
const lastProcessedRound = proposalBlockExecutionContext.getRound();

if (lastProcessedRound !== round) {
consensusLogger.warn({
lastProcessedRound,
round,
}, `Finalizing previously executed round ${round} instead of the last known ${lastProcessedRound}`);

const {
block: {
Expand All @@ -69,7 +73,7 @@ function finalizeBlockHandlerFactory(
},
} = request;

await processProposalHandler({
const processProposalRequest = new RequestProcessProposal({
height,
txs,
coreChainLockedHeight,
Expand All @@ -79,21 +83,27 @@ function finalizeBlockHandlerFactory(
proposerProTxHash,
round,
});

await processProposal(processProposalRequest, consensusLogger);

// Revert consensus logger
proposalBlockExecutionContext.setConsensusLogger(consensusLogger);
}

proposalBlockExecutionContext.setLastCommitInfo(commitInfo);

// Store block execution context
// Store proposal block execution context
await blockExecutionContextRepository.store(
proposalBlockExecutionContext,
{
useTransaction: true,
},
);

// Commit the current block db transactions
// Commit the current block db transactions into storage
await groveDBStore.commitTransaction();

// Update last block execution context with proposal data
latestBlockExecutionContext.populate(proposalBlockExecutionContext);

// Send withdrawal transactions to Core
Expand Down Expand Up @@ -124,11 +134,11 @@ function finalizeBlockHandlerFactory(

const blockExecutionTimings = executionTimer.stopTimer('blockExecution');

consensusLogger.trace(
consensusLogger.info(
{
timings: blockExecutionTimings,
},
`Block #${height} execution took ${blockExecutionTimings} seconds`,
`Block #${height} finalized in ${round + 1} round(s) and ${blockExecutionTimings} seconds`,
);

return new ResponseFinalizeBlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const txAction = {
* @param {beginBlock} beginBlock
* @param {endBlock} endBlock
* @param {createCoreChainLockUpdate} createCoreChainLockUpdate
* @param {ExecutionTimer} executionTimer
* @return {prepareProposalHandler}
*/
function prepareProposalHandlerFactory(
Expand All @@ -31,6 +32,7 @@ function prepareProposalHandlerFactory(
beginBlock,
endBlock,
createCoreChainLockUpdate,
executionTimer,
) {
/**
* @typedef prepareProposalHandler
Expand All @@ -49,20 +51,18 @@ function prepareProposalHandlerFactory(
proposerProTxHash,
round,
} = request;

const consensusLogger = logger.child({
height: height.toString(),
round,
abciMethod: 'prepareProposal',
});

consensusLogger.info(
{
height,
},
`Prepare proposal #${height}`,
);
consensusLogger.debug('PrepareProposal ABCI method requested');
consensusLogger.trace({ abciRequest: request });

consensusLogger.info(`Preparing a block proposal for height #${height} round #${round}`);

await beginBlock(
{
lastCommitInfo,
Expand Down Expand Up @@ -119,6 +119,7 @@ function prepareProposalHandlerFactory(
txResults.push(txResult);
}

// Revert consensus logger after deliverTx
proposalBlockExecutionContext.setConsensusLogger(consensusLogger);

const coreChainLockUpdate = await createCoreChainLockUpdate(round, consensusLogger);
Expand All @@ -134,13 +135,19 @@ function prepareProposalHandlerFactory(
coreChainLockedHeight,
}, consensusLogger);

const roundExecutionTime = executionTimer.getTimer('roundExecution', true);

const mempoolTxCount = txs.length - validTxCount - invalidTxCount;

consensusLogger.info(
{
roundExecutionTime,
validTxCount,
invalidTxCount,
mempoolTxCount,
},
`Prepare proposal #${height} with appHash ${appHash.toString('hex').toUpperCase()}`
+ ` (valid txs = ${validTxCount}, invalid txs = ${invalidTxCount})`,
`Prepared block proposal for height #${height} with appHash ${appHash.toString('hex').toUpperCase()}`
+ ` in ${roundExecutionTime} seconds (valid txs = ${validTxCount}, invalid txs = ${invalidTxCount}, mempool txs = ${mempoolTxCount})`,
);

proposalBlockExecutionContext.setPrepareProposalResult({
Expand Down
Loading