Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] tcpsigner build setup #192

Draft
wants to merge 3 commits into
base: use-random-see-for-newAccountWithSeed
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,25 @@ jobs:
id: checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Build tcpsigner
run: |
sudo apt-get update
mkdir -p tcpsigner-build
mkdir -p container-action/tcpsigner-dist
cd tcpsigner-build
git clone https://github.com/rsksmart/rsk-powhsm.git
cd rsk-powhsm
git checkout 5.2.1
./docker/mware/build
./docker/packer/build
./utils/tcpsigner-bundle/build.sh
cd ../..
ls
tar -xzf tcpsigner-build/rsk-powhsm/utils/tcpsigner-bundle/dist/bin/manager-tcp.tgz -C tcpsigner-build/rsk-powhsm/utils/tcpsigner-bundle/dist/bin/
mv tcpsigner-build/rsk-powhsm/utils/tcpsigner-bundle/dist/bin/* container-action/tcpsigner-dist/
cd container-action/tcpsigner-dist
ls

- name: Docker meta
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
Expand Down
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 : path.resolve(__dirname, `${keysPathResolve}/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 : path.resolve(__dirname, `${keysPathResolve}/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
129 changes: 100 additions & 29 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,71 @@ 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 > tcpsigner.log 2>&1 &`
];

console.log('tcpsignerCommand: ', tcpsignerCommand)

childProcess.spawn(tcpsignerCommand, args, { stdio: 'inherit', shell: true });

await portUtils.waitForPort('localhost', port);

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,12 +263,15 @@ 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}`);
}
}

HSMRunner.prototype.start = function() {
HSMRunner.prototype.start = async function() {
if (this.isRunning()) {
throw "HSM already started";
}
Expand All @@ -223,39 +292,41 @@ HSMRunner.prototype.start = function() {
this.port = selectedPorts[0];
}

this.process = this.spawnProcess();
if (this.process.stdout) {
if (this.options.stdout != null) {
this.process.stdout.pipe(this.options.stdout);
} else {
this.process.stdout.pipe(devnull());
this.spawnProcess().then(process => {
this.process = process;
if (this.process.stdout) {
if (this.options.stdout != null) {
this.process.stdout.pipe(this.options.stdout);
} else {
this.process.stdout.pipe(devnull());
}
}
}

if (this.process.stderr) {
if (this.options.stderr != null) {
this.process.stderr.pipe(this.options.stderr);
} else {
this.process.stderr.pipe(devnull());
if (this.process.stderr) {
if (this.options.stderr != null) {
this.process.stderr.pipe(this.options.stderr);
} else {
this.process.stderr.pipe(devnull());
}
}
}

this.running = false;

this.process.on('exit', () => {
this.running = false;
});

this.client = HsmClient.getClient(this.options.host, this.port);
this.process.on('exit', () => {
this.running = false;
});

this.client = HsmClient.getClient(this.options.host, this.port);

return executeWithRetries(
() => {
return this.getPublicKey();
},
10,
1000).then((r) => {
this.running = true;
return r;
return executeWithRetries(
() => {
return this.getPublicKey();
},
10,
1000).then((r) => {
this.running = true;
return r;
});
});
});
};
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
Loading
Loading