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

feat: use partner-chains-node to initialize partner chain in local-environment #402

Merged
merged 3 commits into from
Jan 24, 2025
Merged
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
2 changes: 0 additions & 2 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ docker:
RUN useradd -m -u 1000 -U -s /bin/sh -d /substrate substrate \
&& mkdir -p /data /substrate/.local/share/partner-chains-node \
&& chown -R substrate:substrate /data /substrate \
# remove package managers
&& rm -rf /usr/bin/apt* /usr/bin/dpkg* \
LGLO marked this conversation as resolved.
Show resolved Hide resolved
&& ln -s /data /substrate/.local/share/partner-chains-node

USER substrate
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This changelog is based on [Keep A Changelog](https://keepachangelog.com/en/1.1.
* Changed the `smart-contracts init-governance` command to `smart-contracts governance init`
* smart-contracts commands and offchain tests now use WebSockets implementation of Ogmios client
* Updated to polkadot-stable2409-3 (aka v1.16.3).
* `local-environment` now uses the `partner-chains-node` based container for the smart-contracts setup.

## Removed

Expand Down
5 changes: 3 additions & 2 deletions dev/local-environment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The local environment includes:
- 1 x Ogmios
- 1 x Kupo
LGLO marked this conversation as resolved.
Show resolved Hide resolved
- 1 x Ubuntu / NodeJS image for running pc-contracts-cli
- 1 x Partner Chains Setup container based on Partner Chains Node Image to setup the smart-contracts

The stack `setup.sh` script will create a docker-compose.yml stack configuration files, and populate an .env file with environment values. The stack can be deployed with `docker-compose up -d`.

Expand All @@ -21,7 +22,7 @@ The stack `setup.sh` script will create a docker-compose.yml stack configuration
- When first run, all images will be pulled from public repositories. This stage may take some time. The stack will then be built and run.
- When the stack is running, the Cardano node begins block production. This is a private testnet and will not connect to the public Cardano network, but rather from a pre-configured genesis file.
- Once the Cardano chain is synced, Ogmios, Kupo and DB-Sync will in turn connect to the Cardano node node.socket and begin syncing the chain.
- The pc-contracts-cli will insert D parameter values and register Partner Chains Node keys with the Cardano chain.
- The partner-chains-setup will insert D parameter values and register Partner Chains Node keys with the Cardano chain.
- Once Postgres is populated with the required data, the Partner Chains nodes will begin syncing the chain and will begin block production after 2 main chain epochs.

## Initialising the environment configuration
Expand Down Expand Up @@ -53,7 +54,7 @@ docker compose down --volumes

## Custom Images and Artifacts

To use custom node image one simply has to update `PARTNER_CHAINS_NODE_IMAGE` (docker image) and `PARTNER_CHAINS_NODE_URL` (node artifact, used to build chain-spec and generate signatures for SPO registration)
To use custom node image one simply has to update `PARTNER_CHAINS_NODE_IMAGE` (docker image) and `PARTNER_CHAINS_NODE_URL` (node artifact, used to build chain-spec and execute chain setup smart-contracts)

These can be found at the very top of the `setup.sh` script.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/bin/sh

echo 'Waiting for Cardano chain to sync and pc-contracts-cli configuration to complete...'
echo 'Waiting for Cardano chain to sync and Partner Chains smart contracts setup to complete...'

while true; do
if [ -f "/shared/pc-contracts-cli.ready" ]; then
if [ -f "/shared/partner-chains-setup.ready" ]; then
break
else
sleep 1
fi
done

echo "pc-contracts-cli configuration complete. Starting node..."
echo "Partner Chains smart contracts setup complete. Starting node..."

export MC__FIRST_EPOCH_TIMESTAMP_MILLIS=$(cat /shared/MC__FIRST_EPOCH_TIMESTAMP_MILLIS)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/bin/sh

echo 'Waiting for Cardano chain to sync and pc-contracts-cli configuraton to complete...'
echo 'Waiting for Cardano chain to sync and Partner Chains smart contracts setup to complete...'

while true; do
if [ -f "/shared/pc-contracts-cli.ready" ]; then
if [ -f "/shared/partner-chains-setup.ready" ]; then
break
else
sleep 1
fi
done

echo "pc-contracts-cli configuration complete. Waiting 2 epochs to start..."
echo "Partner Chains smart contracts setup complete. Waiting 2 epochs to start..."

while true; do
if [ -f "/shared/2-epochs.ready" ]; then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/bin/sh

echo 'Waiting for Cardano chain to sync and pc-contracts-cli configuraton to complete...'
echo 'Waiting for Cardano chain to sync and Partner Chains smart contracts setup to complete...'

while true; do
if [ -f "/shared/pc-contracts-cli.ready" ]; then
if [ -f "/shared/partner-chains-setup.ready" ]; then
break
else
sleep 1
fi
done

echo "pc-contracts-cli configuration complete. Waiting 2 epochs to start..."
echo "Partner Chains smart contracts setup complete. Waiting 2 epochs to start..."

while true; do
if [ -f "/shared/2-epochs.ready" ]; then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/bin/sh

echo 'Waiting for Cardano chain to sync and pc-contracts-cli configuraton to complete...'
echo 'Waiting for Cardano chain to sync and Partner Chains smart contracts setup to complete...'

while true; do
if [ -f "/shared/pc-contracts-cli.ready" ]; then
if [ -f "/shared/partner-chains-setup.ready" ]; then
break
else
sleep 1
fi
done

echo "pc-contracts-cli configuration complete. Waiting 2 epochs to start..."
echo "Partner Chains smart contracts setup complete. Waiting 2 epochs to start..."

while true; do
if [ -f "/shared/2-epochs.ready" ]; then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/bin/sh

echo 'Waiting for Cardano chain to sync and pc-contracts-cli configuraton to complete...'
echo 'Waiting for Cardano chain to sync and Partner Chains smart contracts setup to complete...'

while true; do
if [ -f "/shared/pc-contracts-cli.ready" ]; then
if [ -f "/shared/partner-chains-setup.ready" ]; then
break
else
sleep 1
fi
done

echo "pc-contracts-cli configuration complete. Waiting 2 epochs to start..."
echo "Partner Chains smart contracts setup complete. Waiting 2 epochs to start..."

while true; do
if [ -f "/shared/2-epochs.ready" ]; then
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
#!/bin/bash

apt -qq update &> /dev/null
apt -qq -y install jq ncat &> /dev/null

cp /usr/local/bin/partner-chains-node /partner-chains-node
LGLO marked this conversation as resolved.
Show resolved Hide resolved

echo "Waiting for the Cardano network to sync and for Ogmios to start..."

while true; do
if nc -z ogmios $OGMIOS_PORT; then
break
else
sleep 1
fi
done

echo "Beginning configuration..."

chmod 644 /shared/shelley/genesis-utxo.skey

echo "Initializing governance authority ..."

export GENESIS_UTXO=$(cat /shared/genesis.utxo)

./partner-chains-node smart-contracts governance init \
--ogmios-url http://ogmios:$OGMIOS_PORT \
--genesis-utxo $GENESIS_UTXO \
--payment-key-file /keys/funded_address.skey \
--governance-authority $GOVERNANCE_AUTHORITY

if [ $? -eq 0 ]; then
echo "Successfully initialized governance authority!"
else
echo "Failed to initialize governance authority!"
LGLO marked this conversation as resolved.
Show resolved Hide resolved
exit 1
fi

echo "Generating addresses.json file..."

./partner-chains-node smart-contracts get-scripts \
--ogmios-url http://ogmios:$OGMIOS_PORT \
--genesis-utxo $GENESIS_UTXO \
> addresses.json

export COMMITTEE_CANDIDATE_ADDRESS=$(jq -r '.addresses.CommitteeCandidateValidator' addresses.json)
echo "Committee candidate address: $COMMITTEE_CANDIDATE_ADDRESS"

export D_PARAMETER_POLICY_ID=$(jq -r '.policyIds.DParameter' addresses.json)
echo "D parameter policy ID: $D_PARAMETER_POLICY_ID"

export PERMISSIONED_CANDIDATES_POLICY_ID=$(jq -r '.policyIds.PermissionedCandidates' addresses.json)
echo "Permissioned candidates policy ID: $PERMISSIONED_CANDIDATES_POLICY_ID"

echo "Setting placeholder values for NATIVE_TOKEN_POLICY_ID, NATIVE_TOKEN_ASSET_NAME, and ILLIQUID_SUPPLY_VALIDATOR_ADDRESS for chain-spec creation"
export NATIVE_TOKEN_POLICY_ID="ada83ddd029614381f00e28de0922ab0dec6983ea9dd29ae20eef9b4"
export NATIVE_TOKEN_ASSET_NAME="5043546f6b656e44656d6f"
export ILLIQUID_SUPPLY_VALIDATOR_ADDRESS="addr_test1wrhvtvx3f0g9wv9rx8kfqc60jva3e07nqujk2cspekv4mqs9rjdvz"

echo "Inserting D parameter..."

./partner-chains-node smart-contracts upsert-d-parameter \
--ogmios-url http://ogmios:$OGMIOS_PORT \
--genesis-utxo $GENESIS_UTXO \
--permissioned-candidates-count 3 \
--registered-candidates-count 2 \
--payment-key-file /keys/funded_address.skey

if [ $? -eq 0 ]; then
echo "Successfully inserted D-parameter (P = 3, R = 2)!"
else
echo "Couldn't insert D-parameter..."
exit 1
fi

# sidechain.vkey:aura.vkey:grandpa.vkey
echo "Inserting permissioned candidates for Alice and Bob..."

alice_sidechain_vkey=$(cat /partner-chains-nodes/partner-chains-node-1/keys/sidechain.vkey)
alice_aura_vkey=$(cat /partner-chains-nodes/partner-chains-node-1/keys/aura.vkey)
alice_grandpa_vkey=$(cat /partner-chains-nodes/partner-chains-node-1/keys/grandpa.vkey)

bob_sidechain_vkey=$(cat /partner-chains-nodes/partner-chains-node-2/keys/sidechain.vkey)
bob_aura_vkey=$(cat /partner-chains-nodes/partner-chains-node-2/keys/aura.vkey)
bob_grandpa_vkey=$(cat /partner-chains-nodes/partner-chains-node-2/keys/grandpa.vkey)

cat <<EOF > permissioned_candidates.csv
$alice_sidechain_vkey:$alice_aura_vkey:$alice_grandpa_vkey
$bob_sidechain_vkey:$bob_aura_vkey:$bob_grandpa_vkey
EOF

./partner-chains-node smart-contracts upsert-permissioned-candidates \
--ogmios-url http://ogmios:$OGMIOS_PORT \
--genesis-utxo $GENESIS_UTXO \
--permissioned-candidates-file permissioned_candidates.csv \
LGLO marked this conversation as resolved.
Show resolved Hide resolved
--payment-key-file /keys/funded_address.skey

if [ $? -eq 0 ]; then
echo "Permissioned candidates Alice and Bob inserted successfully!"
else
echo "Permission candidates Alice and Bob failed to be added..."
exit 1
fi

echo "Inserting registered candidate Dave..."

# Prepare Dave registration values
dave_utxo=$(cat /shared/dave.utxo)
dave_mainchain_signing_key=$(jq -r '.cborHex | .[4:]' /partner-chains-nodes/partner-chains-node-4/keys/cold.skey)
dave_sidechain_signing_key=$(cat /partner-chains-nodes/partner-chains-node-4/keys/sidechain.skey)

# Process registration signatures for Dave
dave_output=$(./partner-chains-node registration-signatures \
--genesis-utxo $GENESIS_UTXO \
--mainchain-signing-key $dave_mainchain_signing_key \
--sidechain-signing-key $dave_sidechain_signing_key \
--registration-utxo $dave_utxo)

# Extract signatures and keys from Dave output
dave_spo_public_key=$(echo "$dave_output" | jq -r ".spo_public_key")
dave_spo_signature=$(echo "$dave_output" | jq -r ".spo_signature")
dave_sidechain_public_key=$(echo "$dave_output" | jq -r ".sidechain_public_key")
dave_sidechain_signature=$(echo "$dave_output" | jq -r ".sidechain_signature")
dave_aura_vkey=$(cat /partner-chains-nodes/partner-chains-node-4/keys/aura.vkey)
dave_grandpa_vkey=$(cat /partner-chains-nodes/partner-chains-node-4/keys/grandpa.vkey)

# Register Dave
./partner-chains-node smart-contracts register \
--ogmios-url http://ogmios:$OGMIOS_PORT \
--genesis-utxo $GENESIS_UTXO \
--spo-public-key $dave_spo_public_key \
--spo-signature $dave_spo_signature \
--sidechain-public-keys $dave_sidechain_public_key:$dave_aura_vkey:$dave_grandpa_vkey \
--sidechain-signature $dave_sidechain_signature \
--registration-utxo $dave_utxo \
--payment-key-file /partner-chains-nodes/partner-chains-node-4/keys/payment.skey

if [ $? -eq 0 ]; then
echo "Registered candidate Dave inserted successfully!"
else
echo "Registration for Dave failed."
exit 1
fi

echo "Generating chain-spec.json file for Partnerchain Nodes..."
./partner-chains-node build-spec --disable-default-bootnode > chain-spec.json

echo "Configuring Initial Validators..."
jq '.genesis.runtimeGenesis.config.session.initialValidators = [
[
"5C7C2Z5sWbytvHpuLTvzKunnnRwQxft1jiqrLD5rhucQ5S9X",
{
"aura": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"grandpa": "5FA9nQDVg267DEd8m1ZypXLBnvN7SFxYwV7ndqSYGiN9TTpu"
}
],
[
"5DVskgSC9ncWQpxFMeUn45NU43RUq93ByEge6ApbnLk6BR9N",
{
"aura": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
"grandpa": "5GoNkf6WdbxCFnPdAnYYQyCjAKPJgLNxXwPjwTh6DGg6gN3E"
}
],
[
"5EP2cMaCxLzhfD3aFAqqgu3kfXH7GcwweEv6JXZRP6ysRHkQ",
{
"aura": "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y",
"grandpa": "5DbKjhNLpqX3zqZdNBc9BGb4fHU1cRBaDhJUskrvkwfraDi6"
}
]
]' chain-spec.json > tmp.json && mv tmp.json chain-spec.json

