diff --git a/.golangci.yaml b/.golangci.yaml index deccbb86..7abd2052 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -71,8 +71,6 @@ linters-settings: gomoddirectives: replace-allow-list: - github.com/attestantio/go-eth2-client - - github.com/attestantio/go-builder-client - - github.com/ethereum/go-ethereum maintidx: under: 5 diff --git a/common/types.go b/common/types.go index f4901f74..20ee6138 100644 --- a/common/types.go +++ b/common/types.go @@ -12,6 +12,7 @@ import ( "github.com/attestantio/go-eth2-client/spec/capella" "github.com/attestantio/go-eth2-client/spec/phase0" ssz "github.com/ferranbt/fastssz" + boostSsz "github.com/flashbots/go-boost-utils/ssz" boostTypes "github.com/flashbots/go-boost-utils/types" "github.com/holiman/uint256" ) @@ -92,22 +93,22 @@ func NewEthNetworkDetails(networkName string) (ret *EthNetworkDetails, err error return nil, fmt.Errorf("%w: %s", ErrUnknownNetwork, networkName) } - domainBuilder, err = ComputeDomain(ssz.DomainTypeAppBuilder, genesisForkVersion, phase0.Root{}.String()) + domainBuilder, err = ComputeDomain(boostSsz.DomainTypeAppBuilder, genesisForkVersion, phase0.Root{}.String()) if err != nil { return nil, err } - domainBeaconProposerBellatrix, err = ComputeDomain(ssz.DomainTypeBeaconProposer, bellatrixForkVersion, genesisValidatorsRoot) + domainBeaconProposerBellatrix, err = ComputeDomain(boostSsz.DomainTypeBeaconProposer, bellatrixForkVersion, genesisValidatorsRoot) if err != nil { return nil, err } - domainBeaconProposerCapella, err = ComputeDomain(ssz.DomainTypeBeaconProposer, capellaForkVersion, genesisValidatorsRoot) + domainBeaconProposerCapella, err = ComputeDomain(boostSsz.DomainTypeBeaconProposer, capellaForkVersion, genesisValidatorsRoot) if err != nil { return nil, err } - domainBeaconProposerDeneb, err = ComputeDomain(ssz.DomainTypeBeaconProposer, denebForkVersion, genesisValidatorsRoot) + domainBeaconProposerDeneb, err = ComputeDomain(boostSsz.DomainTypeBeaconProposer, denebForkVersion, genesisValidatorsRoot) if err != nil { return nil, err } @@ -341,11 +342,11 @@ Header only layout: [344-944) = EPH (600 bytes) */ type SubmitBlockRequestV2Optimistic struct { - Message *apiv1.BidTrace - ExecutionPayloadHeader *consensuscapella.ExecutionPayloadHeader - Signature phase0.BLSSignature `ssz-size:"96"` - Transactions []consensusbellatrix.Transaction `ssz-max:"1048576,1073741824" ssz-size:"?,?"` - Withdrawals []*consensuscapella.Withdrawal `ssz-max:"16"` + Message *builderApiV1.BidTrace + ExecutionPayloadHeader *capella.ExecutionPayloadHeader + Signature phase0.BLSSignature `ssz-size:"96"` + Transactions []bellatrix.Transaction `ssz-max:"1048576,1073741824" ssz-size:"?,?"` + Withdrawals []*capella.Withdrawal `ssz-max:"16"` } // MarshalSSZ ssz marshals the SubmitBlockRequestV2Optimistic object @@ -366,7 +367,7 @@ func (s *SubmitBlockRequestV2Optimistic) UnmarshalSSZ(buf []byte) error { // Field (0) 'Message' if s.Message == nil { - s.Message = new(apiv1.BidTrace) + s.Message = new(builderApiV1.BidTrace) } if err = s.Message.UnmarshalSSZ(buf[0:236]); err != nil { return err @@ -398,7 +399,7 @@ func (s *SubmitBlockRequestV2Optimistic) UnmarshalSSZ(buf []byte) error { { buf = tail[o1:o3] if s.ExecutionPayloadHeader == nil { - s.ExecutionPayloadHeader = new(consensuscapella.ExecutionPayloadHeader) + s.ExecutionPayloadHeader = new(capella.ExecutionPayloadHeader) } if err = s.ExecutionPayloadHeader.UnmarshalSSZ(buf); err != nil { return err @@ -412,13 +413,13 @@ func (s *SubmitBlockRequestV2Optimistic) UnmarshalSSZ(buf []byte) error { if err != nil { return err } - s.Transactions = make([]consensusbellatrix.Transaction, num) + s.Transactions = make([]bellatrix.Transaction, num) err = ssz.UnmarshalDynamic(buf, num, func(indx int, buf []byte) (err error) { if len(buf) > 1073741824 { return ssz.ErrBytesLength } if cap(s.Transactions[indx]) == 0 { - s.Transactions[indx] = consensusbellatrix.Transaction(make([]byte, 0, len(buf))) + s.Transactions[indx] = bellatrix.Transaction(make([]byte, 0, len(buf))) } s.Transactions[indx] = append(s.Transactions[indx], buf...) return nil @@ -435,10 +436,10 @@ func (s *SubmitBlockRequestV2Optimistic) UnmarshalSSZ(buf []byte) error { if err != nil { return err } - s.Withdrawals = make([]*consensuscapella.Withdrawal, num) + s.Withdrawals = make([]*capella.Withdrawal, num) for ii := 0; ii < num; ii++ { if s.Withdrawals[ii] == nil { - s.Withdrawals[ii] = new(consensuscapella.Withdrawal) + s.Withdrawals[ii] = new(capella.Withdrawal) } if err = s.Withdrawals[ii].UnmarshalSSZ(buf[ii*44 : (ii+1)*44]); err != nil { return err @@ -461,7 +462,7 @@ func (s *SubmitBlockRequestV2Optimistic) UnmarshalSSZHeaderOnly(buf []byte) erro // Field (0) 'Message' if s.Message == nil { - s.Message = new(apiv1.BidTrace) + s.Message = new(builderApiV1.BidTrace) } if err = s.Message.UnmarshalSSZ(buf[0:236]); err != nil { return err @@ -488,7 +489,7 @@ func (s *SubmitBlockRequestV2Optimistic) UnmarshalSSZHeaderOnly(buf []byte) erro { buf = tail[o1:o3] if s.ExecutionPayloadHeader == nil { - s.ExecutionPayloadHeader = new(consensuscapella.ExecutionPayloadHeader) + s.ExecutionPayloadHeader = new(capella.ExecutionPayloadHeader) } if err = s.ExecutionPayloadHeader.UnmarshalSSZ(buf); err != nil { return err @@ -504,7 +505,7 @@ func (s *SubmitBlockRequestV2Optimistic) MarshalSSZTo(buf []byte) (dst []byte, e // Field (0) 'Message' if s.Message == nil { - s.Message = new(apiv1.BidTrace) + s.Message = new(builderApiV1.BidTrace) } if dst, err = s.Message.MarshalSSZTo(dst); err != nil { return @@ -513,7 +514,7 @@ func (s *SubmitBlockRequestV2Optimistic) MarshalSSZTo(buf []byte) (dst []byte, e // Offset (1) 'ExecutionPayloadHeader' dst = ssz.WriteOffset(dst, offset) if s.ExecutionPayloadHeader == nil { - s.ExecutionPayloadHeader = new(consensuscapella.ExecutionPayloadHeader) + s.ExecutionPayloadHeader = new(capella.ExecutionPayloadHeader) } offset += s.ExecutionPayloadHeader.SizeSSZ() @@ -574,7 +575,7 @@ func (s *SubmitBlockRequestV2Optimistic) SizeSSZ() (size int) { // Field (1) 'ExecutionPayloadHeader' if s.ExecutionPayloadHeader == nil { - s.ExecutionPayloadHeader = new(consensuscapella.ExecutionPayloadHeader) + s.ExecutionPayloadHeader = new(capella.ExecutionPayloadHeader) } size += s.ExecutionPayloadHeader.SizeSSZ() diff --git a/common/types_spec.go b/common/types_spec.go index 59348d65..4cb7068e 100644 --- a/common/types_spec.go +++ b/common/types_spec.go @@ -9,8 +9,8 @@ import ( builderApiDeneb "github.com/attestantio/go-builder-client/api/deneb" builderSpec "github.com/attestantio/go-builder-client/spec" eth2Api "github.com/attestantio/go-eth2-client/api" - eth2ApiV1Capella "github.com/attestantio/go-eth2-client/api/v1/capella" - eth2ApiV1Deneb "github.com/attestantio/go-eth2-client/api/v1/deneb" + eth2builderApiV1Capella "github.com/attestantio/go-eth2-client/api/v1/capella" + eth2builderApiV1Deneb "github.com/attestantio/go-eth2-client/api/v1/deneb" "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/capella" "github.com/attestantio/go-eth2-client/spec/deneb" @@ -197,7 +197,7 @@ func SignedBlindedBeaconBlockToBeaconBlock(signedBlindedBeaconBlock *VersionedSi return &signedBeaconBlock, nil } -func CapellaUnblindSignedBlock(blindedBlock *eth2ApiV1Capella.SignedBlindedBeaconBlock, executionPayload *capella.ExecutionPayload) *capella.SignedBeaconBlock { +func CapellaUnblindSignedBlock(blindedBlock *eth2builderApiV1Capella.SignedBlindedBeaconBlock, executionPayload *capella.ExecutionPayload) *capella.SignedBeaconBlock { return &capella.SignedBeaconBlock{ Signature: blindedBlock.Signature, Message: &capella.BeaconBlock{ @@ -222,7 +222,7 @@ func CapellaUnblindSignedBlock(blindedBlock *eth2ApiV1Capella.SignedBlindedBeaco } } -func DenebUnblindSignedBlock(blindedBlock *eth2ApiV1Deneb.SignedBlindedBeaconBlock, blockPayload *builderApiDeneb.ExecutionPayloadAndBlobsBundle, blockRoot phase0.Root) *eth2ApiV1Deneb.SignedBlockContents { +func DenebUnblindSignedBlock(blindedBlock *eth2builderApiV1Deneb.SignedBlindedBeaconBlock, blockPayload *builderApiDeneb.ExecutionPayloadAndBlobsBundle, blockRoot phase0.Root) *eth2builderApiV1Deneb.SignedBlockContents { denebBlobSidecars := make([]*deneb.SignedBlobSidecar, len(blockPayload.BlobsBundle.Blobs)) for i := range denebBlobSidecars { @@ -240,7 +240,7 @@ func DenebUnblindSignedBlock(blindedBlock *eth2ApiV1Deneb.SignedBlindedBeaconBlo Signature: denebBlobSidecars[i].Signature, } } - return ð2ApiV1Deneb.SignedBlockContents{ + return ð2builderApiV1Deneb.SignedBlockContents{ SignedBlock: &deneb.SignedBeaconBlock{ Message: &deneb.BeaconBlock{ Slot: blindedBlock.Message.Slot, @@ -365,7 +365,7 @@ func (r *VersionedSignedBlockRequest) MarshalJSON() ([]byte, error) { func (r *VersionedSignedBlockRequest) UnmarshalJSON(input []byte) error { var err error - denebContents := new(eth2ApiV1Deneb.SignedBlockContents) + denebContents := new(eth2builderApiV1Deneb.SignedBlockContents) if err = json.Unmarshal(input, denebContents); err == nil { r.Version = spec.DataVersionDeneb r.Deneb = denebContents @@ -401,14 +401,14 @@ func (r *VersionedSignedBlindedBlockRequest) MarshalJSON() ([]byte, error) { func (r *VersionedSignedBlindedBlockRequest) UnmarshalJSON(input []byte) error { var err error - denebContents := new(eth2ApiV1Deneb.SignedBlindedBlockContents) + denebContents := new(eth2builderApiV1Deneb.SignedBlindedBlockContents) if err = json.Unmarshal(input, denebContents); err == nil { r.Version = spec.DataVersionDeneb r.Deneb = denebContents return nil } - capellaBlock := new(eth2ApiV1Capella.SignedBlindedBeaconBlock) + capellaBlock := new(eth2builderApiV1Capella.SignedBlindedBeaconBlock) if err = json.Unmarshal(input, capellaBlock); err == nil { r.Version = spec.DataVersionCapella r.Capella = capellaBlock diff --git a/common/types_test.go b/common/types_test.go index f775fefb..f75d870e 100644 --- a/common/types_test.go +++ b/common/types_test.go @@ -1,56 +1,55 @@ package common import ( - "encoding/hex" "testing" - v1 "github.com/attestantio/go-builder-client/api/v1" - consensusspec "github.com/attestantio/go-eth2-client/spec" + builderApiV1 "github.com/attestantio/go-builder-client/api/v1" + "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/bellatrix" "github.com/attestantio/go-eth2-client/spec/capella" "github.com/attestantio/go-eth2-client/spec/phase0" - boostTypes "github.com/flashbots/go-boost-utils/types" + "github.com/flashbots/go-boost-utils/utils" "github.com/holiman/uint256" "github.com/stretchr/testify/require" ) func makeTestSubmitBlockRequestV2Optimistic(t *testing.T) *SubmitBlockRequestV2Optimistic { t.Helper() - testParentHash, err := hex.DecodeString("ec51bd499a3fa0270f1446fbf05ff0b61157cfe4ec719bb4c3e834e339ee9c5c") + testParentHash, err := utils.HexToHash("0xec51bd499a3fa0270f1446fbf05ff0b61157cfe4ec719bb4c3e834e339ee9c5c") require.Nil(t, err) - testBlockHash, err := hex.DecodeString("3f5b5aaa800a3d25c3f75e72dc45da89fdd58168f1358a9f94aac8b029361a0a") + testBlockHash, err := utils.HexToHash("0x3f5b5aaa800a3d25c3f75e72dc45da89fdd58168f1358a9f94aac8b029361a0a") require.Nil(t, err) - testRandao, err := hex.DecodeString("8cf6b7fbfbaf80da001fe769fd02e9b8dbfa0a646d9cf51b5d7137dd4f8103cc") + testRandao, err := utils.HexToHash("0x8cf6b7fbfbaf80da001fe769fd02e9b8dbfa0a646d9cf51b5d7137dd4f8103cc") require.Nil(t, err) - testRoot, err := hex.DecodeString("7554727cee6d976a1dfdad80b392b37c87f0651ff5b01f6a0b3402bcfce92077") + testRoot, err := utils.HexToHash("0x7554727cee6d976a1dfdad80b392b37c87f0651ff5b01f6a0b3402bcfce92077") require.Nil(t, err) - testBuilderPubkey, err := hex.DecodeString("ae7bde4839fa905b7d8125fd84cfdcd0c32cd74e1be3fa24263d71b520fc78113326ce0a90b95d73f19e6d8150a2f73b") + testBuilderPubkey, err := utils.HexToPubkey("0xae7bde4839fa905b7d8125fd84cfdcd0c32cd74e1be3fa24263d71b520fc78113326ce0a90b95d73f19e6d8150a2f73b") require.Nil(t, err) - testProposerPubkey, err := hex.DecodeString("bb8e223239fa905b7d8125fd84cfdcd0c32cd74e1be3fa24263d71b520fc78113326ce0a90b95d73f19e6d8150a2f73b") + testProposerPubkey, err := utils.HexToPubkey("0xbb8e223239fa905b7d8125fd84cfdcd0c32cd74e1be3fa24263d71b520fc78113326ce0a90b95d73f19e6d8150a2f73b") require.Nil(t, err) - testAddress, err := hex.DecodeString("95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5") + testAddress, err := utils.HexToAddress("0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5") require.Nil(t, err) - testSignature, err := hex.DecodeString("b06311be19c92307c06070578af9ad147c9c6ea902439eac19f785f3dca478c354b79a0af9b09839c3d06c1ccf2185b0162f4d4fbf981220f77586b52ed9ae8a8acfc953baaa30dee15e1b112913c6cbe02c780d7b5363a4af16563fe55c2e88") + testSignature, err := utils.HexToSignature("0xb06311be19c92307c06070578af9ad147c9c6ea902439eac19f785f3dca478c354b79a0af9b09839c3d06c1ccf2185b0162f4d4fbf981220f77586b52ed9ae8a8acfc953baaa30dee15e1b112913c6cbe02c780d7b5363a4af16563fe55c2e88") require.Nil(t, err) testValue := new(uint256.Int) err = testValue.SetFromDecimal("100") require.Nil(t, err) return &SubmitBlockRequestV2Optimistic{ - Message: &v1.BidTrace{ + Message: &builderApiV1.BidTrace{ Slot: 31, - ParentHash: phase0.Hash32(testParentHash), - BlockHash: phase0.Hash32(testBlockHash), - BuilderPubkey: phase0.BLSPubKey(testBuilderPubkey), - ProposerPubkey: phase0.BLSPubKey(testProposerPubkey), - ProposerFeeRecipient: bellatrix.ExecutionAddress(testAddress), + ParentHash: testParentHash, + BlockHash: testBlockHash, + BuilderPubkey: testBuilderPubkey, + ProposerPubkey: testProposerPubkey, + ProposerFeeRecipient: testAddress, GasLimit: 30_000_000, GasUsed: 15_000_000, Value: testValue, }, ExecutionPayloadHeader: &capella.ExecutionPayloadHeader{ - ParentHash: phase0.Hash32(testParentHash), - FeeRecipient: bellatrix.ExecutionAddress(testAddress), + ParentHash: testParentHash, + FeeRecipient: testAddress, StateRoot: [32]byte(testBlockHash), ReceiptsRoot: [32]byte(testBlockHash), LogsBloom: [256]byte{0xaa, 0xbb, 0xcc}, @@ -61,11 +60,11 @@ func makeTestSubmitBlockRequestV2Optimistic(t *testing.T) *SubmitBlockRequestV2O Timestamp: 168318215, ExtraData: make([]byte, 32), BaseFeePerGas: [32]byte{0xaa, 0xbb}, - BlockHash: phase0.Hash32(testBlockHash), + BlockHash: testBlockHash, TransactionsRoot: phase0.Root(testRoot), WithdrawalsRoot: phase0.Root(testRoot), }, - Signature: phase0.BLSSignature(testSignature), + Signature: testSignature, Transactions: []bellatrix.Transaction{ []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}, []byte{0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19}, @@ -78,35 +77,13 @@ func makeTestSubmitBlockRequestV2Optimistic(t *testing.T) *SubmitBlockRequestV2O { Index: capella.WithdrawalIndex(120), ValidatorIndex: phase0.ValidatorIndex(121), - Address: bellatrix.ExecutionAddress(testAddress), + Address: testAddress, Amount: phase0.Gwei(102412521125125), }, }, } } -func TestBoostBidToBidTrace(t *testing.T) { - bidTrace := boostTypes.BidTrace{ - Slot: uint64(25), - ParentHash: boostTypes.Hash{0x02, 0x03}, - BuilderPubkey: boostTypes.PublicKey{0x04, 0x05}, - ProposerPubkey: boostTypes.PublicKey{0x06, 0x07}, - ProposerFeeRecipient: boostTypes.Address{0x08, 0x09}, - GasLimit: uint64(50), - GasUsed: uint64(100), - Value: boostTypes.U256Str{0x0a}, - } - convertedBidTrace := BoostBidToBidTrace(&bidTrace) - require.Equal(t, bidTrace.Slot, convertedBidTrace.Slot) - require.Equal(t, phase0.Hash32(bidTrace.ParentHash), convertedBidTrace.ParentHash) - require.Equal(t, phase0.BLSPubKey(bidTrace.BuilderPubkey), convertedBidTrace.BuilderPubkey) - require.Equal(t, phase0.BLSPubKey(bidTrace.ProposerPubkey), convertedBidTrace.ProposerPubkey) - require.Equal(t, bellatrix.ExecutionAddress(bidTrace.ProposerFeeRecipient), convertedBidTrace.ProposerFeeRecipient) - require.Equal(t, bidTrace.GasLimit, convertedBidTrace.GasLimit) - require.Equal(t, bidTrace.GasUsed, convertedBidTrace.GasUsed) - require.Equal(t, bidTrace.Value.BigInt().String(), convertedBidTrace.Value.ToBig().String()) -} - func TestDataVersion(t *testing.T) { require.Equal(t, ForkVersionStringBellatrix, spec.DataVersionBellatrix.String()) require.Equal(t, ForkVersionStringCapella, spec.DataVersionCapella.String()) diff --git a/database/database_test.go b/database/database_test.go index 9e315bb5..dcff78d2 100644 --- a/database/database_test.go +++ b/database/database_test.go @@ -9,7 +9,7 @@ import ( builderApiV1 "github.com/attestantio/go-builder-client/api/v1" eth2Api "github.com/attestantio/go-eth2-client/api" - eth2ApiV1Deneb "github.com/attestantio/go-eth2-client/api/v1/deneb" + eth2builderApiV1Deneb "github.com/attestantio/go-eth2-client/api/v1/deneb" "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/bellatrix" "github.com/attestantio/go-eth2-client/spec/capella" @@ -374,7 +374,7 @@ func TestUpdateBuilderDemotion(t *testing.T) { beaconBlock: common.VersionedSignedBlockRequest{ VersionedBlockRequest: eth2Api.VersionedBlockRequest{ Version: spec.DataVersionDeneb, - Deneb: ð2ApiV1Deneb.SignedBlockContents{}, + Deneb: ð2builderApiV1Deneb.SignedBlockContents{}, }, }, }, diff --git a/go.mod b/go.mod index 02a85afb..6fb95a49 100644 --- a/go.mod +++ b/go.mod @@ -5,13 +5,13 @@ go 1.20 require ( github.com/NYTimes/gziphandler v1.1.1 github.com/alicebob/miniredis/v2 v2.30.5 - github.com/attestantio/go-builder-client v0.3.2-0.20230701110827-d0ecfee1ab62 - github.com/attestantio/go-eth2-client v0.18.1 + github.com/attestantio/go-builder-client v0.3.2-0.20230809093013-1fa02af241e1 + github.com/attestantio/go-eth2-client v0.18.3 github.com/bradfitz/gomemcache v0.0.0-20230124162541-5f7a7d875746 github.com/btcsuite/btcd/btcutil v1.1.2 github.com/buger/jsonparser v1.1.1 - github.com/ethereum/go-ethereum v1.13.1 - github.com/flashbots/go-boost-utils v1.7.1-0.20230625230411-8c44018f4777 + github.com/ethereum/go-ethereum v1.13.2 + github.com/flashbots/go-boost-utils v1.7.2-0.20230922193448-757aa4804cd5 github.com/flashbots/go-utils v0.5.0 github.com/go-redis/redis/v9 v9.0.0-rc.1 github.com/gorilla/mux v1.8.0 @@ -40,7 +40,7 @@ require ( github.com/cockroachdb/pebble v0.0.0-20230906160148-46873a6a7a06 // indirect github.com/cockroachdb/redact v1.1.3 // indirect github.com/consensys/bavard v0.1.13 // indirect - github.com/consensys/gnark-crypto v0.11.0 // indirect + github.com/consensys/gnark-crypto v0.11.2 // indirect github.com/crate-crypto/go-kzg-4844 v0.3.0 // indirect github.com/ethereum/c-kzg-4844 v0.3.1 // indirect github.com/fatih/color v1.15.0 // indirect @@ -120,8 +120,4 @@ retract ( v1.0.0-alpha1 ) -replace github.com/attestantio/go-builder-client => github.com/avalonche/go-builder-client v0.0.0-20230802220600-85be1e39d33b - replace github.com/attestantio/go-eth2-client => github.com/avalonche/go-eth2-client v0.0.0-20230810012152-c934f6ee3bee - -replace github.com/ethereum/go-ethereum => github.com/MariusVanDerWijden/go-ethereum v1.8.22-0.20230807121326-6861f29a109a diff --git a/go.sum b/go.sum index 5fe81afe..af86cbc5 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,6 @@ github.com/CloudyKit/jet/v3 v3.0.0/go.mod h1:HKQPgSJmdK8hdoAbKUUWajkHyHo4RaU5rMd github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8= github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY= -github.com/MariusVanDerWijden/go-ethereum v1.8.22-0.20230807121326-6861f29a109a h1:ccacEL6nX56gb/p5GnTG+bl+rIWCQqIWPx/YELbHPd4= -github.com/MariusVanDerWijden/go-ethereum v1.8.22-0.20230807121326-6861f29a109a/go.mod h1:zKetLweqBR8ZS+1O9iJWI8DvmmD2NzD19apjEWDCsnw= github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I= github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c= github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0= @@ -24,8 +22,8 @@ github.com/alicebob/miniredis/v2 v2.30.5/go.mod h1:b25qWj4fCEsBeAAR2mlb0ufImGC6u github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/avalonche/go-builder-client v0.0.0-20230802220600-85be1e39d33b h1:DNO0BuKEbXLabPbAw+EvojBfwYjHBWrqCF9xg/XPfqM= -github.com/avalonche/go-builder-client v0.0.0-20230802220600-85be1e39d33b/go.mod h1:8NZx9L/rC7nLhSMbbVR6PXr37tC28wTE4u65n+Pa3BQ= +github.com/attestantio/go-builder-client v0.3.2-0.20230809093013-1fa02af241e1 h1:c6Jmkd6mryaFuWv2/Pa4aLqi+2QOv3gEN+Krj0Nmiq4= +github.com/attestantio/go-builder-client v0.3.2-0.20230809093013-1fa02af241e1/go.mod h1:8NZx9L/rC7nLhSMbbVR6PXr37tC28wTE4u65n+Pa3BQ= github.com/avalonche/go-eth2-client v0.0.0-20230810012152-c934f6ee3bee h1:+Z2E/TGJW7k+MSPWPLvwsOm4SLcRgMeO02WUjDwC8OI= github.com/avalonche/go-eth2-client v0.0.0-20230810012152-c934f6ee3bee/go.mod h1:KSVlZSW1A3jUg5H8O89DLtqxgJprRfTtI7k89fLdhu0= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= @@ -85,8 +83,8 @@ github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZ github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= -github.com/consensys/gnark-crypto v0.11.0 h1:QqzHQlwEqlQr5jfWblGDkwlKHpT+4QodYqqExkAtyks= -github.com/consensys/gnark-crypto v0.11.0/go.mod h1:Iq/P3HHl0ElSjsg2E1gsMwhAyxnxoKK5nVyZKd+/KhU= +github.com/consensys/gnark-crypto v0.11.2 h1:GJjjtWJ+db1xGao7vTsOgAOGgjfPe7eRGPL+xxMX0qE= +github.com/consensys/gnark-crypto v0.11.2/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= @@ -118,14 +116,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.3.1 h1:sR65+68+WdnMKxseNWxSJuAv2tsUrihTpVBTfM/U5Zg= github.com/ethereum/c-kzg-4844 v0.3.1/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= +github.com/ethereum/go-ethereum v1.13.2 h1:g9mCpfPWqCA1OL4e6C98PeVttb0HadfBRuKTGvMnOvw= +github.com/ethereum/go-ethereum v1.13.2/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw= 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-0.20230625230411-8c44018f4777 h1:mnwpdE/JW74My5u3Ag1IMX8PgCa7aZwgFNPB20HN/DM= -github.com/flashbots/go-boost-utils v1.7.1-0.20230625230411-8c44018f4777/go.mod h1:Rckma9iiHGuw4PQj/BFV1ddN13lUib4sTfF3QUY40Z8= +github.com/flashbots/go-boost-utils v1.7.2-0.20230922193448-757aa4804cd5 h1:3OWpIpHHDd4bdOe+ZPGDuWefCkKctD6mVtgDkSHLkiA= +github.com/flashbots/go-boost-utils v1.7.2-0.20230922193448-757aa4804cd5/go.mod h1:gj0BOhAoMTTI/VVkAht+o2kMmSW7WqshyL9wY+lKKj4= 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= diff --git a/services/api/service.go b/services/api/service.go index d2c5c80a..dc67b019 100644 --- a/services/api/service.go +++ b/services/api/service.go @@ -20,6 +20,7 @@ import ( "time" "github.com/NYTimes/gziphandler" + builderApi "github.com/attestantio/go-builder-client/api" builderApiV1 "github.com/attestantio/go-builder-client/api/v1" "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/phase0" @@ -422,10 +423,6 @@ func (api *RelayAPI) StartServer() (err error) { } } - if !foundCapellaEpoch || !foundDenebEpoch { - return ErrMissingForkVersions - } - // Print fork version information if foundDenebEpoch && hasReachedFork(currentSlot, api.denebEpoch) { log.Infof("deneb fork detected (currentEpoch: %d / denebEpoch: %d)", common.SlotToEpoch(currentSlot), api.denebEpoch) @@ -1360,7 +1357,7 @@ func (api *RelayAPI) handleGetPayload(w http.ResponseWriter, req *http.Request) log = log.WithField("timestampAfterSignatureVerify", time.Now().UTC().UnixMilli()) log.Info("getPayload request received") - var getPayloadResp builderApiV1.VersionedExecutionPayload + var getPayloadResp *builderApi.VersionedSubmitBlindedBlockResponse var msNeededForPublishing uint64 // Save information about delivered payload @@ -1409,7 +1406,12 @@ func (api *RelayAPI) handleGetPayload(w http.ResponseWriter, req *http.Request) log.Warn("demotion found in getPayload, inserting refund justification") // Prepare refund data. - signedBeaconBlock := common.SignedBlindedBeaconBlockToBeaconBlock(payload, getPayloadResp) + signedBeaconBlock, err := common.SignedBlindedBeaconBlockToBeaconBlock(payload, getPayloadResp) + if err != nil { + log.WithError(err).Error("failed to convert signed blinded beacon block to beacon block") + api.RespondError(w, http.StatusInternalServerError, "failed to convert signed blinded beacon block to beacon block") + return + } // Get registration entry from the DB. registrationEntry, err := api.db.GetValidatorRegistration(proposerPubkey.String()) @@ -1420,7 +1422,7 @@ func (api *RelayAPI) handleGetPayload(w http.ResponseWriter, req *http.Request) log.WithError(err).Error("error reading validator registration") } } - var signedRegistration *apiv1.SignedValidatorRegistration + var signedRegistration *builderApiV1.SignedValidatorRegistration if registrationEntry != nil { signedRegistration, err = registrationEntry.ToSignedValidatorRegistration() if err != nil { @@ -1705,7 +1707,7 @@ type bidFloorOpts struct { log *logrus.Entry cancellationsEnabled bool simResultC chan *blockSimResult - payload *common.BuilderSubmitBlockRequest + submission *common.BlockSubmissionInfo } func (api *RelayAPI) checkFloorBidValue(opts bidFloorOpts) (*big.Int, bool) { @@ -1713,14 +1715,14 @@ func (api *RelayAPI) checkFloorBidValue(opts bidFloorOpts) (*big.Int, bool) { slotLastPayloadDelivered, err := api.redis.GetLastSlotDelivered(context.Background(), opts.tx) if err != nil && !errors.Is(err, redis.Nil) { opts.log.WithError(err).Error("failed to get delivered payload slot from redis") - } else if opts.payload.Slot() <= slotLastPayloadDelivered { + } else if opts.submission.Slot <= slotLastPayloadDelivered { opts.log.Info("rejecting submission because payload for this slot was already delivered") api.RespondError(opts.w, http.StatusBadRequest, "payload for this slot was already delivered") return nil, false } // Grab floor bid value - floorBidValue, err := api.redis.GetFloorBidValue(context.Background(), opts.tx, opts.payload.Slot(), opts.payload.ParentHash(), opts.payload.ProposerPubkey()) + floorBidValue, err := api.redis.GetFloorBidValue(context.Background(), opts.tx, opts.submission.Slot, opts.submission.ParentHash.String(), opts.submission.Proposer.String()) if err != nil { opts.log.WithError(err).Error("failed to get floor bid value from redis") } else { @@ -1730,12 +1732,12 @@ func (api *RelayAPI) checkFloorBidValue(opts bidFloorOpts) (*big.Int, bool) { // -------------------------------------------- // Skip submission if below the floor bid value // -------------------------------------------- - isBidBelowFloor := floorBidValue != nil && opts.payload.Value().Cmp(floorBidValue) == -1 - isBidAtOrBelowFloor := floorBidValue != nil && opts.payload.Value().Cmp(floorBidValue) < 1 + isBidBelowFloor := floorBidValue != nil && opts.submission.Value.ToBig().Cmp(floorBidValue) == -1 + isBidAtOrBelowFloor := floorBidValue != nil && opts.submission.Value.ToBig().Cmp(floorBidValue) < 1 if opts.cancellationsEnabled && isBidBelowFloor { // with cancellations: if below floor -> delete previous bid opts.simResultC <- &blockSimResult{false, false, nil, nil} opts.log.Info("submission below floor bid value, with cancellation") - err := api.redis.DelBuilderBid(context.Background(), opts.tx, opts.payload.Slot(), opts.payload.ParentHash(), opts.payload.ProposerPubkey(), opts.payload.BuilderPubkey().String()) + err := api.redis.DelBuilderBid(context.Background(), opts.tx, opts.submission.Slot, opts.submission.ParentHash.String(), opts.submission.Proposer.String(), opts.submission.Builder.String()) if err != nil { opts.log.WithError(err).Error("failed processing cancellable bid below floor") api.RespondError(opts.w, http.StatusInternalServerError, "failed processing cancellable bid below floor") @@ -1759,10 +1761,10 @@ type redisUpdateBidOpts struct { cancellationsEnabled bool receivedAt time.Time floorBidValue *big.Int - payload *common.BuilderSubmitBlockRequest + payload *common.VersionedSubmitBlockRequest } -func (api *RelayAPI) updateRedisBid(opts redisUpdateBidOpts) (*datastore.SaveBidAndUpdateTopBidResponse, *builderApiV1.VersionedExecutionPayload, bool) { +func (api *RelayAPI) updateRedisBid(opts redisUpdateBidOpts) (*datastore.SaveBidAndUpdateTopBidResponse, *builderApi.VersionedSubmitBlindedBlockResponse, bool) { // Prepare the response data getHeaderResponse, err := common.BuildGetHeaderResponse(opts.payload, api.blsSk, api.publicKey, api.opts.EthNetDetails.DomainBuilder) if err != nil { @@ -1778,10 +1780,17 @@ func (api *RelayAPI) updateRedisBid(opts redisUpdateBidOpts) (*datastore.SaveBid return nil, nil, false } + submission, err := common.GetBlockSubmissionInfo(opts.payload) + if err != nil { + opts.log.WithError(err).Error("could not get block submission info") + api.RespondError(opts.w, http.StatusBadRequest, err.Error()) + return nil, nil, false + } + bidTrace := common.BidTraceV2{ - BidTrace: *opts.payload.Message(), - BlockNumber: opts.payload.BlockNumber(), - NumTx: uint64(opts.payload.NumTx()), + BidTrace: *submission.BidTrace, + BlockNumber: submission.BlockNumber, + NumTx: uint64(len(submission.Transactions)), } // @@ -1970,13 +1979,20 @@ func (api *RelayAPI) handleSubmitNewBlock(w http.ResponseWriter, req *http.Reque simResultC := make(chan *blockSimResult, 1) var eligibleAt time.Time // will be set once the bid is ready + submission, err = common.GetBlockSubmissionInfo(payload) + if err != nil { + log.WithError(err).Warn("missing fields in submit block request") + api.RespondError(w, http.StatusBadRequest, err.Error()) + return + } + bfOpts := bidFloorOpts{ w: w, tx: tx, log: log, cancellationsEnabled: isCancellationEnabled, simResultC: simResultC, - payload: payload, + submission: submission, } floorBidValue, ok := api.checkFloorBidValue(bfOpts) if !ok { diff --git a/services/api/service_test.go b/services/api/service_test.go index a080ffe5..13a8e301 100644 --- a/services/api/service_test.go +++ b/services/api/service_test.go @@ -372,7 +372,7 @@ func TestBuilderSubmitBlock(t *testing.T) { // Setup the test relay backend backend.relay.headSlot.Store(headSlot) backend.relay.capellaEpoch = 0 - backend.relay.denebEpoch = 1 + backend.relay.denebEpoch = 2 backend.relay.proposerDutiesMap = make(map[uint64]*common.BuilderGetValidatorsResponseEntry) backend.relay.proposerDutiesMap[headSlot+1] = &common.BuilderGetValidatorsResponseEntry{ Slot: headSlot, @@ -887,13 +887,14 @@ func TestCheckFloorBidValue(t *testing.T) { { description: "success", payload: &common.VersionedSubmitBlockRequest{ - spec.VersionedSubmitBlockRequest{ - Version: consensusspec.DataVersionCapella, - Capella: &builderCapella.SubmitBlockRequest{ - Message: &apiv1.BidTrace{ + VersionedSubmitBlockRequest: builderSpec.VersionedSubmitBlockRequest{ + Version: spec.DataVersionCapella, + Capella: &builderApiCapella.SubmitBlockRequest{ + Message: &builderApiV1.BidTrace{ Slot: testSlot, Value: uint256.NewInt(1), }, + ExecutionPayload: &capella.ExecutionPayload{}, }, }, }, @@ -902,12 +903,13 @@ func TestCheckFloorBidValue(t *testing.T) { { description: "failure_slot_already_delivered", payload: &common.VersionedSubmitBlockRequest{ - spec.VersionedSubmitBlockRequest{ - Version: consensusspec.DataVersionCapella, - Capella: &builderCapella.SubmitBlockRequest{ - Message: &apiv1.BidTrace{ + VersionedSubmitBlockRequest: builderSpec.VersionedSubmitBlockRequest{ + Version: spec.DataVersionCapella, + Capella: &builderApiCapella.SubmitBlockRequest{ + Message: &builderApiV1.BidTrace{ Slot: 0, }, + ExecutionPayload: &capella.ExecutionPayload{}, }, }, }, @@ -916,13 +918,14 @@ func TestCheckFloorBidValue(t *testing.T) { { description: "failure_cancellations_below_floor", payload: &common.VersionedSubmitBlockRequest{ - spec.VersionedSubmitBlockRequest{ - Version: consensusspec.DataVersionCapella, - Capella: &builderCapella.SubmitBlockRequest{ - Message: &apiv1.BidTrace{ + VersionedSubmitBlockRequest: builderSpec.VersionedSubmitBlockRequest{ + Version: spec.DataVersionCapella, + Capella: &builderApiCapella.SubmitBlockRequest{ + Message: &builderApiV1.BidTrace{ Slot: testSlot, Value: uint256.NewInt(1), }, + ExecutionPayload: &capella.ExecutionPayload{}, }, }, }, @@ -933,13 +936,14 @@ func TestCheckFloorBidValue(t *testing.T) { { description: "failure_no_cancellations_at_floor", payload: &common.VersionedSubmitBlockRequest{ - spec.VersionedSubmitBlockRequest{ - Version: consensusspec.DataVersionCapella, - Capella: &builderCapella.SubmitBlockRequest{ - Message: &apiv1.BidTrace{ + VersionedSubmitBlockRequest: builderSpec.VersionedSubmitBlockRequest{ + Version: spec.DataVersionCapella, + Capella: &builderApiCapella.SubmitBlockRequest{ + Message: &builderApiV1.BidTrace{ Slot: testSlot, Value: uint256.NewInt(0), }, + ExecutionPayload: &capella.ExecutionPayload{}, }, }, }, @@ -959,13 +963,15 @@ func TestCheckFloorBidValue(t *testing.T) { log := logrus.NewEntry(logger) tx := backend.redis.NewTxPipeline() simResultC := make(chan *blockSimResult, 1) + submission, err = common.GetBlockSubmissionInfo(tc.payload) + require.NoError(t, err) bfOpts := bidFloorOpts{ w: w, tx: tx, log: log, cancellationsEnabled: tc.cancellationsEnabled, simResultC: simResultC, - payload: tc.payload, + submission: submission, } floor, ok := backend.relay.checkFloorBidValue(bfOpts) require.Equal(t, tc.expectOk, ok) @@ -989,10 +995,10 @@ func TestUpdateRedis(t *testing.T) { description: "success", floorValue: "10", payload: &common.VersionedSubmitBlockRequest{ - spec.VersionedSubmitBlockRequest{ - Version: consensusspec.DataVersionCapella, - Capella: &builderCapella.SubmitBlockRequest{ - Message: &apiv1.BidTrace{ + VersionedSubmitBlockRequest: builderSpec.VersionedSubmitBlockRequest{ + Version: spec.DataVersionCapella, + Capella: &builderApiCapella.SubmitBlockRequest{ + Message: &builderApiV1.BidTrace{ Slot: testSlot, Value: uint256.NewInt(1), }, @@ -1012,10 +1018,10 @@ func TestUpdateRedis(t *testing.T) { description: "failure_encode_failure_too_long_extra_data", floorValue: "10", payload: &common.VersionedSubmitBlockRequest{ - spec.VersionedSubmitBlockRequest{ - Version: consensusspec.DataVersionCapella, - Capella: &builderCapella.SubmitBlockRequest{ - Message: &apiv1.BidTrace{ + VersionedSubmitBlockRequest: builderSpec.VersionedSubmitBlockRequest{ + Version: spec.DataVersionCapella, + Capella: &builderApiCapella.SubmitBlockRequest{ + Message: &builderApiV1.BidTrace{ Slot: testSlot, Value: uint256.NewInt(1), },