Skip to content

Commit

Permalink
Gnosis const preset
Browse files Browse the repository at this point in the history
  • Loading branch information
zah committed Jan 13, 2023
1 parent c01e53e commit b06502b
Show file tree
Hide file tree
Showing 18 changed files with 304 additions and 120 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,6 @@
path = vendor/merge-testnets
url = https://github.com/eth-clients/merge-testnets.git
branch = main
[submodule "vendor/gnosis-chain-configs"]
path = vendor/gnosis-chain-configs
url = https://github.com/zah/gnosis-chain-configs.git
11 changes: 2 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,7 @@ clean-sepolia:
### Gnosis chain binary
###

# TODO The constants overrides below should not be necessary if we restore
# the support for compiling with custom const presets.
# See the prepared preset file in media/gnosis/preset.yaml
#
# The `-d:gnosisChainBinary` override can be removed if the web3 library
# TODO The `-d:gnosisChainBinary` override can be removed if the web3 library
# gains support for multiple "Chain Profiles" that consist of a set of
# consensus object (such as blocks and transactions) that are specific
# to the chain.
Expand All @@ -604,11 +600,8 @@ gnosis-build gnosis-chain-build: | build deps
beacon_chain/nimbus_beacon_node.nim \
$(NIM_PARAMS) \
-d:gnosisChainBinary \
-d:const_preset=gnosis \
-d:has_genesis_detection \
-d:SLOTS_PER_EPOCH=16 \
-d:SECONDS_PER_SLOT=5 \
-d:BASE_REWARD_FACTOR=25 \
-d:EPOCHS_PER_SYNC_COMMITTEE_PERIOD=512 \
&& \
echo -e $(BUILD_END_MSG) "build/nimbus_beacon_node_gnosis"

