Skip to content

Commit

Permalink
refactor genesis package
Browse files Browse the repository at this point in the history
* don't pass genesisBytes as arg on SetNode, NewVochain, newTendermint, etc

* notably, now cometbft has it's own datadir separate from our state,
  allowing to wipe cometbft data without wiping our state.

* drop genesis.AutoUpdateGenesis in favor of a new flag AutoWipeDataDir
* add AutoWipeCometBFT flag

* move SeedNodes from genesis into config package (DefaultSeedNodes)
* add config consts: DefaultCometBFTPath and DefaultGenesisPath

* testsuite: use genesis.go instead of hardcoded genesis.json
    this increases the code coverage of testsuite and helps
    developing refactors of genesis.go
* now testsuite network is `test` (instead of `dev`)

* app.genesisDoc is now populated during newTendermint, instead of
  pulling from app.NodeClient.Genesis, since it's needed during Info() handshake

* cometbft: removed redundant app.State.SetHeight(lastHeight) during Info()

* cometbft: now Info() supports doing a chain bump, if genesis InitialHeight > lastHeight

* genesis: remove copypasted types, use upstream comettypes directly
* genesis: deduplicate ConsensusParams literals using DefaultBlockParams, etc
* genesis: remove useless hardcoded StateSyncParams
  • Loading branch information
altergui committed May 13, 2024
1 parent 114f6b6 commit cc8f620
Show file tree
Hide file tree
Showing 21 changed files with 405 additions and 543 deletions.
4 changes: 1 addition & 3 deletions cmd/tools/vochaininspector/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"go.vocdoni.io/dvote/statedb"
"go.vocdoni.io/dvote/util"
"go.vocdoni.io/dvote/vochain"
"go.vocdoni.io/dvote/vochain/genesis"
"go.vocdoni.io/dvote/vochain/state"
"go.vocdoni.io/dvote/vochain/vochaininfo"
"go.vocdoni.io/proto/build/go/models"
Expand Down Expand Up @@ -191,8 +190,7 @@ func newVochain(network, dataDir string) *vochain.BaseApplication {
}
log.Infof("external ip address %s", cfg.PublicAddr)
// Create the vochain node
genesisBytes := genesis.Genesis[network].Genesis.Marshal()
return vochain.NewVochain(cfg, genesisBytes)
return vochain.NewVochain(cfg)
}

