coreblocks
coreblocks copied to clipboard
Layout checking of contructor passed methods
There are two types of Method interfaces in our code:
- Declaring Methods with
def_method
to be called by some external Transaction - Passing external Methods via Module constructor to use them internally
Using the first method has the benefit that expected layout of the data is clearly defined by Method i=
and o=
layouts.
This form of convenience is lacking in the second approach. We just specify that we expect some Method on the input. If the wrong method is applied, then it will almost certainly cause some problems with calling it / using its result in code, but having the layout 'type' clearly specified would have two benefits:
- more understandable code - some information on the Method can be directly gained by reading it's layout type, in the code when it is used. Currently usage of the specific module in external code need to be found to track it back to layouts of some external Method defined elsewhere.
- automatic generation of mocks in
SimpleTestCircuit
. Currently mocks are automatically generated for all of the first solution Methods, but need to be manually specified (with some boilerplate) for external methods. If expected layouts of external methods would be sepecified in__init__
, then this information could be used to generated mocks automatically inSimpleTestCircuit
.
It was discussed on the meeting in winter semester. My proposition was to create some additional class, that would create constraint on external methods. Use of it would be optional (it is only 'convince' wrapper ) . It would raise exception on Method layout mismatch and provide information for mock generation. example:
def __init__(self, free_rf: Method):
self.free_rf = ExternalMethod(free_rf, i=[("rp", ...
This proposition needs to be further explored. Alternative ways to implement the same concept could be also discussed.