Skip to content

Commit

Permalink
Merge pull request #523 from input-output-hk/build/ADP-1989-stake-poo…
Browse files Browse the repository at this point in the history
…l-number-increse

configurable stake pools number in local network
  • Loading branch information
rhyslbw committed Nov 18, 2022
2 parents f1cebb4 + fe2020a commit 22794be
Show file tree
Hide file tree
Showing 35 changed files with 1,182 additions and 304 deletions.
11 changes: 10 additions & 1 deletion packages/core/src/Cardano/types/StakePool/primitives.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Hash28ByteBase16, OpaqueString, typedBech32, typedHex } from '../../util/primitives';
import { Ed25519KeyHash } from '../Key';
import { Hash28ByteBase16, HexBlob, OpaqueString, typedBech32, typedHex } from '../../util';

/**
* pool operator verification key hash as bech32 string or a genesis pool ID
Expand All @@ -12,6 +13,14 @@ export type PoolId = OpaqueString<'PoolId'>;
*/
export const PoolId = (value: string): PoolId => typedBech32(value, 'pool', 45);

/**
* @param {string} value blake2b_224 digest of an operator verification key hash
* @throws InvalidStringError
*/
PoolId.fromKeyHash = (value: Ed25519KeyHash): PoolId =>
HexBlob.toTypedBech32('pool', HexBlob.fromEd25519KeyHash(value));

/**
/**
* pool operator verification key hash as hex string
*/
Expand Down
12 changes: 12 additions & 0 deletions packages/core/src/Cardano/util/primitives.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Decoded, bech32 } from 'bech32';
import { Ed25519KeyHash } from '../types';
import { InvalidStringError } from '../../errors';

const MAX_BECH32_LENGTH_LIMIT = 1023;
Expand Down Expand Up @@ -100,6 +101,17 @@ export type HexBlob = OpaqueString<'HexBlob'>;
export const HexBlob = (target: string): HexBlob => typedHex(target);
HexBlob.fromBytes = (bytes: Uint8Array) => Buffer.from(bytes).toString('hex') as unknown as HexBlob;

/**
* Converts a hex string into a typed bech32 encoded string.
*
* @param prefix The prefix of the bech32 string.
* @param hexString The hex string to be encoded.
*/
HexBlob.toTypedBech32 = <T>(prefix: string, hexString: HexBlob): T =>
bech32.encode(prefix, bech32.toWords(Uint8Array.from(Buffer.from(hexString, 'hex')))) as unknown as T;

HexBlob.fromEd25519KeyHash = (hash: Ed25519KeyHash) => hash as unknown as HexBlob;

