@@ -16,13 +16,19 @@ const {
16
16
isHexaString : isHexString ,
17
17
} = utils ;
18
18
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 ;
20
25
21
26
/**
22
27
* @typedef {Object } SMLQuorumEntry
23
28
* @property {number } version
24
29
* @property {number } llmqType
25
30
* @property {string } quorumHash
31
+ * @property {number } [quorumIndex]
26
32
* @property {number } signersCount
27
33
* @property {string } signers
28
34
* @property {number } validMembersCount
@@ -41,6 +47,7 @@ const { BLS_PUBLIC_KEY_SIZE, BLS_SIGNATURE_SIZE, SHA256_HASH_SIZE } = constants;
41
47
* @property {number } version
42
48
* @property {number } llmqType
43
49
* @property {string } quorumHash
50
+ * @property {number } [quorumIndex]
44
51
* @property {number } signersCount
45
52
* @property {string } signers
46
53
* @property {number } validMembersCount
@@ -92,6 +99,11 @@ QuorumEntry.fromBuffer = function fromBuffer(buffer) {
92
99
. read ( constants . SHA256_HASH_SIZE )
93
100
. reverse ( )
94
101
. toString ( 'hex' ) ;
102
+
103
+ if ( this . version >= HASH_QUORUM_INDEX_REQUIRED_VERSION ) {
104
+ SMLQuorumEntry . quorumIndex = buffer . readInt16LE ( ) ;
105
+ }
106
+
95
107
SMLQuorumEntry . signersCount = bufferReader . readVarintNum ( ) ;
96
108
SMLQuorumEntry . validMembersCount = bufferReader . readVarintNum ( ) ;
97
109
SMLQuorumEntry . quorumPublicKey = bufferReader
@@ -107,6 +119,11 @@ QuorumEntry.fromBuffer = function fromBuffer(buffer) {
107
119
. read ( constants . SHA256_HASH_SIZE )
108
120
. reverse ( )
109
121
. toString ( 'hex' ) ;
122
+
123
+ if ( this . version >= HASH_QUORUM_INDEX_REQUIRED_VERSION ) {
124
+ SMLQuorumEntry . quorumIndex = bufferReader . readInt16LE ( ) ;
125
+ }
126
+
110
127
SMLQuorumEntry . signersCount = bufferReader . readVarintNum ( ) ;
111
128
const signersBytesToRead =
112
129
Math . floor ( ( SMLQuorumEntry . getParams ( ) . size + 7 ) / 8 ) || 1 ;
@@ -155,7 +172,13 @@ QuorumEntry.prototype.toBuffer = function toBuffer() {
155
172
bufferWriter . writeUInt16LE ( this . version ) ;
156
173
bufferWriter . writeUInt8 ( this . llmqType ) ;
157
174
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
+
158
180
bufferWriter . writeVarintNum ( this . signersCount ) ;
181
+
159
182
if ( this . isOutdatedRPC ) {
160
183
bufferWriter . writeVarintNum ( this . validMembersCount ) ;
161
184
bufferWriter . write ( Buffer . from ( this . quorumPublicKey , 'hex' ) ) ;
@@ -185,6 +208,11 @@ QuorumEntry.prototype.toBufferForHashing = function toBufferForHashing() {
185
208
bufferWriter . writeUInt16LE ( this . version ) ;
186
209
bufferWriter . writeUInt8 ( this . llmqType ) ;
187
210
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
+
188
216
bufferWriter . writeVarintNum ( fixedCounterLength ) ;
189
217
bufferWriter . write ( Buffer . from ( this . signers , 'hex' ) ) ;
190
218
bufferWriter . writeVarintNum ( fixedCounterLength ) ;
@@ -209,6 +237,7 @@ QuorumEntry.fromObject = function fromObject(obj) {
209
237
SMLQuorumEntry . version = obj . version ;
210
238
SMLQuorumEntry . llmqType = obj . llmqType ;
211
239
SMLQuorumEntry . quorumHash = obj . quorumHash ;
240
+ SMLQuorumEntry . quorumIndex = obj . quorumIndex ;
212
241
SMLQuorumEntry . signersCount = obj . signersCount ;
213
242
SMLQuorumEntry . signers = obj . signers ;
214
243
SMLQuorumEntry . validMembersCount = obj . validMembersCount ;
@@ -237,6 +266,14 @@ QuorumEntry.prototype.validate = function validate() {
237
266
isSha256 ( this . quorumHash ) ,
238
267
'Expected quorumHash to be a sha256 hex string'
239
268
) ;
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
+
240
277
$ . checkArgument (
241
278
isUnsignedInteger ( this . signersCount ) ,
242
279
'Expect signersCount to be an unsigned integer'
@@ -274,7 +311,7 @@ QuorumEntry.prototype.validate = function validate() {
274
311
} ;
275
312
276
313
QuorumEntry . prototype . toObject = function toObject ( ) {
277
- return {
314
+ const result = {
278
315
version : this . version ,
279
316
llmqType : this . llmqType ,
280
317
quorumHash : this . quorumHash ,
@@ -287,6 +324,12 @@ QuorumEntry.prototype.toObject = function toObject() {
287
324
quorumSig : this . quorumSig ,
288
325
membersSig : this . membersSig ,
289
326
} ;
327
+
328
+ if ( this . version >= HASH_QUORUM_INDEX_REQUIRED_VERSION ) {
329
+ result . quorumIndex = this . quorumIndex ;
330
+ }
331
+
332
+ return result ;
290
333
} ;
291
334
292
335
QuorumEntry . getParams = function getParams ( llmqType ) {
@@ -323,9 +366,9 @@ QuorumEntry.getParams = function getParams(llmqType) {
323
366
params . maximumActiveQuorumsCount = 2 ;
324
367
return params ;
325
368
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 ;
329
372
return params ;
330
373
case constants . LLMQ_TYPES . LLMQ_TYPE_TEST_V17 :
331
374
params . size = 3 ;
0 commit comments