Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
bed0380
feat!: credit refunds
shumkov Dec 12, 2022
3ebd39c
feat: pass refunds to RS Drive
shumkov Dec 13, 2022
c735816
chore: manage pending updates
shumkov Dec 14, 2022
5f60496
tests: pending updates management
shumkov Dec 15, 2022
03d8e2a
tests: fixed removed bytes assertions
shumkov Dec 15, 2022
58c0bae
Merge branch 'v0.24-dev' into credit-refunds-continuation
shumkov Dec 15, 2022
4952f5a
chore: distribution function and other wip stuff
shumkov Dec 15, 2022
2c29e6f
fix: non deterministic updates
shumkov Dec 15, 2022
f0cb2f5
refactor: change to HashMap with nohasher
shumkov Dec 16, 2022
8c121bf
chore: continue distribution
shumkov Dec 16, 2022
feb1be0
chore: continue distribution
shumkov Dec 16, 2022
e454552
chore: accomplish distribution
shumkov Dec 17, 2022
28afc1d
chore: accomplish distribution
shumkov Dec 17, 2022
081c26c
test: fix some tests
shumkov Dec 18, 2022
e372dad
test: fix some tests
shumkov Dec 18, 2022
9a1a071
test: implement tests for distribution
shumkov Dec 18, 2022
3628244
tests: update_epoch_storage_fee_pools in progress
shumkov Dec 18, 2022
0e1773d
tests: add_update_epoch_storage_fee_pools_operations
shumkov Dec 19, 2022
dffb8be
tests: fix all tests
shumkov Dec 19, 2022
0208c15
tests: fix tests
shumkov Dec 19, 2022
1e1c1b5
chore: misc changes
shumkov Dec 19, 2022
0aeab31
chore: remove unused import
shumkov Dec 19, 2022
f0aa40e
tests: update fixtures
shumkov Dec 19, 2022
4b62a8f
fix: Cannot read properties of undefined (reading 'creditsPerEpoch')
shumkov Dec 19, 2022
8937ec2
revert: enable dry run fee validation
shumkov Dec 20, 2022
61326dc
docs: add documentation for modules
shumkov Dec 20, 2022
6c9d2c4
chore: switch from unpaid to current epoch index to simplify logic
shumkov Dec 20, 2022
592d9f2
feat: reduce paid epochs and leftovers from identity balance
shumkov Dec 20, 2022
8ee265c
Merge remote-tracking branch 'origin/v0.24-dev' into credit-refunds-c…
shumkov Dec 20, 2022
ddd8971
tests: remove calculateFees method
shumkov Dec 20, 2022
2823d1c
fix: calculateStorageFeeDistributionAmountAndLeftovers
shumkov Dec 21, 2022
5937029
style: add semi
shumkov Dec 21, 2022
f8b99fc
temp
QuantumExplorer Dec 21, 2022
a01f86e
small fixes
QuantumExplorer Dec 21, 2022
b9148f6
chore: switch to sum trees and refactoring
shumkov Dec 21, 2022
3d856ba
refactor: add_update_epoch_storage_fee_pools_operations
shumkov Dec 21, 2022
0f43b3a
refactor: add_update_epoch_storage_fee_pools_sequence_operations
shumkov Dec 21, 2022
9919aa1
refactor: small
shumkov Dec 21, 2022
92362a0
chore: using new grovedb v0.8.2
QuantumExplorer Dec 21, 2022
a46b07d
revert: reverted unworking change"
QuantumExplorer Dec 21, 2022
7dd42c6
Merge branch 'credit-refunds-continuation-sam' of github.com:dashpay/…
QuantumExplorer Dec 21, 2022
f6845da
test: fix tests
shumkov Dec 22, 2022
0e3a53d
test: fix JS tests
shumkov Dec 22, 2022
7836912
tests: addition fixes
shumkov Dec 22, 2022
6f18d16
fix: calculateOperationFees is not a function
shumkov Dec 22, 2022
8b13fa5
feat(drive): ABCI context logger
shumkov Dec 22, 2022
192b36f
WIP
Dec 22, 2022
bce914a
WIP
Dec 22, 2022
3eac947
WIP
Dec 23, 2022
e8090aa
Merge branch 'v0.24-dev' into context-logger
Jan 10, 2023
81c0c2c
WIP
Jan 10, 2023
6fead49
WIP
Jan 10, 2023
24d01f7
WIP
Jan 10, 2023
b71df6f
WIP
Jan 10, 2023
5f91611
WIP
Jan 10, 2023
2ca74c4
WIP
Jan 11, 2023
df8eef6
WIP
Jan 11, 2023
9b75046
WIP
Jan 11, 2023
03cb583
Merge branch 'v0.24-dev' into context-logger
Jan 17, 2023
da34920
Merge branch 'v0.24-dev' into context-logger
Jan 17, 2023
8f5b0b2
Merge remote-tracking branch 'origin/context-logger' into context-logger
Jan 17, 2023
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
24 changes: 24 additions & 0 deletions packages/js-drive/lib/abci/errors/createContextLoggerFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
*
* @param {AsyncLocalStorage} abciAsyncLocalStorage
* @return {createContextLogger}
*/
function createContextLoggerFactory(abciAsyncLocalStorage) {
/**
* @typedef {createContextLogger}
* @param {Logger} logger
* @param {Object} context
* @return {Logger}
*/
function createContextLogger(logger, context) {
const contextLogger = logger.child(context);

abciAsyncLocalStorage.getStore().set('logger', contextLogger);

return contextLogger;
}

return createContextLogger;
}