/**
* Cast HexBlob it into another OpaqueString type.
*
Expand Down
7 changes: 7 additions & 0 deletions packages/core/test/Cardano/types/StakePool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ describe('Cardano/types/StakePool', () => {
expect(() => Cardano.PoolId('pool1zuevzm3xlrhmwjw87ec38mzs02tlkwec9wxpgafcaykmwg7efhh')).not.toThrow();
});

it('PoolId.fromKeyHash() returns valid pool id encoded as a bech32 string', () => {
const poolId = Cardano.PoolId.fromKeyHash(
Cardano.Ed25519KeyHash('594df1c896f6b05d4bebec0287627cf83416db779a3273205d3db9e0')
);
expect(poolId).toEqual(Cardano.PoolId('pool1t9xlrjyk76c96jltaspgwcnulq6pdkmhnge8xgza8ku7qvpsy9r'));
});

it('PoolIdHex() accepts a valid pool id hex string', () => {
expect(() => Cardano.PoolIdHex('e4b1c8ec89415ce6349755a1aa44b4affbb5f1248ff29943d190c715')).not.toThrow();
});
Expand Down
13 changes: 12 additions & 1 deletion packages/core/test/Cardano/util/primitives.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
typedBech32,
typedHex
} from '../../../src/Cardano/util';
import { InvalidStringError } from '../../../src/errors';
import { InvalidStringError } from '../../../src';

describe('Cardano.util/primitives', () => {
describe('typedBech32', () => {
Expand Down Expand Up @@ -51,6 +51,17 @@ describe('Cardano.util/primitives', () => {
});
});

describe('HexBlob.toTypedBech32', () => {
it('throw when given an invalid hex', () => {
expect(() => HexBlob.toTypedBech32('', HexBlob('ffsa'))).toThrow();
});

it('returns the correct bech32 string when given a valid prefix and valid payload', () => {
const bech32 = HexBlob.toTypedBech32('pool', HexBlob('594df1c896f6b05d4bebec0287627cf83416db779a3273205d3db9e0'));
expect(bech32).toEqual('pool1t9xlrjyk76c96jltaspgwcnulq6pdkmhnge8xgza8ku7qvpsy9r');
});
});

describe('typedHex', () => {
it('does not throw when asserting an empty string', () => {
expect(() => typedHex('')).not.toThrow();
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
ports:
- 3001:3001
volumes:
- ./local-network/network-files/node-spo1/:/root/network-files/node-spo1
- ./local-network/network-files/node-sp1/:/root/network-files/node-sp1
- ./local-network/config:/root/config
depends_on:
# We need the file server here in order to calculate the pool metadata hashes
Expand Down
6 changes: 6 additions & 0 deletions packages/e2e/local-network/file-server/SP10.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Stake Pool - 10",
"ticker": "SP10",
"description": "This is the stake pool 10 description.",
"homepage": "https://stakepool10.com"
}
6 changes: 6 additions & 0 deletions packages/e2e/local-network/file-server/SP11.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Stake Pool - 11",
"ticker": "SP11",
"description": "This is the stake pool 11 description.",
"homepage": "https://stakepool11.com"
}
6 changes: 6 additions & 0 deletions packages/e2e/local-network/file-server/SP4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Same Name",
"ticker": "SP4",
"description": "This is the stake pool 4 description.",
"homepage": "https://stakepool4.com"
}
6 changes: 6 additions & 0 deletions packages/e2e/local-network/file-server/SP5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Same Name",
"ticker": "SP5",
"description": "This is the stake pool 5 description.",
"homepage": "https://stakepool5.com"
}
6 changes: 6 additions & 0 deletions packages/e2e/local-network/file-server/SP6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Stake Pool - 6",
"ticker": "SP6a7",
"description": "This is the stake pool 6 description.",
"homepage": "https://stakepool6.com"
}
6 changes: 6 additions & 0 deletions packages/e2e/local-network/file-server/SP7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Stake Pool - 7",
"ticker": "SP6a7",
"description": "This is the stake pool 7 description.",
"homepage": "https://stakepool7.com"
}
6 changes: 6 additions & 0 deletions packages/e2e/local-network/file-server/SP8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Stake Pool - 8",
"ticker": "SP8",
"description": "This is the stake pool 8 description.",
"homepage": "https://stakepool8.com"
}
6 changes: 6 additions & 0 deletions packages/e2e/local-network/file-server/SP9.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Stake Pool - 9",
"ticker": "SP9",
"description": "This is the stake pool 9 description.",
"homepage": "https://stakepool9.com"
}
6 changes: 2 additions & 4 deletions packages/e2e/local-network/scripts/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ here="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)"
root_path="$(cd "$here/.." && pwd)"
cd "$root_path"

rm -rf ./network-files/node-spo1/*
rm -rf ./network-files/node-spo2/*
rm -rf ./network-files/node-spo3/*
rm -rf ./network-files/node-sp*/*
rm -rf ./sockets/*
rm -rf ./config/*
rm -rf ./logs/*
rm -rf ./logs/*
2 changes: 1 addition & 1 deletion packages/e2e/local-network/scripts/get-epoch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ root="$(cd "$here/.." && pwd)"
cd "$root"

export PATH=$PWD/bin:$PATH
export CARDANO_NODE_SOCKET_PATH=$PWD/network-files/node-spo1/node.sock
export CARDANO_NODE_SOCKET_PATH=$PWD/network-files/node-sp1/node.sock

if [ ! -S "$CARDANO_NODE_SOCKET_PATH" ]; then
echo "-1"
Expand Down
134 changes: 49 additions & 85 deletions packages/e2e/local-network/scripts/make-babbage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ cd "$root_path"

export PATH=$PWD/bin:$PATH

source ./scripts/nodes-configuration.sh

UNAME=$(uname -s) SED=
case $UNAME in
Darwin ) SED="gsed";;
Expand Down Expand Up @@ -46,8 +48,7 @@ esac

NETWORK_MAGIC=888
SECURITY_PARAM=10
NUM_SPO_NODES=3
INIT_SUPPLY=10020000000
INIT_SUPPLY=10020000012
MAX_SUPPLY=45000000000000000
START_TIME="$(${DATE} -d "now + 30 seconds" +%s)"
ROOT=network-files
Expand Down Expand Up @@ -88,9 +89,9 @@ EOF
cardano-cli byron genesis genesis \
--protocol-magic ${NETWORK_MAGIC} \
--start-time "${START_TIME}" \
--k ${SECURITY_PARAM} \
--k "${SECURITY_PARAM}" \
--n-poor-addresses 0 \
--n-delegate-addresses ${NUM_SPO_NODES} \
--n-delegate-addresses "${NUM_SP_NODES}" \
--total-balance ${INIT_SUPPLY} \
--delegate-share 1 \
--avvm-entry-count 0 \
Expand All @@ -100,7 +101,7 @@ cardano-cli byron genesis genesis \

# Because in Babbage the overlay schedule and decentralization parameter
# are deprecated, we must use the "create-staked" cli command to create
# SPOs in the ShelleyGenesis
# SPs in the ShelleyGenesis

cp templates/babbage/alonzo-babbage-test-genesis.json "${ROOT}/genesis.alonzo.spec.json"
cp templates/babbage/byron-configuration.yaml "${ROOT}/configuration.yaml"
Expand All @@ -126,22 +127,17 @@ $SED -i "${ROOT}/configuration.yaml" \
echo "TestEnableDevelopmentNetworkProtocols: True" >> "${ROOT}/configuration.yaml"

# Copy the cost mode

cardano-cli genesis create-staked --genesis-dir "${ROOT}" \
--testnet-magic "${NETWORK_MAGIC}" \
--gen-pools 3 \
--gen-pools ${NUM_SP_NODES} \
--supply ${MAX_SUPPLY} \
--supply-delegated ${MAX_SUPPLY} \
--gen-stake-delegs 3 \
--gen-utxo-keys 3

SPO_NODES="node-spo1 node-spo2 node-spo3"
--gen-stake-delegs ${NUM_SP_NODES} \
--gen-utxo-keys ${NUM_SP_NODES}

# create the node directories
for NODE in ${SPO_NODES}; do

for NODE in ${SP_NODES}; do
mkdir -p "${ROOT}/${NODE}"

done

# Here we move all of the keys etc generated by create-staked
Expand Down Expand Up @@ -175,86 +171,54 @@ $SED -i "${ROOT}/genesis/shelley/genesis.json" \
-e 's/"tau": 0.0/"tau": 0.1/' \
-e 's/"updateQuorum": 5/"updateQuorum": 2/'

mv "${ROOT}/pools/vrf1.skey" "${ROOT}/node-spo1/vrf.skey"
mv "${ROOT}/pools/vrf2.skey" "${ROOT}/node-spo2/vrf.skey"
mv "${ROOT}/pools/vrf3.skey" "${ROOT}/node-spo3/vrf.skey"

mv "${ROOT}/pools/opcert1.cert" "${ROOT}/node-spo1/opcert.cert"
mv "${ROOT}/pools/opcert2.cert" "${ROOT}/node-spo2/opcert.cert"
mv "${ROOT}/pools/opcert3.cert" "${ROOT}/node-spo3/opcert.cert"
for NODE_ID in ${SP_NODES_ID}; do
TARGET="${ROOT}/node-sp${NODE_ID}"
PORT="$(("$NODE_ID" + 3000))"

mv "${ROOT}/pools/kes1.skey" "${ROOT}/node-spo1/kes.skey"
mv "${ROOT}/pools/kes2.skey" "${ROOT}/node-spo2/kes.skey"
mv "${ROOT}/pools/kes3.skey" "${ROOT}/node-spo3/kes.skey"
mv "${ROOT}/pools/vrf${NODE_ID}.skey" "${TARGET}/vrf.skey"
mv "${ROOT}/pools/opcert${NODE_ID}.cert" "${TARGET}/opcert.cert"
mv "${ROOT}/pools/kes${NODE_ID}.skey" "${TARGET}/kes.skey"

#Byron related
BYRON_KEYS_POSFIX=$(seq -f '%03.f' $(("$NODE_ID" - 1)) $(("$NODE_ID" - 1)))
#Byron related
mv "${ROOT}/byron-gen-command/delegate-keys.${BYRON_KEYS_POSFIX}.key" "${TARGET}/byron-delegate.key"
mv "${ROOT}/byron-gen-command/delegation-cert.${BYRON_KEYS_POSFIX}.json" "${TARGET}/byron-delegation.cert"

mv "${ROOT}/byron-gen-command/delegate-keys.000.key" "${ROOT}/node-spo1/byron-delegate.key"
mv "${ROOT}/byron-gen-command/delegate-keys.001.key" "${ROOT}/node-spo2/byron-delegate.key"
mv "${ROOT}/byron-gen-command/delegate-keys.002.key" "${ROOT}/node-spo3/byron-delegate.key"
echo "${PORT}" > "${TARGET}/port"

mv "${ROOT}/byron-gen-command/delegation-cert.000.json" "${ROOT}/node-spo1/byron-delegation.cert"
mv "${ROOT}/byron-gen-command/delegation-cert.001.json" "${ROOT}/node-spo2/byron-delegation.cert"
mv "${ROOT}/byron-gen-command/delegation-cert.002.json" "${ROOT}/node-spo3/byron-delegation.cert"

echo 3001 > "${ROOT}/node-spo1/port"
echo 3002 > "${ROOT}/node-spo2/port"
echo 3003 > "${ROOT}/node-spo3/port"
done

# Make topology files
#TODO generalise this over the N BFT nodes and pool nodes
cat > "${ROOT}/node-spo1/topology.json" <<EOF
{
"Producers": [
{
"addr": "127.0.0.1",
"port": 3002,
"valency": 1
}
, {
"addr": "127.0.0.1",
"port": 3003,
"valency": 1
}
]
}
EOF
for ID in ${SP_NODES_ID}; do
port="$(("$ID" + 3001))"

cat > "${ROOT}/node-spo2/topology.json" <<EOF
{
"Producers": [
{
"addr": "127.0.0.1",
"port": 3001,
"valency": 1
}
, {
"addr": "127.0.0.1",
"port": 3003,
"valency": 1
}
]
}
EOF
if [ "$ID" -ge "$(("$NUM_SP_NODES" - 1))" ] # Wrap around
then
port="$(("$port" - "$(("$NUM_SP_NODES" - 1))"))"
fi
cat > "${ROOT}/node-spo3/topology.json" <<EOF
{
"Producers": [
{
"addr": "127.0.0.1",
"port": 3001,
"valency": 1
}
, {
"addr": "127.0.0.1",
"port": 3002,
"valency": 1
}
]
}
secondPort="$(("$port" + 1))"
cat > "${ROOT}/node-sp${ID}/topology.json" <<EOF
{
"Producers": [
{
"addr": "127.0.0.1",
"port": ${port},
"valency": 1
}
, {
"addr": "127.0.0.1",
"port": ${secondPort},
"valency": 1
}
]
}
EOF
for NODE in ${SPO_NODES}; do
done
for NODE in ${SP_NODES}; do
(
echo "#!/usr/bin/env bash"
echo ""
Expand Down Expand Up @@ -333,7 +297,7 @@ echo "" >> "${ROOT}/run/all.sh"
echo "export PATH=\$PWD/bin:\$PATH" >> "${ROOT}/run/all.sh"
echo "" >> "${ROOT}/run/all.sh"

for NODE in ${SPO_NODES}; do
for NODE in ${SP_NODES}; do
echo "$ROOT/${NODE}.sh &" >> "${ROOT}/run/all.sh"
done
echo "" >> "${ROOT}/run/all.sh"
Expand Down
6 changes: 6 additions & 0 deletions packages/e2e/local-network/scripts/nodes-configuration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

AMOUNT_PER_NODE='10000000000000'
NUM_SP_NODES=11
SP_NODES_ID=$(seq 1 ${NUM_SP_NODES})
SP_NODES=$(for i in ${SP_NODES_ID} ; do echo "node-sp${i}" ; done)

0 comments on commit 22794be

Please sign in to comment.