Skip to content

Commit

Permalink
separate attester from sync committee
Browse files Browse the repository at this point in the history
  • Loading branch information
anatolie-ssv committed Feb 17, 2025
1 parent 011655a commit af64b7d
Show file tree
Hide file tree
Showing 7 changed files with 356 additions and 328 deletions.
9 changes: 7 additions & 2 deletions api/handlers/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ 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

if len(request.Committees) == 0 && len(request.CommitteeIDs) == 0 {
return api.BadRequestError(fmt.Errorf("committees are required"))
}

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

View check run for this annotation

Codecov / codecov/patch

api/handlers/exporter.go#L153-L155

Added lines #L153 - L155 were not covered by tests

var committeeIDs []spectypes.CommitteeID

for _, cmt := range request.CommitteeIDs {
Expand All @@ -161,8 +165,9 @@ func (e *Exporter) CommitteeTraces(w http.ResponseWriter, r *http.Request) error
committeeIDs = append(committeeIDs, id)

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

View check run for this annotation

Codecov / codecov/patch

api/handlers/exporter.go#L157-L165

Added lines #L157 - L165 were not covered by tests
}

if len(committeeIDs) == 0 {
// map request.Committees
if len(committeeIDs) == 0 { // double check
id := spectypes.GetCommitteeID(request.Committees)
committeeIDs = append(committeeIDs, id)
}

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

View check run for this annotation

Codecov / codecov/patch

api/handlers/exporter.go#L168-L171

Added lines #L168 - L171 were not covered by tests

var duties []*model.CommitteeDutyTrace
Expand Down
58 changes: 19 additions & 39 deletions api/handlers/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/attestantio/go-eth2-client/spec/phase0"
spectypes "github.com/ssvlabs/ssv-spec/types"
model "github.com/ssvlabs/ssv/exporter/v2"
qbftmsg "github.com/ssvlabs/ssv/protocol/v2/message"
)

