-
Notifications
You must be signed in to change notification settings - Fork 214
refactor: remove the Addr and Hash generics in consensus #2855
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2855 +/- ##
==========================================
- Coverage 74.83% 74.77% -0.06%
==========================================
Files 206 207 +1
Lines 22469 22473 +4
==========================================
- Hits 16815 16805 -10
- Misses 4598 4607 +9
- Partials 1056 1061 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
type Hash felt.Felt | ||
|
||
type Addr felt.Felt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we use existing types in core
instead? That would reduce one layer of conversion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, also happy to do that
} | ||
|
||
type ( | ||
Address = address.Address | ||
Hash = hash.Hash | ||
Hash = types.Hash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we use existing hash type from core
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, also happy to do that
I'm against this change because:
|
Imo, the implementation doesn't need to work with an abstract type since it's directly tied to Starkenet. Also it's not clear to me what tests we would be taking from other implementations (that are compatible with Starknets implementation), and if we couldn't just write a simple adapter for this case (eg
I agree this helps separate the Starknet types and the generic Tendermint logic. I just don't think it's worth it, particularly given Starknet is using their own custom Tendermint logic, not the vanilla implementation. It might be worth getting a third. @rodrigo-pino what are your thoughts? |
As far as I understand, the only changes in Starknet are not in the core part of the algorithm including state machine and driver, but instead in the communication part, namely proposal stream and re-broadcast. |
To do: investigate if we can remove the interfaces, but keep the Tendermint-Starknet abstraction layer |
Summary
The consensus implementation currently defines
Hash
andAddr
as generic interfaces to support flexibility across protocols. This was originally intended to allow the consensus logic to work with any hash and address types that can be represented as[4]uint
.However, in the context of the Starknet protocol, both the address and hash types are explicitly defined as
felt.Felt
, and this is not expected to change. As a result, the use of generics here is unnecessary and introduces avoidable complexity.Motivation
Unnecessary Boilerplate: Since
Hash
andAddr
are used pervasively across the consensus package, requiring them to be passed explicitly as generic parameters to every struct and function results in significant boilerplate and reduces readability.Interface Overhead: Defining these as interfaces requires explicit type declarations, type assertions, and additional complexity that brings no real benefit in this fixed-type context.
Improved Ergonomics: By redefining
Hash
andAddr
as aliases (e.g.,type Addr felt.Felt
), we significantly reduce syntactic noise and make the code more straightforward and maintainable.Change
This PR:
Hash
andAddr
interfaces with type aliases tofelt.Felt
.This change simplifies the consensus implementation while preserving all intended functionality under the assumption of fixed
felt.Felt
-based types.Next (this can be done in a separate PR)
Investigate whether the
Hashable
interface can also be removed by explicitly defining the concrete value types used in the Starknet protocol (e.g.,Block
,StateUpdate
, etc.).Since these types are known and fixed within the protocol, relying on an interface abstraction may be unnecessary. Replacing
Hashable
with concrete types could further simplify the codebase and eliminate another layer of indirection.