diff --git a/examples/interop/common/mainchain_registration.ts b/examples/interop/common/mainchain_registration.ts index 939757f5d1..bd91ed7483 100644 --- a/examples/interop/common/mainchain_registration.ts +++ b/examples/interop/common/mainchain_registration.ts @@ -3,9 +3,7 @@ import { registrationSignatureMessageSchema, mainchainRegParams as mainchainRegParamsSchema, MESSAGE_TAG_CHAIN_REG, - MODULE_NAME_INTEROPERABILITY, -} from 'lisk-framework'; -import { COMMAND_NAME_MAINCHAIN_REG } from 'lisk-framework/dist-node/modules/interoperability/constants'; +} from 'lisk-sdk'; export const registerMainchain = async ( num: string, @@ -17,6 +15,7 @@ export const registerMainchain = async ( const mainchainClient = await apiClient.createIPCClient(`~/.lisk/mainchain-node-${num}`); const sidechainClient = await apiClient.createIPCClient(`~/.lisk/pos-sidechain-example-${num}`); + // Get node info from sidechain and mainchain const mainchainNodeInfo = await mainchainClient.invoke('system_getNodeInfo'); const sidechainNodeInfo = await sidechainClient.invoke('system_getNodeInfo'); @@ -55,25 +54,29 @@ export const registerMainchain = async ( { height: sidechainNodeInfo.height }, ); - const activeValidatorsWithPrivateKey: { blsPublicKey: Buffer; blsPrivateKey: Buffer }[] = []; + // Add validator private keys to the sidechain validator list + const activeValidatorsBLSKeys: { blsPublicKey: Buffer; blsPrivateKey: Buffer }[] = []; for (const v of sidechainActiveValidators as { blsKey: string; bftWeight: string }[]) { const validatorInfo = sidechainValidatorsKeys.find( configValidator => configValidator.plain.blsKey === v.blsKey, ); if (validatorInfo) { - activeValidatorsWithPrivateKey.push({ + activeValidatorsBLSKeys.push({ blsPublicKey: Buffer.from(v.blsKey, 'hex'), blsPrivateKey: Buffer.from(validatorInfo.plain.blsPrivateKey, 'hex'), }); } } - console.log('Total activeValidatorsWithPrivateKey:', activeValidatorsWithPrivateKey.length); - // Sort active validators from sidechainChain - activeValidatorsWithPrivateKey.sort((a, b) => a.blsPublicKey.compare(b.blsPublicKey)); + + console.log('Total activeValidatorsBLSKeys:', activeValidatorsBLSKeys.length); + + // Sort active validators from sidechain lexicographically after their BLS public key + activeValidatorsBLSKeys.sort((a, b) => a.blsPublicKey.compare(b.blsPublicKey)); const sidechainValidatorsSignatures: { publicKey: Buffer; signature: Buffer }[] = []; - // Sign with each active validator - for (const validator of activeValidatorsWithPrivateKey) { + + // Sign parameters with each active sidechain validator + for (const validator of activeValidatorsBLSKeys) { const signature = bls.signData( MESSAGE_TAG_CHAIN_REG, params.ownChainID, @@ -83,7 +86,7 @@ export const registerMainchain = async ( sidechainValidatorsSignatures.push({ publicKey: validator.blsPublicKey, signature }); } - const publicKeysList = activeValidatorsWithPrivateKey.map(v => v.blsPublicKey); + const publicKeysList = activeValidatorsBLSKeys.map(v => v.blsPublicKey); console.log('Total active sidechain validators:', sidechainValidatorsSignatures.length); // Create an aggregated signature @@ -102,8 +105,8 @@ export const registerMainchain = async ( aggregationBits: aggregationBits.toString('hex'), }; const tx = new Transaction({ - module: MODULE_NAME_INTEROPERABILITY, - command: COMMAND_NAME_MAINCHAIN_REG, + module: 'interoperability', + command: 'registerMainchain', fee: BigInt(2000000000), params: codec.encodeJSON(mainchainRegParamsSchema, mainchainRegParams), nonce: BigInt(nonce),