func listBlockVotes(_ int64, _ string) {
Expand Down
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ type VochainCfg struct {
PrivValidatorListenAddr string
// NoWaitSync if enabled the Vochain synchronization won't be blocking
NoWaitSync bool
// AutoWipeDataDir enables wiping out the whole datadir when hardcoded genesis changes
AutoWipeDataDir bool
// AutoWipeCometBFT enables wiping out the cometbft datadir when hardcoded genesis changes
AutoWipeCometBFT bool
// MempoolSize is the size of the mempool
MempoolSize int
// SkipPreviousOffchainData if enabled, the node will skip downloading the previous off-chain data to the current block
Expand Down
25 changes: 25 additions & 0 deletions config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,29 @@ package config
// These consts are defaults used in VochainCfg
const (
DefaultMinerTargetBlockTimeSeconds = 10
DefaultCometBFTPath = "cometbft"
DefaultGenesisPath = DefaultCometBFTPath + "/config/genesis.json"
)

// DefaultSeedNodes is a map indexed by network name
var DefaultSeedNodes = map[string][]string{
// testsuite test network
"test": {
"3c3765494e758ae7baccb1f5b0661755302ddc47@seed:26656",
},
// Development network
"dev": {
"[email protected]:26656",
},

// Staging network
"stage": {
"[email protected]:26656",
},

// LTS production network
"lts": {
"[email protected]:26656",
"[email protected]:26656",
},
}
2 changes: 0 additions & 2 deletions dockerfiles/testsuite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ the testnet is composed of:
* four [miners](https://docs.vocdoni.io/architecture/services/vochain.html#miner) (aka [validator nodes](https://docs.tendermint.com/master/nodes/#validators) in tendermint jargon)
* one [gateway](https://docs.vocdoni.io/architecture/components.html#gateway)

the `genesis.json` file lists the public keys of all the miners, since vochain is a Proof-of-Authority.

the seed node will serve to bootstrap the network: it'll just wait for incoming connections from other nodes, and provide them a list of peers which they can connect to.
the miners will first connect to the seed node, get the list of peers, and connect to each other. when there are at least 3 miners online, they can reach consensus and start producing blocks.

Expand Down
21 changes: 7 additions & 14 deletions dockerfiles/testsuite/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ services:
- blockchain
volumes:
- data-seed:/app/run/
- ${COMPOSE_HOST_PATH:-.}/genesis.json:/app/misc/genesis.json
- /tmp/.vochain-zkCircuits/:/app/run/dev/zkCircuits/
- /tmp/.vochain-zkCircuits/:/app/run/test/zkCircuits/
- gocoverage-seed:/app/run/gocoverage
environment:
- GOCOVERDIR=/app/run/gocoverage
Expand All @@ -24,8 +23,7 @@ services:
- blockchain
volumes:
- data-miner0:/app/run/
- ${COMPOSE_HOST_PATH:-.}/genesis.json:/app/misc/genesis.json
- /tmp/.vochain-zkCircuits/:/app/run/dev/zkCircuits/
- /tmp/.vochain-zkCircuits/:/app/run/test/zkCircuits/
- gocoverage-miner0:/app/run/gocoverage
environment:
- GOCOVERDIR=/app/run/gocoverage
Expand All @@ -38,8 +36,7 @@ services:
- blockchain
volumes:
- data-miner1:/app/run/
- ${COMPOSE_HOST_PATH:-.}/genesis.json:/app/misc/genesis.json
- /tmp/.vochain-zkCircuits/:/app/run/dev/zkCircuits/
- /tmp/.vochain-zkCircuits/:/app/run/test/zkCircuits/
- gocoverage-miner1:/app/run/gocoverage
environment:
- GOCOVERDIR=/app/run/gocoverage
Expand All @@ -52,8 +49,7 @@ services:
- blockchain
volumes:
- data-miner2:/app/run/
- ${COMPOSE_HOST_PATH:-.}/genesis.json:/app/misc/genesis.json
- /tmp/.vochain-zkCircuits/:/app/run/dev/zkCircuits/
- /tmp/.vochain-zkCircuits/:/app/run/test/zkCircuits/
- gocoverage-miner2:/app/run/gocoverage
environment:
- GOCOVERDIR=/app/run/gocoverage
Expand All @@ -66,8 +62,7 @@ services:
- blockchain
volumes:
- data-miner3:/app/run/
- ${COMPOSE_HOST_PATH:-.}/genesis.json:/app/misc/genesis.json
- /tmp/.vochain-zkCircuits/:/app/run/dev/zkCircuits/
- /tmp/.vochain-zkCircuits/:/app/run/test/zkCircuits/
- gocoverage-miner3:/app/run/gocoverage
environment:
- GOCOVERDIR=/app/run/gocoverage
Expand All @@ -82,8 +77,7 @@ services:
- blockchain
volumes:
- data-gateway0:/app/run/
- ${COMPOSE_HOST_PATH:-.}/genesis.json:/app/misc/genesis.json
- /tmp/.vochain-zkCircuits/:/app/run/dev/zkCircuits/
- /tmp/.vochain-zkCircuits/:/app/run/test/zkCircuits/
- gocoverage-gateway0:/app/run/gocoverage
environment:
- GOCOVERDIR=/app/run/gocoverage
Expand Down Expand Up @@ -163,8 +157,7 @@ services:
- blockchain
volumes:
- data-gatewaySync:/app/run/
- ${COMPOSE_HOST_PATH:-.}/genesis.json:/app/misc/genesis.json
- /tmp/.vochain-zkCircuits/:/app/run/dev/zkCircuits/
- /tmp/.vochain-zkCircuits/:/app/run/test/zkCircuits/
- gocoverage-gatewaySync:/app/run/gocoverage
environment:
- GOCOVERDIR=/app/run/gocoverage
Expand Down
3 changes: 1 addition & 2 deletions dockerfiles/testsuite/env.gateway0
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
VOCDONI_DATADIR=/app/run
VOCDONI_MODE=gateway
VOCDONI_CHAIN=test
VOCDONI_LOGLEVEL=debug
VOCDONI_VOCHAIN_LOGLEVEL=error
VOCDONI_DEV=True
Expand All @@ -8,11 +9,9 @@ VOCDONI_ENABLERPC=True
VOCDONI_ENABLEFAUCETWITHAMOUNT=100000
VOCDONI_VOCHAIN_PUBLICADDR=gateway0:26656
VOCDONI_VOCHAIN_SEEDS=3c3765494e758ae7baccb1f5b0661755302ddc47@seed:26656
VOCDONI_VOCHAIN_GENESIS=/app/misc/genesis.json
VOCDONI_VOCHAIN_NOWAITSYNC=True
VOCDONI_METRICS_ENABLED=True
VOCDONI_METRICS_REFRESHINTERVAL=5
VOCDONI_CHAIN=dev
VOCDONI_SIGNINGKEY=e0f1412b86d6ca9f2b318f1d243ef50be23d315a2e6c1c3035bc72d44c8b2f90 # 0x88a499cEf9D1330111b41360173967c9C1bf703f
VOCDONI_ARCHIVEURL=none
VOCDONI_VOCHAIN_STATESYNCENABLED=false
Expand Down
3 changes: 1 addition & 2 deletions dockerfiles/testsuite/env.gatewaySync
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
VOCDONI_DATADIR=/app/run
VOCDONI_MODE=gateway
VOCDONI_CHAIN=test
VOCDONI_LOGLEVEL=debug
VOCDONI_VOCHAIN_LOGLEVEL=info
VOCDONI_DEV=True
Expand All @@ -8,11 +9,9 @@ VOCDONI_ENABLERPC=True
VOCDONI_ENABLEFAUCETWITHAMOUNT=100000
VOCDONI_VOCHAIN_PUBLICADDR=gatewaySync:26656
VOCDONI_VOCHAIN_SEEDS=3c3765494e758ae7baccb1f5b0661755302ddc47@seed:26656
VOCDONI_VOCHAIN_GENESIS=/app/misc/genesis.json
VOCDONI_VOCHAIN_NOWAITSYNC=True
VOCDONI_METRICS_ENABLED=True
VOCDONI_METRICS_REFRESHINTERVAL=5
VOCDONI_CHAIN=dev
VOCDONI_SIGNINGKEY=f50be23d315a2e6c1c30e0f1412b86d6ca9f2b318f1d243e35bc72d44c8b2f90
VOCDONI_ARCHIVEURL=none
VOCDONI_VOCHAIN_SNAPSHOTINTERVAL=3
2 changes: 1 addition & 1 deletion dockerfiles/testsuite/env.miner0
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
VOCDONI_DATADIR=/app/run
VOCDONI_MODE=miner
VOCDONI_CHAIN=test
VOCDONI_LOGLEVEL=debug
VOCDONI_VOCHAIN_LOGLEVEL=error
VOCDONI_DEV=True
VOCDONI_VOCHAIN_PUBLICADDR=miner0:26656
VOCDONI_VOCHAIN_SEEDS=3c3765494e758ae7baccb1f5b0661755302ddc47@seed:26656
VOCDONI_VOCHAIN_GENESIS=/app/misc/genesis.json
VOCDONI_VOCHAIN_MINERKEY=cda909c34901c137e12bb7d0afbcb9d1c8abc66f03862a42344b1f509d1ae4ce
VOCDONI_METRICS_ENABLED=True
VOCDONI_METRICS_REFRESHINTERVAL=5
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/testsuite/env.miner1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
VOCDONI_DATADIR=/app/run
VOCDONI_MODE=miner
VOCDONI_CHAIN=test
VOCDONI_LOGLEVEL=info
VOCDONI_DEV=True
VOCDONI_VOCHAIN_PUBLICADDR=miner1:26656
VOCDONI_VOCHAIN_SEEDS=3c3765494e758ae7baccb1f5b0661755302ddc47@seed:26656
VOCDONI_VOCHAIN_GENESIS=/app/misc/genesis.json
VOCDONI_VOCHAIN_MINERKEY=d52a488fa1511a07778cc94ed9d8130fb255537783ea7c669f38292b4f53ac4f
VOCDONI_METRICS_ENABLED=True
VOCDONI_METRICS_REFRESHINTERVAL=5
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/testsuite/env.miner2
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
VOCDONI_DATADIR=/app/run
VOCDONI_MODE=miner
VOCDONI_CHAIN=test
VOCDONI_LOGLEVEL=info
VOCDONI_DEV=True
VOCDONI_VOCHAIN_PUBLICADDR=miner2:26656
VOCDONI_VOCHAIN_SEEDS=3c3765494e758ae7baccb1f5b0661755302ddc47@seed:26656
VOCDONI_VOCHAIN_GENESIS=/app/misc/genesis.json
VOCDONI_VOCHAIN_MINERKEY=e06976e5eaf3f147e12763eb140e3d5c2ed16a6fa747d787d8b92ca961fa7dc4
VOCDONI_METRICS_ENABLED=True
VOCDONI_METRICS_REFRESHINTERVAL=5
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/testsuite/env.miner3
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
VOCDONI_DATADIR=/app/run
VOCDONI_MODE=miner
VOCDONI_CHAIN=test
VOCDONI_LOGLEVEL=info
VOCDONI_DEV=True
VOCDONI_VOCHAIN_PUBLICADDR=miner3:26656
VOCDONI_VOCHAIN_SEEDS=3c3765494e758ae7baccb1f5b0661755302ddc47@seed:26656
VOCDONI_VOCHAIN_GENESIS=/app/misc/genesis.json
VOCDONI_VOCHAIN_MINERKEY=b8d258559adee836a43e964badf541ec106cc68a01f989d3c3c9a030ae3945a6
VOCDONI_METRICS_ENABLED=True
VOCDONI_METRICS_REFRESHINTERVAL=5
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/testsuite/env.seed
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
VOCDONI_DATADIR=/app/run
VOCDONI_MODE=seed
VOCDONI_CHAIN=test
VOCDONI_LOGLEVEL=debug
VOCDONI_DEV=True
VOCDONI_VOCHAIN_PUBLICADDR=seed:26656
VOCDONI_VOCHAIN_LOGLEVEL=info
VOCDONI_VOCHAIN_GENESIS=/app/misc/genesis.json
VOCDONI_VOCHAIN_NODEKEY=0x2060e20d1f0894d6b23901bce3f20f26107baf0335451ad75ef27b14e4fc56ae050a65ae3883c379b70d811d6e12db2fe1e3a5cf0cae4d03dbbbfebc68601bdd
VOCDONI_METRICS_ENABLED=True
VOCDONI_METRICS_REFRESHINTERVAL=5
Expand Down
80 changes: 0 additions & 80 deletions dockerfiles/testsuite/genesis.json

This file was deleted.

Loading

0 comments on commit cc8f620

Please sign in to comment.