type validatorTraceResponse struct {
Expand All @@ -26,7 +25,7 @@ type validatorTrace struct {

type decided struct {
Round uint64 `json:"round"`
BeaconRoot phase0.Root `json:"beaconRoot"`
BeaconRoot phase0.Root `json:"ssvRoot"`
Signers []spectypes.OperatorID `json:"signers"`
ReceivedTime time.Time `json:"time"`
}
Expand All @@ -41,7 +40,7 @@ type round struct {

type proposalTrace struct {
Round uint64 `json:"round"`
BeaconRoot phase0.Root `json:"beaconRoot"`
BeaconRoot phase0.Root `json:"ssvRoot"`
Signer spectypes.OperatorID `json:"signer"`
RoundChanges []roundChange `json:"roundChanges"`
PrepareMessages []message `json:"prepareMessages"`
Expand All @@ -56,17 +55,11 @@ type roundChange struct {

type message struct {
Round uint64 `json:"round"`
BeaconRoot phase0.Root `json:"beaconRoot"`
BeaconRoot phase0.Root `json:"ssvRoot"`
Signer spectypes.OperatorID `json:"signer"`
ReceivedTime time.Time `json:"time"`
}

type partialSigMessage struct {
BeaconRoot phase0.Root `json:"beaconRoot"`
Signer spectypes.OperatorID `json:"signer"`
Validator phase0.ValidatorIndex `json:"validator"`
}

func toValidatorTrace(t *model.ValidatorDutyTrace) validatorTrace {
return validatorTrace{
Slot: t.Slot,
Expand Down Expand Up @@ -155,30 +148,31 @@ type committeeTraceResponse struct {
}

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

SyncCommittee []committeeMessage `json:"sync_committee"`
Attester []committeeMessage `json:"attester"`

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

type committeeMessage struct {
Type string `json:"type"`
Signer spectypes.OperatorID `json:"signer"`
Messages []partialSigMessage `json:"messages"`
ReceivedTime time.Time `json:"time"`
Signers []spectypes.OperatorID `json:"signers"`
ReceivedTime time.Time `json:"time"`
}

func toCommitteeTrace(t *model.CommitteeDutyTrace) committeeTrace {
return committeeTrace{
// consensus trace
Rounds: toRounds(t.Rounds),
Decideds: toDecidedTrace(t.Decideds),
Slot: t.Slot,
Post: toCommitteePost(t.Post),
CommitteeID: hex.EncodeToString(t.CommitteeID[:]),
Slot: t.Slot,
Rounds: toRounds(t.Rounds),
Decideds: toDecidedTrace(t.Decideds),
SyncCommittee: toCommitteePost(t.SyncCommittee),
Attester: toCommitteePost(t.Attester),
CommitteeID: hex.EncodeToString(t.CommitteeID[:]),
// OperatorIDs: t.OperatorIDs,
}

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

View check run for this annotation

Codecov / codecov/patch

api/handlers/model.go#L167-L177

Added lines #L167 - L177 were not covered by tests
}
Expand All @@ -196,27 +190,13 @@ func toDecidedTrace(d []*model.DecidedTrace) (out []decided) {
return

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

View check run for this annotation

Codecov / codecov/patch

api/handlers/model.go#L190

Added line #L190 was not covered by tests
}

func toCommitteePost(m []*model.CommitteePartialSigMessageTrace) (out []committeeMessage) {
func toCommitteePost(m []*model.SignerData) (out []committeeMessage) {
for _, mt := range m {
out = append(out, committeeMessage{
Type: qbftmsg.PartialMsgTypeToString(mt.Type),
Signer: mt.Signer,
Messages: toCommitteePartSigMessage(mt.Messages),
Signers: mt.Signers,
ReceivedTime: mt.ReceivedTime,
})
}

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

View check run for this annotation

Codecov / codecov/patch

api/handlers/model.go#L193-L199

Added lines #L193 - L199 were not covered by tests

return

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

View check run for this annotation

Codecov / codecov/patch

api/handlers/model.go#L201

Added line #L201 was not covered by tests
}

func toCommitteePartSigMessage(m []*model.PartialSigMessage) (out []partialSigMessage) {
for _, mt := range m {
out = append(out, partialSigMessage{
BeaconRoot: mt.BeaconRoot,
Signer: mt.Signer,
Validator: mt.ValidatorIndex,
})
}

return
}
2 changes: 1 addition & 1 deletion cli/operator/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ var StartNodeCmd = &cobra.Command{
var tracer validator.DutyTracer = validator.NoOp()
if cfg.SSVOptions.ValidatorOptions.ExporterEnableDutyTracing {
logger.Info("exporter duty tracing enabled")
tracer = validator.NewTracer(logger)
tracer = validator.NewTracer(logger, consensusClient)
}
cfg.SSVOptions.ValidatorOptions.DutyTracer = tracer

Check warning on line 351 in cli/operator/node.go

View check run for this annotation

Codecov / codecov/patch

cli/operator/node.go#L345-L351

Added lines #L345 - L351 were not covered by tests
Expand Down
16 changes: 5 additions & 11 deletions exporter/v2/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,19 @@ type CommitteeDutyTrace struct {
ConsensusTrace

Slot phase0.Slot
Post []*CommitteePartialSigMessageTrace `ssz-max:"13"`

CommitteeID spectypes.CommitteeID `ssz-size:"32"`
OperatorIDs []spectypes.OperatorID `ssz-max:"13"`

SyncCommittee []*SignerData `ssz-max:"1512"`
Attester []*SignerData `ssz-max:"1512"`

// maybe not needed
AttestationDataRoot phase0.Root `ssz-size:"32"`
SyncCommitteeMessageRoot phase0.Root `ssz-size:"32"`
}

type CommitteePartialSigMessageTrace struct {
Type spectypes.PartialSigMsgType
Signer spectypes.OperatorID
Messages []*PartialSigMessage `ssz-max:"1512"`
type SignerData struct {
Signers []spectypes.OperatorID `ssz-max:"13"`
ReceivedTime time.Time
}

type PartialSigMessage struct {
BeaconRoot phase0.Root `ssz-size:"32"`
Signer spectypes.OperatorID
ValidatorIndex phase0.ValidatorIndex
}
Loading

0 comments on commit af64b7d

Please sign in to comment.