Skip to content

Commit

Permalink
test 9
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-then committed Dec 11, 2024
1 parent 8c7c2b1 commit 0764e1c
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 18 deletions.
24 changes: 22 additions & 2 deletions config/node-configs/rsk-reg-4.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
24 changes: 22 additions & 2 deletions config/node-configs/rsk-reg-5.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
"m/44'/137'/1'/0/0": "47b9249139474a00470c1dd5b01c9ed7ca2a67c71ab9ec4ff1a8698fb2937d7c"
}
Original file line number Diff line number Diff line change
@@ -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"
}
"m/44'/137'/1'/0/0": "a8a8dda1dcd067850a510cc1042d6b137a632792194a2d3ff7cdd69f21b54104"
}
2 changes: 2 additions & 0 deletions container-action/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
17 changes: 17 additions & 0 deletions container-action/rit-local-configs/regtest-all-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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'
},
{
Expand All @@ -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'
}
]
Expand Down
1 change: 1 addition & 0 deletions container-action/scripts/configure_rit_locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
75 changes: 73 additions & 2 deletions lib/hsm-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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}`);
}
Expand Down
9 changes: 7 additions & 2 deletions tests/00_00_04-change-federation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {

Expand Down Expand Up @@ -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;

};
Expand Down Expand Up @@ -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);

});

Expand Down
19 changes: 19 additions & 0 deletions tests/04_00_02-aditional-feds.js
Original file line number Diff line number Diff line change
@@ -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);

});

});

0 comments on commit 0764e1c

Please sign in to comment.