Tezlink/Node: distinguish Tezlink from Etherlink using GADTs
Stacked on !18001 (merged).
What
This MR turns a few variant types which have an Etherlink and a Tezlink case into GADTs.
Why
This will enable enforcing statically that the Tezlink and Etherlink parts of the code base are not mixed. In particular that the chain family from the configuration, the type of the tx-container, and the RPC server are consistent.
How
First commit
We introduce two types which are only used to tag other types:
type evm_chain_family = Evm_chain_family
type michelson_chain_family = Michelson_chain_family
The only thing that matters is that these two types are considered different by the OCaml type checker.
Then we turn the chain_family type into a GADT:
-type chain_family = EVM | Michelson
+type _ chain_family =
+ | EVM : evm_chain_family chain_family
+ | Michelson : michelson_chain_family chain_family
We also introduce an existential boxing for this type:
type ex_chain_family = Ex_chain_family : _ chain_family -> ex_chain_family
We propagate the change by using _ chain_family as function argument and ex_chain_family in record fields and as function return type.
Second commit
We introduce a GADT wrapping the (module Tx_container) type:
type 'family tx_container =
| Evm_tx_container :
(module Tx_container)
-> L2_types.evm_chain_family tx_container
| Michelson_tx_container :
(module Tx_container)
-> L2_types.michelson_chain_family tx_container
let tx_container_module (type f) (tx_container : f tx_container) =
match tx_container with
| Evm_tx_container m -> (m :> (module Tx_container))
| Michelson_tx_container m -> m
and use it everywhere (module Tx_container) was used.
Third commit
We turn the rpc_server_family variant into a GADT and ensure that in the single-chain case, the type matches the given chain family:
-type rpc_server_family =
- | Multichain_sequencer_rpc_server
- | Single_chain_node_rpc_server of L2_types.ex_chain_family
+type 'f rpc_server_family =
+ | Multichain_sequencer_rpc_server : _ rpc_server_family
+ | Single_chain_node_rpc_server :
+ 'f L2_types.chain_family
+ -> 'f rpc_server_family
Manually testing the MR
Checklist
-
Document the interface of any function added or modified (see the coding guidelines) -
Document any change to the user interface, including configuration parameters (see node configuration) -
Provide automatic testing (see the testing guide). -
For new features and bug fixes, add an item in the appropriate changelog ( docs/protocols/alpha.rstfor the protocol and the environment,CHANGES.rstat the root of the repository for everything else). -
Select suitable reviewers using the Reviewersfield below. -
Select as Assigneethe next person who should take action on that MR