echo "Configuring Initial Authorities..."
jq '.genesis.runtimeGenesis.config.sessionCommitteeManagement.initialAuthorities = [
[
"KW39r9CJjAVzmkf9zQ4YDb2hqfAVGdRqn53eRqyruqpxAP5YL",
{
"aura": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"grandpa": "5FA9nQDVg267DEd8m1ZypXLBnvN7SFxYwV7ndqSYGiN9TTpu"
}
],
[
"KWByAN7WfZABWS5AoWqxriRmF5f2jnDqy3rB5pfHLGkY93ibN",
{
"aura": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
"grandpa": "5GoNkf6WdbxCFnPdAnYYQyCjAKPJgLNxXwPjwTh6DGg6gN3E"
}
],
[
"KWBpGtyJLBkJERdZT1a1uu19c2uPpZm9nFd8SGtCfRUAT3Y4w",
{
"aura": "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y",
"grandpa": "5DbKjhNLpqX3zqZdNBc9BGb4fHU1cRBaDhJUskrvkwfraDi6"
}
]
]' chain-spec.json > tmp.json && mv tmp.json chain-spec.json

echo "Configuring Balances..."
jq '.genesis.runtimeGenesis.config.balances.balances = [
["5C7C2Z5sWbytvHpuLTvzKunnnRwQxft1jiqrLD5rhucQ5S9X", 1000000000000000],
["5D9eDKbFt4JKaEndQvMmbJYnpX9ENUj8U9UUg1AxSa64FJxE", 1000000000000000]
]' chain-spec.json > tmp.json && mv tmp.json chain-spec.json

