Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Deneb Types and Flow #553

Merged
merged 15 commits into from
Jan 19, 2024
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ linters:
- wrapcheck
- wsl
- musttag
- depguard

#
# Maybe fix later:
Expand Down
18 changes: 9 additions & 9 deletions cmd/test-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"os"
"strconv"

"github.com/attestantio/go-builder-client/api"
"github.com/attestantio/go-builder-client/spec"
"github.com/attestantio/go-eth2-client/api/v1/capella"
builderApi "github.com/attestantio/go-builder-client/api"
builderSpec "github.com/attestantio/go-builder-client/spec"
eth2ApiV1Capella "github.com/attestantio/go-eth2-client/api/v1/capella"
"github.com/attestantio/go-eth2-client/spec/altair"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -44,7 +44,7 @@ func doRegisterValidator(v validatorPrivateData, boostEndpoint string, builderSi
log.WithError(err).Info("Registered validator")
}

func doGetHeader(v validatorPrivateData, boostEndpoint string, beaconNode Beacon, engineEndpoint string, builderSigningDomain phase0.Domain) spec.VersionedSignedBuilderBid {
func doGetHeader(v validatorPrivateData, boostEndpoint string, beaconNode Beacon, engineEndpoint string, builderSigningDomain phase0.Domain) builderSpec.VersionedSignedBuilderBid {
// Mergemock needs to call forkchoice update before getHeader, for non-mergemock beacon node this is a no-op
err := beaconNode.onGetHeader()
if err != nil {
Expand All @@ -71,7 +71,7 @@ func doGetHeader(v validatorPrivateData, boostEndpoint string, beaconNode Beacon

uri := fmt.Sprintf("%s/eth/v1/builder/header/%d/%s/%s", boostEndpoint, currentBlock.Slot+1, currentBlockHash, v.Pk.String())

var getHeaderResp spec.VersionedSignedBuilderBid
var getHeaderResp builderSpec.VersionedSignedBuilderBid
if _, err := server.SendHTTPRequest(context.TODO(), *http.DefaultClient, http.MethodGet, uri, "test-cli", nil, nil, &getHeaderResp); err != nil {
log.WithError(err).WithField("currentBlockHash", currentBlockHash).Fatal("Could not get header")
}
Expand All @@ -95,12 +95,12 @@ func doGetHeader(v validatorPrivateData, boostEndpoint string, beaconNode Beacon
func doGetPayload(v validatorPrivateData, boostEndpoint string, beaconNode Beacon, engineEndpoint string, builderSigningDomain, proposerSigningDomain phase0.Domain) {
header := doGetHeader(v, boostEndpoint, beaconNode, engineEndpoint, builderSigningDomain)

blindedBeaconBlock := capella.BlindedBeaconBlock{
blindedBeaconBlock := eth2ApiV1Capella.BlindedBeaconBlock{
Slot: 0,
ProposerIndex: 0,
ParentRoot: phase0.Root{},
StateRoot: phase0.Root{},
Body: &capella.BlindedBeaconBlockBody{
Body: &eth2ApiV1Capella.BlindedBeaconBlockBody{
RANDAOReveal: phase0.BLSSignature{},
ETH1Data: &phase0.ETH1Data{},
Graffiti: phase0.Hash32{},
Expand All @@ -119,11 +119,11 @@ func doGetPayload(v validatorPrivateData, boostEndpoint string, beaconNode Beaco
log.WithError(err).Fatal("could not sign blinded beacon block")
}

payload := capella.SignedBlindedBeaconBlock{
payload := eth2ApiV1Capella.SignedBlindedBeaconBlock{
Message: &blindedBeaconBlock,
Signature: signature,
}
var respPayload api.VersionedExecutionPayload
var respPayload builderApi.VersionedExecutionPayload
if _, err := server.SendHTTPRequest(context.TODO(), *http.DefaultClient, http.MethodPost, boostEndpoint+"/eth/v1/builder/blinded_blocks", "test-cli", nil, payload, &respPayload); err != nil {
log.WithError(err).Fatal("could not get payload")
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/test-cli/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"time"

apiv1 "github.com/attestantio/go-builder-client/api/v1"
builderApiV1 "github.com/attestantio/go-builder-client/api/v1"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/flashbots/go-boost-utils/bls"
Expand Down Expand Up @@ -52,29 +52,29 @@ func newRandomValidator(gasLimit uint64, feeRecipient string) validatorPrivateDa
return validatorPrivateData{bls.SecretKeyToBytes(sk), bls.PublicKeyToBytes(pk), hexutil.Uint64(gasLimit), feeRecipient}
}

func (v *validatorPrivateData) PrepareRegistrationMessage(builderSigningDomain phase0.Domain) ([]apiv1.SignedValidatorRegistration, error) {
func (v *validatorPrivateData) PrepareRegistrationMessage(builderSigningDomain phase0.Domain) ([]builderApiV1.SignedValidatorRegistration, error) {
pk := phase0.BLSPubKey{}
if len(v.Pk) != len(pk) {
return []apiv1.SignedValidatorRegistration{}, errInvalidLength
return []builderApiV1.SignedValidatorRegistration{}, errInvalidLength
}
copy(pk[:], v.Pk)

addr, err := utils.HexToAddress(v.FeeRecipientHex)
if err != nil {
return []apiv1.SignedValidatorRegistration{}, err
return []builderApiV1.SignedValidatorRegistration{}, err
}
msg := apiv1.ValidatorRegistration{
msg := builderApiV1.ValidatorRegistration{
FeeRecipient: addr,
Timestamp: time.Now(),
Pubkey: pk,
GasLimit: uint64(v.GasLimit),
}
signature, err := v.Sign(&msg, builderSigningDomain)
if err != nil {
return []apiv1.SignedValidatorRegistration{}, err
return []builderApiV1.SignedValidatorRegistration{}, err
}

return []apiv1.SignedValidatorRegistration{{
return []builderApiV1.SignedValidatorRegistration{{
Message: &msg,
Signature: signature,
}}, nil
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module github.com/flashbots/mev-boost
go 1.20

require (
github.com/ethereum/go-ethereum v1.13.9
github.com/flashbots/go-boost-utils v1.7.1
github.com/ethereum/go-ethereum v1.13.10
github.com/flashbots/go-boost-utils v1.8.0
github.com/flashbots/go-utils v0.5.0
github.com/google/uuid v1.5.0
github.com/gorilla/mux v1.8.1
github.com/gorilla/mux v1.8.0
github.com/holiman/uint256 v1.2.4
github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7
github.com/sirupsen/logrus v1.9.3
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw=
github.com/ethereum/c-kzg-4844 v0.4.0 h1:3MS1s4JtA868KpJxroZoepdV0ZKBp3u/O5HcZ7R3nlY=
github.com/ethereum/c-kzg-4844 v0.4.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
github.com/ethereum/go-ethereum v1.13.9 h1:ed4e4c7NWPrO2VX2wsMhWs5+6Lf2D591DmdE8RgmtcU=
github.com/ethereum/go-ethereum v1.13.9/go.mod h1:sc48XYQxCzH3fG9BcrXCOOgQk2JfZzNAmIKnceogzsA=
github.com/ethereum/go-ethereum v1.13.10 h1:Ppdil79nN+Vc+mXfge0AuUgmKWuVv4eMqzoIVSdqZek=
github.com/ethereum/go-ethereum v1.13.10/go.mod h1:sc48XYQxCzH3fG9BcrXCOOgQk2JfZzNAmIKnceogzsA=
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/ferranbt/fastssz v0.1.3 h1:ZI+z3JH05h4kgmFXdHuR1aWYsgrg7o+Fw7/NCzM16Mo=
github.com/ferranbt/fastssz v0.1.3/go.mod h1:0Y9TEd/9XuFlh7mskMPfXiI2Dkw4Ddg9EyXt1W7MRvE=
github.com/flashbots/go-boost-utils v1.7.1 h1:JN0JFOCuuQoPhyZEaFxFHC2dWVScixItJ2nijzfE6IQ=
github.com/flashbots/go-boost-utils v1.7.1/go.mod h1:O2LUD1QAqi1oMzU1mtj7f1NMunNySJizQGrw7xujSe8=
github.com/flashbots/go-boost-utils v1.8.0 h1:z3K1hw+Fbl9AGMNQKnK7Bvf0M/rKgjfruAEvra+Z8Mg=
github.com/flashbots/go-boost-utils v1.8.0/go.mod h1:Ry1Rw8Lx5v1rpAR0+IvR4sV10jYAeQaGVM3vRD8mYdM=
github.com/flashbots/go-utils v0.5.0 h1:ldjWta9B9//DJU2QcwRbErez3+1aKhSn6EoFc6d5kPY=
github.com/flashbots/go-utils v0.5.0/go.mod h1:LauDwifaRdSK0mS5X34GR59pJtUu1T/lOFNdff1BqtI=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down Expand Up @@ -174,8 +174,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
Expand Down
71 changes: 37 additions & 34 deletions server/mock_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
"testing"
"time"

"github.com/attestantio/go-builder-client/api"
apibellatrix "github.com/attestantio/go-builder-client/api/bellatrix"
apicapella "github.com/attestantio/go-builder-client/api/capella"
apiv1 "github.com/attestantio/go-builder-client/api/v1"
"github.com/attestantio/go-builder-client/spec"
consensusspec "github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/bellatrix"
builderApi "github.com/attestantio/go-builder-client/api"
builderApiCapella "github.com/attestantio/go-builder-client/api/capella"
builderApiDeneb "github.com/attestantio/go-builder-client/api/deneb"
builderApiV1 "github.com/attestantio/go-builder-client/api/v1"
builderSpec "github.com/attestantio/go-builder-client/spec"
"github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/capella"
"github.com/attestantio/go-eth2-client/spec/deneb"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/flashbots/go-boost-utils/bls"
Expand Down Expand Up @@ -59,8 +59,8 @@ type mockRelay struct {
handlerOverrideGetPayload func(w http.ResponseWriter, req *http.Request)

// Default responses placeholders, used if overrider does not exist
GetHeaderResponse *spec.VersionedSignedBuilderBid
GetPayloadResponse *api.VersionedExecutionPayload
GetHeaderResponse *builderSpec.VersionedSignedBuilderBid
GetPayloadResponse *builderApi.VersionedSubmitBlindedBlockResponse

// Server section
Server *httptest.Server
Expand Down Expand Up @@ -141,7 +141,7 @@ func (m *mockRelay) handleStatus(w http.ResponseWriter, _ *http.Request) {
fmt.Fprintf(w, `{}`)
}

// By default, handleRegisterValidator returns a default apiv1.SignedValidatorRegistration
// By default, handleRegisterValidator returns a default builderApiV1.SignedValidatorRegistration
func (m *mockRelay) handleRegisterValidator(w http.ResponseWriter, req *http.Request) {
m.mu.Lock()
defer m.mu.Unlock()
Expand All @@ -154,7 +154,7 @@ func (m *mockRelay) handleRegisterValidator(w http.ResponseWriter, req *http.Req

// defaultHandleRegisterValidator returns the default handler for handleRegisterValidator
func (m *mockRelay) defaultHandleRegisterValidator(w http.ResponseWriter, req *http.Request) {
payload := []apiv1.SignedValidatorRegistration{}
payload := []builderApiV1.SignedValidatorRegistration{}
if err := DecodeJSON(req.Body, &payload); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
Expand All @@ -166,14 +166,15 @@ func (m *mockRelay) defaultHandleRegisterValidator(w http.ResponseWriter, req *h

// MakeGetHeaderResponse is used to create the default or can be used to create a custom response to the getHeader
// method
func (m *mockRelay) MakeGetHeaderResponse(value uint64, blockHash, parentHash, publicKey string, version consensusspec.DataVersion) *spec.VersionedSignedBuilderBid {
func (m *mockRelay) MakeGetHeaderResponse(value uint64, blockHash, parentHash, publicKey string, version spec.DataVersion) *builderSpec.VersionedSignedBuilderBid {
switch version {
case consensusspec.DataVersionBellatrix:
case spec.DataVersionCapella:
// Fill the payload with custom values.
message := &apibellatrix.BuilderBid{
Header: &bellatrix.ExecutionPayloadHeader{
BlockHash: _HexToHash(blockHash),
ParentHash: _HexToHash(parentHash),
message := &builderApiCapella.BuilderBid{
Header: &capella.ExecutionPayloadHeader{
BlockHash: _HexToHash(blockHash),
ParentHash: _HexToHash(parentHash),
WithdrawalsRoot: phase0.Root{},
},
Value: uint256.NewInt(value),
Pubkey: _HexToPubkey(publicKey),
Expand All @@ -183,37 +184,38 @@ func (m *mockRelay) MakeGetHeaderResponse(value uint64, blockHash, parentHash, p
signature, err := ssz.SignMessage(message, ssz.DomainBuilder, m.secretKey)
require.NoError(m.t, err)

return &spec.VersionedSignedBuilderBid{
Version: consensusspec.DataVersionCapella,
Bellatrix: &apibellatrix.SignedBuilderBid{
return &builderSpec.VersionedSignedBuilderBid{
Version: spec.DataVersionCapella,
Capella: &builderApiCapella.SignedBuilderBid{
Message: message,
Signature: signature,
},
}
case consensusspec.DataVersionCapella:
// Fill the payload with custom values.
message := &apicapella.BuilderBid{
Header: &capella.ExecutionPayloadHeader{
case spec.DataVersionDeneb:
message := &builderApiDeneb.BuilderBid{
Header: &deneb.ExecutionPayloadHeader{
BlockHash: _HexToHash(blockHash),
ParentHash: _HexToHash(parentHash),
WithdrawalsRoot: phase0.Root{},
BaseFeePerGas: uint256.NewInt(0),
},
Value: uint256.NewInt(value),
Pubkey: _HexToPubkey(publicKey),
BlobKZGCommitments: make([]deneb.KZGCommitment, 0),
Value: uint256.NewInt(value),
Pubkey: _HexToPubkey(publicKey),
}

// Sign the message.
signature, err := ssz.SignMessage(message, ssz.DomainBuilder, m.secretKey)
require.NoError(m.t, err)

return &spec.VersionedSignedBuilderBid{
Version: consensusspec.DataVersionCapella,
Capella: &apicapella.SignedBuilderBid{
return &builderSpec.VersionedSignedBuilderBid{
Version: spec.DataVersionDeneb,
Deneb: &builderApiDeneb.SignedBuilderBid{
Message: message,
Signature: signature,
},
}
case consensusspec.DataVersionUnknown, consensusspec.DataVersionPhase0, consensusspec.DataVersionAltair, consensusspec.DataVersionDeneb:
case spec.DataVersionUnknown, spec.DataVersionPhase0, spec.DataVersionAltair, spec.DataVersionBellatrix:
return nil
}
return nil
Expand Down Expand Up @@ -243,7 +245,7 @@ func (m *mockRelay) defaultHandleGetHeader(w http.ResponseWriter) {
"0xe28385e7bd68df656cd0042b74b69c3104b5356ed1f20eb69f1f925df47a3ab7",
"0xe28385e7bd68df656cd0042b74b69c3104b5356ed1f20eb69f1f925df47a3ab7",
"0x8a1d7b8dd64e0aafe7ea7b6c95065c9364cf99d38470c12ee807d55f7de1529ad29ce2c422e0b65e3d5a05c02caca249",
consensusspec.DataVersionCapella,
spec.DataVersionCapella,
)
if m.GetHeaderResponse != nil {
response = m.GetHeaderResponse
Expand All @@ -257,9 +259,9 @@ func (m *mockRelay) defaultHandleGetHeader(w http.ResponseWriter) {

// MakeGetPayloadResponse is used to create the default or can be used to create a custom response to the getPayload
// method
func (m *mockRelay) MakeGetPayloadResponse(parentHash, blockHash, feeRecipient string, blockNumber uint64) *api.VersionedExecutionPayload {
return &api.VersionedExecutionPayload{
Version: consensusspec.DataVersionCapella,
func (m *mockRelay) MakeGetPayloadResponse(parentHash, blockHash, feeRecipient string, blockNumber uint64, version spec.DataVersion) *builderApi.VersionedSubmitBlindedBlockResponse {
return &builderApi.VersionedSubmitBlindedBlockResponse{
Version: version,
Capella: &capella.ExecutionPayload{
ParentHash: _HexToHash(parentHash),
BlockHash: _HexToHash(blockHash),
Expand Down Expand Up @@ -294,6 +296,7 @@ func (m *mockRelay) defaultHandleGetPayload(w http.ResponseWriter) {
"0x534809bd2b6832edff8d8ce4cb0e50068804fd1ef432c8362ad708a74fdc0e46",
"0xdb65fEd33dc262Fe09D9a2Ba8F80b329BA25f941",
12345,
spec.DataVersionCapella,
)

if m.GetPayloadResponse != nil {
Expand Down
4 changes: 2 additions & 2 deletions server/mock_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package server
import (
"testing"

capellaapi "github.com/attestantio/go-builder-client/api/capella"
builderApiCapella "github.com/attestantio/go-builder-client/api/capella"
"github.com/attestantio/go-eth2-client/spec/bellatrix"
"github.com/attestantio/go-eth2-client/spec/capella"
"github.com/attestantio/go-eth2-client/spec/phase0"
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestHexToSignature(t *testing.T) {

publicKey := hexutil.Encode(bls.PublicKeyToBytes(blsPublicKey))

message := &capellaapi.BuilderBid{
message := &builderApiCapella.BuilderBid{
Header: &capella.ExecutionPayloadHeader{
BlockHash: _HexToHash("0xe28385e7bd68df656cd0042b74b69c3104b5356ed1f20eb69f1f925df47a3ab7"),
},
Expand Down
Loading
Loading