|
12 | 12 | * Removal or modification of this copyright notice is prohibited.
|
13 | 13 | */
|
14 | 14 | /* eslint-disable no-bitwise */
|
15 |
| -import { |
16 |
| - ActiveValidator, |
17 |
| - Certificate, |
18 |
| - LastCertificate, |
19 |
| - utils, |
20 |
| - ActiveValidatorsUpdate, |
21 |
| -} from 'lisk-sdk'; |
22 |
| -import { ValidatorsData } from './types'; |
| 15 | +import { ActiveValidator, utils, ActiveValidatorsUpdate } from 'lisk-sdk'; |
| 16 | +import { ValidatorsDataWithHeight } from './types'; |
23 | 17 |
|
24 | 18 | /**
|
25 | 19 | * @see https://github.com/LiskHQ/lips/blob/main/proposals/lip-0053.md#computing-the-validators-update
|
26 | 20 | */
|
| 21 | + |
27 | 22 | export const calculateActiveValidatorsUpdate = (
|
28 |
| - certificate: Certificate, |
29 |
| - validatorsHashPreimage: ValidatorsData[], |
30 |
| - lastCertificate: LastCertificate, |
| 23 | + validatorsDataAtLastCertificate: ValidatorsDataWithHeight, |
| 24 | + validatorsDataAtNewCertificate: ValidatorsDataWithHeight, |
31 | 25 | ): { activeValidatorsUpdate: ActiveValidatorsUpdate; certificateThreshold: bigint } => {
|
32 | 26 | let certificateThreshold;
|
33 |
| - const validatorDataAtCertificate = validatorsHashPreimage.find(validatorsData => |
34 |
| - validatorsData.validatorsHash.equals(certificate.validatorsHash), |
35 |
| - ); |
36 |
| - |
37 |
| - if (!validatorDataAtCertificate) { |
38 |
| - throw new Error('No validators data found for the certificate height.'); |
39 |
| - } |
40 |
| - |
41 |
| - const validatorDataAtLastCertificate = validatorsHashPreimage.find(validatorsData => |
42 |
| - validatorsData.validatorsHash.equals(lastCertificate.validatorsHash), |
43 |
| - ); |
44 |
| - |
45 |
| - if (!validatorDataAtLastCertificate) { |
46 |
| - throw new Error('No validators data found for the given last certificate height.'); |
47 |
| - } |
48 |
| - |
49 | 27 | // If the certificate threshold is not changed from last certificate then we assign zero
|
50 | 28 | if (
|
51 |
| - validatorDataAtCertificate.certificateThreshold === |
52 |
| - validatorDataAtLastCertificate.certificateThreshold |
| 29 | + validatorsDataAtNewCertificate.certificateThreshold === |
| 30 | + validatorsDataAtLastCertificate.certificateThreshold |
53 | 31 | ) {
|
54 |
| - certificateThreshold = validatorDataAtLastCertificate.certificateThreshold; |
| 32 | + certificateThreshold = validatorsDataAtLastCertificate.certificateThreshold; |
55 | 33 | } else {
|
56 |
| - certificateThreshold = validatorDataAtCertificate.certificateThreshold; |
| 34 | + certificateThreshold = validatorsDataAtNewCertificate.certificateThreshold; |
57 | 35 | }
|
58 | 36 |
|
59 | 37 | const activeValidatorsUpdate = getActiveValidatorsUpdate(
|
60 |
| - validatorDataAtLastCertificate.validators, |
61 |
| - validatorDataAtCertificate.validators, |
| 38 | + validatorsDataAtLastCertificate.validators, |
| 39 | + validatorsDataAtNewCertificate.validators, |
62 | 40 | );
|
63 | 41 |
|
64 | 42 | return { activeValidatorsUpdate, certificateThreshold };
|
|
0 commit comments