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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -33,6 +34,7 @@ function initChainHandlerFactory(
registerSystemDataContracts,
groveDBStore,
rsAbci,
createCoreChainLockUpdate,
) {
/**
* @typedef initChainHandler
Expand Down Expand Up @@ -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(
Expand All @@ -125,6 +133,7 @@ function initChainHandlerFactory(
appHash,
validatorSetUpdate,
initialCoreHeight: initialCoreChainLockedHeight,
nextCoreChainLockUpdate: coreChainLockUpdate,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoreChainLock>}
*/
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const {
ResponseInitChain,
ValidatorSetUpdate,
},
types: {
CoreChainLock,
},
},
} = require('@dashevo/abci/types');

Expand All @@ -29,6 +32,8 @@ describe('initChainHandlerFactory', () => {
let groveDBStoreMock;
let appHashFixture;
let rsAbciMock;
let createCoreChainLockUpdateMock;
let coreChainLockUpdate;

beforeEach(function beforeEach() {
initialCoreChainLockedHeight = 1;
Expand Down Expand Up @@ -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,
Expand All @@ -76,6 +89,7 @@ describe('initChainHandlerFactory', () => {
registerSystemDataContractsMock,
groveDBStoreMock,
rsAbciMock,
createCoreChainLockUpdateMock,
);
});

Expand Down Expand Up @@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -16,7 +15,6 @@ describe('createCoreChainLockUpdateFactory', () => {
let coreChainLockedHeight;
let loggerMock;
let round;
let proposalBlockExecutionContextMock;

beforeEach(function beforeEach() {
round = 0;
Expand All @@ -30,25 +28,19 @@ 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,
);
});

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();

Expand All @@ -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();

Expand Down