Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
Adjust the epoch0 EBB construction to follow the consensus era
Browse files Browse the repository at this point in the history
When we start a chain from a genesis in the OBFT era, rather than the
Original era, the epoch zero EBB must still exist, even though all other
epoch EBBs do not exist.

That EBB ought to have an empty slot leader schedule, otherwise we
cannot have new non-legcay nodes create the same EBB, since new nodes do
not implement the logic for Original era leader schedules. This does not
affects any existing chain, since existing chains all start in the
Original era and go through a hard fork to enter the OBFT era. This
change only affects new test/dev chains that start in the OBFT era. This
is needed to test mixed clusters of old/new nodes in a convenient way,
that all start from genesis in the OBFT era.
  • Loading branch information
dcoutts committed Mar 18, 2020
1 parent 15d8679 commit 8d67080
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
8 changes: 6 additions & 2 deletions chain/src/Pos/Chain/Block/Block.hs
Expand Up @@ -252,8 +252,12 @@ mkGenesisBlock pm prevHeader epoch leaders = GenericBlock header body extra
extra = GenesisExtraBodyData $ mkAttributes ()

-- | Creates the very first genesis block.
genesisBlock0 :: ProtocolMagic -> GenesisHash -> SlotLeaders -> GenesisBlock
genesisBlock0 pm genesisHash leaders = mkGenesisBlock pm (Left genesisHash) 0 leaders
genesisBlock0 :: ConsensusEra -> ProtocolMagic -> GenesisHash -> SlotLeaders -> GenesisBlock
genesisBlock0 Original pm genesisHash leaders =
mkGenesisBlock pm (Left genesisHash) 0 leaders

genesisBlock0 (OBFT _) pm genesisHash _leaders =
mkGenesisBlock pm (Left genesisHash) 0 []

-- | To verify a genesis block we only have to check the body proof.
verifyGenesisBlock
Expand Down
4 changes: 3 additions & 1 deletion client/src/Pos/Client/Txp/History.hs
Expand Up @@ -39,13 +39,14 @@ import Serokell.Util.Text (listJson)
import Pos.Chain.Block (Block, MainBlock, genesisBlock0, headerHash,
mainBlockSlot, mainBlockTxPayload)
import Pos.Chain.Genesis as Genesis (Config (..))
import Pos.Chain.Genesis (GenesisData)
import Pos.Chain.Genesis (GenesisData, configBlockVersionData)
import Pos.Chain.Lrc (genesisLeaders)
import Pos.Chain.Txp (ToilVerFailure, Tx (..), TxAux (..), TxId,
TxOut, TxOutAux (..), TxWitness, TxpConfiguration,
TxpError (..), UtxoLookup, UtxoM, UtxoModifier,
applyTxToUtxo, evalUtxoM, flattenTxPayload, genesisUtxo,
runUtxoM, topsortTxs, txOutAddress, utxoGet, utxoToLookup)
import Pos.Chain.Update (consensusEraBVD)
import Pos.Core (Address, ChainDifficulty, Timestamp (..),
difficultyL)
import Pos.Core.JsonLog (CanJsonLog (..))
Expand Down Expand Up @@ -222,6 +223,7 @@ getBlockHistoryDefault
getBlockHistoryDefault genesisConfig addrs = do
let genesisHash = configGenesisHash genesisConfig
let bot = headerHash $ genesisBlock0
(consensusEraBVD (configBlockVersionData genesisConfig))
(configProtocolMagic genesisConfig)
genesisHash
(genesisLeaders genesisConfig)
Expand Down
1 change: 0 additions & 1 deletion core/test/Test/Pos/Core/Gen.hs
Expand Up @@ -65,7 +65,6 @@ import Universum

import Data.Fixed (Fixed (..))
import qualified Data.Map as M
import Data.Maybe
import Data.Time.Units (Microsecond, Millisecond, fromMicroseconds)
import Hedgehog
import qualified Hedgehog.Gen as Gen
Expand Down
7 changes: 4 additions & 3 deletions lib/src/Pos/DB/DB.hs
Expand Up @@ -8,9 +8,9 @@ module Pos.DB.DB
import Universum

import Pos.Chain.Block (genesisBlock0, headerHash)
import Pos.Chain.Genesis as Genesis (Config (..))
import Pos.Chain.Genesis as Genesis (Config (..), configBlockVersionData)
import Pos.Chain.Lrc (genesisLeaders)
import Pos.Chain.Update (BlockVersionData)
import Pos.Chain.Update (BlockVersionData, consensusEraBVD)
import Pos.DB.Block (prepareBlockDB)
import Pos.DB.Class (MonadDB, MonadDBRead (..))
import Pos.DB.Lrc (prepareLrcDB)
Expand All @@ -30,7 +30,8 @@ initNodeDBs genesisConfig = do
prepareGStateDB genesisConfig initialTip
prepareLrcDB genesisConfig
where
gb = genesisBlock0 (configProtocolMagic genesisConfig)
gb = genesisBlock0 (consensusEraBVD (configBlockVersionData genesisConfig))
(configProtocolMagic genesisConfig)
(configGenesisHash genesisConfig)
(genesisLeaders genesisConfig)

Expand Down
6 changes: 4 additions & 2 deletions utxo/src/UTxO/Context.hs
Expand Up @@ -54,9 +54,10 @@ import Pos.Chain.Delegation (ProxySKHeavy)
import Pos.Chain.Genesis as Genesis (Config (..),
GeneratedSecrets (..), GenesisData (..),
GenesisDelegation (..), PoorSecret (..), RichSecrets (..),
configEpochSlots)
configEpochSlots, configBlockVersionData)
import Pos.Chain.Lrc
import Pos.Chain.Txp
import Pos.Chain.Update (consensusEraBVD)
import Pos.Core as Core
import Pos.Core.NetworkMagic (NetworkMagic (..))
import Pos.Crypto
Expand Down Expand Up @@ -113,7 +114,8 @@ initCardanoContext genesisConfig = CardanoContext
ccData = configGenesisData genesisConfig
ccLeaders = genesisLeaders genesisConfig
ccMagic = configProtocolMagic genesisConfig
ccBlock0 = genesisBlock0 ccMagic (configGenesisHash genesisConfig) ccLeaders
consensusEra = consensusEraBVD (configBlockVersionData genesisConfig)
ccBlock0 = genesisBlock0 consensusEra ccMagic (configGenesisHash genesisConfig) ccLeaders
ccUtxo = genesisUtxo ccData

{-------------------------------------------------------------------------------
Expand Down

0 comments on commit 8d67080

Please sign in to comment.