This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Code improvements and remove shuffleValidatorList from PoA * Revert changes that has already been resolved in #8967 at update_generator_key --------- Co-authored-by: !shan <ishantiw.quasar@gmail.com>
- Loading branch information
Showing
12 changed files
with
134 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +0,0 @@ | ||
/* | ||
* Copyright © 2023 Lisk Foundation | ||
* | ||
* See the LICENSE file at the top-level directory of this distribution | ||
* for licensing information. | ||
* | ||
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, | ||
* no part of this software, including this file, may be copied, modified, | ||
* propagated, or distributed except according to the terms contained in the | ||
* LICENSE file. | ||
* | ||
* Removal or modification of this copyright notice is prohibited. | ||
*/ | ||
|
||
import { utils } from '@liskhq/lisk-cryptography'; | ||
import { ValidatorWeightWithRoundHash, ActiveValidator } from './types'; | ||
|
||
// Same as pos/utils/shuffleValidatorList | ||
export const shuffleValidatorList = ( | ||
roundSeed: Buffer, | ||
validators: ActiveValidator[], | ||
): ValidatorWeightWithRoundHash[] => { | ||
const validatorsWithRoundHash: ValidatorWeightWithRoundHash[] = []; | ||
for (const validator of validators) { | ||
const seedSource = Buffer.concat([roundSeed, validator.address]); | ||
validatorsWithRoundHash.push({ | ||
...validator, | ||
roundHash: utils.hash(seedSource), | ||
}); | ||
} | ||
|
||
validatorsWithRoundHash.sort((validator1, validator2) => { | ||
const diff = validator1.roundHash.compare(validator2.roundHash); | ||
if (diff !== 0) { | ||
return diff; | ||
} | ||
|
||
return validator1.address.compare(validator2.address); | ||
}); | ||
|
||
return validatorsWithRoundHash; | ||
}; | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright © 2023 Lisk Foundation | ||
* | ||
* See the LICENSE file at the top-level directory of this distribution | ||
* for licensing information. | ||
* | ||
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, | ||
* no part of this software, including this file, may be copied, modified, | ||
* propagated, or distributed except according to the terms contained in the | ||
* LICENSE file. | ||
* | ||
* Removal or modification of this copyright notice is prohibited. | ||
*/ | ||
|
||
export { shuffleValidatorList } from './shuffleValidatorList'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright © 2023 Lisk Foundation | ||
* | ||
* See the LICENSE file at the top-level directory of this distribution | ||
* for licensing information. | ||
* | ||
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, | ||
* no part of this software, including this file, may be copied, modified, | ||
* propagated, or distributed except according to the terms contained in the | ||
* LICENSE file. | ||
* | ||
* Removal or modification of this copyright notice is prohibited. | ||
*/ | ||
|
||
import { utils } from '@liskhq/lisk-cryptography'; | ||
|
||
export const shuffleValidatorList = < | ||
T extends { | ||
readonly address: Buffer; | ||
weight: bigint; | ||
}, | ||
>( | ||
roundSeed: Buffer, | ||
addresses: T[], | ||
): (T & { roundHash: Buffer })[] => { | ||
const validatorList = [...addresses].map(validator => ({ | ||
...validator, | ||
roundHash: Buffer.from([]), | ||
})) as (T & { roundHash: Buffer })[]; | ||
|
||
for (const validator of validatorList) { | ||
const seedSource = Buffer.concat([roundSeed, validator.address]); | ||
validator.roundHash = utils.hash(seedSource); | ||
} | ||
|
||
validatorList.sort((validator1, validator2) => { | ||
const diff = validator1.roundHash.compare(validator2.roundHash); | ||
if (diff !== 0) { | ||
return diff; | ||
} | ||
|
||
return validator1.address.compare(validator2.address); | ||
}); | ||
|
||
return validatorList; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.