Skip to content
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

*: convert to uint64 #2668

Merged
merged 6 commits into from
Nov 6, 2023
Merged

*: convert to uint64 #2668

merged 6 commits into from
Nov 6, 2023

Conversation

xenowits
Copy link
Contributor

Convert Duty.Slot from int64 to uint64.

This is recommended according to ethereum consensus specs: https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#custom-types

category: feature
ticket: #2658

@xenowits xenowits self-assigned this Oct 31, 2023
core/tracing.go Fixed Show fixed Hide fixed
@codecov
Copy link

codecov bot commented Oct 31, 2023

Codecov Report

Attention: 57 lines in your changes are missing coverage. Please review.

Comparison is base (e4f2047) 53.00% compared to head (09a368c) 52.94%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2668      +/-   ##
==========================================
- Coverage   53.00%   52.94%   -0.06%     
==========================================
  Files         202      202              
  Lines       28006    28011       +5     
==========================================
- Hits        14844    14830      -14     
- Misses      11301    11321      +20     
+ Partials     1861     1860       -1     
Files Coverage Δ
app/app.go 6.70% <100.00%> (ø)
core/bcast/bcast.go 66.17% <100.00%> (ø)
core/consensus/component.go 66.52% <100.00%> (ø)
core/consensus/roundtimer.go 100.00% <100.00%> (ø)
core/dutydb/memory.go 73.56% <100.00%> (ø)
core/fetcher/fetcher.go 68.38% <100.00%> (ø)
core/gater.go 74.28% <100.00%> (ø)
core/interfaces.go 0.00% <ø> (ø)
core/tracker/tracker.go 79.51% <100.00%> (ø)
dkg/exchanger.go 82.60% <100.00%> (ø)
... and 9 more

... and 8 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -743,7 +743,7 @@ func fmtStepPeers(step roundStep) string {

// leader return the deterministic leader index.
func leader(duty core.Duty, round int64, nodes int) int64 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't this function return uint64?

Copy link
Contributor Author

@xenowits xenowits Nov 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can, but uint64 is not really required by the code that uses this leader helper function

I have tried to use uint64s only where's necessary (most for spec compliance)

core/corepb/v1/core.proto Outdated Show resolved Hide resolved
@@ -319,11 +319,11 @@ func (s *Scheduler) resolveAttDuties(ctx context.Context, slot core.Slot, vals v
continue
}

duty := core.NewAttesterDuty(int64(attDuty.Slot))
duty := core.NewAttesterDuty(uint64(attDuty.Slot))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can attDuty.Slot be moved to uint64 as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attDuty.Slot is of eth2p0.Slot type. Since, NewAttesterDuty(slot uint64), we need to typecast the eth2p0.Slot to uint64 type

@@ -29,7 +30,7 @@ func StartDutyTrace(ctx context.Context, duty Duty, spanName string, opts ...tra
ctx, outerSpan = tracer.Start(tracer.RootedCtx(ctx, traceID), fmt.Sprintf("core/duty.%s", strings.Title(duty.Type.String())))
ctx, innerSpan = tracer.Start(ctx, spanName, opts...)

outerSpan.SetAttributes(attribute.Int64("slot", duty.Slot))
outerSpan.SetAttributes(attribute.Int64("slot", safeInt64(duty.Slot)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, i wonder if we can have Slot as uint64 and eventually do the safeint64 checks when creating the struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attribute has only 3 methods: attribute.Int(), attribute.Int64() & attribute.String()

q: why would we need to perform safeint checks if we define slots are uint64, won't the compiler already catch this?

@@ -131,7 +131,7 @@ func newExchanger(tcpNode host.Host, peerIdx int, peers []peer.ID, vals int, sig
// signatures of the group according to public key of each DV.
func (e *exchanger) exchange(ctx context.Context, sigType sigType, set core.ParSignedDataSet) (map[core.PubKey][]core.ParSignedData, error) {
// Start the process by storing current peer's ParSignedDataSet
duty := core.NewSignatureDuty(int64(sigType))
duty := core.NewSignatureDuty(uint64(sigType))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would change sigType to uint64 instead.

Copy link
Contributor Author

@xenowits xenowits Nov 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's required, what'd be the reason to change type for sigType which is currently an int to uint64?

slots, committee indices etc should be uint64 because the spec mandates that.

Copy link

sonarcloud bot commented Nov 3, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.6% 0.6% Duplication

@xenowits xenowits requested a review from gsora November 6, 2023 07:04
@xenowits xenowits added the merge when ready Indicates bulldozer bot may merge when all checks pass label Nov 6, 2023
@obol-bulldozer obol-bulldozer bot merged commit 1aa0bb4 into main Nov 6, 2023
15 checks passed
@obol-bulldozer obol-bulldozer bot deleted the xenowits/int64-uint64 branch November 6, 2023 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge when ready Indicates bulldozer bot may merge when all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants