Skip to content

Commit

Permalink
Merge branch 'develop' into naive-aggregate-contribution
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Jun 29, 2021
2 parents 0c48e79 + 0347b4b commit 64de87a
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 2 deletions.
4 changes: 2 additions & 2 deletions beacon-chain/server/main.go
Expand Up @@ -20,7 +20,7 @@ import (
var (
beaconRPC = flag.String("beacon-rpc", "localhost:4000", "Beacon chain gRPC endpoint")
port = flag.Int("port", 8000, "Port to serve on")
EthApiPort = flag.Int("port", 8001, "Port to serve Ethereum API on")
ethApiPort = flag.Int("port", 8001, "Port to serve Ethereum API on")
host = flag.String("host", "127.0.0.1", "Host to serve on")
debug = flag.Bool("debug", false, "Enable debug logging")
allowedOrigins = flag.String("corsdomain", "localhost:4242", "A comma separated list of CORS domains to allow")
Expand Down Expand Up @@ -48,7 +48,7 @@ func main() {
fmt.Sprintf("%s:%d", *host, *port),
).WithAllowedOrigins(strings.Split(*allowedOrigins, ",")).
WithMaxCallRecvMsgSize(uint64(*grpcMaxMsgSize)).
WithApiMiddleware(fmt.Sprintf("%s:%d", *host, *EthApiPort), &apimiddleware.BeaconEndpointFactory{})
WithApiMiddleware(fmt.Sprintf("%s:%d", *host, *ethApiPort), &apimiddleware.BeaconEndpointFactory{})

mux := http.NewServeMux()
mux.HandleFunc("/swagger/", gateway.SwaggerServer())
Expand Down
1 change: 1 addition & 0 deletions endtoend/evaluators/BUILD.bazel
Expand Up @@ -4,6 +4,7 @@ go_library(
name = "go_default_library",
testonly = True,
srcs = [
"api.go",
"data.go",
"finality.go",
"metrics.go",
Expand Down
254 changes: 254 additions & 0 deletions endtoend/evaluators/api.go
@@ -0,0 +1,254 @@
package evaluators

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"time"

"github.com/pkg/errors"
e2e "github.com/prysmaticlabs/prysm/endtoend/params"
"github.com/prysmaticlabs/prysm/endtoend/policies"
e2etypes "github.com/prysmaticlabs/prysm/endtoend/types"
"google.golang.org/grpc"
)

type stateValidatorsResponseJson struct {
Data []*validatorContainerJson `json:"data"`
}

type validatorContainerJson struct {
Index string `json:"index"`
Balance string `json:"balance"`
Status string `json:"status"`
Validator *validatorJson `json:"validator"`
}

type validatorJson struct {
PublicKey string `json:"pubkey"`
WithdrawalCredentials string `json:"withdrawal_credentials"`
EffectiveBalance string `json:"effective_balance"`
Slashed bool `json:"slashed"`
ActivationEligibilityEpoch string `json:"activation_eligibility_epoch"`
ActivationEpoch string `json:"activation_epoch"`
ExitEpoch string `json:"exit_epoch"`
WithdrawableEpoch string `json:"withdrawable_epoch"`
}

// ApiVerifyValidators ensures the Ethereum API returns correct validator data.
var ApiVerifyValidators = e2etypes.Evaluator{
Name: "api_verify_validators_epoch_%d",
Policy: policies.OnEpoch(1),
Evaluation: apiVerifyValidators,
}

func apiVerifyValidators(conns ...*grpc.ClientConn) error {
count := len(conns)
for i := 0; i < count; i++ {
resp, err := http.Get(
fmt.Sprintf("http://localhost:%d/eth/v1/beacon/states/head/validators?status=exited", e2e.TestParams.BeaconNodeRPCPort+i+30),
)
if err != nil {
// Continue if the connection fails, regular flake.
continue
}
if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
return fmt.Errorf("expected status code OK for beacon node %d, received %v with body %s", i, resp.StatusCode, body)
}
validators := &stateValidatorsResponseJson{}
if err = json.NewDecoder(resp.Body).Decode(&validators); err != nil {
return err
}
if len(validators.Data) != 0 {
return fmt.Errorf("expected no exited validators to be returned from the API request for beacon node %d", i)
}
resp, err = http.Get(
fmt.Sprintf("http://localhost:%d/eth/v1/beacon/states/head/validators?id=100&id=200", e2e.TestParams.BeaconNodeRPCPort+i+30),
)
if err != nil {
// Continue if the connection fails, regular flake.
continue
}
if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
return fmt.Errorf("expected status code OK for beacon node %d, received %v with body %s", i, resp.StatusCode, body)
}
validators = &stateValidatorsResponseJson{}
if err = json.NewDecoder(resp.Body).Decode(&validators); err != nil {
return err
}
if len(validators.Data) != 2 {
return fmt.Errorf("expected 2 validators to be returned from the API request for beacon node %d", i)
}
if err = assertValidator(validators.Data[0]); err != nil {
return errors.Wrapf(err, "incorrect validator data returned from the API request for beacon node %d", i)
}
if err = assertValidator(validators.Data[1]); err != nil {
return errors.Wrapf(err, "incorrect validator data returned from the API request for beacon node %d", i)
}

if err = resp.Body.Close(); err != nil {
return err
}
time.Sleep(connTimeDelay)
}
return nil
}

func assertValidator(v *validatorContainerJson) error {
if v == nil {
return errors.New("validator is nil")
}
if v.Index != "100" && v.Index != "200" {
return fmt.Errorf("unexpected validator index '%s'", v.Index)
}

valid := false
var field, expected, actual string

switch v.Index {
case "100":
if v.Balance != "32000000000" {
field = "Balance"
expected = "32000000000"
actual = v.Balance
break
}
if v.Status != "active_ongoing" {
field = "Status"
expected = "active_ongoing"
actual = v.Status
break
}
if v.Validator == nil {
return errors.New("validator is nil")
}
if v.Validator.PublicKey != "0x8931cd39ec3133b6ec91f26eec4de555cd7966086b1993dfe69c2b16e80adc62ce82d353b3356d8cc249e4e2d4254122" {
field = "PublicKey"
expected = "0x8931cd39ec3133b6ec91f26eec4de555cd7966086b1993dfe69c2b16e80adc62ce82d353b3356d8cc249e4e2d4254122"
actual = v.Validator.PublicKey
break
}
if v.Validator.WithdrawalCredentials != "0x00b5a389a138ec5069e430a91ec2884660fbb77a4bffdefd03f5e5769c2ba1a9" {
field = "WithdrawalCredentials"
expected = "0x00b5a389a138ec5069e430a91ec2884660fbb77a4bffdefd03f5e5769c2ba1a9"
actual = v.Validator.WithdrawalCredentials
break
}
if v.Validator.EffectiveBalance != "32000000000" {
field = "EffectiveBalance"
expected = "32000000000"
actual = v.Validator.EffectiveBalance
break
}
if v.Validator.Slashed {
field = "Slashed"
expected = "32000000000"
actual = "true"
break
}
if v.Validator.ActivationEligibilityEpoch != "0" {
field = "ActivationEligibilityEpoch"
expected = "0"
actual = v.Validator.ActivationEligibilityEpoch
break
}
if v.Validator.ActivationEpoch != "0" {
field = "ActivationEpoch"
expected = "0"
actual = v.Validator.ActivationEpoch
break
}
if v.Validator.ExitEpoch != "18446744073709551615" {
field = "ExitEpoch"
expected = "18446744073709551615"
actual = v.Validator.ExitEpoch
break
}
if v.Validator.WithdrawableEpoch != "18446744073709551615" {
field = "WithdrawableEpoch"
expected = "18446744073709551615"
actual = v.Validator.WithdrawableEpoch
break
}
valid = true
case "200":
if v.Balance != "32000000000" {
field = "Balance"
expected = "32000000000"
actual = v.Balance
break
}
if v.Status != "active_ongoing" {
field = "Status"
expected = "active_ongoing"
actual = v.Status
break
}
if v.Validator == nil {
return errors.New("validator is nil")
}
if v.Validator.PublicKey != "0x8b4ff71ee947785f545c017bbb9ce84c3f6a90097368cf79663b2e11acc53e18e8f7159919784f4d28282cb39a7113f7" {
field = "PublicKey"
expected = "0x8b4ff71ee947785f545c017bbb9ce84c3f6a90097368cf79663b2e11acc53e18e8f7159919784f4d28282cb39a7113f7"
actual = v.Validator.PublicKey
break
}
if v.Validator.WithdrawalCredentials != "0x00b9ea0e53f64def81fe2e783a8bb02e57fb519f56a7224f93f2d37e1572417d" {
field = "WithdrawalCredentials"
expected = "0x00b9ea0e53f64def81fe2e783a8bb02e57fb519f56a7224f93f2d37e1572417d"
actual = v.Validator.WithdrawalCredentials
break
}
if v.Validator.EffectiveBalance != "32000000000" {
field = "EffectiveBalance"
expected = "32000000000"
actual = v.Validator.EffectiveBalance
break
}
if v.Validator.Slashed {
field = "Slashed"
expected = "32000000000"
actual = "true"
break
}
if v.Validator.ActivationEligibilityEpoch != "0" {
field = "ActivationEligibilityEpoch"
expected = "0"
actual = v.Validator.ActivationEligibilityEpoch
break
}
if v.Validator.ActivationEpoch != "0" {
field = "ActivationEpoch"
expected = "0"
actual = v.Validator.ActivationEpoch
break
}
if v.Validator.ExitEpoch != "18446744073709551615" {
field = "ExitEpoch"
expected = "18446744073709551615"
actual = v.Validator.ExitEpoch
break
}
if v.Validator.WithdrawableEpoch != "18446744073709551615" {
field = "WithdrawableEpoch"
expected = "18446744073709551615"
actual = v.Validator.WithdrawableEpoch
break
}
valid = true
}

if !valid {
return fmt.Errorf("value of '%s' was expected to be '%s' but was '%s'", field, expected, actual)
}
return nil
}
1 change: 1 addition & 0 deletions endtoend/minimal_e2e_test.go
Expand Up @@ -61,6 +61,7 @@ func e2eMinimal(t *testing.T, usePrysmSh bool) {
ev.ValidatorHasExited,
ev.ValidatorsVoteWithTheMajority,
ev.ColdStateCheckpoint,
ev.ApiVerifyValidators,
},
}

Expand Down

0 comments on commit 64de87a

Please sign in to comment.