Skip to content

Commit

Permalink
Merge #2791
Browse files Browse the repository at this point in the history
2791: Negotiate NodeToClientVersion for non-breaking mainnet support r=Anviking a=Anviking

# Issue Number

ADP-1025

# Background

#2763 made the wallet demand NodeToClientV_9. With cardano-node 1.28.0, V_9 is only enabled if  `TestEnableDevelopmentNetworkProtocols` is set in the node config.

# Overview

- [x] Make the wallet support both `V_8` and `V_9`.
- [x] Ensure integration tests on Mary are run without `TestEnableDevelopmentNetworkProtocols: True`


# Comments

<!-- Additional comments or screenshots to attach if any -->

<!--
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Jira will detect and link to this PR once created, but you can also link this PR in the description of the corresponding ticket
 ✓ Acknowledge any changes required to the Wiki
 ✓ Finally, in the PR description delete any empty sections and all text commented in <!--, so that this text does not appear in merge commit messages.
-->


Co-authored-by: Johannes Lund <[email protected]>
  • Loading branch information
iohk-bors[bot] and Anviking authored Aug 2, 2021
2 parents f4f83c1 + 10c0573 commit 007c5be
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 81 deletions.
12 changes: 8 additions & 4 deletions lib/shelley/bench/Restore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ import Cardano.Wallet.Primitive.Types.UTxO
import Cardano.Wallet.Shelley
( SomeNetworkDiscriminant (..) )
import Cardano.Wallet.Shelley.Compatibility
( HasNetworkId (..), NodeVersionData, emptyGenesis, fromCardanoBlock )
( HasNetworkId (..)
, NodeToClientVersionData
, emptyGenesis
, fromCardanoBlock
)
import Cardano.Wallet.Shelley.Launch
( CardanoNodeConn, NetworkConfiguration (..), parseGenesisData )
import Cardano.Wallet.Shelley.Network
Expand Down Expand Up @@ -585,7 +589,7 @@ bench_restoration
-> Trace IO Text -- ^ For wallet tracing
-> CardanoNodeConn -- ^ Socket path
-> NetworkParameters
-> NodeVersionData
-> NodeToClientVersionData
-> Text -- ^ Benchmark name (used for naming resulting files)
-> [(WalletId, WalletName, s)]
-> Bool -- ^ If @True@, will trace detailed progress to a .timelog file.
Expand Down Expand Up @@ -707,7 +711,7 @@ prepareNode
-> Proxy n
-> CardanoNodeConn
-> NetworkParameters
-> NodeVersionData
-> NodeToClientVersionData
-> IO ()
prepareNode tr proxy socketPath np vData = do
traceWith tr $ MsgSyncStart proxy
Expand All @@ -728,7 +732,7 @@ waitForWalletsSyncTo
-> WalletLayer IO s k
-> [WalletId]
-> GenesisParameters
-> NodeVersionData
-> NodeToClientVersionData
-> IO ()
waitForWalletsSyncTo targetSync tr proxy walletLayer wids gp vData = do
posixNow <- utcTimeToPOSIXSeconds <$> getCurrentTime
Expand Down
8 changes: 1 addition & 7 deletions lib/shelley/src/Cardano/Wallet/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ import Network.Wai.Handler.Warp
( setBeforeMainLoop )
import Network.Wai.Middleware.Logging
( ApiLog (..) )
import Ouroboros.Network.CodecCBORTerm
( CodecCBORTerm )
import Ouroboros.Network.NodeToClient
( NodeToClientVersionData (..) )
import System.Exit
Expand Down Expand Up @@ -245,11 +243,7 @@ serveWallet
-- ^ Socket for communicating with the node
-> Block
-- ^ The genesis block, or some starting point.
-> ( NetworkParameters
, ( NodeToClientVersionData
, CodecCBORTerm Text NodeToClientVersionData
)
)
-> ( NetworkParameters, NodeToClientVersionData)
-- ^ Network parameters needed to connect to the underlying network.
--
-- See also: 'Cardano.Wallet.Shelley.Compatibility#KnownNetwork'.
Expand Down
21 changes: 4 additions & 17 deletions lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ module Cardano.Wallet.Shelley.Compatibility
, CardanoBlock
, NetworkId

