-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exporter: decideds endpoint; fix signers; fix resolving role; cache d…
…omain; fix convert (#1766) * draft * add comment * use runner role instead beacon role * lint fix * add log * run exporter post-fork * support hex strings with '0x' prefix for public keys in exporter API * cleanups * revert to beacon role * use trim * adapt to older response format * fix JSON capital case * change type of From and To * fix error text if values are equal * continue if one of pubkeys/duties has no participants * allow saving participants not equal to 3f+1 * save participants if quorum is longer than existing one * remove redundant check * add uint in Bind * consider failure to bind params as a bad request * fix role order in convert package * Revert "fix role order in convert package" This reverts commit 50c86a5. * Revert "fix JSON capital case" This reverts commit d8da4a7. * use casts * go fmt * Revert "allow saving participants not equal to 3f+1" This reverts commit 1a53ee6. * Revert "save participants if quorum is longer than existing one" This reverts commit bd94915. * allow saving participants not equal to 3f+1 * add logs * Revert "add logs" This reverts commit e373882. * add tmp log * adjust log * use duty store instead of root to determine existence of duty * Revert "use duty store instead of root to determine existence of duty" This reverts commit 59b3f7a. * save both attester and sync committee roots * sort imports * handle case when both attester and sync committee roles exist * add msg_id log * fix validator PK logging in CommitteeObserver * fix role order in convert package * Revert "fix role order in convert package" This reverts commit c31192d. * fix casting issues * process all message types by CommitteeObserver * disable ErrTooManyDutiesPerEpoch * attempt to fix issues with conversion to convert runner role * Revert "process all message types by CommitteeObserver" This reverts commit 04f7db2. * add log when no roles * fix saving sync committee roots * logs on saving block root * log root on saving * use attestation data hash * use signed attestation data and block root for checking beacon role * check err after signing * add validator log when saving participants * more logs * improve logs * save roots for all committee indices * more logs * more logs for committee index * fix committee index logs * more committee index logs * set max committee index to 128 * Revert "set max committee index to 128" This reverts commit aa0baa0. * fix data race * fix typo on mutex unlock * identifier logs * global root store * revert disabling ErrTooManyDutiesPerEpoch * cleanup logs * fix exporter unit tests * use duty store instead of storing roots * add comments * leftovers * revert non role committee logic * Revert "revert non role committee logic" This reverts commit 7de9236. * revert remobing validator index log fiekd * adjust log * get rid of Root in processMessage * fix remaining casting issues between roles * Revert "use duty store instead of storing roots" This reverts commit 8378f8f * Revert "get rid of Root in processMessage" This reverts commit b3f63ea * cache DomainData calls * fix TestNewController * add logs when saving roots * Revert "add logs when saving roots" This reverts commit e091617. * fix event syncer tests * fix TestHandleBlockEventsStream * avoid redundant root computations * Delete root_cache.go * improve handling non-existing roles * wrap errors into api.Error * merge quorums * revert config change * approve spec diff --------- Co-authored-by: Nikita Kryuchkov <nkryuchkov10@gmail.com> Co-authored-by: moshe-blox <moshe@blox.io>
- Loading branch information
1 parent
73e99f5
commit a020f5a
Showing
25 changed files
with
663 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package handlers | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/attestantio/go-eth2-client/spec/phase0" | ||
spectypes "github.com/ssvlabs/ssv-spec/types" | ||
|
||
"github.com/ssvlabs/ssv/api" | ||
exporterapi "github.com/ssvlabs/ssv/exporter/api" | ||
"github.com/ssvlabs/ssv/exporter/convert" | ||
ibftstorage "github.com/ssvlabs/ssv/ibft/storage" | ||
qbftstorage "github.com/ssvlabs/ssv/protocol/v2/qbft/storage" | ||
"github.com/ssvlabs/ssv/utils/casts" | ||
) | ||
|
||
type Exporter struct { | ||
DomainType spectypes.DomainType | ||
QBFTStores *ibftstorage.QBFTStores | ||
} | ||
|
||
type ParticipantResponse struct { | ||
Role string `json:"role"` | ||
Slot uint64 `json:"slot"` | ||
PublicKey string `json:"public_key"` | ||
Message struct { | ||
// We're keeping "Signers" capitalized to avoid breaking existing clients that rely on the current structure | ||
Signers []uint64 `json:"Signers"` | ||
} `json:"message"` | ||
} | ||
|
||
func (e *Exporter) Decideds(w http.ResponseWriter, r *http.Request) error { | ||
var request struct { | ||
From uint64 `json:"from"` | ||
To uint64 `json:"to"` | ||
Roles api.RoleSlice `json:"roles"` | ||
PubKeys api.HexSlice `json:"pubkeys"` | ||
} | ||
var response struct { | ||
Data []*ParticipantResponse `json:"data"` | ||
} | ||
|
||
if err := api.Bind(r, &request); err != nil { | ||
return api.BadRequestError(err) | ||
} | ||
|
||
if request.From > request.To { | ||
return api.BadRequestError(fmt.Errorf("'from' must be less than or equal to 'to'")) | ||
} | ||
|
||
if len(request.PubKeys) == 0 { | ||
return api.BadRequestError(fmt.Errorf("at least one public key is required")) | ||
} | ||
|
||
if len(request.Roles) == 0 { | ||
return api.BadRequestError(fmt.Errorf("at least one role is required")) | ||
} | ||
|
||
response.Data = []*ParticipantResponse{} | ||
|
||
qbftStores := make(map[convert.RunnerRole]qbftstorage.QBFTStore, len(request.Roles)) | ||
for _, role := range request.Roles { | ||
runnerRole := casts.BeaconRoleToConvertRole(spectypes.BeaconRole(role)) | ||
storage := e.QBFTStores.Get(runnerRole) | ||
if storage == nil { | ||
return api.Error(fmt.Errorf("role storage doesn't exist: %v", role)) | ||
} | ||
|
||
qbftStores[runnerRole] = storage | ||
} | ||
|
||
for _, role := range request.Roles { | ||
runnerRole := casts.BeaconRoleToConvertRole(spectypes.BeaconRole(role)) | ||
qbftStore := qbftStores[runnerRole] | ||
|
||
for _, pubKey := range request.PubKeys { | ||
msgID := convert.NewMsgID(e.DomainType, pubKey, runnerRole) | ||
from := phase0.Slot(request.From) | ||
to := phase0.Slot(request.To) | ||
|
||
participantsList, err := qbftStore.GetParticipantsInRange(msgID, from, to) | ||
if err != nil { | ||
return api.Error(fmt.Errorf("error getting participants: %w", err)) | ||
} | ||
|
||
if len(participantsList) == 0 { | ||
continue | ||
} | ||
|
||
data, err := exporterapi.ParticipantsAPIData(participantsList...) | ||
if err != nil { | ||
return api.Error(fmt.Errorf("error getting participants API data: %w", err)) | ||
} | ||
|
||
apiData, ok := data.([]*exporterapi.ParticipantsAPI) | ||
if !ok { | ||
return api.Error(fmt.Errorf("invalid type for participants API data")) | ||
} | ||
|
||
for _, apiMsg := range apiData { | ||
response.Data = append(response.Data, transformToParticipantResponse(apiMsg)) | ||
} | ||
} | ||
} | ||
|
||
return api.Render(w, r, response) | ||
} | ||
|
||
func transformToParticipantResponse(apiMsg *exporterapi.ParticipantsAPI) *ParticipantResponse { | ||
response := &ParticipantResponse{ | ||
Role: apiMsg.Role, | ||
Slot: uint64(apiMsg.Slot), | ||
PublicKey: apiMsg.ValidatorPK, | ||
} | ||
response.Message.Signers = apiMsg.Signers | ||
|
||
return response | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.