Skip to content

Commit

Permalink
rename remove fields frou UI json
Browse files Browse the repository at this point in the history
  • Loading branch information
anatolie-ssv committed Feb 13, 2025
1 parent 3bb78a8 commit 456f202
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 56 deletions.
89 changes: 46 additions & 43 deletions api/handlers/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ func (e *Exporter) OperatorTraces(w http.ResponseWriter, r *http.Request) error

func (e *Exporter) CommitteeTraces(w http.ResponseWriter, r *http.Request) error {
var request struct {
From uint64 `json:"from"`
To uint64 `json:"to"`
CommitteeID api.Hex `json:"committeeID"`
Operators api.Uint64Slice `json:"operators"`
From uint64 `json:"from"`
To uint64 `json:"to"`
CommitteeIDs api.HexSlice `json:"committeeIDs"`
Committees api.Uint64Slice `json:"committees"` // TBD
}

if err := api.Bind(r, &request); err != nil {
Expand All @@ -150,25 +150,31 @@ func (e *Exporter) CommitteeTraces(w http.ResponseWriter, r *http.Request) error
return api.BadRequestError(fmt.Errorf("'from' must be less than or equal to 'to'"))
}

Check warning on line 151 in api/handlers/exporter.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/exporter.go#L149-L151

Added lines #L149 - L151 were not covered by tests

var committeeID spectypes.CommitteeID
var committeeIDs []spectypes.CommitteeID

if len(request.Operators) > 0 { // operators take precedence
committeeID = spectypes.GetCommitteeID(request.Operators)
} else {
if len(request.CommitteeID) != len(committeeID) {
return api.BadRequestError(fmt.Errorf("invalid committee ID length"))
for _, cmt := range request.CommitteeIDs {
var id spectypes.CommitteeID
if len(cmt) != len(id) {
return api.BadRequestError(fmt.Errorf("invalid committee ID length: %s", hex.EncodeToString(cmt)))
}
copy(committeeID[:], request.CommitteeID)
copy(id[:], cmt)
committeeIDs = append(committeeIDs, id)

Check warning on line 161 in api/handlers/exporter.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/exporter.go#L153-L161

Added lines #L153 - L161 were not covered by tests
}

if len(committeeIDs) == 0 {
// map request.Committees
}

Check warning on line 166 in api/handlers/exporter.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/exporter.go#L164-L166

Added lines #L164 - L166 were not covered by tests

var duties []*model.CommitteeDutyTrace
for s := request.From; s <= request.To; s++ {
slot := phase0.Slot(s)
duty, err := e.TraceStore.GetCommitteeDuty(slot, committeeID)
if err != nil {
return api.Error(fmt.Errorf("error getting duties: %w", err))
for _, cmtID := range committeeIDs {
for s := request.From; s <= request.To; s++ {
slot := phase0.Slot(s)
duty, err := e.TraceStore.GetCommitteeDuty(slot, cmtID)
if err != nil {
return api.Error(fmt.Errorf("error getting duties: %w", err))
}
duties = append(duties, duty)

Check warning on line 176 in api/handlers/exporter.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/exporter.go#L168-L176

Added lines #L168 - L176 were not covered by tests
}
duties = append(duties, duty)
}

return api.Render(w, r, toCommitteeTraceResponse(duties))

Check warning on line 180 in api/handlers/exporter.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/exporter.go#L180

Added line #L180 was not covered by tests
Expand All @@ -184,10 +190,11 @@ func toCommitteeTraceResponse(duties []*model.CommitteeDutyTrace) *committeeTrac

func (e *Exporter) ValidatorTraces(w http.ResponseWriter, r *http.Request) error {
var request struct {
From uint64 `json:"from"`
To uint64 `json:"to"`
Roles api.RoleSlice `json:"roles"`
PubKey api.Hex `json:"pubkey"` // optional
From uint64 `json:"from"`
To uint64 `json:"to"`
Roles api.RoleSlice `json:"roles"`
PubKeys api.HexSlice `json:"pubkeys"`
Indices api.Uint64Slice `json:"indices"`
}

if err := api.Bind(r, &request); err != nil {
Expand All @@ -202,41 +209,37 @@ func (e *Exporter) ValidatorTraces(w http.ResponseWriter, r *http.Request) error
return api.BadRequestError(fmt.Errorf("at least one role is required"))
}

Check warning on line 210 in api/handlers/exporter.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/exporter.go#L208-L210

Added lines #L208 - L210 were not covered by tests

if len(request.PubKeys) == 0 && len(request.Indices) == 0 {
return api.BadRequestError(fmt.Errorf("either pubkeys or indices is required"))
}

Check warning on line 214 in api/handlers/exporter.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/exporter.go#L212-L214

Added lines #L212 - L214 were not covered by tests

var results []*model.ValidatorDutyTrace

if len(request.PubKey) == 0 {
for _, req := range request.PubKeys {
// convert to pubkey
var pubkey spectypes.ValidatorPK
if len(req) != len(pubkey) {
return api.BadRequestError(fmt.Errorf("invalid pubkey length"))
}
copy(pubkey[:], req)

// get for each slot
for s := request.From; s <= request.To; s++ {
slot := phase0.Slot(s)
for _, r := range request.Roles {
role := spectypes.BeaconRole(r)
duties, err := e.TraceStore.GetAllValidatorDuties(role, slot)
duty, err := e.TraceStore.GetValidatorDuty(role, slot, pubkey)
if err != nil {
return api.Error(fmt.Errorf("error getting duties: %w", err))
}
results = append(results, duties...)
results = append(results, duty)

Check warning on line 235 in api/handlers/exporter.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/exporter.go#L216-L235

Added lines #L216 - L235 were not covered by tests
}
}
return api.Render(w, r, toValidatorTraceResponse(results))
}

var pubkey spectypes.ValidatorPK

if len(request.PubKey) != len(pubkey) {
return api.BadRequestError(fmt.Errorf("invalid pubkey length"))
}

copy(pubkey[:], request.PubKey)

for s := request.From; s <= request.To; s++ {
slot := phase0.Slot(s)
for _, r := range request.Roles {
role := spectypes.BeaconRole(r)
duty, err := e.TraceStore.GetValidatorDuty(role, slot, pubkey)
if err != nil {
return api.Error(fmt.Errorf("error getting duties: %w", err))
}
results = append(results, duty)
}
for _, index := range request.Indices {
_ = index // convert to validator pubkey
// repeat above
}

Check warning on line 243 in api/handlers/exporter.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/exporter.go#L240-L243

Added lines #L240 - L243 were not covered by tests

return api.Render(w, r, toValidatorTraceResponse(results))

Check warning on line 245 in api/handlers/exporter.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/exporter.go#L245

Added line #L245 was not covered by tests
Expand Down
26 changes: 13 additions & 13 deletions api/handlers/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ type validatorTraceResponse struct {
}

type validatorTrace struct {
Slot phase0.Slot `json:"slot"`
Rounds []round
Decideds []decided
Slot phase0.Slot `json:"slot"`
Rounds []round `json:"consensus"`
Decideds []decided `json:"decideds"`
Pre []message `json:"pre"`
Post []message `json:"post"`
Role string `json:"role"`
Expand All @@ -32,11 +32,11 @@ type decided struct {
}

type round struct {
ProposalTrace *proposalTrace `json:"proposal"`
Proposer spectypes.OperatorID `json:"proposer"`
Prepares []message `json:"prepares"`
Commits []message `json:"commits"`
RoundChanges []roundChange `json:"roundChanges"`
ProposalTrace *proposalTrace `json:"proposal"`
// Proposer spectypes.OperatorID `json:"proposer"` not needed
Prepares []message `json:"prepares"`
Commits []message `json:"commits"`
RoundChanges []roundChange `json:"roundChanges"`
}

type proposalTrace struct {
Expand Down Expand Up @@ -93,7 +93,7 @@ func toMessageTrace(m []*model.PartialSigTrace) (out []message) {
func toRounds(r []*model.RoundTrace) (out []round) {
for _, rt := range r {
out = append(out, round{
Proposer: rt.Proposer,
// Proposer: rt.Proposer,
ProposalTrace: toProposalTrace(rt.ProposalTrace),
Prepares: toUIMessageTrace(rt.Prepares),
Commits: toUIMessageTrace(rt.Commits),
Expand Down Expand Up @@ -156,12 +156,12 @@ type committeeTraceResponse struct {

type committeeTrace struct {
Slot phase0.Slot `json:"slot"`
Rounds []round `json:"rounds"`
Rounds []round `json:"consensus"`
Decideds []decided `json:"decideds"`
Post []committeeMessage `json:"post"`

CommitteeID string `json:"committeeID"`
OperatorIDs []spectypes.OperatorID `json:"operatorIDs"`
CommitteeID string `json:"committeeID"`
// OperatorIDs []spectypes.OperatorID `json:"operatorIDs"` not needed?
}

type committeeMessage struct {
Expand All @@ -179,7 +179,7 @@ func toCommitteeTrace(t *model.CommitteeDutyTrace) committeeTrace {
Slot: t.Slot,
Post: toCommitteePost(t.Post),
CommitteeID: hex.EncodeToString(t.CommitteeID[:]),
OperatorIDs: t.OperatorIDs,
// OperatorIDs: t.OperatorIDs,
}

Check warning on line 183 in api/handlers/model.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/model.go#L174-L183

Added lines #L174 - L183 were not covered by tests
}

Expand Down

0 comments on commit 456f202

Please sign in to comment.