, NodeVersionData
, NodeToClientVersionData
, StandardCrypto
, StandardShelley

-- * Protocol Parameters
, nodeToClientVersion
, testnetVersionData
, nodeToClientVersions

-- * Genesis
, emptyGenesis
Expand Down Expand Up @@ -348,20 +347,8 @@ emptyGenesis gp = W.Block
-- Network Parameters

-- | The protocol client version. Distinct from the codecs version.
nodeToClientVersion :: NodeToClientVersion
nodeToClientVersion = NodeToClientV_9

-- | Settings for configuring a TestNet network client
testnetVersionData
:: W.ProtocolMagic
-> NodeVersionData
testnetVersionData pm =
( NodeToClientVersionData
{ networkMagic =
NetworkMagic $ fromIntegral $ W.getProtocolMagic pm
}
, nodeToClientCodecCBORTerm nodeToClientVersion
)
nodeToClientVersions :: [NodeToClientVersion]
nodeToClientVersions = [NodeToClientV_8, NodeToClientV_9]

--------------------------------------------------------------------------------
--
Expand Down
17 changes: 6 additions & 11 deletions lib/shelley/src/Cardano/Wallet/Shelley/Launch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ import Cardano.Wallet.Primitive.Types
( Block (..), NetworkParameters (..), ProtocolMagic (..) )
import Cardano.Wallet.Shelley
( SomeNetworkDiscriminant (..) )
import Cardano.Wallet.Shelley.Compatibility
( NodeVersionData, nodeToClientVersion )
import Control.Monad.IO.Unlift
( MonadUnliftIO, liftIO )
import Control.Monad.Trans.Except
Expand All @@ -80,7 +78,7 @@ import Options.Applicative
import Ouroboros.Network.Magic
( NetworkMagic (..) )
import Ouroboros.Network.NodeToClient
( NodeToClientVersionData (..), nodeToClientCodecCBORTerm )
( NodeToClientVersionData (..) )
import System.Environment
( lookupEnv )
import System.Exit
Expand All @@ -92,7 +90,6 @@ import UnliftIO.Temporary

import qualified Cardano.Wallet.Byron.Compatibility as Byron
import qualified Cardano.Wallet.Primitive.Types as W
import qualified Cardano.Wallet.Shelley.Compatibility as Shelley
import qualified Data.ByteString.Lazy.Char8 as BL8
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
Expand Down Expand Up @@ -156,27 +153,25 @@ networkConfigurationOption = mainnet <|> testnet <|> staging
someCustomDiscriminant
:: (forall (pm :: Nat). KnownNat pm => Proxy pm -> SomeNetworkDiscriminant)
-> ProtocolMagic
-> (SomeNetworkDiscriminant, NodeVersionData)
-> (SomeNetworkDiscriminant, NodeToClientVersionData)
someCustomDiscriminant mkSomeNetwork pm@(ProtocolMagic n) =
case someNatVal (fromIntegral n) of
Just (SomeNat proxy) ->
( mkSomeNetwork proxy
, Shelley.testnetVersionData pm
, NodeToClientVersionData $
NetworkMagic $ fromIntegral $ W.getProtocolMagic pm
)
_ -> error "networkDiscriminantFlag: failed to convert \
\ProtocolMagic to SomeNat."

