Skip to content
This repository was archived by the owner on Jun 11, 2024. It is now read-only.

Commit 182f93d

Browse files
authored
Improve chain connector storage (#9198)
* ♻️ Add ability to save inclusion proofs at every new block - Add config to take keepInclusionProofsForHeights and inclusionProofKeys - Add DB update to get/set/delete inclusionProofs - Add handler in new block event to save inclusion proofs - Add endpoint for chain to get inclusion proofs by height * ♻️ Move inclusion proof collection to consensus * ♻️ Save inclusionProofs on both block receive and generate * ♻️ Improve chain connector plugin - Improve storage to retrieve by key/val and delete efficiently instead of managing full array - Reduce number of RPC calls during new block event - Improve cleanup * ♻️ Update plugin to manage last sent CCU and CCM * ♻️ Update interop examples * 🌱 Add license * ♻️ Manage validatorsHash by height * ♻️ Improve CCU storage management * ♻️ Add tests and improve code base * ✅ Add tests for block event handler * ✅ Add ccmHandler unit tests * ♻️ Unable CCU sending when receiving chain is syncing * ♻️ Handle error at new block subscribe
1 parent 39c521f commit 182f93d

26 files changed

+4839
-3518
lines changed

Diff for: examples/interop/pos-mainchain-fast/config/custom_config_node_one.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
{
22
"system": {
3-
"dataPath": "~/.lisk/pos-mainchain-node-one",
4-
"logLevel": "info"
3+
"dataPath": "~/.lisk/mainchain-node-one",
4+
"logLevel": "debug",
5+
"keepEventsForHeights": -1,
6+
"keepInclusionProofsForHeights": -1,
7+
"inclusionProofKeys": [
8+
"83ed0d250000160811fdaf692ba77eabfbfc3a6bb3c4cf6a87beafd28cfe90b5dc64cb20ab46"
9+
]
510
},
611
"rpc": {
712
"modes": ["ipc"],

Diff for: examples/interop/pos-mainchain-fast/config/custom_config_node_two.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
{
22
"system": {
3-
"dataPath": "~/.lisk/pos-mainchain-node-two",
4-
"logLevel": "info"
3+
"dataPath": "~/.lisk/mainchain-node-two",
4+
"logLevel": "debug",
5+
"keepEventsForHeights": -1,
6+
"keepInclusionProofsForHeights": -1,
7+
"inclusionProofKeys": [
8+
"83ed0d250000ac894ab085f50b81fe000e99ccb27e5543de69f63d4f9105daab15dce90f81b3"
9+
]
510
},
611
"rpc": {
712
"modes": ["ipc"],

Diff for: examples/interop/pos-mainchain-fast/config/default/config.json

-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
{
2-
"system": {
3-
"dataPath": "~/.lisk/pos-mainchain-fast",
4-
"keepEventsForHeights": -1,
5-
"keepInclusionProofsForHeights": -1,
6-
"inclusionProofKeys": [
7-
"83ed0d250000160811fdaf692ba77eabfbfc3a6bb3c4cf6a87beafd28cfe90b5dc64cb20ab46"
8-
],
9-
"logLevel": "info"
10-
},
112
"rpc": {
123
"modes": ["ipc"],
134
"port": 7881,

Diff for: examples/interop/pos-sidechain-example-one/config/default/config.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
"system": {
33
"dataPath": "~/.lisk/pos-sidechain-example-one",
44
"keepEventsForHeights": 300,
5-
"logLevel": "info"
5+
"logLevel": "info",
6+
"keepInclusionProofsForHeights": -1,
7+
"inclusionProofKeys": [
8+
"83ed0d250000fb5e512425fc9449316ec95969ebe71e2d576dbab833d61e2a5b9330fd70ee02"
9+
]
610
},
711
"rpc": {
812
"modes": ["ipc"],

Diff for: examples/interop/pos-sidechain-example-two/config/default/config.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
"system": {
33
"dataPath": "~/.lisk/pos-sidechain-example-two",
44
"keepEventsForHeights": 300,
5-
"logLevel": "info"
5+
"logLevel": "info",
6+
"keepInclusionProofsForHeights": -1,
7+
"inclusionProofKeys": [
8+
"83ed0d250000fb5e512425fc9449316ec95969ebe71e2d576dbab833d61e2a5b9330fd70ee02"
9+
]
610
},
711
"rpc": {
812
"modes": ["ipc"],

Diff for: framework-plugins/lisk-framework-chain-connector-plugin/src/active_validators_update.ts

+11-33
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,31 @@
1212
* Removal or modification of this copyright notice is prohibited.
1313
*/
1414
/* 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';
2317

2418
/**
2519
* @see https://github.com/LiskHQ/lips/blob/main/proposals/lip-0053.md#computing-the-validators-update
2620
*/
21+
2722
export const calculateActiveValidatorsUpdate = (
28-
certificate: Certificate,
29-
validatorsHashPreimage: ValidatorsData[],
30-
lastCertificate: LastCertificate,
23+
validatorsDataAtLastCertificate: ValidatorsDataWithHeight,
24+
validatorsDataAtNewCertificate: ValidatorsDataWithHeight,
3125
): { activeValidatorsUpdate: ActiveValidatorsUpdate; certificateThreshold: bigint } => {
3226
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-
4927
// If the certificate threshold is not changed from last certificate then we assign zero
5028
if (
51-
validatorDataAtCertificate.certificateThreshold ===
52-
validatorDataAtLastCertificate.certificateThreshold
29+
validatorsDataAtNewCertificate.certificateThreshold ===
30+
validatorsDataAtLastCertificate.certificateThreshold
5331
) {
54-
certificateThreshold = validatorDataAtLastCertificate.certificateThreshold;
32+
certificateThreshold = validatorsDataAtLastCertificate.certificateThreshold;
5533
} else {
56-
certificateThreshold = validatorDataAtCertificate.certificateThreshold;
34+
certificateThreshold = validatorsDataAtNewCertificate.certificateThreshold;
5735
}
5836

5937
const activeValidatorsUpdate = getActiveValidatorsUpdate(
60-
validatorDataAtLastCertificate.validators,
61-
validatorDataAtCertificate.validators,
38+
validatorsDataAtLastCertificate.validators,
39+
validatorsDataAtNewCertificate.validators,
6240
);
6341

6442
return { activeValidatorsUpdate, certificateThreshold };

0 commit comments

Comments
 (0)