echo "Configuring Epoch Length..."
jq '.genesis.runtimeGenesis.config.sidechain.slotsPerEpoch = 5' chain-spec.json > tmp.json && mv tmp.json chain-spec.json

echo "Copying chain-spec.json file to /shared/chain-spec.json..."
cp chain-spec.json /shared/chain-spec.json
echo "chain-spec.json generation complete."

echo "Partnerchain configuration is complete, and will be able to start after two mainchain epochs."
touch /shared/partner-chains-setup.ready

echo -e "\n===== Partnerchain Configuration Complete =====\n"
echo -e "Container will now idle, but will remain available for accessing the partner-chains-node commands as follows:\n"
echo "docker exec partner-chains-setup partner-chains-node smart-contracts --help"

echo "Waiting 2 epochs for DParam to become active..."
epoch=$(curl -s --request POST \
--url "http://ogmios:1337" \
--header 'Content-Type: application/json' \
--data '{"jsonrpc": "2.0", "method": "queryLedgerState/epoch"}' | jq .result)
n_2_epoch=$((epoch + 2))
echo "Current epoch: $epoch"
while [ $epoch -lt $n_2_epoch ]; do
sleep 10
epoch=$(curl -s --request POST \
--url "http://ogmios:1337" \
--header 'Content-Type: application/json' \
--data '{"jsonrpc": "2.0", "method": "queryLedgerState/epoch"}' | jq .result)
echo "Current epoch: $epoch"
done
echo "DParam is now active!"
touch /shared/2-epochs.ready

tail -f /dev/null
Loading
Loading