Skip to content

Genesis contracts related automation #149

@AnnaShaleva

Description

@AnnaShaleva

Rationale

We have a set of genesis contracts that should be deployed on different networks (privnet/devenv/testnet/mainnet) with different parameters (contract-specific parameters like epoch duration in Governance contract and etc.). These contracts have to be compiled and properly inserted into genesis.json configuration file of the corresponding network. Also, some initial storage items should be filled for these contracts (including network-dependent parameters).

genesis.json allocations may be constructed manually, but this way is error-prone. And thus, we need an automated solution for compilation/deployment of genesis contracts.

Implementation

Luckily, we're not the first team who is trying to solve this task, so after some digging I'd suggest to use the approach of BNB Smart chain developers, it's good: https://github.com/bnb-chain/bsc-genesis-contract

In particular, this issue is about three automation steps:

  1. Contract storage pre-filling depending on some network-specific parameters. It may be done using two different approaches:

    a. Fill contract storage items in the storage section of genesis.json file based on storage values fetched from "normal" test contract deployment (e.g. from Remix). Like it's done now and like discussed in Governance V2 #146 (comment). I don't like this approach because it inevitably will cause sync errors once contracts need to be updated. And thus, I vote for the alternative approach.

    b. Create contract template, fill all necessary template values with network-specific parameters via script. The result of this step is a ready-to-compile contract with properly filled network-specific constants/variables. Exactly like https://github.com/bnb-chain/bsc-genesis-contract/blob/ed70acf722cd21013e81ec05d370893ea3bb5b9b/scripts/generate.py#L153.

  2. Contracts compilation. The easiest step, in general, it can be done with a set of scripts (written on Python or Go) running solc under the hood and compiling contracts got from the previous step. Exactly like https://github.com/bnb-chain/bsc-genesis-contract/blob/ed70acf722cd21013e81ec05d370893ea3bb5b9b/scripts/generate-genesis.js#L45.

  3. genesis.json file generation. Based on the previous step, compiled contracts should be put into genesis.json together with network-dependent information (stand by validators, network id and etc.).

So the whole pipeline will look like this: https://github.com/bnb-chain/bsc-genesis-contract/blob/ed70acf722cd21013e81ec05d370893ea3bb5b9b/scripts/generate.py#L294.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions