Skip to content

Commit 9a2c396

Browse files
authored
Merge pull request #25 from rabbitprincess/feature/jsonnet
Feature/jsonnet
2 parents 03f2c14 + e146a34 commit 9a2c396

5 files changed

Lines changed: 214 additions & 122 deletions

File tree

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.env text eol=lf
22
*.sh text eol=lf
3+
*.jsonnet test eol=lf
34
entrypoint* text eol=lf
45
Dockerfile text eol=lf

init/3_config.jsonnet

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
//-----------------------------------------------------------------------//
2+
// args / funcs
3+
4+
local config = std.extVar("config");
5+
6+
// if not exist conf, throw an error
7+
local require(key, conf) =
8+
if std.objectHas(config, conf) then
9+
{ [key]: config[conf] }
10+
else
11+
error "required field not found :" + conf;
12+
13+
// if not exist conf, return the default value
14+
local default(key, conf, default) =
15+
if std.objectHas(config, conf) then
16+
{ [key]: config[conf] }
17+
else
18+
{ [key]: default };
19+
20+
// if not exist conf, return empty
21+
local optional(key, conf) =
22+
if std.objectHas(config, conf) then
23+
{ [key]: config[conf] }
24+
else
25+
{};
26+
27+
//-----------------------------------------------------------------------//
28+
// elements
29+
30+
local L1StartingBlockTag =
31+
require("l1StartingBlockTag", "l1StartingBlockTag");
32+
33+
local DevDeployConfig =
34+
default("fundDevAccounts", "fundDevAccounts", false);
35+
36+
local L2GenesisBlockDeployConfig =
37+
optional("l2GenesisBlockNonce", "l2GenesisBlockNonce")
38+
+ default("l2GenesisBlockGasLimit", "l2GenesisBlockGasLimit", "0x1c9c380") // 30_000_000
39+
+ optional("l2GenesisBlockDifficulty", "l2GenesisBlockDifficulty")
40+
+ optional("l2GenesisBlockMixHash", "l2GenesisBlockMixHash")
41+
+ optional("l2GenesisBlockNumber", "l2GenesisBlockNumber")
42+
+ optional("l2GenesisBlockGasUsed", "l2GenesisBlockGasUsed")
43+
+ optional("l2GenesisBlockParentHash", "l2GenesisBlockParentHash")
44+
+ default("l2GenesisBlockBaseFeePerGas", "l2GenesisBlockBaseFeePerGas", "0x3b9aca00") // 1_000_000_000
45+
+ optional("l2GenesisBlockExtraData", "l2GenesisBlockExtraData");
46+
47+
local OwnershipDeployConfig =
48+
require("proxyAdminOwner", "ADMIN_ADDRESS")
49+
+ require("finalSystemOwner", "ADMIN_ADDRESS");
50+
51+
local L2VaultsDeployConfig =
52+
require("baseFeeVaultRecipient", "ADMIN_ADDRESS")
53+
+ require("l1FeeVaultRecipient", "ADMIN_ADDRESS")
54+
+ require("sequencerFeeVaultRecipient", "ADMIN_ADDRESS")
55+
+ default("baseFeeVaultMinimumWithdrawalAmount", "baseFeeVaultMinimumWithdrawalAmount", "0x8ac7230489e80000") // 10000000000000000000
56+
+ default("l1FeeVaultMinimumWithdrawalAmount", "l1FeeVaultMinimumWithdrawalAmount", "0x8ac7230489e80000") // 10000000000000000000
57+
+ default("sequencerFeeVaultMinimumWithdrawalAmount", "sequencerFeeVaultMinimumWithdrawalAmount", "0x8ac7230489e80000") // 10000000000000000000
58+
+ default("baseFeeVaultWithdrawalNetwork", "baseFeeVaultWithdrawalNetwork", 0)
59+
+ default("l1FeeVaultWithdrawalNetwork", "l1FeeVaultWithdrawalNetwork", 0)
60+
+ default("sequencerFeeVaultWithdrawalNetwork", "sequencerFeeVaultWithdrawalNetwork", 0);
61+
62+
local GovernanceDeployConfig =
63+
default("enableGovernance", "enableGovernance", false)
64+
+ default("governanceTokenSymbol", "governanceTokenSymbol", "NA")
65+
+ default("governanceTokenName", "governanceTokenName", "NotApplicable")
66+
+ require("governanceTokenOwner", "ADMIN_ADDRESS");
67+
68+
local GasPriceOracleDeployConfig =
69+
default("gasPriceOracleOverhead", "gasPriceOracleOverhead", 2100)
70+
+ default("gasPriceOracleScalar", "gasPriceOracleScalar", 1000000)
71+
+ default("gasPriceOracleBaseFeeScalar", "gasPriceOracleBaseFeeScalar", 1368)
72+
+ default("gasPriceOracleBlobBaseFeeScalar", "gasPriceOracleBlobBaseFeeScalar", 810949);
73+
74+
local GasTokenDeployConfig =
75+
default("useCustomGasToken", "useCustomGasToken", false)
76+
+ optional("customGasTokenAddress", "customGasTokenAddress");
77+
78+
local OperatorDeployConfig =
79+
require("p2pSequencerAddress", "SEQUENCER_ADDRESS")
80+
+ require("batchSenderAddress", "BATCHER_ADDRESS");
81+
82+
local EIP1559DeployConfig =
83+
default("eip1559Elasticity", "eip1559Elasticity", 6)
84+
+ default("eip1559Denominator", "eip1559Denominator", 50)
85+
+ default("eip1559DenominatorCanyon", "eip1559DenominatorCanyon", 250);
86+
87+
local UpgradeScheduleDeployConfig =
88+
default("l2GenesisRegolithTimeOffset", "l2GenesisRegolithTimeOffset", "0x0")
89+
+ default("l2GenesisCanyonTimeOffset", "l2GenesisCanyonTimeOffset", "0x0")
90+
+ default("l2GenesisDeltaTimeOffset", "l2GenesisDeltaTimeOffset", "0x0")
91+
+ default("l2GenesisEcotoneTimeOffset", "l2GenesisEcotoneTimeOffset", "0x0")
92+
+ default("l2GenesisFjordTimeOffset", "l2GenesisFjordTimeOffset", "0x0")
93+
// + default("l2GenesisGraniteTimeOffset", "l2GenesisGraniteTimeOffset", "0x0") // not used now
94+
+ default("l2GenesisInteropTimeOffset", "l2GenesisInteropTimeOffset", "0x0")
95+
+ default("useInterop", "useInterop", false);
96+
97+
local L2CoreDeployConfig =
98+
require("l1ChainID", "l1ChainID")
99+
+ require("l2ChainID", "l2ChainID")
100+
+ default("l2BlockTime", "l2BlockTime", 2)
101+
+ default("finalizationPeriodSeconds", "finalizationPeriodSeconds", 12)
102+
+ default("maxSequencerDrift", "maxSequencerDrift", 600)
103+
+ default("sequencerWindowSize", "sequencerWindowSize", 3600)
104+
+ default("channelTimeout", "channelTimeout", 300)
105+
+ optional("channelTimeoutGranite", "channelTimeoutGranite")
106+
+ default("batchInboxAddress", "batchInboxAddress", "0xff00000000000000000000000000000000000000")
107+
+ default("systemConfigStartBlock", "systemConfigStartBlock", 0);
108+
109+
local AltDADeployConfig =
110+
default("usePlasma", "usePlasma", false)
111+
+ default("daCommitmentType", "daCommitmentType", "KeccakCommitment")
112+
+ default("daChallengeWindow", "daChallengeWindow", 16)
113+
+ default("daResolveWindow", "daResolveWindow", 16)
114+
+ default("daBondSize", "daBondSize", 1000000)
115+
+ default("daResolverRefundPercentage", "daResolverRefundPercentage", 0);
116+
117+
local DevL1DeployConfig =
118+
default("l1BlockTime", "l1BlockTime", 12)
119+
+ optional("l1GenesisBlockTimestamp", "l1GenesisBlockTimestamp")
120+
+ optional("l1GenesisBlockNonce", "l1GenesisBlockNonce")
121+
+ optional("l1GenesisBlockGasLimit", "l1GenesisBlockGasLimit")
122+
+ optional("l1GenesisBlockDifficulty", "l1GenesisBlockDifficulty")
123+
+ optional("l1GenesisBlockMixHash", "l1GenesisBlockMixHash")
124+
+ optional("l1GenesisBlockCoinbase", "l1GenesisBlockCoinbase")
125+
+ optional("l1GenesisBlockNumber", "l1GenesisBlockNumber")
126+
+ optional("l1GenesisBlockGasUsed", "l1GenesisBlockGasUsed")
127+
+ optional("l1GenesisBlockParentHash", "l1GenesisBlockParentHash")
128+
+ optional("l1GenesisBlockBaseFeePerGas", "l1GenesisBlockBaseFeePerGas")
129+
+ optional("l1GenesisBlockExcessBlobGas", "l1GenesisBlockExcessBlobGas")
130+
+ optional("l1GenesisBlockblobGasUsed", "l1GenesisBlockblobGasUsed");
131+
132+
local SuperchainL1DeployConfig =
133+
require("superchainConfigGuardian", "ADMIN_ADDRESS")
134+
+ default("requiredProtocolVersion", "requiredProtocolVersion", "0x0000000000000000000000000000000000000000000000000000000000000000")
135+
+ default("recommendedProtocolVersion", "recommendedProtocolVersion", "0x0000000000000000000000000000000000000000000000000000000000000000");
136+
137+
local OutputOracleDeployConfig =
138+
default("l2OutputOracleSubmissionInterval", "l2OutputOracleSubmissionInterval", 1800)
139+
+ require("l2OutputOracleStartingTimestamp", "TIMESTAMP")
140+
+ default("l2OutputOracleStartingBlockNumber", "l2OutputOracleStartingBlockNumber", 0)
141+
+ require("l2OutputOracleProposer", "PROPOSER_ADDRESS")
142+
+ require("l2OutputOracleChallenger", "ADMIN_ADDRESS");
143+
144+
local FaultProofDeployConfig =
145+
default("useFaultProofs", "useFaultProofs", true)
146+
+ default("faultGameAbsolutePrestate", "faultGameAbsolutePrestate", "0x0000000000000000000000000000000000000000000000000000000000000000")
147+
+ default("faultGameMaxDepth", "faultGameMaxDepth", 73)
148+
+ default("faultGameClockExtension", "faultGameClockExtension", 18000)
149+
+ default("faultGameMaxClockDuration", "faultGameMaxClockDuration", 302400)
150+
+ default("faultGameGenesisBlock", "faultGameGenesisBlock", 0)
151+
+ default("faultGameGenesisOutputRoot", "faultGameGenesisOutputRoot", "0x0000000000000000000000000000000000000000000000000000000000000000")
152+
+ default("faultGameSplitDepth", "faultGameSplitDepth", 30)
153+
+ default("faultGameWithdrawalDelay", "faultGameWithdrawalDelay", 604800)
154+
+ default("preimageOracleMinProposalSize", "preimageOracleMinProposalSize", 126000)
155+
+ default("preimageOracleChallengePeriod", "preimageOracleChallengePeriod", 86400)
156+
+ default("proofMaturityDelaySeconds", "proofMaturityDelaySeconds", 604800)
157+
+ default("disputeGameFinalityDelaySeconds", "disputeGameFinalityDelaySeconds", 302400)
158+
+ default("respectedGameType", "respectedGameType", 0);
159+
160+
//-----------------------------------------------------------------------//
161+
// output
162+
163+
L1StartingBlockTag
164+
+ DevDeployConfig
165+
+ L2GenesisBlockDeployConfig
166+
+ OwnershipDeployConfig
167+
+ L2VaultsDeployConfig
168+
+ GovernanceDeployConfig
169+
+ GasPriceOracleDeployConfig
170+
+ GasTokenDeployConfig
171+
+ OperatorDeployConfig
172+
+ EIP1559DeployConfig
173+
+ UpgradeScheduleDeployConfig
174+
+ L2CoreDeployConfig
175+
+ AltDADeployConfig
176+
+ DevL1DeployConfig
177+
+ SuperchainL1DeployConfig
178+
+ OutputOracleDeployConfig
179+
+ FaultProofDeployConfig

