Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
bf3ee96
feat: create wallet to support Core v18.2.0-beta.2
jawid-h Oct 27, 2022
0291ec8
chore: linter fix
jawid-h Oct 27, 2022
833128b
feat(drive): do not switch to validator quorum which will be removed …
Nov 8, 2022
9143dfa
WIP
Nov 8, 2022
66a5732
WIP
Nov 8, 2022
7e88596
WIP
Nov 9, 2022
485ba88
WIP
Nov 9, 2022
a40752c
WIP
Nov 9, 2022
f9818bf
WIP
Nov 9, 2022
ddfeaaa
Merge branch 'v0.24-dev' into filter-by-ttl
Nov 16, 2022
712fc09
Merge branch 'v0.24-dev' into filter-by-ttl
Nov 29, 2022
abc65cd
WIP
Nov 29, 2022
43f2db7
WIP
Nov 30, 2022
6ccb5e8
WIP
Dec 1, 2022
539fdb7
Merge branch 'v0.24-dev' into feat/support-core
Dec 1, 2022
e42f449
WIP
Dec 1, 2022
d4c4bcb
WIP
Dec 1, 2022
b558157
WIP
Dec 1, 2022
0b54748
Merge branch 'feat/support-core' into filter-by-ttl
Dec 1, 2022
e992eaf
Merge branch 'v0.24-dev' into filter-by-ttl
Dec 5, 2022
dbbc999
WIP
Dec 5, 2022
b705261
WIP
Dec 5, 2022
c08083d
Merge branch 'v0.24-dev' into filter-by-ttl
Dec 6, 2022
02c52b8
WIP
Dec 6, 2022
ddde833
WIP
Dec 6, 2022
ef23e58
WIP
Dec 7, 2022
ec18e09
WIP
Dec 7, 2022
d272ecf
WIP
Dec 7, 2022
c0c55dc
Merge branch 'v0.24-dev' into filter-by-ttl
Dec 8, 2022
5e8673c
WIP
Dec 8, 2022
683e4e6
WIP
Dec 8, 2022
202ebd7
Merge branch 'v0.24-dev' into feat/support-core
Dec 23, 2022
27ba3d8
WIP
Dec 23, 2022
e1544a7
WIP
Dec 23, 2022
71396a7
WIP
Dec 23, 2022
5e477b8
WIP
Dec 27, 2022
2a6e5db
WIP
Dec 27, 2022
bd9c7a7
WIP
Dec 28, 2022
8834b01
WIP
Dec 28, 2022
6384722
WIP
Dec 28, 2022
4c73159
Merge branch 'v0.24-dev' into feat/support-core
Dec 29, 2022
4b8b886
Merge branch 'feat/support-core' into filter-by-ttl
Dec 29, 2022
b6321f6
WIP
Dec 29, 2022
3368bd4
WIP
Dec 29, 2022
e78bbd1
Merge branch 'v0.24-dev' into filter-by-ttl
Jan 9, 2023
d0a8ac2
WIP
Jan 9, 2023
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
8 changes: 4 additions & 4 deletions .pnp.cjs

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

Binary file not shown.
Binary file not shown.
65 changes: 0 additions & 65 deletions packages/js-drive/lib/core/getRandomQuorum.js

This file was deleted.

108 changes: 108 additions & 0 deletions packages/js-drive/lib/core/getRandomQuorumFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
const BufferWriter = require('@dashevo/dashcore-lib/lib/encoding/bufferwriter');
const Hash = require('@dashevo/dashcore-lib/lib/crypto/hash');
const QuorumsNotFoundError = require('./errors/QuorumsNotFoundError');
const ValidatorSet = require('../validator/ValidatorSet');
const llmqMap = require('./llmqMap');

const MIN_QUORUM_VALID_MEMBERS = 90;

/**
* Calculates scores for validator quorum selection
* it calculates sha256(hash, modifier) per quorumHash
* Please note that this is not a double-sha256 but a single-sha256
*
* @param {Buffer[]} quorumHashes
* @param {Buffer} modifier
* @return {Object[]} scores
*/
function calculateQuorumHashScores(quorumHashes, modifier) {
return quorumHashes.map((hash) => {
const bufferWriter = new BufferWriter();

bufferWriter.write(hash);
bufferWriter.write(modifier);

return { score: Hash.sha256(bufferWriter.toBuffer()), hash };
});
}

