diff --git a/config/node-configs/rsk-reg-4.conf b/config/node-configs/rsk-reg-4.conf index a6e45cfb..f43a1736 100644 --- a/config/node-configs/rsk-reg-4.conf +++ b/config/node-configs/rsk-reg-4.conf @@ -11,9 +11,29 @@ federator { enabled = true signers { BTC { - type = "hsm" #hsm or keyFile (keyfile is deprecated) - #path = "/var/lib/jenkins/workspace/Pipeline/utilities/configs/keys/reg4.key" #needed when using keyfile + type = "hsm" + host = "127.0.0.1" + port = 9999 keyId = "m/44'/1'/0'/0/0" + bookkeeping { # Notice these new fields, for the hsm tcpsigner + difficultyTarget = 3 + informerInterval = 5000 + maxAmountBlockHeaders = 100 + maxChunkSizeToHsm = 100 + }, + socketTimeout = 20000 + } + RSK { + type = "hsm" + host = "127.0.0.1" + port = 9999 + keyId = "m/44'/1'/1'/0/0" + } + MST { + type = "hsm" + host = "127.0.0.1" + port = 9999 + keyId = "m/44'/1'/2'/0/0" } } bitcoinPeerAddresses = [ diff --git a/config/node-configs/rsk-reg-5.conf b/config/node-configs/rsk-reg-5.conf index 424f2bf2..fc6a5d9b 100644 --- a/config/node-configs/rsk-reg-5.conf +++ b/config/node-configs/rsk-reg-5.conf @@ -11,9 +11,29 @@ federator { enabled = true signers { BTC { - type = "hsm" #hsm or keyFile (keyfile is deprecated) - #path = "/var/lib/jenkins/workspace/Pipeline/utilities/configs/keys/reg5.key" #needed when using keyfile + type = "hsm" + host = "127.0.0.1" + port = 9999 keyId = "m/44'/1'/0'/0/0" + bookkeeping { # Notice these new fields, for the hsm tcpsigner + difficultyTarget = 3 + informerInterval = 5000 + maxAmountBlockHeaders = 100 + maxChunkSizeToHsm = 100 + }, + socketTimeout = 20000 + } + RSK { + type = "hsm" + host = "127.0.0.1" + port = 9999 + keyId = "m/44'/1'/1'/0/0" + } + MST { + type = "hsm" + host = "127.0.0.1" + port = 9999 + keyId = "m/44'/1'/2'/0/0" } } bitcoinPeerAddresses = [ diff --git a/config/node-keys/reg4-v2-key.json b/config/node-keys/reg4-tcpsigner-v5-key.json similarity index 64% rename from config/node-keys/reg4-v2-key.json rename to config/node-keys/reg4-tcpsigner-v5-key.json index 81bcdea8..1910880e 100644 --- a/config/node-keys/reg4-v2-key.json +++ b/config/node-keys/reg4-tcpsigner-v5-key.json @@ -1,8 +1,8 @@ { - "m/44'/1'/0'/0/0": "47b9249139474a00470c1dd5b01c9ed7ca2a67c71ab9ec4ff1a8698fb2937d7c", - "m/44'/1'/0'/0/1": "47b9249139474a00470c1dd5b01c9ed7ca2a67c71ab9ec4ff1a8698fb2937d7c", - "m/44'/1'/0'/0/2": "47b9249139474a00470c1dd5b01c9ed7ca2a67c71ab9ec4ff1a8698fb2937d7c", "m/44'/0'/0'/0/0": "47b9249139474a00470c1dd5b01c9ed7ca2a67c71ab9ec4ff1a8698fb2937d7c", + "m/44'/1'/0'/0/0": "47b9249139474a00470c1dd5b01c9ed7ca2a67c71ab9ec4ff1a8698fb2937d7c", + "m/44'/1'/1'/0/0": "47b9249139474a00470c1dd5b01c9ed7ca2a67c71ab9ec4ff1a8698fb2937d7c", + "m/44'/1'/2'/0/0": "47b9249139474a00470c1dd5b01c9ed7ca2a67c71ab9ec4ff1a8698fb2937d7c", "m/44'/137'/0'/0/0": "47b9249139474a00470c1dd5b01c9ed7ca2a67c71ab9ec4ff1a8698fb2937d7c", - "m/44'/137'/0'/0/1": "47b9249139474a00470c1dd5b01c9ed7ca2a67c71ab9ec4ff1a8698fb2937d7c" -} \ No newline at end of file + "m/44'/137'/1'/0/0": "47b9249139474a00470c1dd5b01c9ed7ca2a67c71ab9ec4ff1a8698fb2937d7c" +} diff --git a/config/node-keys/reg5-v2-key.json b/config/node-keys/reg5-tcpsigner-v5-key.json similarity index 64% rename from config/node-keys/reg5-v2-key.json rename to config/node-keys/reg5-tcpsigner-v5-key.json index 97de10db..64400365 100644 --- a/config/node-keys/reg5-v2-key.json +++ b/config/node-keys/reg5-tcpsigner-v5-key.json @@ -1,8 +1,8 @@ { - "m/44'/1'/0'/0/0": "a8a8dda1dcd067850a510cc1042d6b137a632792194a2d3ff7cdd69f21b54104", - "m/44'/1'/0'/0/1": "a8a8dda1dcd067850a510cc1042d6b137a632792194a2d3ff7cdd69f21b54104", - "m/44'/1'/0'/0/2": "a8a8dda1dcd067850a510cc1042d6b137a632792194a2d3ff7cdd69f21b54104", "m/44'/0'/0'/0/0": "a8a8dda1dcd067850a510cc1042d6b137a632792194a2d3ff7cdd69f21b54104", + "m/44'/1'/0'/0/0": "a8a8dda1dcd067850a510cc1042d6b137a632792194a2d3ff7cdd69f21b54104", + "m/44'/1'/1'/0/0": "a8a8dda1dcd067850a510cc1042d6b137a632792194a2d3ff7cdd69f21b54104", + "m/44'/1'/2'/0/0": "a8a8dda1dcd067850a510cc1042d6b137a632792194a2d3ff7cdd69f21b54104", "m/44'/137'/0'/0/0": "a8a8dda1dcd067850a510cc1042d6b137a632792194a2d3ff7cdd69f21b54104", - "m/44'/137'/0'/0/1": "a8a8dda1dcd067850a510cc1042d6b137a632792194a2d3ff7cdd69f21b54104" -} \ No newline at end of file + "m/44'/137'/1'/0/0": "a8a8dda1dcd067850a510cc1042d6b137a632792194a2d3ff7cdd69f21b54104" +} diff --git a/container-action/Dockerfile b/container-action/Dockerfile index 368c1146..405ab7f7 100644 --- a/container-action/Dockerfile +++ b/container-action/Dockerfile @@ -41,12 +41,14 @@ RUN cd /tmp \ # -- configure entrypoint to run RIT-------------------------------------------- RUN mkdir -p /usr/src/logbacks +RUN mkdir -p /usr/src/tcpsigner-dist WORKDIR /usr/src COPY entrypoint.sh /usr/src/entrypoint.sh COPY rit-local-configs/regtest-all-keys.js /usr/src/regtest.js COPY rit-local-configs/logbacks/* /usr/src/logbacks/ +COPY tcpsigner-dist/* /usr/src/tcpsigner-dist/ COPY scripts/* /usr/src/ RUN chmod +x /usr/src/entrypoint.sh \ diff --git a/container-action/rit-local-configs/regtest-all-keys.js b/container-action/rit-local-configs/regtest-all-keys.js index 20a62915..f911abe1 100644 --- a/container-action/rit-local-configs/regtest-all-keys.js +++ b/container-action/rit-local-configs/regtest-all-keys.js @@ -3,6 +3,9 @@ const nodesConfigPath = 'config/node-configs'; const keysPathResolve = 'node-keys'; const classpath = process.env.POWPEG_NODE_JAR_PATH; const federatesLogbackPath = path.resolve(__dirname, 'logbacks'); +const tcpsignerPath = process.env.TCPSIGNER_PATH; + +console.log('tcpsignerPath: ', tcpsignerPath) module.exports = { init: { @@ -91,6 +94,13 @@ module.exports = { 'federator.signers.MST.type': 'keyFile', 'federator.signers.MST.path': path.resolve(__dirname, `${keysPathResolve}/reg4.key`) }, + hsmConfigs: { + btc: { + serverPath: tcpsignerPath, + keyPath : keysPath + 'reg4-tcpsigner-v5-key.json', + version: '5', + }, + }, nodeId: '1da807c71c2f303b7f409dd2605b297ac494a563be3b9ca5f52d95a43d183cc52191fc2bd3b06ece06b68390cbb3ba306284aed9ca7cb61dd6289e66e693126f' }, { @@ -110,6 +120,13 @@ module.exports = { 'federator.signers.MST.type': 'keyFile', 'federator.signers.MST.path': path.resolve(__dirname, `${keysPathResolve}/reg5.key`) }, + hsmConfigs: { + btc: { + serverPath: tcpsignerPath, + keyPath : keysPath + 'reg4-tcpsigner-v5-key.json', + version: '5', + }, + }, nodeId: '6bb9eab797eadc8b697f0e82a01d01cabbfaaca37e5bafc06fdc6fdd38af894a9a8cbaf526d344b5df39b80433609e006586050fd2188d30ab000b0fb6a6baaf' } ] diff --git a/container-action/scripts/configure_rit_locally.sh b/container-action/scripts/configure_rit_locally.sh index 2c0bc511..5729a203 100755 --- a/container-action/scripts/configure_rit_locally.sh +++ b/container-action/scripts/configure_rit_locally.sh @@ -16,6 +16,7 @@ BITCOIND_BIN_PATH=/usr/local/bin/bitcoind BITCOIN_DATA_DIR=/usr/src/bitcoindata WAIT_FOR_BLOCK_ATTEMPT_TIME_MILLIS=800 WAIT_FOR_BLOCK_MAX_ATTEMPTS=1200 +TCPSIGNER_PATH=/usr/src/tcpsigner-dist EOF echo -e "\n\n---------- Configuring RIT to run the tests locally -----------\n\n" diff --git a/lib/hsm-runner.js b/lib/hsm-runner.js index 29fe5412..8d42d11b 100644 --- a/lib/hsm-runner.js +++ b/lib/hsm-runner.js @@ -3,12 +3,14 @@ var devnull = require('dev-null'); var portUtils = require('./port-utils'); var path = require('path'); let HsmClient = require('./hsm-client'); -let { executeWithRetries } = require('./utils'); +let { executeWithRetries, wait } = require('./utils'); +const fs = require('fs'); const VERSIONS = { V1: '1', V2: '2', - V2_STATELESS: '2_stateless' + V2_STATELESS: '2_stateless', + V5: '5', }; let HSM_IDENTIFIERS = 0; @@ -154,6 +156,7 @@ let parseNetworkUpgrades = (forks) => { }; var HSMRunner = function(options) { + console.log('HSMRunner options: ', options) this.options = Object.assign({}, options); if (!this.options.version) { this.options.version = DEFAULT_OPTIONS.version; @@ -166,8 +169,73 @@ var HSMRunner = function(options) { HSM_IDENTIFIERS++; } +const spawnProcessVersion5 = async (serverPath, port, keyPath, latestBlockHash, difficultyTarget) => { + + console.log('serverPath, port, keyPath, latestBlockHash, difficultyTarget: ', serverPath, port, keyPath, latestBlockHash, difficultyTarget) + + if (!fs.existsSync(keyPath)) { + throw new Error(`Key file not found at ${keyPath}`); + } + + console.log('After keyPath check') + + if (!fs.existsSync(serverPath)) { + throw new Error(`Tcpsigner Server path not found at ${serverPath}`); + } + + console.log('After serverPath check') + + const targetPath = path.join(serverPath, 'keys.json'); + + console.log('targetPath: ', targetPath) + + try { + fs.copyFileSync(keyPath, targetPath); + } catch (err) { + throw new Error(`Failed to copy file: ${err.message}`); + } + + console.log('After copyFileSync') + + const tcpsignerCommand = `${serverPath}/tcpsigner`; + + console.log('tcpsignerCommand: ', tcpsignerCommand) + + let args = [ + `-p${port}`, + `--c=${latestBlockHash}`, + `--difficulty=0x${difficultyTarget.toString(16).padStart(2, '0')}`, + `-k keys.json`, + `-p8888 > /bundle/tcpsigner.log 2>&1 &` + ]; + + // const tcpsignerCommand = `${serverPath}/tcpsigner -p${port} --c=${latestBlockHash} --difficulty=0x${difficultyTarget.toString(16).padStart(2, '0')} -k keys.json -p8888 > /bundle/tcpsigner.log 2>&1 &`; + + console.log('tcpsignerCommand: ', tcpsignerCommand) + + childProcess.spawn(tcpsignerCommand, args, { stdio: 'inherit', shell: true }); + + await wait(2000); + + const tcpsignerManagerArgs = [ + `-b0.0.0.0`, + `-p${port}`, + `&` + ]; + + const tcpsignermanagerCommand = `${serverPath}/manager-tcp`; + + console.log('args: ', args) + + return childProcess.spawn(tcpsignermanagerCommand, tcpsignerManagerArgs, { stdio: 'inherit', shell: true }); + +}; HSMRunner.prototype.spawnProcess = function() { + + console.log('this.options.version: ', this.options.version) + console.log('this.options.serverPath, this.port, this.options.keyPath, this.options.latestBlockHash, this.options.difficultyTarget: ', this.options.serverPath, this.port, this.options.keyPath, this.options.latestBlockHash, this.options.difficultyTarget) + switch (this.options.version) { case VERSIONS.V1: return spawnProcessVersion1(this.options.serverPath, this.port, this.options.keyPath); @@ -197,6 +265,9 @@ HSMRunner.prototype.spawnProcess = function() { this.options.version == VERSIONS.V2 ); } + case VERSIONS.V5: + console.log('in case VERSIONS.V5') + return spawnProcessVersion5(this.options.serverPath, this.port, this.options.keyPath, this.options.latestBlockHash, this.options.difficultyTarget); default: throw new Error(`invalid version ${this.options.version}`); } diff --git a/tests/00_00_04-change-federation.js b/tests/00_00_04-change-federation.js index 456d3528..e4f59c52 100644 --- a/tests/00_00_04-change-federation.js +++ b/tests/00_00_04-change-federation.js @@ -18,9 +18,9 @@ const { } = require('../lib/constants/federation-constants'); // Generated with seed newFed1 -const newFederator1PublicKey = '0x02f80abfd3dac069887f974ac033cb62991a0ed55b9880faf8b8cbd713b75d649e'; +const newFederator1PublicKey = '0x031da807c71c2f303b7f409dd2605b297ac494a563be3b9ca5f52d95a43d183cc5'; // Generated with seed newFed2 -const newFederator2PublicKey = '0x03488898918c76758e52842c700060adbbbd0a38aa836838fd7215147b924ef7dc'; +const newFederator2PublicKey = '0x036bb9eab797eadc8b697f0e82a01d01cabbfaaca37e5bafc06fdc6fdd38af894a'; const getCurrentFederationKeys = async (bridge) => { @@ -65,6 +65,8 @@ const createNewFederationKeys = (currentFederationKeys) => { // Sort by btc public key newFederationKeys.sort((keyA, keyB) => keyA.btc.localeCompare(keyB.btc)) + console.log('newFederationKeys: ', newFederationKeys); + return newFederationKeys; }; @@ -280,6 +282,9 @@ describe('Change federation', async function() { const actualRetiringFederationSize = Number(await bridge.methods.getRetiringFederationSize().call()); const expectedRetiringFederationSize = -1; expect(actualRetiringFederationSize).to.be.equal(expectedRetiringFederationSize, 'The retiring federation should not exist anymore.'); + + const currentFederationKeys = await getCurrentFederationKeys(bridge); + console.log('currentFederationKeys after federation change: ', currentFederationKeys); }); diff --git a/tests/04_00_02-aditional-feds.js b/tests/04_00_02-aditional-feds.js new file mode 100644 index 00000000..11546694 --- /dev/null +++ b/tests/04_00_02-aditional-feds.js @@ -0,0 +1,19 @@ +const { getRskTransactionHelper } = require('../lib/rsk-tx-helper-provider'); + +describe('RSK Federation change', function() { + + let rskTxHelper; + + before(async () => { + rskTxHelper = getRskTransactionHelper(); + }); + + it('should add a new federation node', async () => { + + const latestBlock = await rskTxHelper.getBlock('latest'); + + await Runners.startAdditionalFederateNodes(latestBlock); + + }); + +});