[FR] - Make it easier to connect to a local node using the API
Internal/External Internal (an IOHK staff member)
Area API
Describe the feature you'd like
In order to connect to the local node (eg for submitting a transaction) one needs to fill in the following struct (Cardano.Api.IPC):
data LocalNodeConnectInfo mode =
LocalNodeConnectInfo {
localConsensusModeParams :: ConsensusModeParams mode,
localNodeNetworkId :: NetworkId,
localNodeSocketPath :: FilePath
}
Why can't we just provide the node socket path and get the rest filled in by connecting to the node?
The node that the client is connecting to via the node socket already knows these the NetworkId and the ConsensusModeParams so why should the client have to specify them? Even f the client does need them (eg maybe the NetworkId), it should get if from the node which is the source of truth.
Describe alternatives you've considered One can fill in that struct but its a huge pain in the neck.
I finally got something that compiles and will be correct for mainnet:
_localNodeConnectInfo :: LocalNodeConnectInfo Api.CardanoMode
_localNodeConnectInfo =
LocalNodeConnectInfo
{ localConsensusModeParams = Api.CardanoModeParams (Api.EpochSlots 21600)
, localNodeNetworkId = networkId
, localNodeSocketPath = nodeSocket
}
but the 21600 magic number (which is correct for mainnet) just should not be there.
I know this is a slight inconvenience for the programmer but it saves headaches when misconfiguration a complex system. If you're service expects to see mainnet node on the other end, the issue should be solved in cardano-api by providing smart constructors; if you're service doesn't care about the node it connects to (e.g. cardano-cli query tip) then there's a room for improvement.
The node socket is the source of truth. What can go wrong?
If a client connects to a node socket it should query the NetworkId and make sure it is what it expects.
What can go wrong is that there can be a mismatch of expectations. The client can think that it is connecting to the testnet, while the node is on the mainnet, or the other way around. So specifying the network you think you're connecting to is a useful sanity check.
I agree that it would be nice for that to be an optional sanity check.
Similarly for the mode. Things will go squiffy quickly if you connect to a node that's in a different mode to the one you expected, and not necessarily with very good error messages (since you're talking almost but not quite the same protocols).
That said, I agree we would rather not have to specify the epoch slots. That should be known for the cardano mode.
To make either of these optional sanity checks will require changes to the local IPC handshake.
On the topic of making it easier to connect to the node: we do still have a branch with support for getting the initial ledger config & state from the node, so that it's not needed to read the genesis file or other config files. The branch was approved but got held back by various code freezes and other priorities.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 120 days.