module.exports = createContextLoggerFactory;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Add consensus logger to an error (factory)
*
* @param {AsyncLocalStorage} abciAsyncLocalStorage
* @return {enrichErrorWithContextLogger}
*/
function enrichErrorWithContextLoggerFactory(abciAsyncLocalStorage) {
/**
* Add consensus logger to an error
*
* @typedef enrichErrorWithContextLogger
*
* @param {Function} method
*
* @return {Function}
*/
function enrichErrorWithContextLogger(method) {
/**
* @param {*[]} args
*/
async function methodHandler(...args) {
return abciAsyncLocalStorage.run(
new Map(),
() => method(...args).catch((error) => {
// eslint-disable-next-line no-param-reassign
error.contextLogger = abciAsyncLocalStorage.getStore().get('logger');

return Promise.reject(error);
}),
);
}

return methodHandler;
}

return enrichErrorWithContextLogger;
}

module.exports = enrichErrorWithContextLoggerFactory;
34 changes: 10 additions & 24 deletions packages/js-drive/lib/abci/errors/wrapInErrorHandlerFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,42 @@ function wrapInErrorHandlerFactory(logger, isProductionEnvironment) {
* @typedef wrapInErrorHandler
*
* @param {Function} method
* @param {Object} [options={}]
* @param {boolean} [options.respondWithInternalError=false]
*
* @return {Function}
*/
function wrapInErrorHandler(method, options = {}) {
// eslint-disable-next-line no-param-reassign
options = {
respondWithInternalError: false,
...options,
};

function wrapInErrorHandler(method) {
/**
* @param {*[]} args
*/
async function methodErrorHandler(...args) {
try {
return await method(...args);
} catch (e) {
let error = e;
let abciError = e;

// Wrap all non ABCI errors to an internal ABCI error
if (!(e instanceof AbstractAbciError)) {
error = new InternalAbciError(e);
abciError = new InternalAbciError(e);
}

// Log only internal ABCI errors
if (error instanceof InternalAbciError) {
// in consensus ABCI handlers (blockBegin, deliverTx, blockEnd, commit)
// we should propagate the error upwards
// to halt the Drive
// in order cases like query and checkTx
// we need to respond with internal errors
if (!options.respondWithInternalError) {
throw error.getError();
}
if (abciError instanceof InternalAbciError) {
const originalError = abciError.getError();

const originalError = error.getError();
const preferredLogger = originalError.contextLogger || logger;
delete originalError.contextLogger;

(originalError.consensusLogger || logger).error(
preferredLogger.error(
{ err: originalError },
originalError.message,
);

if (!isProductionEnvironment) {
error = new VerboseInternalAbciError(error);
abciError = new VerboseInternalAbciError(abciError);
}
}

return error.getAbciResponse();
return abciError.getAbciResponse();
}
}

Expand Down
9 changes: 9 additions & 0 deletions packages/js-drive/lib/abci/handlers/checkTxHandlerFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ const {

/**
* @param {unserializeStateTransition} unserializeStateTransition
* @param {AsyncLocalStorage} unserializeStateTransition
* @param {createContextLogger} createContextLogger
* @param {Logger} logger
*
* @returns {checkTxHandler}
*/
function checkTxHandlerFactory(
unserializeStateTransition,
createContextLogger,
logger,
) {
/**
* CheckTx ABCI Handler
Expand All @@ -24,6 +29,10 @@ function checkTxHandlerFactory(
* @returns {Promise<abci.ResponseCheckTx>}
*/
async function checkTxHandler({ tx: stateTransitionByteArray }) {
createContextLogger(logger, {
abciMethod: 'checkTx',
});

await unserializeStateTransition(stateTransitionByteArray);

return new ResponseCheckTx();
Expand Down
14 changes: 7 additions & 7 deletions packages/js-drive/lib/abci/handlers/extendVoteHandlerFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ const {

/**
* @param {BlockExecutionContext} proposalBlockExecutionContext
* @param {createContextLogger} createContextLogger
*
* @return {extendVoteHandler}
*/
function extendVoteHandlerFactory(proposalBlockExecutionContext) {
function extendVoteHandlerFactory(proposalBlockExecutionContext, createContextLogger) {
/**
* @typedef extendVoteHandler
* @return {Promise<abci.ResponseExtendVote>}
*/
async function extendVoteHandler() {
const consensusLogger = proposalBlockExecutionContext.getConsensusLogger()
.child({
abciMethod: 'extendVote',
});
const contextLogger = createContextLogger(proposalBlockExecutionContext.getContextLogger(), {
abciMethod: 'extendVote',
});

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

const unsignedWithdrawalTransactionsMap = proposalBlockExecutionContext
.getWithdrawalTransactionsMap();
Expand All @@ -50,7 +50,7 @@ function extendVoteHandlerFactory(proposalBlockExecutionContext) {
Math.min(30, extensionString.length),
);

consensusLogger.debug({
contextLogger.debug({
type,
extension: extensionString,
}, `Vote extended to obtain ${voteExtensionTypeName} signature for ${extensionTruncatedString}... payload`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const lodashCloneDeep = require('lodash/cloneDeep');
* @param {BlockExecutionContext} latestBlockExecutionContext
* @param {BlockExecutionContext} proposalBlockExecutionContext
* @param {processProposal} processProposal
* @param {createContextLogger} createContextLogger
*
*/
function finalizeBlockHandlerFactory(
groveDBStore,
Expand All @@ -29,6 +31,7 @@ function finalizeBlockHandlerFactory(
latestBlockExecutionContext,
proposalBlockExecutionContext,
processProposal,
createContextLogger,
) {
/**
* @typedef finalizeBlockHandler
Expand All @@ -43,7 +46,7 @@ function finalizeBlockHandlerFactory(
round,
} = request;

const consensusLogger = logger.child({
const contextLogger = createContextLogger(logger, {
height: height.toString(),
round,
abciMethod: 'finalizeBlock',
Expand All @@ -52,13 +55,13 @@ function finalizeBlockHandlerFactory(
const requestToLog = lodashCloneDeep(request);
delete requestToLog.block.data;

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

const lastProcessedRound = proposalBlockExecutionContext.getRound();

if (lastProcessedRound !== round) {
consensusLogger.warn({
contextLogger.warn({
lastProcessedRound,
round,
}, `Finalizing previously executed round ${round} instead of the last known ${lastProcessedRound}`);
Expand Down Expand Up @@ -88,10 +91,7 @@ function finalizeBlockHandlerFactory(
round,
});

await processProposal(processProposalRequest, consensusLogger);

// Revert consensus logger
proposalBlockExecutionContext.setConsensusLogger(consensusLogger);
await processProposal(processProposalRequest, contextLogger);
}

proposalBlockExecutionContext.setLastCommitInfo(commitInfo);
Expand Down Expand Up @@ -138,7 +138,7 @@ function finalizeBlockHandlerFactory(

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

consensusLogger.info(
contextLogger.info(
{
timings: blockExecutionTimings,
},
Expand Down
29 changes: 13 additions & 16 deletions packages/js-drive/lib/abci/handlers/infoHandlerFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const { version: driveVersion } = require('../../../package.json');
* @param {updateSimplifiedMasternodeList} updateSimplifiedMasternodeList
* @param {BaseLogger} logger
* @param {GroveDBStore} groveDBStore
* @param {createContextLogger} createContextLogger
* @return {infoHandler}
*/
function infoHandlerFactory(
Expand All @@ -26,6 +27,7 @@ function infoHandlerFactory(
updateSimplifiedMasternodeList,
logger,
groveDBStore,
createContextLogger,
) {
/**
* Info ABCI handler
Expand All @@ -36,37 +38,32 @@ function infoHandlerFactory(
* @return {Promise<ResponseInfo>}
*/
async function infoHandler(request) {
let contextLogger = logger.child({
let contextLogger = createContextLogger(logger, {
abciMethod: 'info',
});

contextLogger.debug('Info ABCI method requested');
contextLogger.trace({ abciRequest: request });

// Initialize Block Execution Contexts

const persistedBlockExecutionContext = await blockExecutionContextRepository.fetch();
if (persistedBlockExecutionContext) {
latestBlockExecutionContext.populate(persistedBlockExecutionContext);
}

// Initialize current heights

let lastHeight = Long.fromNumber(0);
let lastCoreChainLockedHeight = 0;

if (!latestBlockExecutionContext.isEmpty()) {
// Initialize latest Block Execution Context
const persistedBlockExecutionContext = await blockExecutionContextRepository.fetch();
if (!persistedBlockExecutionContext.isEmpty()) {
latestBlockExecutionContext.populate(persistedBlockExecutionContext);

lastHeight = latestBlockExecutionContext.getHeight();
lastCoreChainLockedHeight = latestBlockExecutionContext.getCoreChainLockedHeight();
}

contextLogger = contextLogger.child({
height: lastHeight.toString(),
});
contextLogger = createContextLogger(contextLogger, {
height: lastHeight.toString(),
});

// Update SML store to latest saved core chain lock to make sure
// that verify chain lock handler has updated SML Store to verify signatures
if (!latestBlockExecutionContext.isEmpty()) {
// Update SML store to latest saved core chain lock to make sure
// that verify chain lock handler has updated SML Store to verify signatures
await updateSimplifiedMasternodeList(lastCoreChainLockedHeight, {
logger: contextLogger,
});
Expand Down
Loading