Should Automatic Marshaling Remove or Retain Size, Marshal, and Unmarshal in the Action Interface? #1473
Closed
Description
While working on PR #1198, we faced a choice: With automatic marshaling, we could remove the Size
, Marshal
, and Unmarshal[ActionName]
functions from the Action
interface. However, these functions might still be necessary for users who want to implement custom marshaling/unmarshaling to potentially achieve higher TPS (even though it's not proven that marshaling is a bottleneck).
The question is, should we be explicit and require users to manually include this code in each action file:
func (t *Transfer) Size() int {
size, _ := codec.LinearCodec.Size(t)
return size
}
func (t *Transfer) Marshal(p *codec.Packer) {
codec.LinearCodec.MarshalInto(t, p.Packer)
}
func UnmarshalTransfer(p *codec.Packer) (chain.Action, error) {
var transfer Transfer
err := codec.LinearCodec.UnmarshalFrom(p.Packer, &transfer)
return &transfer, err
}
Or should we be implicit and hide this behind optional interfaces, so these functions are only used if the user defines them? I’m looking for feedback on the best approach.
🚀 for explicit but redundant code, 🎉 for clean and implicit implementation.