init/3_generate_config.sh

Lines changed: 32 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
#!/bin/bash
2-
3-
# !!!!check https://docs.optimism.io/builders/chain-operators/management/configuration!!!!!
4-
# original path : https://github.com/ethereum-optimism/optimism\packages\contracts-bedrock\scripts\getting-started\config.sh
5-
# This script is used to generate the getting-started.json configuration file
6-
# used in the Getting Started quickstart guide on the docs site. Avoids the
7-
# need to have the getting-started.json committed to the repo since it's an
8-
# invalid JSON file when not filled in, which is annoying.
2+
set -eu
93

104
echo "[3/5] : generate config"
115

@@ -14,128 +8,45 @@ block=$(cast block finalized --rpc-url "$L1_RPC_URL")
148
timestamp=$(echo "$block" | awk '/timestamp/ { print $2 }')
159
blockhash=$(echo "$block" | awk '/hash/ { print $2 }')
1610

17-
# generate the batch inbox address by L2_CHAIN_ID
1811
base_address="0xff00000000000000000000000000000000000000"
1912
BatchInboxAddress="${base_address%${base_address: -${#L2_CHAIN_ID}}}$L2_CHAIN_ID"
2013

21-
govConfig=""
14+
# basic config
15+
config="{"
16+
config+="ADMIN_ADDRESS: \"$ADMIN_ADDRESS\", "
17+
config+="BATCHER_ADDRESS: \"$BATCHER_ADDRESS\", "
18+
config+="SEQUENCER_ADDRESS: \"$SEQUENCER_ADDRESS\", "
19+
config+="PROPOSER_ADDRESS: \"$PROPOSER_ADDRESS\", "
20+
config+="TIMESTAMP: $timestamp, "
21+
config+="l1StartingBlockTag: \"$blockhash\", "
22+
config+="l1ChainID: $L1_CHAIN_ID, "
23+
config+="l2ChainID: $L2_CHAIN_ID, "
24+
config+="batchInboxAddress: \"$BatchInboxAddress\""
25+
26+
# Governance config
2227
if [ -n "$GOVERNANCE_TOKEN_SYMBOL" ]; then
23-
govConfig=$(cat << EOL
24-
"enableGovernance": true,
25-
"governanceTokenSymbol": "$GOVERNANCE_TOKEN_SYMBOL",
26-
"governanceTokenName": "$GOVERNANCE_TOKEN_SYMBOL",
27-
"governanceTokenOwner": "$ADMIN_ADDRESS",
28-
EOL
29-
)
30-
else
31-
govConfig=$(cat << EOL
32-
"enableGovernance": false,
33-
"governanceTokenSymbol": "NA",
34-
"governanceTokenName": "NotApplicable",
35-
"governanceTokenOwner": "$ADMIN_ADDRESS",
36-
EOL
37-
)
28+
config+=", "
29+
config+="enableGovernance: true, "
30+
config+="governanceTokenSymbol: \"$GOVERNANCE_TOKEN_SYMBOL\", "
31+
config+="governanceTokenName: \"$GOVERNANCE_TOKEN_SYMBOL\", "
32+
config+="governanceTokenOwner: \"$ADMIN_ADDRESS\""
3833
fi
3934

