Skip to content

Commit 04529ba

Browse files
committed
Merge branch 'master' of github.com:dashevo/dashcore-lib
2 parents a5947f4 + 399909b commit 04529ba

File tree

6 files changed

+404
-7
lines changed

6 files changed

+404
-7
lines changed

lib/constants/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module.exports = {
5959
// Params might differ when -llmqtestparams is used
6060
LLMQ_TYPE_LLMQ_TEST: 100,
6161

62-
// 10 members, 6 (60%) threshold, one per hour (24 blocks)
62+
// 12 members, 6 (60%) threshold, one per hour (24 blocks)
6363
// Params might differ when -llmqdevnetparams is used
6464
LLMQ_TYPE_LLMQ_DEVNET: 101,
6565

@@ -83,4 +83,6 @@ module.exports = {
8383

8484
// keep diffs for 30 hours (720 blocks)
8585
SMLSTORE_MAX_DIFFS: 720,
86+
87+
HASH_QUORUM_INDEX_REQUIRED_VERSION: 2,
8688
};

lib/deterministicmnlist/QuorumEntry.js

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ const {
1616
isHexaString: isHexString,
1717
} = utils;
1818

19-
const { BLS_PUBLIC_KEY_SIZE, BLS_SIGNATURE_SIZE, SHA256_HASH_SIZE } = constants;
19+
const {
20+
BLS_PUBLIC_KEY_SIZE,
21+
BLS_SIGNATURE_SIZE,
22+
SHA256_HASH_SIZE,
23+
HASH_QUORUM_INDEX_REQUIRED_VERSION,
24+
} = constants;
2025

2126
/**
2227
* @typedef {Object} SMLQuorumEntry
2328
* @property {number} version
2429
* @property {number} llmqType
2530
* @property {string} quorumHash
31+
* @property {number} [quorumIndex]
2632
* @property {number} signersCount
2733
* @property {string} signers
2834
* @property {number} validMembersCount
@@ -41,6 +47,7 @@ const { BLS_PUBLIC_KEY_SIZE, BLS_SIGNATURE_SIZE, SHA256_HASH_SIZE } = constants;
4147
* @property {number} version
4248
* @property {number} llmqType
4349
* @property {string} quorumHash
50+
* @property {number} [quorumIndex]
4451
* @property {number} signersCount
4552
* @property {string} signers
4653
* @property {number} validMembersCount
@@ -92,6 +99,11 @@ QuorumEntry.fromBuffer = function fromBuffer(buffer) {
9299
.read(constants.SHA256_HASH_SIZE)
93100
.reverse()
94101
.toString('hex');
102+
103+
if (this.version >= HASH_QUORUM_INDEX_REQUIRED_VERSION) {
104+
SMLQuorumEntry.quorumIndex = buffer.readInt16LE();
105+
}
106+
95107
SMLQuorumEntry.signersCount = bufferReader.readVarintNum();
96108
SMLQuorumEntry.validMembersCount = bufferReader.readVarintNum();
97109
SMLQuorumEntry.quorumPublicKey = bufferReader
@@ -107,6 +119,11 @@ QuorumEntry.fromBuffer = function fromBuffer(buffer) {
107119
.read(constants.SHA256_HASH_SIZE)
108120
.reverse()
109121
.toString('hex');
122+
123+
if (this.version >= HASH_QUORUM_INDEX_REQUIRED_VERSION) {
124+
SMLQuorumEntry.quorumIndex = bufferReader.readInt16LE();
125+
}
126+
110127
SMLQuorumEntry.signersCount = bufferReader.readVarintNum();
111128
const signersBytesToRead =
112129
Math.floor((SMLQuorumEntry.getParams().size + 7) / 8) || 1;
@@ -155,7 +172,13 @@ QuorumEntry.prototype.toBuffer = function toBuffer() {
155172
bufferWriter.writeUInt16LE(this.version);
156173
bufferWriter.writeUInt8(this.llmqType);
157174
bufferWriter.write(Buffer.from(this.quorumHash, 'hex').reverse());
175+
176+
if (this.version >= HASH_QUORUM_INDEX_REQUIRED_VERSION) {
177+
bufferWriter.writeInt16LE(this.quorumIndex);
178+
}
179+
158180
bufferWriter.writeVarintNum(this.signersCount);
181+
159182
if (this.isOutdatedRPC) {
160183
bufferWriter.writeVarintNum(this.validMembersCount);
161184
bufferWriter.write(Buffer.from(this.quorumPublicKey, 'hex'));
@@ -185,6 +208,11 @@ QuorumEntry.prototype.toBufferForHashing = function toBufferForHashing() {
185208
bufferWriter.writeUInt16LE(this.version);
186209
bufferWriter.writeUInt8(this.llmqType);
187210
bufferWriter.write(Buffer.from(this.quorumHash, 'hex').reverse());
211+
212+
if (this.version >= HASH_QUORUM_INDEX_REQUIRED_VERSION) {
213+
bufferWriter.writeInt16LE(this.quorumIndex);
214+
}
215+
188216
bufferWriter.writeVarintNum(fixedCounterLength);
189217
bufferWriter.write(Buffer.from(this.signers, 'hex'));
190218
bufferWriter.writeVarintNum(fixedCounterLength);
@@ -209,6 +237,7 @@ QuorumEntry.fromObject = function fromObject(obj) {
209237
SMLQuorumEntry.version = obj.version;
210238
SMLQuorumEntry.llmqType = obj.llmqType;
211239
SMLQuorumEntry.quorumHash = obj.quorumHash;
240+
SMLQuorumEntry.quorumIndex = obj.quorumIndex;
212241
SMLQuorumEntry.signersCount = obj.signersCount;
213242
SMLQuorumEntry.signers = obj.signers;
214243
SMLQuorumEntry.validMembersCount = obj.validMembersCount;
@@ -237,6 +266,14 @@ QuorumEntry.prototype.validate = function validate() {
237266
isSha256(this.quorumHash),
238267
'Expected quorumHash to be a sha256 hex string'
239268
);
269+
270+
if (this.version >= HASH_QUORUM_INDEX_REQUIRED_VERSION) {
271+
$.checkArgument(
272+
Number.isInteger(this.quorumIndex),
273+
'Expected quorumIndex to be an integer'
274+
);
275+
}
276+
240277
$.checkArgument(
241278
isUnsignedInteger(this.signersCount),
242279
'Expect signersCount to be an unsigned integer'
@@ -274,7 +311,7 @@ QuorumEntry.prototype.validate = function validate() {
274311
};
275312

276313
QuorumEntry.prototype.toObject = function toObject() {
277-
return {
314+
const result = {
278315
version: this.version,
279316
llmqType: this.llmqType,
280317
quorumHash: this.quorumHash,
@@ -287,6 +324,12 @@ QuorumEntry.prototype.toObject = function toObject() {
287324
quorumSig: this.quorumSig,
288325
membersSig: this.membersSig,
289326
};
327+
328+
if (this.version >= HASH_QUORUM_INDEX_REQUIRED_VERSION) {
329+
result.quorumIndex = this.quorumIndex;
330+
}
331+
332+
return result;
290333
};
291334

292335
QuorumEntry.getParams = function getParams(llmqType) {
@@ -323,9 +366,9 @@ QuorumEntry.getParams = function getParams(llmqType) {
323366
params.maximumActiveQuorumsCount = 2;
324367
return params;
325368
case constants.LLMQ_TYPES.LLMQ_TYPE_LLMQ_DEVNET:
326-
params.size = 10;
327-
params.threshold = 3;
328-
params.maximumActiveQuorumsCount = 7;
369+
params.size = 12;
370+
params.threshold = 6;
371+
params.maximumActiveQuorumsCount = 4;
329372
return params;
330373
case constants.LLMQ_TYPES.LLMQ_TYPE_TEST_V17:
331374
params.size = 3;

lib/encoding/bufferreader.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ BufferReader.prototype.readUInt64BEBN = function () {
137137
return bn;
138138
};
139139

140+
/**
141+
* Read the next Int16LE
142+
*
143+
* @return {number}
144+
*/
145+
BufferReader.prototype.readInt16LE = function () {
146+
var val = this.buf.readInt16LE(this.pos);
147+
this.pos = this.pos + 2;
148+
return val;
149+
}
150+
140151
/**
141152
* Read the next UInt64LEBN
142153
* @return {number}

lib/encoding/bufferwriter.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ BufferWriter.prototype.writeUInt32BE = function (n) {
113113
return this;
114114
};
115115

116+
/**
117+
* Write a Int32LE to the local buffer array
118+
* @param {number} n
119+
* @return {BufferWriter}
120+
*/
121+
BufferWriter.prototype.writeInt16LE = function (n) {
122+
var buf = Buffer.alloc(2);
123+
buf.writeInt16LE(n, 0);
124+
this.write(buf);
125+
return this;
126+
};
127+
116128
/**
117129
* Write a Int32LE to the local buffer array
118130
* @param {number} n

0 commit comments

Comments
 (0)