-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: framing_sv2
crate
#903
Comments
Is this enforceable somehow? |
I would allow unreachable and expect |
A not on the payload panic. The API can and must be refactored in a way that avoid it just return a Result. When that is not possible (for reason x) IMO is better to panic and fail fast, rather the let the user use something in a wrong way. |
as discussed here #858 (comment) the usage of generic
we should replace as a result, both |
In |
This was addressed here 05f9b4c |
This task is an outcome of #845
While documenting the
framing_sv2
crate, a lot of things stood out as needing to refactor.The documentation effort was an immediate action, while a refactoring (which implies breaking API changes) is not so urgent priority, so for now we should leave this in the backlog for an appropriate moment in the future.
Below are the different items that I believe deserve to be rewritten on
framing_sv2
crate.rename
framing2.rs
the character
2
in filenameframing2.rs
seems to make some kind of allusion to SV2, but this isn't following any pattern or convention in naming files.so IMO this file should be renamed to
framing.rs
.Frame trait removal
The
Frame
trait is unnecessary. It is never really used anywhere in the code as a Trait bound. The only usage of this trait is in theimpl Frame
blocks forSv2Frame
andHandShakeFrame
. I even did a quick experiment where I commented out theFrame
trait declaration and with small adaptations, I easily got the code to compile and run without errors.The
Frame
trait makes some impositions into the APIs ofSv2Frame
andHandShakeFrame
structs by trying to unify them logically (they're both kinds of "frame"). But unfortunately, the resulting APIs are unintuitive, more complex, and dirtier than they need to be.For example, the
Sv2Frame::payload
method is emitting apanic!
when the API is used incorrectly. Ideally, the API should be built so that there's no footguns on when this function is used.stratum/protocols/v2/framing-sv2/src/framing2.rs
Lines 132 to 145 in 24b8b1d
Since the
Frame
trait is never used anywhere else, there's only penalty for its existence (confusing APIs), for no profit.I propose we remove
Frame
trait and refactor the APIs ofSv2Frame
andHandShakeFrame
so they become more concise and intuitive.code organization
impl
blocks should be written immediately after the declaration of the respectivestruct
orenum
.We should avoid mixing
impl
blocks for different entities together. If they need to co-exist in the same file, they should be grouped logically in different regions of the file, so the reader can easily find methods right next to the declaration of thestruct
orenum
they belong to.sv2_frame::get_header
note from @Fi3:
error handling and edge cases
unwrap
,expect
)unimplemented!
,todo!
,panic!
,unreachable!
, etc)The text was updated successfully, but these errors were encountered: