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

Serve API to return poet registrations state #6266

Open
wants to merge 68 commits into
base: develop
Choose a base branch
from

Conversation

ConvallariaMaj
Copy link
Contributor

@ConvallariaMaj ConvallariaMaj commented Aug 19, 2024

Motivation

Smesher needs to understand situation with poet registrations (success, failed, residual, no registrations and etc.)
Easiest way is providing API for that.

Description

Closes #6174

  • created smesher identity states
  • created new grpc service (SmeshingIdentitiesService) to serve new API
  • implemented logic to save failed registrations, retry to register in case if deadline for submit challenge is not passed, and update recording into db in case, if registrations were successful after another try
  • fixed tests
  • made some small refactoring

Connected PR:
spacemeshos/api#369

Test Plan

Unit tests

TODO

  • Explain motivation or link existing issue(s)
  • Test changes and document test plan
  • Update documentation as needed
  • Update changelog as needed

Copy link

codecov bot commented Oct 1, 2024

Codecov Report

Attention: Patch coverage is 69.56522% with 84 lines in your changes missing coverage. Please review.

Project coverage is 79.9%. Comparing base (c4e59b6) to head (0aa7d97).

Files with missing lines Patch % Lines
activation/nipost.go 71.9% 19 Missing and 6 partials ⚠️
activation/activation.go 29.4% 22 Missing and 2 partials ⚠️
api/grpcserver/v2alpha1/smeshing_identities.go 81.1% 10 Missing and 3 partials ⚠️
node/node.go 29.4% 11 Missing and 1 partial ⚠️
activation/identity_states.go 84.4% 8 Missing and 1 partial ⚠️
sql/localsql/nipost/poet_registration.go 85.7% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           develop   #6266     +/-   ##
=========================================
- Coverage     79.9%   79.9%   -0.1%     
=========================================
  Files          353     355      +2     
  Lines        46396   46614    +218     
=========================================
+ Hits         37103   37246    +143     
- Misses        7191    7255     +64     
- Partials      2102    2113     +11     

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

@ivan4th
Copy link
Contributor

ivan4th commented Oct 2, 2024

Some quite minor nits, otherwise looks good

@fasmat fasmat requested a review from jellonek as a code owner October 9, 2024 08:26
Copy link
Contributor

@poszu poszu left a comment

Choose a reason for hiding this comment

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

I'm wondering whether it would make sense to combine the existing "post states" (PROVING/IDLE) with this (extend the existing API)?

Comment on lines -352 to +362
tab := newTestBuilder(t, 1, WithPoetConfig(PoetConfig{PhaseShift: layerDuration}))
ctrl := gomock.NewController(t)
idStates := NewMockIdentityStates(ctrl)
idStates.EXPECT().Set(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()

tab := newTestBuilder(t, 1,
WithPoetConfig(PoetConfig{PhaseShift: layerDuration}),
WithIdentityStates(idStates))

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the point of adding the "identitystates` in these tests? It doesn't verify anything additionally (compared to the original test) but it complicates the tests.

Comment on lines +21 to +27
ctrl := gomock.NewController(t)
idStates := NewMockIdentityStates(ctrl)
idStates.EXPECT().Set(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()

tab := newTestBuilder(t, 1,
WithPoetConfig(PoetConfig{PhaseShift: layerDuration}),
WithIdentityStates(idStates),
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

Suggested change
ctrl := gomock.NewController(t)
idStates := NewMockIdentityStates(ctrl)
idStates.EXPECT().Set(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
tab := newTestBuilder(t, 1,
WithPoetConfig(PoetConfig{PhaseShift: layerDuration}),
WithIdentityStates(idStates),
tab := newTestBuilder(t, 1,
WithPoetConfig(PoetConfig{PhaseShift: layerDuration}),

Comment on lines +267 to +278
func (b *Builder) IdentityStates() map[types.IdentityDescriptor]IdentityState {
states := b.identitiesStates.All()
res := make(map[types.IdentityDescriptor]IdentityState, len(states))
b.smeshingMutex.Lock()
defer b.smeshingMutex.Unlock()
for id, state := range states {
if sig, exists := b.signers[id]; exists {
res[sig] = state
}
}
return res
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How about not adding this to the ATX Builder? The builder doesn't need this at all. AFAIR, it's only used in the grpc service, which could do read directly from the "identities state", wdyt?

We don't support unregistering, so the GRPC service could just return all the state of all IDs.

Comment on lines +576 to +578
if len(r.RoundID) == 0 {
continue // skip failed registrations
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It's incorrect as the first poet round has ID 0. IMHO, it's better not to give existing fields "extra meaning" but to have a dedicated field.

@jellonek
Copy link
Contributor

jellonek commented Nov 5, 2024

Note: this PR depends on spacemeshos/api#369

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Serve API per each NodeID configured / known poets
6 participants