Expand Down
4 changes: 2 additions & 2 deletions beacon_chain/conf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ proc loadEth2Network*(
eth2Network: Option[string]
): Eth2NetworkMetadata {.raises: [Defect, IOError].} =
const defaultName =
when defined(gnosisChainBinary) and const_preset == "mainnet":
when const_preset == "gnosis":
"gnosis"
elif const_preset == "mainnet":
"mainnet"
Expand All @@ -1276,7 +1276,7 @@ proc loadEth2Network*(
if eth2Network.isSome:
getMetadataForNetwork(eth2Network.get)
else:
when defined(gnosisChainBinary) and const_preset == "mainnet":
when const_preset == "gnosis":
gnosisMetadata
elif const_preset == "mainnet":
mainnetMetadata
Expand Down
10 changes: 6 additions & 4 deletions beacon_chain/networking/eth2_network.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1867,14 +1867,16 @@ proc startListening*(node: Eth2Node) {.async.} =
if node.discoveryEnabled:
try:
node.discovery.open()
except CatchableError:
fatal "Failed to start discovery service. UDP port may be already in use"
except CatchableError as err:
fatal "Failed to start discovery service. UDP port may be already in use",
err = err.msg
quit 1

try:
await node.switch.start()
except CatchableError:
fatal "Failed to start LibP2P transport. TCP port may be already in use"
except CatchableError as err:
fatal "Failed to start LibP2P transport. TCP port may be already in use",
err = err.msg
quit 1

proc peerPingerHeartbeat(node: Eth2Node): Future[void] {.gcsafe.}
Expand Down
13 changes: 6 additions & 7 deletions beacon_chain/networking/network_metadata.nim
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ template mergeTestnet(path: string, eth1Network: Eth1Network): Eth2NetworkMetada
loadCompileTimeNetworkMetadata(mergeTestnetsDir & "/" & path,
some eth1Network)

when defined(gnosisChainBinary) and const_preset == "mainnet":
when const_preset == "gnosis":
const
gnosisMetadata* = loadCompileTimeNetworkMetadata(
currentSourcePath.parentDir.replace('\\', '/') &
"/../../media/gnosis")
"/../../vendor/gnosis-chain-configs/mainnet")
static:
checkForkConsistency(gnosisMetadata.cfg)
doAssert gnosisMetadata.cfg.CAPELLA_FORK_EPOCH == FAR_FUTURE_EPOCH
Expand Down Expand Up @@ -252,7 +252,7 @@ proc getMetadataForNetwork*(
warn "Ropsten is unsupported; https://blog.ethereum.org/2022/11/30/ropsten-shutdown-announcement suggests migrating to Goerli or Sepolia"

let metadata =
when defined(gnosisChainBinary) and const_preset == "mainnet":
when const_preset == "gnosis":
case toLowerAscii(networkName)
of "gnosis":
gnosisMetadata
Expand Down Expand Up @@ -298,10 +298,9 @@ proc getRuntimeConfig*(
return getMetadataForNetwork(eth2Network.get).cfg

when const_preset == "mainnet":
when defined(gnosisChainBinary):
gnosisMetadata.cfg
else:
mainnetMetadata.cfg
mainnetMetadata.cfg
elif const_preset == "gnosis":
gnosisMetadata.cfg
else:
# This is a non-standard build (i.e. minimal), and the function was most
# likely executed in a test. The best we can do is return a fully default
Expand Down
107 changes: 107 additions & 0 deletions beacon_chain/spec/presets.nim
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,113 @@ when const_preset == "mainnet":
DEPOSIT_CONTRACT_ADDRESS: default(Eth1Address)
)

elif const_preset == "gnosis":
import ./presets/gnosis
export gnosis

# TODO Move this to RuntimeConfig
const SECONDS_PER_SLOT* {.intdefine.}: uint64 = 5

# The default run-time config specifies the default configuration values
# that will be used if a particular run-time config is missing specific
# confugration values (which will be then taken from this config object).
# It mostly matches the gnosis config with the exception of few properties
# such as `CONFIG_NAME`, `TERMINAL_TOTAL_DIFFICULTY`, `*_FORK_EPOCH`, etc
# which must be effectively overriden in all network (including mainnet).
const defaultRuntimeConfig* = RuntimeConfig(
# Mainnet config

# Extends the mainnet preset
PRESET_BASE: "gnosis",

# Free-form short name of the network that this configuration applies to - known
# canonical network names include:
# * 'mainnet' - there can be only one
# * 'prater' - testnet
# * 'ropsten' - testnet
# * 'sepolia' - testnet
# Must match the regex: [a-z0-9\-]
CONFIG_NAME: "",

# Transition
# ---------------------------------------------------------------
# TBD, 2**256-2**10 is a placeholder
TERMINAL_TOTAL_DIFFICULTY:
u256"115792089237316195423570985008687907853269984665640564039457584007913129638912",
# By default, don't use these params
TERMINAL_BLOCK_HASH: BlockHash.fromHex(
"0x0000000000000000000000000000000000000000000000000000000000000000"),
# TODO TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: Epoch(uint64.high),

# Genesis
# ---------------------------------------------------------------
# `2**14` (= 16,384)
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT: 4096,
# Dec 1, 2020, 12pm UTC
MIN_GENESIS_TIME: 1638968400,
# Mainnet initial fork version, recommend altering for testnets
GENESIS_FORK_VERSION: Version [byte 0x00, 0x00, 0x00, 0x64],
# 604800 seconds (7 days)
GENESIS_DELAY: 604800,

# Forking
# ---------------------------------------------------------------
# Some forks are disabled for now:
# - These may be re-assigned to another fork-version later
# - Temporarily set to max uint64 value: 2**64 - 1

# Altair
ALTAIR_FORK_VERSION: Version [byte 0x01, 0x00, 0x00, 0x64],
ALTAIR_FORK_EPOCH: FAR_FUTURE_EPOCH,
# Bellatrix
BELLATRIX_FORK_VERSION: Version [byte 0x02, 0x00, 0x00, 0x64],
BELLATRIX_FORK_EPOCH: FAR_FUTURE_EPOCH,
# Capella
CAPELLA_FORK_VERSION: Version [byte 0x03, 0x00, 0x00, 0x64],
CAPELLA_FORK_EPOCH: FAR_FUTURE_EPOCH,
# eip4844
EIP4844_FORK_VERSION: Version [byte 0x04, 0x00, 0x00, 0x64],
EIP4844_FORK_EPOCH: FAR_FUTURE_EPOCH,
# Sharding
SHARDING_FORK_VERSION: Version [byte 0x05, 0x00, 0x00, 0x64],
SHARDING_FORK_EPOCH: FAR_FUTURE_EPOCH,

# Time parameters
# ---------------------------------------------------------------
# 12 seconds
# TODO SECONDS_PER_SLOT: 12,
# 14 (estimate from Eth1 mainnet)
SECONDS_PER_ETH1_BLOCK: 5,
# 2**8 (= 256) epochs ~27 hours
MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256,
# 2**8 (= 256) epochs ~27 hours
SHARD_COMMITTEE_PERIOD: 256,
# 2**11 (= 2,048) Eth1 blocks ~8 hours
ETH1_FOLLOW_DISTANCE: 2048,


# Validator cycle
# ---------------------------------------------------------------
# 2**2 (= 4)
INACTIVITY_SCORE_BIAS: 4,
# 2**4 (= 16)
INACTIVITY_SCORE_RECOVERY_RATE: 16,
# 2**4 * 10**9 (= 16,000,000,000) Gwei
EJECTION_BALANCE: 16000000000'u64,
# 2**2 (= 4)
MIN_PER_EPOCH_CHURN_LIMIT: 4,
# 2**16 (= 65,536)
CHURN_LIMIT_QUOTIENT: 4096,


# Deposit contract
# ---------------------------------------------------------------
# Gnosis PoW Mainnet
DEPOSIT_CHAIN_ID: 100,
DEPOSIT_NETWORK_ID: 100,
DEPOSIT_CONTRACT_ADDRESS: default(Eth1Address)
)

elif const_preset == "minimal":
import ./presets/minimal
export minimal
Expand Down
4 changes: 4 additions & 0 deletions beacon_chain/spec/presets/gnosis.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import
./gnosis/[altair_preset, bellatrix_preset, capella_preset, eip4844_preset, phase0_preset]

export altair_preset, bellatrix_preset, capella_preset, eip4844_preset, phase0_preset
27 changes: 27 additions & 0 deletions beacon_chain/spec/presets/gnosis/altair_preset.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Mainnet preset - Altair
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.2/presets/mainnet/altair.yaml
const
# Updated penalty values
# ---------------------------------------------------------------
# 3 * 2**24 (= 50,331,648)
INACTIVITY_PENALTY_QUOTIENT_ALTAIR*: uint64 = 50331648
# 2**6 (= 64)
MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR*: uint64 = 64
# 2
PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR*: uint64 = 2


# Sync committee
# ---------------------------------------------------------------
# 2**9 (= 512)
SYNC_COMMITTEE_SIZE* = 512
# 2**8 (= 256)
EPOCHS_PER_SYNC_COMMITTEE_PERIOD* {.intdefine.}: uint64 = 512


# Sync protocol
# ---------------------------------------------------------------
# 1
MIN_SYNC_COMMITTEE_PARTICIPANTS* = 1
# SLOTS_PER_EPOCH * EPOCHS_PER_SYNC_COMMITTEE_PERIOD (= 32 * 256)
UPDATE_TIMEOUT*: uint64 = 8192
23 changes: 23 additions & 0 deletions beacon_chain/spec/presets/gnosis/bellatrix_preset.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Mainnet preset - Bellatrix
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.2/presets/mainnet/bellatrix.yaml
const
# Updated penalty values
# ---------------------------------------------------------------
# 2**24 (= 16,777,216)
INACTIVITY_PENALTY_QUOTIENT_BELLATRIX*: uint64 = 16777216
# 2**5 (= 32)
MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX*: uint64 = 32
# 3
PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX*: uint64 = 3


# Execution
# ---------------------------------------------------------------
# 2**30 (= 1,073,741,824)
MAX_BYTES_PER_TRANSACTION* = 1073741824
# 2**20 (= 1,048,576)
MAX_TRANSACTIONS_PER_PAYLOAD* = 1048576
# 2**8 (= 256)
BYTES_PER_LOGS_BLOOM* = 256
# 2**5 (= 32)
MAX_EXTRA_DATA_BYTES* = 32
19 changes: 19 additions & 0 deletions beacon_chain/spec/presets/gnosis/capella_preset.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Mainnet preset - Capella
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.2/presets/mainnet/capella.yaml
const
# Max operations per block
# ---------------------------------------------------------------
# 2**4 (= 16)
MAX_BLS_TO_EXECUTION_CHANGES* = 16


# Execution
# ---------------------------------------------------------------
# 2**4 (= 16) withdrawals
MAX_WITHDRAWALS_PER_PAYLOAD* = 16


# Withdrawals processing
# ---------------------------------------------------------------
# 2**14 (= 16384) validators
MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP* = 16384
7 changes: 7 additions & 0 deletions beacon_chain/spec/presets/gnosis/eip4844_preset.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Mainnet preset - EIP-4844
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.2/presets/mainnet/eip4844.yaml
const
# `uint64(4096)`
FIELD_ELEMENTS_PER_BLOB*: uint64 = 4096
# `uint64(2**2)` (= 4)
MAX_BLOBS_PER_BLOCK*: uint64 = 4
Loading

0 comments on commit b06502b

Please sign in to comment.