prysm-pulse/testing/endtoend/evaluators/execution_engine.go
Nishant Das 4a515c36e6
Deneb E2E (#13040)
* save changes

* add dep

* add changes

* add latest changes

* push changes

* hack it for mainnet

* fix deps

* update it

* add changes

* fix e2e

* revert it

* gaz

* remove log

* preston's review

* clear up

* add more logs

* fix nonce gaps

* make it better

* fix blobs

* set value

* add support for deneb scenario paths

* update to fix scenario

* go mod

* clean up

* fix up

* reduce cog complexity

* lint

* remove

* go sec

* Update testing/endtoend/evaluators/fork.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update proto/ssz_proto_library.bzl

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* fix

* radek's review

* make it atomic

* gaz

* add deneb case

* remove deneb activation

* change e2e yaml

---------

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
2023-11-08 12:24:23 +00:00

144 lines
4.4 KiB
Go

package evaluators
import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/beacon"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared"
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
http2 "github.com/prysmaticlabs/prysm/v4/network/http"
"github.com/prysmaticlabs/prysm/v4/runtime/version"
"github.com/prysmaticlabs/prysm/v4/testing/endtoend/params"
"github.com/prysmaticlabs/prysm/v4/testing/endtoend/policies"
"github.com/prysmaticlabs/prysm/v4/testing/endtoend/types"
"github.com/prysmaticlabs/prysm/v4/time/slots"
"google.golang.org/grpc"
)
// OptimisticSyncEnabled checks that the node is in an optimistic state.
var OptimisticSyncEnabled = types.Evaluator{
Name: "optimistic_sync_at_epoch_%d",
Policy: policies.AllEpochs,
Evaluation: optimisticSyncEnabled,
}
func optimisticSyncEnabled(_ *types.EvaluationContext, conns ...*grpc.ClientConn) error {
for nodeIndex := range conns {
path := fmt.Sprintf("http://localhost:%d/eth/v1/beacon/blinded_blocks/head", params.TestParams.Ports.PrysmBeaconNodeGatewayPort+nodeIndex)
resp := beacon.GetBlockV2Response{}
httpResp, err := http.Get(path) // #nosec G107 -- path can't be constant because it depends on port param and node index
if err != nil {
return err
}
if httpResp.StatusCode != http.StatusOK {
e := http2.DefaultErrorJson{}
if err = json.NewDecoder(httpResp.Body).Decode(&e); err != nil {
return err
}
return fmt.Errorf("%s (status code %d)", e.Message, e.Code)
}
if err = json.NewDecoder(httpResp.Body).Decode(&resp); err != nil {
return err
}
headSlot, err := retrieveHeadSlot(&resp)
if err != nil {
return err
}
currEpoch := slots.ToEpoch(primitives.Slot(headSlot))
startSlot, err := slots.EpochStart(currEpoch)
if err != nil {
return err
}
isOptimistic := false
for i := startSlot; i <= primitives.Slot(headSlot); i++ {
path = fmt.Sprintf("http://localhost:%d/eth/v1/beacon/blinded_blocks/%d", params.TestParams.Ports.PrysmBeaconNodeGatewayPort+nodeIndex, i)
resp = beacon.GetBlockV2Response{}
httpResp, err = http.Get(path) // #nosec G107 -- path can't be constant because it depends on port param and node index
if err != nil {
return err
}
if httpResp.StatusCode == http.StatusNotFound {
// Continue in the event of non-existent blocks.
continue
}
if httpResp.StatusCode != http.StatusOK {
e := http2.DefaultErrorJson{}
if err = json.NewDecoder(httpResp.Body).Decode(&e); err != nil {
return err
}
return fmt.Errorf("%s (status code %d)", e.Message, e.Code)
}
if err = json.NewDecoder(httpResp.Body).Decode(&resp); err != nil {
return err
}
if !resp.ExecutionOptimistic {
return errors.New("expected block to be optimistic, but it is not")
}
isOptimistic = true
}
if !isOptimistic {
return errors.New("expected block to be optimistic, but it is not")
}
}
return nil
}
func retrieveHeadSlot(resp *beacon.GetBlockV2Response) (uint64, error) {
headSlot := uint64(0)
var err error
switch resp.Version {
case version.String(version.Phase0):
b := &shared.BeaconBlock{}
if err := json.Unmarshal(resp.Data.Message, b); err != nil {
return 0, err
}
headSlot, err = strconv.ParseUint(b.Slot, 10, 64)
if err != nil {
return 0, err
}
case version.String(version.Altair):
b := &shared.BeaconBlockAltair{}
if err := json.Unmarshal(resp.Data.Message, b); err != nil {
return 0, err
}
headSlot, err = strconv.ParseUint(b.Slot, 10, 64)
if err != nil {
return 0, err
}
case version.String(version.Bellatrix):
b := &shared.BeaconBlockBellatrix{}
if err := json.Unmarshal(resp.Data.Message, b); err != nil {
return 0, err
}
headSlot, err = strconv.ParseUint(b.Slot, 10, 64)
if err != nil {
return 0, err
}
case version.String(version.Capella):
b := &shared.BeaconBlockCapella{}
if err := json.Unmarshal(resp.Data.Message, b); err != nil {
return 0, err
}
headSlot, err = strconv.ParseUint(b.Slot, 10, 64)
if err != nil {
return 0, err
}
case version.String(version.Deneb):
b := &shared.BeaconBlockDeneb{}
if err := json.Unmarshal(resp.Data.Message, b); err != nil {
return 0, err
}
headSlot, err = strconv.ParseUint(b.Slot, 10, 64)
if err != nil {
return 0, err
}
default:
return 0, errors.New("no valid block type retrieved")
}
return headSlot, nil
}