Skip to content

Commit

Permalink
Merge pull request #19 from Conflux-Chain/posConfig
Browse files Browse the repository at this point in the history
add script to create pos configurations
  • Loading branch information
iosh authored Jul 8, 2024
2 parents d2f0965 + b529d70 commit 2c64882
Show file tree
Hide file tree
Showing 12 changed files with 1,107 additions and 369 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ jobs:
VERSION=v${{ steps.meta.outputs.version }}
file: ./Dockerfile.dev.buildx
platforms: ${{ matrix.platform }}
tags: ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }},${{ env.REGISTRY_IMAGE }}:latest
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true

- name: Export digest
Expand Down Expand Up @@ -94,7 +93,7 @@ jobs:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Create manifest list and push
Expand Down
21 changes: 12 additions & 9 deletions .github/workflows/mainAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ jobs:
platform:
- linux/amd64
- linux/arm64

steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
Expand All @@ -34,6 +28,16 @@ jobs:
# get the tag version eg: v1.0.0 => 1.0.0
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
- name: Prepare
id: prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
VERSION=${{ steps.meta.outputs.version }}
[[ ${VERSION} == *-testnet* ]] && echo "CONFLUX_GIT_TAG=${VERSION}" >> ${GITHUB_OUTPUT} || echo "CONFLUX_GIT_TAG=${VERSION%-mainnet}" >> ${GITHUB_OUTPUT}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
Expand All @@ -49,10 +53,9 @@ jobs:
uses: docker/build-push-action@v6
with:
build-args: |
VERSION=v{{ steps.meta.outputs.major }}.{{ steps.meta.outputs.minor }}.{{ steps.meta.outputs.patch }}
VERSION=v${{ steps.prepare.outputs.CONFLUX_GIT_TAG }}
file: ./Dockerfile.buildx
platforms: ${{ matrix.platform }}
tags: ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true

- name: Export digest
Expand Down Expand Up @@ -93,7 +96,7 @@ jobs:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Create manifest list and push
Expand Down
5 changes: 2 additions & 3 deletions cfxrun/conflux.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash

# init config
cd ./scripts
node initConfig.js
cd ..
cd ./scripts && node initConfig.js && cd ..

# start conflux
/bin/conflux --config ./conflux.toml
Binary file removed cfxrun/pos_config/genesis_file
Binary file not shown.
56 changes: 0 additions & 56 deletions cfxrun/pos_config/initial_nodes.json

This file was deleted.

Binary file removed cfxrun/pos_config/pos_key
Binary file not shown.
2 changes: 1 addition & 1 deletion cfxrun/scripts/account.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {providerFactory: provider} = require('js-conflux-sdk');
import {providerFactory as provider} from 'js-conflux-sdk';

const client = provider({url: 'http://localhost:12537'});

Expand Down
21 changes: 21 additions & 0 deletions cfxrun/scripts/createPosConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { execa } from "execa";
import fs from "node:fs/promises";
import YAML from 'yaml'


export async function createPosConfig(chainId) {
await execa`pos-genesis-tool random --initial-seed=0000000000000000000000000000000000000000000000000000000000000000 --num-validator=1 --num-genesis-validator=1 --chain-id=${chainId}`;

const waypoint_config = await fs.readFile('./waypoint_config', 'utf8');
const posConfigRaw = await fs.readFile('../pos_config/pos_config.yaml', 'utf8');

const posConfig = YAML.parse(posConfigRaw);
console.log("posConfig", posConfig);
posConfig.base.waypoint.from_config = waypoint_config;
console.log("update posConfig", posConfig);
await fs.writeFile('../pos_config/pos_config.yaml', YAML.stringify(posConfig));
await execa`ls -l`
await execa`mv ./genesis_file ../pos_config/genesis_file`;

await execa`mv ./initial_nodes.json ../pos_config/initial_nodes.json`;
}
7 changes: 4 additions & 3 deletions cfxrun/scripts/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const {Conflux, providerFactory: provider, Drip} = require('js-conflux-sdk');
const TOML = require('@iarna/toml');
const fs = require('fs');
import {Conflux, providerFactory as provider, Drip} from 'js-conflux-sdk';
import fs from 'node:fs'
import TOML from '@iarna/toml';

const PASSWORD = '123456';
const URL = "http://localhost:12537";
const client = provider({url: URL});
Expand Down
48 changes: 39 additions & 9 deletions cfxrun/scripts/initConfig.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
const TOML = require('@iarna/toml');
const fs = require('fs');
const {PrivateKeyAccount: Account, format} = require('js-conflux-sdk');
import TOML from '@iarna/toml'
import fs from 'node:fs'
import {PrivateKeyAccount as Account, format} from 'js-conflux-sdk'
import { createPosConfig } from './createPosConfig.js';

function initialConfig() {
async function initialConfig() {
const configStr = fs.readFileSync("../conflux.toml", "utf-8");
const config = TOML.parse(configStr);

// if "mode" is not docker leave it alone
if (config.mode !== 'docker') {
return;

if (config.mode !== "docker") {
// If the mode is not Docker, refrain from altering the conflux.toml file or any other elements, including comments or spaces.
const stream = fs.createWriteStream("../conflux.toml", {flags: 'a'});

if (!config.chain_id) {
config.chain_id = parseInt(Math.random() * 10000);

console.warn(
"chain_id not found in conflux.toml, generate a random one: " +
config.chain_id
);

stream.write(`\nchain_id = ${config.chain_id}\n`);
}
if (!config.evm_chain_id) {
config.evm_chain_id = config.chain_id + 1;

console.warn(
"evm_chain_id not found in conflux.toml, generate a one: " +
config.evm_chain_id
);

stream.write(`\nevm_chain_id = ${config.evm_chain_id}\n`);
}

// The createPosConfig function must always be executed to generate the pos configuration.
stream.end();
await createPosConfig(config.chain_id);
return;
}

config.mode = 'dev';

// generate a random chain_id
Expand All @@ -27,7 +55,9 @@ function initialConfig() {

// write config back
fs.writeFileSync("../conflux.toml", TOML.stringify(config));

await createPosConfig(config.chain_id)
console.log('CFXDOCKER: config file set success !');
}

initialConfig();
await initialConfig();
Loading

0 comments on commit 2c64882

Please sign in to comment.