Skip to content
This repository was archived by the owner on Dec 16, 2021. It is now read-only.

Commit

Permalink
feat: update dashcore-lib to be able to handle rawchainlocksig (#443
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jawid-h authored Dec 24, 2020
1 parent ff6995c commit 27235bd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
1 change: 1 addition & 0 deletions lib/core/ZmqClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const ZMQ_TOPICS = {
rawtxlock: 'rawtxlock',
rawtxlocksig: 'rawtxlocksig',
rawchainlock: 'rawchainlock',
rawchainlocksig: 'rawchainlocksig',
};

const defaultOptions = { topics: ZMQ_TOPICS, maxRetryCount: 20 };
Expand Down
9 changes: 4 additions & 5 deletions lib/core/waitForCoreChainLockSyncFactory.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { ChainLock } = require('@dashevo/dashcore-lib');

const ChainLockSigMessage = require('@dashevo/dashcore-lib/lib/zmqMessages/ChainLockSigMessage');
const ZMQClient = require('./ZmqClient');

const ensureBlock = require('./ensureBlock');
Expand Down Expand Up @@ -29,7 +30,7 @@ function waitForCoreChainLockSyncFactory(
* @returns {Promise<void>}
*/
async function waitForCoreChainLockSync() {
coreZMQClient.subscribe(ZMQClient.TOPICS.rawchainlock);
coreZMQClient.subscribe(ZMQClient.TOPICS.rawchainlocksig);

logger.trace('Subscribe to rawchainlock ZMQ room');

Expand All @@ -38,10 +39,8 @@ function waitForCoreChainLockSyncFactory(
resolveFirstChainLockFromZMQPromise = resolve;
});

coreZMQClient.on(ZMQClient.TOPICS.rawchainlock, async (rawChainLockMessage) => {
const socketChainLock = new ChainLock(rawChainLockMessage);

await ensureBlock(coreZMQClient, coreRpcClient, socketChainLock.blockHash);
coreZMQClient.on(ZMQClient.TOPICS.rawchainlocksig, async (rawChainLockMessage) => {
const { chainLock: socketChainLock } = new ChainLockSigMessage(rawChainLockMessage);

latestCoreChainLock.update(socketChainLock);

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"sinon-chai": "^3.5.0"
},
"dependencies": {
"@dashevo/dashcore-lib": "~0.19.13",
"@dashevo/dashcore-lib": "~0.19.15",
"@dashevo/dashd-rpc": "^2.0.2",
"@dashevo/dashd-zmq": "^1.2.0",
"@dashevo/dpp": "~0.17.0-dev.4",
Expand Down
26 changes: 12 additions & 14 deletions test/unit/core/waitForCoreChainLockSyncFactory.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ describe('waitForCoreChainLockSyncFactory', () => {
let coreZMQClientMock;
let latestCoreChainLock;
let chainLock;
let rawChainLockSigMessage;

beforeEach(function beforeEach() {
chainLock = {
height: 84202,
blockHash: '0000000007e0a65b763c0a4fb2274ff757abdbd19c9efe9de189f5828c70a5f4',
signature: '0a43f1c3e5b3e8dbd670bca8d437dc25572f72d8e1e9be673e9ebbb606570307c3e5f5d073f7beb209dd7e0b8f96c751060ab3a7fb69a71d5ccab697b8cfa5a91038a6fecf76b7a827d75d17f01496302942aa5e2c7f4a48246efc8d3941bf6c',
blockHash: '0000003df90e1cec3fea6bd17508f653cea093c536199e9d50a05bd69ee23b5d',
height: 3887,
signature: '1770e35c281ebfcf14b8a62071f76146eb0a5ede6fb43543a9c0ccddf3cf87fcdd0a96eea867595bb980dcea13e6283f16744631df895404434c7840f9b3d9c1069790a0459a0d35b7ae353519f5d437ded547f8d65f6c4916e988c842488e7a',
};

rawChainLockSigMessage = Buffer.from('00000020fd0ab0fc0fb0cbecb62cf7555aee6a8ce18564a9bbed8b22585d9f8563000000ee131c25019aaee0f1bdde2a5d6eb99ec0b4497e68776f18916951e8ddb6b922dd3be45f62f6011ed18800000103000500010000000000000000000000000000000000000000000000000000000000000000ffffffff05024c0f010bffffffff0200c817a8040000001976a91416b93a3b9168a20605cc3cda62f6135a3baa531a88ac00ac23fc060000001976a91416b93a3b9168a20605cc3cda62f6135a3baa531a88ac000000004602004c0f00003d8e273bf286d48ccba5a87b5adf332ed070a15e4e2d81eeb9ff685373be5656961e0b73ea855fdac9cc530782a7f0a22d25d1eaab4b2068efa647e9da0915d02f0f00005d3be29ed65ba0509d9e1936c593a0ce53f60875d16bea3fec1c0ef93d0000001770e35c281ebfcf14b8a62071f76146eb0a5ede6fb43543a9c0ccddf3cf87fcdd0a96eea867595bb980dcea13e6283f16744631df895404434c7840f9b3d9c1069790a0459a0d35b7ae353519f5d437ded547f8d65f6c4916e988c842488e7a', 'hex');

latestCoreChainLock = new LatestCoreChainLock();
coreRpcClientMock = {
getBestChainLock: this.sinon.stub().resolves({
Expand Down Expand Up @@ -52,7 +55,7 @@ describe('waitForCoreChainLockSyncFactory', () => {
expect(latestCoreChainLock.chainLock.toJSON()).to.deep.equal(chainLock);

expect(coreZMQClientMock.subscribe).to.be.calledTwice();
expect(coreZMQClientMock.subscribe).to.be.calledWith(ZMQClient.TOPICS.rawchainlock);
expect(coreZMQClientMock.subscribe).to.be.calledWith(ZMQClient.TOPICS.rawchainlocksig);
expect(coreZMQClientMock.subscribe).to.be.calledWith(ZMQClient.TOPICS.hashblock);
expect(coreRpcClientMock.getBestChainLock).to.be.calledOnce();
});
Expand All @@ -71,22 +74,17 @@ describe('waitForCoreChainLockSyncFactory', () => {
expect(latestCoreChainLock.chainLock.toJSON()).to.deep.equal(chainLock);

expect(coreZMQClientMock.subscribe).to.be.calledTwice();
expect(coreZMQClientMock.subscribe).to.be.calledWith(ZMQClient.TOPICS.rawchainlock);
expect(coreZMQClientMock.subscribe).to.be.calledWith(ZMQClient.TOPICS.rawchainlocksig);
expect(coreZMQClientMock.subscribe).to.be.calledWith(ZMQClient.TOPICS.hashblock);
expect(coreRpcClientMock.getBestChainLock).to.be.calledOnce();
done();
});

setImmediate(() => {
coreZMQClientMock.emit(ZMQClient.TOPICS.rawchainlock, {
height: 84202,
blockHash: '0000000007e0a65b763c0a4fb2274ff757abdbd19c9efe9de189f5828c70a5f4',
signature: '0a43f1c3e5b3e8dbd670bca8d437dc25572f72d8e1e9be673e9ebbb606570307c3e5f5d073f7beb209dd7e0b8f96c751060ab3a7fb69a71d5ccab697b8cfa5a91038a6fecf76b7a827d75d17f01496302942aa5e2c7f4a48246efc8d3941bf6c',
});
});

setImmediate(() => {
coreZMQClientMock.emit(ZMQClient.TOPICS.hashblock, '0000000007e0a65b763c0a4fb2274ff757abdbd19c9efe9de189f5828c70a5f4');
coreZMQClientMock.emit(
ZMQClient.TOPICS.rawchainlocksig,
rawChainLockSigMessage,
);
});
});
});

0 comments on commit 27235bd

Please sign in to comment.