40-
altDaConfig=""
41-
if [ -n "$ALT_DA_SERVER" ]; then
42-
altDaConfig=$(cat << EOL
43-
"usePlasma": true,
44-
"daCommitmentType": "KeccakCommitment",
45-
"daChallengeWindow": 16,
46-
"daResolveWindow": 16,
47-
"daBondSize": 1000000,
48-
"daResolverRefundPercentage": 0,
49-
EOL
50-
)
35+
# Alt DA config
36+
if [ -n "${ALT_DA_SERVER}" ]; then
37+
config+=", "
38+
config+="altDAServer: \"$ALT_DA_SERVER\", "
39+
config+="usePlasma: true, "
40+
config+="daCommitmentType: \"KeccakCommitment\", ",
41+
config+="daChallengeWindow: 16, ",
42+
config+="daResolveWindow: 16, ",
43+
config+="daBondSize: 1000000, ",
44+
config+="daResolverRefundPercentage: 0"
5145
fi
5246

53-
# Generate the config file
54-
config=$(cat << EOL
55-
{
56-
"l1StartingBlockTag": "$blockhash",
57-
58-
"l1ChainID": $L1_CHAIN_ID,
59-
"l2ChainID": $L2_CHAIN_ID,
60-
"l2BlockTime": 2,
61-
"l1BlockTime": 12,
62-
63-
"maxSequencerDrift": 600,
64-
"sequencerWindowSize": 3600,
65-
"channelTimeout": 300,
66-
67-
"p2pSequencerAddress": "$SEQUENCER_ADDRESS",
68-
"batchInboxAddress": "$BatchInboxAddress",
69-
"batchSenderAddress": "$BATCHER_ADDRESS",
70-
71-
"l2OutputOracleSubmissionInterval": 1800,
72-
"l2OutputOracleStartingBlockNumber": 0,
73-
"l2OutputOracleStartingTimestamp": $timestamp,
74-
75-
"l2OutputOracleProposer": "$PROPOSER_ADDRESS",
76-
"l2OutputOracleChallenger": "$ADMIN_ADDRESS",
77-
78-
"finalizationPeriodSeconds": 12,
79-
80-
"proxyAdminOwner": "$ADMIN_ADDRESS",
81-
"baseFeeVaultRecipient": "$ADMIN_ADDRESS",
82-
"l1FeeVaultRecipient": "$ADMIN_ADDRESS",
83-
"sequencerFeeVaultRecipient": "$ADMIN_ADDRESS",
84-
"finalSystemOwner": "$ADMIN_ADDRESS",
85-
"superchainConfigGuardian": "$ADMIN_ADDRESS",
86-
87-
"baseFeeVaultMinimumWithdrawalAmount": "0x8ac7230489e80000",
88-
"l1FeeVaultMinimumWithdrawalAmount": "0x8ac7230489e80000",
89-
"sequencerFeeVaultMinimumWithdrawalAmount": "0x8ac7230489e80000",
90-
"baseFeeVaultWithdrawalNetwork": 0,
91-
"l1FeeVaultWithdrawalNetwork": 0,
92-
"sequencerFeeVaultWithdrawalNetwork": 0,
93-
94-
"gasPriceOracleOverhead": 2100,
95-
"gasPriceOracleScalar": 1000000,
96-
"gasPriceOracleBaseFeeScalar": 1368,
97-
"gasPriceOracleBlobBaseFeeScalar": 810949,
98-
99-
$govConfig
100-
101-
"l2GenesisBlockGasLimit": "0x1c9c380",
102-
"l2GenesisBlockBaseFeePerGas": "0x3b9aca00",
103-
"l2GenesisRegolithTimeOffset": "0x0",
104-
"l2GenesisCanyonTimeOffset": "0x0",
105-
"l2GenesisDeltaTimeOffset": "0x0",
106-
"l2GenesisEcotoneTimeOffset": "0x0",
107-
"l2GenesisFjordTimeOffset": "0x0",
108-
109-
"eip1559Denominator": 50,
110-
"eip1559DenominatorCanyon": 250,
111-
"eip1559Elasticity": 6,
112-
113-
"systemConfigStartBlock": 0,
114-
115-
$altDaConfig
116-
117-
"requiredProtocolVersion": "0x0000000000000000000000000000000000000004000000000000000000000000",
118-
"recommendedProtocolVersion": "0x0000000000000000000000000000000000000004000000000000000000000000",
119-
"fundDevAccounts": false,
120-
"faultGameAbsolutePrestate": "0x037ef3c1a487960b0e633d3e513df020c43432769f41a634d18a9595cbf53c55",
121-
"faultGameMaxDepth": 73,
122-
"faultGameClockExtension": 10800,
123-
"faultGameMaxClockDuration": 302400,
124-
"faultGameGenesisBlock": 0,
125-
"faultGameGenesisOutputRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
126-
"faultGameSplitDepth": 30,
127-
"faultGameWithdrawalDelay": 604800,
128-
"preimageOracleMinProposalSize": 126000,
129-
"preimageOracleChallengePeriod": 86400,
130-
"proofMaturityDelaySeconds": 604800,
131-
"disputeGameFinalityDelaySeconds": 302400,
132-
"respectedGameType": 0,
133-
"useFaultProofs": true
134-
}
135-
EOL
136-
)
47+
config+="}"
13748