/**
*
* @param {RpcClient} coreRpcClient
* @return {getRandomQuorum}
*/
function getRandomQuorumFactory(coreRpcClient) {
/**
* Gets the current validator set quorum hash for a particular core height
*
* @typedef {getRandomQuorum}
* @param {SimplifiedMNList} sml
* @param {number} quorumType
* @param {Buffer} entropy - the entropy to select the quorum
* @param {number} coreHeight
* @return return {Promise<QuorumEntry>} - the current validator set's quorumHash
*/
async function getRandomQuorum(sml, quorumType, entropy, coreHeight) {
const validatorQuorums = sml.getQuorumsOfType(quorumType);

if (validatorQuorums.length === 0) {
throw new QuorumsNotFoundError(sml, quorumType);
}

const { result: allValidatorQuorumsExtendedInfo } = await coreRpcClient.quorum('listextended', coreHeight);

// convert to object
const validatorQuorumsInfo = allValidatorQuorumsExtendedInfo[llmqMap[quorumType]]
.reduce(
(obj, item) => ({
...obj,
...item,
}),
{},
);

const numberOfQuorums = validatorQuorums.length;
const minTtl = ValidatorSet.ROTATION_BLOCK_INTERVAL * 3;
const dkgInterval = 24;

// filter quorum by the number of valid members to choose the most vital ones
let filteredValidatorQuorums = validatorQuorums
.filter(
(validatorQuorum) => validatorQuorum.validMembersCount >= MIN_QUORUM_VALID_MEMBERS,
)
.filter((validatorQuorum) => {
const validatorQuorumInfo = validatorQuorumsInfo[validatorQuorum.quorumHash];

if (!validatorQuorumInfo) {
return false;
}

const quorumRemoveHeight = validatorQuorumInfo.creationHeight
+ (dkgInterval * numberOfQuorums);
const howMuchInRest = quorumRemoveHeight - coreHeight;
const quorumTtl = howMuchInRest * 2.5;

return quorumTtl > minTtl;
});

if (filteredValidatorQuorums.length === 0) {
// if there is no "vital" quorums, we choose among others with default min quorum size
filteredValidatorQuorums = validatorQuorums;
}

const validatorQuorumHashes = filteredValidatorQuorums
.map((quorum) => Buffer.from(quorum.quorumHash, 'hex'));

const scoredHashes = calculateQuorumHashScores(validatorQuorumHashes, entropy);

scoredHashes.sort((a, b) => Buffer.compare(a.score, b.score));

const quorumHash = scoredHashes[0].hash.toString('hex');

return sml.getQuorum(quorumType, quorumHash);
}

return getRandomQuorum;
}

module.exports = getRandomQuorumFactory;
25 changes: 25 additions & 0 deletions packages/js-drive/lib/core/llmqMap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
0xff: 'llmq_none',

1: 'llmq_50_60', // 50 members, 30 (60%) threshold, one per hour
2: 'llmq_400_60', // 400 members, 240 (60%) threshold, one every 12 hours
3: 'llmq_400_85', // 400 members, 340 (85%) threshold, one every 24 hours
4: 'llmq_100_67', // 100 members, 67 (67%) threshold, one per hour
5: 'llmq_60_75', // 60 members, 45 (75%) threshold, one every 12 hours

// for testing only
100: 'llmq_test', // 3 members, 2(66%) threshold, one per hour.

// for devnets only
101: 'llmq_devnet', // 12 members, 6 (50%) threshold, one per hour.

// for testing activation of new quorums only
102: 'llmq_test_v17', // 3 members, 2 (66%) threshold, one per hour.

// for testing only
103: 'llmq_test_dip0024', // 4 members, 2 (66%) threshold, one per hour.
104: 'llmq_test_instantsend', // 3 members, 2 (66%) threshold, one per hour.

// for devnets only. rotated version (v2) for devnets
105: 'llmq_devnet_dip0024', // 8 members, 4 (50%) threshold, one per hour.
};
4 changes: 2 additions & 2 deletions packages/js-drive/lib/createDIContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const getFeatureFlagForHeightFactory = require('./featureFlag/getFeatureFlagForH
const ValidatorSet = require('./validator/ValidatorSet');
const createValidatorSetUpdate = require('./abci/handlers/validator/createValidatorSetUpdate');
const fetchQuorumMembersFactory = require('./core/fetchQuorumMembersFactory');
const getRandomQuorum = require('./core/getRandomQuorum');
const getRandomQuorumFactory = require('./core/getRandomQuorumFactory');
const createQueryResponseFactory = require('./abci/handlers/query/response/createQueryResponseFactory');
const BlockExecutionContextRepository = require('./blockExecution/BlockExecutionContextRepository');

Expand Down Expand Up @@ -350,8 +350,8 @@ function createDIContainer(options) {
latestCoreChainLock: asValue(new LatestCoreChainLock()),
simplifiedMasternodeList: asClass(SimplifiedMasternodeList).proxy().singleton(),
fetchQuorumMembers: asFunction(fetchQuorumMembersFactory),
getRandomQuorum: asValue(getRandomQuorum),
fetchSimplifiedMNList: asFunction(fetchSimplifiedMNListFactory),
getRandomQuorum: asFunction(getRandomQuorumFactory),
coreZMQClient: asFunction((
coreZMQHost,
coreZMQPort,
Expand Down
1 change: 1 addition & 0 deletions packages/js-drive/lib/validator/ValidatorSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class ValidatorSet {
sml,
this.validatorSetLLMQType,
rotationEntropy,
coreHeight,
);

const quorumMembers = await this.fetchQuorumMembers(
Expand Down
104 changes: 0 additions & 104 deletions packages/js-drive/test/unit/core/getRandomQuorum.spec.js

This file was deleted.

Loading