lisk-sdk icon indicating copy to clipboard operation
lisk-sdk copied to clipboard

Create Mainchain, Sidechain and BaseRecoveryManager class and declare functions

Open ishantiw opened this issue 1 year ago • 0 comments

Description

Create BaseRecoveryManager class and declare functions

abstract class BaseRecoveryManager {
	private _stateRecoveryDB: Database;
	private _apiClient: APIClient;
	private config: Config;
	private _queryKeys: Map<chainID, queryKey[]>;
	private _mainchainClient: APIClient;
	public _sidechainClientMap: Map<chainID, SidechainClient>

	constructor({ config, chainID, stateRecoveryDB }) {
		this._stateRecoveryDB = stateRecoveryDB;
		this.config = config;
		this._sidechainClientMap = new Map();
	}

	public load() {}

	public unload() {}

	// Add a client
	public addSideChainClient(chainID, connectionURL) {
		const sidechainClient = new SidechainClient((chainID, connectionURL);
		this._sidechainClientMap.set(chainID, sidechainClient);
	}

	// add key for state recovery based on the chain and add it to client.addQueryKeyForInclusionProof
	public addKeyForStateRecovery(chainID, queryKey) {}

	// this is common to both mainchain and sidechain; gets information from DB stored by clients
	public triggerStateRecovery(chainID, queryKey) {
// calls private method `computeStateRecoveryParams ` which computes all the params stored in the messageRecoveryDB
       }
	
      // This method will be called once a recovery was done successfully and we need to update all the inclusionProofs
    public updateInclusionProofs(chainID, queryKey) {}

	// Clean mechanism will include checking last certificate height of the sidechain on mainchain
    public cleanup()
}

class MainchainRecoveryManager extends BaseRecoveryManager {
	private _messageRecoveryDB: Database;

	constructor({ config, chainID, stateRecoveryDB, messageRecoveryDB, sidechainChainID }) {
		super({ config, chainID, stateRecoveryDB });
		this._messageRecoveryDB = messageRecoveryDB;
	}

	// saves CCMs and inclusion proof on the mainchain on every new block
	public enableMessageRecovery() {}

	// creates tx
	public triggerMessageRecovery(chainID){
		// calls private method `computeMessageRecoveryParams ` which computes all the params stored in the messageRecoveryDB
	}

// creates tx
	public triggerInitMessageRecovery(chainID){
		// calls private method `computeInitMessageRecoveryParams ` which computes all the params stored in the messageRecoveryDB
	}

      public cleanup()
}

class SidechainRecoveryManager extends BaseRecoveryManager {
	private _mainchainClient: APIClient;

	constructor({ config, chainID, stateRecoveryDB, mainchainClient }) {
		super({ config, chainID, stateRecoveryDB });
		this._mainchainClient = mainchainClient;
	}

	// Only init state recovery is extra command as compared to BaseRecoveryManager
	// we can call mainchainClient to build the params
	public triggerInitStateRecovery(chainID, queryKey){
// calls private method `computeInitStateRecoveryParams ` which computes all the params stored in the StateRecoveryDB
       }
    
      public cleanup()
}
  • Implement logic for addSideChainClient and addKeyForStateRecovery

Acceptance Criteria

  • Should have all the interfaces present
  • Should have all the unit tests present for addSideChainClient and addKeyForStateRecovery

ishantiw avatar Nov 29 '23 13:11 ishantiw