138-
# Write the config file
49+
# Generate the configuration using Jsonnet
13950
cd ~/optimism/packages/contracts-bedrock && \
14051
mkdir -p ./deployments/$DEPLOYMENT_CONTEXT && \
141-
echo "$config" > ./deployments/$DEPLOYMENT_CONTEXT/.deploy
52+
jsonnet /script/3_config.jsonnet --ext-code config="$config" > ./deployments/$DEPLOYMENT_CONTEXT/.deploy

init/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM debian
33
WORKDIR /app
44

55
# init system dependencies
6-
RUN apt-get -y update && apt-get install -y sudo jq wget curl gnupg git make bc ca-certificates && \
6+
RUN apt-get -y update && apt-get install -y sudo jq wget curl gnupg git make bc ca-certificates jsonnet && \
77
sudo rm -rf /var/lib/apt/lists
88

99
# install go

init/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ services:
88
- ${CONFIG_DIR}:/config
99
- ./1_init_environment.sh:/script/1_init_environment.sh
1010
- ./2_faucet.sh:/script/2_faucet.sh
11+
- ./3_config.jsonnet:/script/3_config.jsonnet
1112
- ./3_generate_config.sh:/script/3_generate_config.sh
1213
- ./4_deploy_contract.sh:/script/4_deploy_contract.sh
1314
- ./5_export_genesis.sh:/script/5_export_genesis.sh

0 commit comments

Comments
 (0)