-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Location
[wire], [pkg/io], [wire/net]
Motivation
Currently, wire messages in go-perun are encoded/decoded using a home-baked. When developing alternate implementations of the perun channel client, in a different programming language, the encoders and decoders have to be re-implemented in that language.
If we are able to exchange the custom format for standard ones like "protocol buffers", the messages can be defined once and the encoders/decoders can be generated for different programming languages. This will eliminate the overhead of implementing and maintaining the encoders/decoders in multiple languages.
However, this it is currently not possible to exchange custom format for a different one, as the necessary abstractions are missing. The scope of this task is to introduce the necessary abstractions.
Details
Abstractions necessary for making the wire serialization format exchangeable has been discussed and accepted in proposal#5.
This can be implemented in 6 steps, each involving one PR. This an umbrella issue to track the complete task.
-
Step 1
- Refactor Address,Asset, Data, Action types from (En|De)coder to binary.(Un)marshaler. Discussed in this comment and tracked in Refactor encoder/decoder interfaces for abstract types in the core packages of go-perun #257.
- Move out
pkg/iopackage towire/perun. Move pkg/io to wire/perunio #285 - Package
pkg/io/test, which defines generic tests for encoders/decoders is moved towire/testpackage. Merge perunio/test into wire/test #287
-
Step 2 Add env serializer interface #297
- Define
EnvelopeSerializerinterface.
type EnvelopeSerializer interface { Encode(io.Writer, Envelope) error Decode(io.Reader) (Envelope, error) }- Add a unexported package level variable that holds an instance of
EnvelopeSerializerand an exported function
SetEnvelopeSerializer, for setting it. The function should panic, if invoked more than once. - Implement the
EnvelopeSerializerfor perunio serialization format. The implementation should be placed in new package :wire/perunio/serializer. Because, packagewire/peruniocannot import packagewire. - Add an
initfunction in packagewire/perunio/serializer, which sets thewire.enveloperSerializerto perunio envelope serializer.
Remark: It would be nicer to have the
EnvelopeSerializerimplementation directly in packagewire/perunio. However, this might require some refactoring (as described in step 7) and hence could be done later. - Define
-
Step 3 Add env serializer interface #297
- Replace the
wire.(Encode/Decode)methods with functionsEncodeEnvelopeandDecodeEvelope. - Update the
RecvandSendonioconnin thewire/netpackage to use the newly defined functions instead ofwire.(Encode/Decode)methods.
- Replace the
-
Step 4 Use UnmarshalBinary and MarshalBinary for converting to/from Binary form #298
-
Step 5 (Can be done later)
- Introduce an abstract type for
wallet.Sig. Described and tracked in Add an abstract type for wallet.Sig #292.
- Introduce an abstract type for
-
Step 6 (Can be done later)
- Move the decoders map from the
wirepackage to thewire/perunpackage. - In the
wirepackage, decode envelopes instead of messages.
- Move the decoders map from the
-
Step 7 (Can be done later)
From theclientpackage,- Move the message definitions to the
wirepackage and - Move the encoder/decoder implementations to the
wire/perunpackage. - After these changes, merge
wire/perunio/serializerpackage intowire/perunio. Because, now it would be possible forwire/peruniopackage to importwirepackage.
- Move the message definitions to the
Notes:
-
Regarding persistence, we can continue to use the perunio protocol as that is used for wire serialization. This should continue to work without any additional changes unless we implement step 7. When we implement step 7, we could rethink how we should handle it.
-
Make
ProposalIDindependent of perunio Mechanism for proposal ID generation #301 -
Export all relevant all message types 💥 Off-chain messages: Naming conventions and type export for wire serialization #302