parseGenesisData
:: NetworkConfiguration
-> ExceptT String IO
(SomeNetworkDiscriminant, NetworkParameters, NodeVersionData, Block)
(SomeNetworkDiscriminant, NetworkParameters, NodeToClientVersionData, Block)
parseGenesisData = \case
MainnetConfig -> do
let nm = NetworkMagic $ fromIntegral $ W.getProtocolMagic W.mainnetMagic
let mainnetVersionData =
( NodeToClientVersionData nm
, nodeToClientCodecCBORTerm nodeToClientVersion
)
let mainnetVersionData = NodeToClientVersionData nm
pure
( SomeNetworkDiscriminant $ Proxy @'Mainnet
, Byron.mainnetNetworkParameters
Expand Down
21 changes: 12 additions & 9 deletions lib/shelley/src/Cardano/Wallet/Shelley/Launch/Cluster.hs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ import Cardano.Wallet.Primitive.Types.TokenQuantity
import Cardano.Wallet.Primitive.Types.Tx
( TxOut )
import Cardano.Wallet.Shelley.Compatibility
( NodeVersionData, StandardShelley, nodeToClientVersion )
( StandardShelley )
import Cardano.Wallet.Shelley.Launch
( TempDirLog (..), envFromText, isEnvSet, lookupEnvNonEmpty )
import Cardano.Wallet.Unsafe
Expand Down Expand Up @@ -176,7 +176,7 @@ import Data.Time.Clock.POSIX
import Ouroboros.Network.Magic
( NetworkMagic (..) )
import Ouroboros.Network.NodeToClient
( NodeToClientVersionData (..), nodeToClientCodecCBORTerm )
( NodeToClientVersionData (..) )
import System.Directory
( copyFile, createDirectory, createDirectoryIfMissing, makeAbsolute )
import System.Environment
Expand Down Expand Up @@ -503,7 +503,7 @@ data RunningNode = RunningNode
-- ^ Socket path
Block
-- ^ Genesis block
(NetworkParameters, NodeVersionData)
(NetworkParameters, NodeToClientVersionData)

-- | Execute an action after starting a cluster of stake pools. The cluster also
-- contains a single BFT node that is pre-configured with keys available in the
Expand Down Expand Up @@ -645,7 +645,7 @@ withBFTNode
-- this.
-> NodeParams
-- ^ Parameters used to generate config files.
-> (CardanoNodeConn -> Block -> (NetworkParameters, NodeVersionData) -> IO a)
-> (CardanoNodeConn -> Block -> (NetworkParameters, NodeToClientVersionData) -> IO a)
-- ^ Callback function with genesis parameters
-> IO a
withBFTNode tr baseDir params action =
Expand Down Expand Up @@ -908,7 +908,7 @@ genConfig
-- ^ Last era to hard fork into.
-> LogFileConfig
-- ^ Minimum severity level for logging and optional /extra/ logging output
-> IO (FilePath, Block, NetworkParameters, NodeVersionData)
-> IO (FilePath, Block, NetworkParameters, NodeToClientVersionData)
genConfig dir systemStart clusterEra logCfg = do
let LogFileConfig severity mExtraLogFile extraSev = logCfg
let startTime = round @_ @Int . utcTimeToPOSIXSeconds $ systemStart
Expand Down Expand Up @@ -936,6 +936,7 @@ genConfig dir systemStart clusterEra logCfg = do
>>= withAddedKey "ShelleyGenesisFile" shelleyGenesisFile
>>= withAddedKey "ByronGenesisFile" byronGenesisFile
>>= withAddedKey "AlonzoGenesisFile" alonzoGenesisFile
>>= enableAlonzoIfNeeded
>>= withHardForks clusterEra
>>= withAddedKey "minSeverity" Debug
>>= withScribes scribes
Expand Down Expand Up @@ -977,10 +978,7 @@ genConfig dir systemStart clusterEra logCfg = do
@_ @(ShelleyGenesis StandardShelley) shelleyGenesisFile
let networkMagic = sgNetworkMagic shelleyGenesis
let shelleyParams = fst $ Shelley.fromGenesisData shelleyGenesis []
let versionData =
( NodeToClientVersionData $ NetworkMagic networkMagic
, nodeToClientCodecCBORTerm nodeToClientVersion
)
let versionData = NodeToClientVersionData $ NetworkMagic networkMagic

pure
( dir </> "node.config"
Expand Down Expand Up @@ -1011,6 +1009,11 @@ genConfig dir systemStart clusterEra logCfg = do
[ ("Test" <> T.pack (show hardFork) <> "AtEpoch", Yaml.Number 0)
| hardFork <- [ShelleyHardFork .. era] ]


enableAlonzoIfNeeded =
if clusterEra == AlonzoHardFork
then withAddedKey "TestEnableDevelopmentNetworkProtocols" True
else return
-- | Generate a topology file from a list of peers.
genTopology :: FilePath -> [Int] -> IO FilePath
genTopology dir peers = do
Expand Down
Loading

0 comments on commit 007c5be

Please sign in to comment.