LiskArchive / lisk-sdk

🔩 Lisk software development kit
https://lisk.com
Apache License 2.0
2.72k stars 457 forks source link

Create Base, Mainchain and Sidechain RecoveryClient classes #9167

Open ishantiw opened 7 months ago

ishantiw commented 7 months ago

Description


abstract class BaseRecoveryClient {
    private _apiClient!: apiClient.APIClient;
    private _queryKeys!: Set<string>;

    public connect(_connectionObj: ConnectionObj) {
        // check for mode of connection and use connectionString to connect to the relevant client
    }
    public async getInclusionProof(_keys: string[]) {
        // Call RPC to get inclusionProof and return in appropriate format
        // await this._apiClient.invoke('state_prove', {});
    }
    public addQueryKeyForInclusionProof(queryKey: string) {
        this._queryKeys.add(queryKey);
    }

    public collectInclusionProofs() {
        // subscribe to chain_newBlock event and on every new block query the client with all the proofs
        this._apiClient.subscribe('chain_newBlock', _ => {
            this.getInclusionProof([...this._queryKeys.values()]);
            // save proof for each key in stateRecoveryDB with key { sidechainID+queryKey }
        });
    }

    public removeQueryKey(queryKey: string) {
        this._queryKeys.delete(queryKey);
    }

    // Based on finalized height and last certificate on the other chain delete irrelevant recovery data
    public cleanupStateRecoveryData() {}

    // Disconnect client and release resources
    public disconnectClient() {}
}

class MainchainRecoveryClient extends BaseRecoveryClient {
    // Collect new CCMs from the on-chain events
    // Collect inclusionProofs for the sidechain outbox for the CCMs: This part is done by calling addQueryKeyForInclusionProof from the manager class
    public collectCCMsAndProofs() {
        // collect CCMs on every newBlock and by calling getEvents for the block height and save them in messageRecoveryDB
    }

    // Based on finalized height and last certificate on the other chain delete irrelevant message recovery data
    public cleanupMessageRecoveryData() {}
}

class SidechainRecoveryClient extends BaseRecoveryClient {}

Acceptance Criteria