diff --git a/packages/js-drive/lib/abci/handlers/initChainHandlerFactory.js b/packages/js-drive/lib/abci/handlers/initChainHandlerFactory.js index a1276994cd7..6364252d3e7 100644 --- a/packages/js-drive/lib/abci/handlers/initChainHandlerFactory.js +++ b/packages/js-drive/lib/abci/handlers/initChainHandlerFactory.js @@ -21,6 +21,7 @@ const protoTimestampToMillis = require('../../util/protoTimestampToMillis'); * @param {registerSystemDataContracts} registerSystemDataContracts * @param {GroveDBStore} groveDBStore * @param {RSAbci} rsAbci + * @param {createCoreChainLockUpdate} createCoreChainLockUpdate * @return {initChainHandler} */ function initChainHandlerFactory( @@ -33,6 +34,7 @@ function initChainHandlerFactory( registerSystemDataContracts, groveDBStore, rsAbci, + createCoreChainLockUpdate, ) { /** * @typedef initChainHandler @@ -109,6 +111,12 @@ function initChainHandlerFactory( const validatorSetUpdate = createValidatorSetUpdate(validatorSet); + const coreChainLockUpdate = await createCoreChainLockUpdate( + initialCoreChainLockedHeight, + 0, + consensusLogger, + ); + consensusLogger.trace(validatorSetUpdate, `Validator set initialized with ${quorumHash} quorum`); consensusLogger.info( @@ -125,6 +133,7 @@ function initChainHandlerFactory( appHash, validatorSetUpdate, initialCoreHeight: initialCoreChainLockedHeight, + nextCoreChainLockUpdate: coreChainLockUpdate, }); } diff --git a/packages/js-drive/lib/abci/handlers/prepareProposalHandlerFactory.js b/packages/js-drive/lib/abci/handlers/prepareProposalHandlerFactory.js index 730522c1095..d52dfe59b3e 100644 --- a/packages/js-drive/lib/abci/handlers/prepareProposalHandlerFactory.js +++ b/packages/js-drive/lib/abci/handlers/prepareProposalHandlerFactory.js @@ -122,7 +122,11 @@ function prepareProposalHandlerFactory( // Revert consensus logger after deliverTx proposalBlockExecutionContext.setConsensusLogger(consensusLogger); - const coreChainLockUpdate = await createCoreChainLockUpdate(round, consensusLogger); + const coreChainLockUpdate = await createCoreChainLockUpdate( + coreChainLockedHeight, + round, + consensusLogger, + ); const { consensusParamUpdates, diff --git a/packages/js-drive/lib/abci/handlers/proposal/createCoreChainLockUpdateFactory.js b/packages/js-drive/lib/abci/handlers/proposal/createCoreChainLockUpdateFactory.js index 2c9856c449f..d13008a3aea 100644 --- a/packages/js-drive/lib/abci/handlers/proposal/createCoreChainLockUpdateFactory.js +++ b/packages/js-drive/lib/abci/handlers/proposal/createCoreChainLockUpdateFactory.js @@ -7,23 +7,21 @@ const { } = require('@dashevo/abci/types'); /** * - * @param {BlockExecutionContext} proposalBlockExecutionContext * @param {LatestCoreChainLock} latestCoreChainLock * @return {createCoreChainLockUpdate} */ function createCoreChainLockUpdateFactory( - proposalBlockExecutionContext, latestCoreChainLock, ) { /** * @typedef createCoreChainLockUpdate + * @param {number} contextCoreChainLockedHeight * @param {number} round * @param {BaseLogger} consensusLogger * @return {Promise} */ - async function createCoreChainLockUpdate(round, consensusLogger) { + async function createCoreChainLockUpdate(contextCoreChainLockedHeight, round, consensusLogger) { // Update Core Chain Locks - const contextCoreChainLockedHeight = proposalBlockExecutionContext.getCoreChainLockedHeight(); const coreChainLock = latestCoreChainLock.getChainLock(); let coreChainLockUpdate; diff --git a/packages/js-drive/test/unit/abci/handlers/initChainHandlerFactory.spec.js b/packages/js-drive/test/unit/abci/handlers/initChainHandlerFactory.spec.js index c82a572c536..f637a2cca3f 100644 --- a/packages/js-drive/test/unit/abci/handlers/initChainHandlerFactory.spec.js +++ b/packages/js-drive/test/unit/abci/handlers/initChainHandlerFactory.spec.js @@ -6,6 +6,9 @@ const { ResponseInitChain, ValidatorSetUpdate, }, + types: { + CoreChainLock, + }, }, } = require('@dashevo/abci/types'); @@ -29,6 +32,8 @@ describe('initChainHandlerFactory', () => { let groveDBStoreMock; let appHashFixture; let rsAbciMock; + let createCoreChainLockUpdateMock; + let coreChainLockUpdate; beforeEach(function beforeEach() { initialCoreChainLockedHeight = 1; @@ -66,6 +71,14 @@ describe('initChainHandlerFactory', () => { groveDBStoreMock = new GroveDBStoreMock(this.sinon); groveDBStoreMock.getRootHash.resolves(appHashFixture); + coreChainLockUpdate = new CoreChainLock({ + coreBlockHeight: 42, + coreBlockHash: '1528e523f4c20fa84ba70dd96372d34e00ce260f357d53ad1a8bc892ebf20e2d', + signature: '1897ce8f54d2070f44ca5c29983b68b391e8137c25e44f67416e579f3e3bdfef7b4fd22db7818399147e52907998857b0fbc8edfdc40a64f2c7df0e88544d31d12ca8c15e73d50dda25ca23f754ed3f789ed4bcb392161995f464017c10df404', + }); + + createCoreChainLockUpdateMock = this.sinon.stub().resolves(coreChainLockUpdate); + initChainHandler = initChainHandlerFactory( updateSimplifiedMasternodeListMock, initialCoreChainLockedHeight, @@ -76,6 +89,7 @@ describe('initChainHandlerFactory', () => { registerSystemDataContractsMock, groveDBStoreMock, rsAbciMock, + createCoreChainLockUpdateMock, ); }); @@ -130,5 +144,8 @@ describe('initChainHandlerFactory', () => { expect(validatorSetMock.getQuorum).to.be.calledOnce(); expect(createValidatorSetUpdateMock).to.be.calledOnceWithExactly(validatorSetMock); + + expect(createCoreChainLockUpdateMock) + .to.be.calledOnceWithExactly(initialCoreChainLockedHeight, 0, loggerMock); }); }); diff --git a/packages/js-drive/test/unit/abci/handlers/prepareProposalHandlerFactory.spec.js b/packages/js-drive/test/unit/abci/handlers/prepareProposalHandlerFactory.spec.js index b2a3a3e977f..27d70c5e9fd 100644 --- a/packages/js-drive/test/unit/abci/handlers/prepareProposalHandlerFactory.spec.js +++ b/packages/js-drive/test/unit/abci/handlers/prepareProposalHandlerFactory.spec.js @@ -164,7 +164,11 @@ describe('prepareProposalHandlerFactory', () => { expect(deliverTxMock).to.be.calledThrice(); - expect(updateCoreChainLockMock).to.be.calledOnceWithExactly(round, loggerMock); + expect(updateCoreChainLockMock).to.be.calledOnceWithExactly( + request.coreChainLockedHeight, + round, + loggerMock, + ); expect(endBlockMock).to.be.calledOnceWithExactly( { diff --git a/packages/js-drive/test/unit/abci/handlers/proposal/createCoreChainLockUpdateFactory.spec.js b/packages/js-drive/test/unit/abci/handlers/proposal/createCoreChainLockUpdateFactory.spec.js index 3ec8a29a421..7e52c580dfc 100644 --- a/packages/js-drive/test/unit/abci/handlers/proposal/createCoreChainLockUpdateFactory.spec.js +++ b/packages/js-drive/test/unit/abci/handlers/proposal/createCoreChainLockUpdateFactory.spec.js @@ -6,7 +6,6 @@ const { }, } = require('@dashevo/abci/types'); const createCoreChainLockUpdateFactory = require('../../../../../lib/abci/handlers/proposal/createCoreChainLockUpdateFactory'); -const BlockExecutionContextMock = require('../../../../../lib/test/mock/BlockExecutionContextMock'); const LoggerMock = require('../../../../../lib/test/mock/LoggerMock'); describe('createCoreChainLockUpdateFactory', () => { @@ -16,7 +15,6 @@ describe('createCoreChainLockUpdateFactory', () => { let coreChainLockedHeight; let loggerMock; let round; - let proposalBlockExecutionContextMock; beforeEach(function beforeEach() { round = 0; @@ -30,17 +28,11 @@ describe('createCoreChainLockUpdateFactory', () => { coreChainLockedHeight = 2; - proposalBlockExecutionContextMock = new BlockExecutionContextMock(this.sinon); - - proposalBlockExecutionContextMock.hasDataContract.returns(true); - proposalBlockExecutionContextMock.getCoreChainLockedHeight.returns(coreChainLockedHeight); - latestCoreChainLockMock = { getChainLock: this.sinon.stub().returns(chainLockMock), }; createCoreChainLockUpdate = createCoreChainLockUpdateFactory( - proposalBlockExecutionContextMock, latestCoreChainLockMock, ); }); @@ -48,7 +40,7 @@ describe('createCoreChainLockUpdateFactory', () => { it('should return nextCoreChainLockUpdate if latestCoreChainLock above header height', async () => { chainLockMock.height = 3; - const response = await createCoreChainLockUpdate(round, loggerMock); + const response = await createCoreChainLockUpdate(coreChainLockedHeight, round, loggerMock); expect(latestCoreChainLockMock.getChainLock).to.have.been.calledOnceWithExactly(); @@ -64,7 +56,7 @@ describe('createCoreChainLockUpdateFactory', () => { it('should return undefined', async () => { chainLockMock.height = 1; - const response = await createCoreChainLockUpdate(round, loggerMock); + const response = await createCoreChainLockUpdate(coreChainLockedHeight, round, loggerMock); expect(latestCoreChainLockMock.getChainLock).to.have.been.calledOnceWithExactly();