From b9565e015163948dd295291cfa26231423c4860b Mon Sep 17 00:00:00 2001 From: avalonche Date: Thu, 1 Jun 2023 14:10:46 +1000 Subject: [PATCH 1/4] Update go-boost-utils and type upgrades --- beacon/engine/types.go | 19 +++-- builder/builder.go | 117 ++++++++++++---------------- builder/builder_test.go | 35 +++++---- builder/local_relay.go | 130 +++++++++++++++++++++---------- builder/local_relay_test.go | 101 ++++++++++++------------ builder/relay.go | 18 ++--- builder/relay_aggregator.go | 4 +- builder/relay_aggregator_test.go | 22 +++--- builder/relay_test.go | 8 +- builder/service.go | 19 +++-- builder/utils.go | 59 ++++++++++++++ builder/validator.go | 38 +++++---- eth/block-validation/api.go | 19 ++--- eth/block-validation/api_test.go | 35 ++++----- flashbotsextra/database.go | 4 +- flashbotsextra/database_test.go | 2 +- go.mod | 29 ++++--- go.sum | 55 +++++++------ 18 files changed, 419 insertions(+), 295 deletions(-) diff --git a/beacon/engine/types.go b/beacon/engine/types.go index 8d79d55c98..37a7dc73ac 100644 --- a/beacon/engine/types.go +++ b/beacon/engine/types.go @@ -20,13 +20,12 @@ import ( "fmt" "math/big" + "github.com/attestantio/go-eth2-client/spec/bellatrix" "github.com/attestantio/go-eth2-client/spec/capella" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/trie" - - boostTypes "github.com/flashbots/go-boost-utils/types" ) //go:generate go run github.com/fjl/gencodec -type PayloadAttributes -field-override payloadAttributesMarshaling -out gen_blockparams.go @@ -241,8 +240,8 @@ type ExecutionPayloadBodyV1 struct { Withdrawals []*types.Withdrawal `json:"withdrawals"` } -func ExecutionPayloadToBlock(payload *boostTypes.ExecutionPayload) (*types.Block, error) { - // TODO: separate decode function to avoid allocating twice +func ExecutionPayloadToBlock(payload *bellatrix.ExecutionPayload) (*types.Block, error) { + // TODO: consolidate this into one function that handles all forks transactionBytes := make([][]byte, len(payload.Transactions)) for i, txHexBytes := range payload.Transactions { transactionBytes[i] = txHexBytes[:] @@ -252,6 +251,14 @@ func ExecutionPayloadToBlock(payload *boostTypes.ExecutionPayload) (*types.Block return nil, err } + // base fee per gas is stored little-endian but we need it + // big-endian for big.Int. + var baseFeePerGasBytes [32]byte + for i := 0; i < 32; i++ { + baseFeePerGasBytes[i] = payload.BaseFeePerGas[32-1-i] + } + baseFeePerGas := new(big.Int).SetBytes(baseFeePerGasBytes[:]) + header := &types.Header{ ParentHash: common.Hash(payload.ParentHash), UncleHash: types.EmptyUncleHash, @@ -265,9 +272,9 @@ func ExecutionPayloadToBlock(payload *boostTypes.ExecutionPayload) (*types.Block GasLimit: payload.GasLimit, GasUsed: payload.GasUsed, Time: payload.Timestamp, - BaseFee: payload.BaseFeePerGas.BigInt(), + BaseFee: baseFeePerGas, Extra: payload.ExtraData, - MixDigest: common.Hash(payload.Random), + MixDigest: common.Hash(payload.PrevRandao), } block := types.NewBlockWithHeader(header).WithBody(txs, nil /* uncles */) return block, nil diff --git a/builder/builder.go b/builder/builder.go index a8802298f3..e223a5618a 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -9,6 +9,7 @@ import ( "sync" "time" + bellatrixapi "github.com/attestantio/go-builder-client/api/bellatrix" capellaapi "github.com/attestantio/go-builder-client/api/capella" apiv1 "github.com/attestantio/go-builder-client/api/v1" "github.com/attestantio/go-eth2-client/spec/bellatrix" @@ -16,15 +17,17 @@ import ( "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/ethereum/go-ethereum/beacon/engine" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" blockvalidation "github.com/ethereum/go-ethereum/eth/block-validation" "github.com/ethereum/go-ethereum/flashbotsextra" "github.com/ethereum/go-ethereum/log" "github.com/flashbots/go-boost-utils/bls" - boostTypes "github.com/flashbots/go-boost-utils/types" + "github.com/flashbots/go-boost-utils/ssz" + "github.com/flashbots/go-boost-utils/utils" "github.com/holiman/uint256" "golang.org/x/time/rate" + + boostTypes "github.com/flashbots/go-boost-utils/types" ) const ( @@ -39,12 +42,12 @@ type PubkeyHex string type ValidatorData struct { Pubkey PubkeyHex - FeeRecipient boostTypes.Address + FeeRecipient bellatrix.ExecutionAddress GasLimit uint64 } type IRelay interface { - SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest, vd ValidatorData) error + SubmitBlock(msg *bellatrixapi.SubmitBlockRequest, vd ValidatorData) error SubmitBlockCapella(msg *capellaapi.SubmitBlockRequest, vd ValidatorData) error GetValidatorForSlot(nextSlot uint64) (ValidatorData, error) Config() RelayConfig @@ -59,17 +62,17 @@ type IBuilder interface { } type Builder struct { - ds flashbotsextra.IDatabaseService - relay IRelay - eth IEthereumService - dryRun bool - ignoreLatePayloadAttributes bool - validator *blockvalidation.BlockValidationAPI - beaconClient IBeaconClient - builderSecretKey *bls.SecretKey - builderPublicKey boostTypes.PublicKey - builderSigningDomain boostTypes.Domain - builderResubmitInterval time.Duration + ds flashbotsextra.IDatabaseService + relay IRelay + eth IEthereumService + dryRun bool + ignoreLatePayloadAttributes bool + validator *blockvalidation.BlockValidationAPI + beaconClient IBeaconClient + builderSecretKey *bls.SecretKey + builderPublicKey phase0.BLSPubKey + builderSigningDomain phase0.Domain + builderResubmitInterval time.Duration limiter *rate.Limiter @@ -86,7 +89,7 @@ type BuilderArgs struct { sk *bls.SecretKey ds flashbotsextra.IDatabaseService relay IRelay - builderSigningDomain boostTypes.Domain + builderSigningDomain phase0.Domain builderBlockResubmitInterval time.Duration eth IEthereumService dryRun bool @@ -97,10 +100,15 @@ type BuilderArgs struct { limiter *rate.Limiter } -func NewBuilder(args BuilderArgs) *Builder { - pkBytes := bls.PublicKeyFromSecretKey(args.sk).Compress() - pk := boostTypes.PublicKey{} - pk.FromSlice(pkBytes) +func NewBuilder(args BuilderArgs) (*Builder, error) { + blsPk, err := bls.PublicKeyFromSecretKey(args.sk) + if err != nil { + return nil, err + } + pk, err := utils.BlsPublicKeyToPublicKey(blsPk) + if err != nil { + return nil, err + } if args.limiter == nil { args.limiter = rate.NewLimiter(rate.Every(RateLimitIntervalDefault), RateLimitBurstDefault) @@ -129,7 +137,7 @@ func NewBuilder(args BuilderArgs) *Builder { slotCtxCancel: slotCtxCancel, stop: make(chan struct{}, 1), - } + }, nil } func (b *Builder) Start() error { @@ -212,14 +220,13 @@ func (b *Builder) submitBellatrixBlock(block *types.Block, blockValue *big.Int, return err } - value := new(boostTypes.U256Str) - err = value.FromBig(blockValue) - if err != nil { - log.Error("could not set block value", "err", err) + value, overflow := uint256.FromBig(blockValue) + if overflow { + log.Error("could not set block value due to value overflow") return err } - blockBidMsg := boostTypes.BidTrace{ + blockBidMsg := apiv1.BidTrace{ Slot: attrs.Slot, ParentHash: payload.ParentHash, BlockHash: payload.BlockHash, @@ -228,23 +235,23 @@ func (b *Builder) submitBellatrixBlock(block *types.Block, blockValue *big.Int, ProposerFeeRecipient: vd.FeeRecipient, GasLimit: executableData.ExecutionPayload.GasLimit, GasUsed: executableData.ExecutionPayload.GasUsed, - Value: *value, + Value: value, } - signature, err := boostTypes.SignMessage(&blockBidMsg, b.builderSigningDomain, b.builderSecretKey) + signature, err := ssz.SignMessage(&blockBidMsg, b.builderSigningDomain, b.builderSecretKey) if err != nil { log.Error("could not sign builder bid", "err", err) return err } - blockSubmitReq := boostTypes.BuilderSubmitBlockRequest{ - Signature: signature, + blockSubmitReq := bellatrixapi.SubmitBlockRequest{ + Signature: phase0.BLSSignature(signature), Message: &blockBidMsg, ExecutionPayload: payload, } if b.dryRun { - err = b.validator.ValidateBuilderSubmissionV1(&blockvalidation.BuilderBlockValidationRequest{BuilderSubmitBlockRequest: blockSubmitReq, RegisteredGasLimit: vd.GasLimit}) + err = b.validator.ValidateBuilderSubmissionV1(&blockvalidation.BuilderBlockValidationRequest{SubmitBlockRequest: blockSubmitReq, RegisteredGasLimit: vd.GasLimit}) if err != nil { log.Error("could not validate bellatrix block", "err", err) } @@ -290,13 +297,7 @@ func (b *Builder) submitCapellaBlock(block *types.Block, blockValue *big.Int, or Value: value, } - boostBidTrace, err := convertBidTrace(blockBidMsg) - if err != nil { - log.Error("could not convert bid trace", "err", err) - return err - } - - signature, err := boostTypes.SignMessage(&blockBidMsg, b.builderSigningDomain, b.builderSecretKey) + signature, err := ssz.SignMessage(&blockBidMsg, b.builderSigningDomain, b.builderSecretKey) if err != nil { log.Error("could not sign builder bid", "err", err) return err @@ -339,7 +340,7 @@ func (b *Builder) OnPayloadAttribute(attrs *types.BuilderPayloadAttributes) erro attrs.SuggestedFeeRecipient = [20]byte(vd.FeeRecipient) attrs.GasLimit = vd.GasLimit - proposerPubkey, err := boostTypes.HexToPubkey(string(vd.Pubkey)) + proposerPubkey, err := utils.HexToPubkey(string(vd.Pubkey)) if err != nil { return fmt.Errorf("could not parse pubkey (%s) - %w", vd.Pubkey, err) } @@ -370,7 +371,7 @@ func (b *Builder) OnPayloadAttribute(attrs *types.BuilderPayloadAttributes) erro b.slotCtx = slotCtx b.slotCtxCancel = slotCtxCancel - go b.runBuildingJob(b.slotCtx, proposerPubkey, vd, attrs) + go b.runBuildingJob(b.slotCtx, phase0.BLSPubKey(proposerPubkey), vd, attrs) return nil } @@ -384,7 +385,7 @@ type blockQueueEntry struct { usedSbundles []types.UsedSBundle } -func (b *Builder) runBuildingJob(slotCtx context.Context, proposerPubkey boostTypes.PublicKey, vd ValidatorData, attrs *types.BuilderPayloadAttributes) { +func (b *Builder) runBuildingJob(slotCtx context.Context, proposerPubkey phase0.BLSPubKey, vd ValidatorData, attrs *types.BuilderPayloadAttributes) { ctx, cancel := context.WithTimeout(slotCtx, 12*time.Second) defer cancel() @@ -471,10 +472,10 @@ func (b *Builder) runBuildingJob(slotCtx context.Context, proposerPubkey boostTy }) } -func executableDataToExecutionPayload(data *engine.ExecutableData) (*boostTypes.ExecutionPayload, error) { - transactionData := make([]hexutil.Bytes, len(data.Transactions)) +func executableDataToExecutionPayload(data *engine.ExecutableData) (*bellatrix.ExecutionPayload, error) { + transactionData := make([]bellatrix.Transaction, len(data.Transactions)) for i, tx := range data.Transactions { - transactionData[i] = hexutil.Bytes(tx) + transactionData[i] = bellatrix.Transaction(tx) } baseFeePerGas := new(boostTypes.U256Str) @@ -483,13 +484,13 @@ func executableDataToExecutionPayload(data *engine.ExecutableData) (*boostTypes. return nil, err } - return &boostTypes.ExecutionPayload{ + return &bellatrix.ExecutionPayload{ ParentHash: [32]byte(data.ParentHash), FeeRecipient: [20]byte(data.FeeRecipient), StateRoot: [32]byte(data.StateRoot), ReceiptsRoot: [32]byte(data.ReceiptsRoot), - LogsBloom: boostTypes.Bloom(types.BytesToBloom(data.LogsBloom)), - Random: [32]byte(data.Random), + LogsBloom: types.BytesToBloom(data.LogsBloom), + PrevRandao: [32]byte(data.Random), BlockNumber: data.Number, GasLimit: data.GasLimit, GasUsed: data.GasUsed, @@ -528,7 +529,7 @@ func executableDataToCapellaExecutionPayload(data *engine.ExecutableData) (*cape FeeRecipient: [20]byte(data.FeeRecipient), StateRoot: [32]byte(data.StateRoot), ReceiptsRoot: [32]byte(data.ReceiptsRoot), - LogsBloom: boostTypes.Bloom(types.BytesToBloom(data.LogsBloom)), + LogsBloom: types.BytesToBloom(data.LogsBloom), PrevRandao: [32]byte(data.Random), BlockNumber: data.Number, GasLimit: data.GasLimit, @@ -541,23 +542,3 @@ func executableDataToCapellaExecutionPayload(data *engine.ExecutableData) (*cape Withdrawals: withdrawalData, }, nil } - -func convertBidTrace(bidTrace apiv1.BidTrace) (boostTypes.BidTrace, error) { - value := new(boostTypes.U256Str) - err := value.FromBig(bidTrace.Value.ToBig()) - if err != nil { - return boostTypes.BidTrace{}, err - } - - return boostTypes.BidTrace{ - Slot: bidTrace.Slot, - ParentHash: boostTypes.Hash(bidTrace.ParentHash), - BlockHash: boostTypes.Hash(bidTrace.BlockHash), - BuilderPubkey: boostTypes.PublicKey(bidTrace.BuilderPubkey), - ProposerPubkey: boostTypes.PublicKey(bidTrace.ProposerPubkey), - ProposerFeeRecipient: boostTypes.Address(bidTrace.ProposerFeeRecipient), - GasLimit: bidTrace.GasLimit, - GasUsed: bidTrace.GasUsed, - Value: *value, - }, nil -} diff --git a/builder/builder_test.go b/builder/builder_test.go index 937b69f75f..6b6f03b0e4 100644 --- a/builder/builder_test.go +++ b/builder/builder_test.go @@ -5,13 +5,18 @@ import ( "testing" "time" + apiv1 "github.com/attestantio/go-builder-client/api/v1" + "github.com/attestantio/go-eth2-client/spec/bellatrix" + "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/ethereum/go-ethereum/beacon/engine" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/flashbotsextra" "github.com/flashbots/go-boost-utils/bls" - boostTypes "github.com/flashbots/go-boost-utils/types" + "github.com/flashbots/go-boost-utils/ssz" + "github.com/flashbots/go-boost-utils/utils" + "github.com/holiman/uint256" "github.com/stretchr/testify/require" ) @@ -28,7 +33,7 @@ func TestOnPayloadAttributes(t *testing.T) { slot: 56, } - feeRecipient, _ := boostTypes.HexToAddress("0xabcf8e0d4e9587369b2301d0790347320302cc00") + feeRecipient, _ := utils.HexToAddress("0xabcf8e0d4e9587369b2301d0790347320302cc00") testRelay := testRelay{ gvsVd: ValidatorData{ Pubkey: PubkeyHex(testBeacon.validator.Pk.String()), @@ -40,7 +45,7 @@ func TestOnPayloadAttributes(t *testing.T) { sk, err := bls.SecretKeyFromBytes(hexutil.MustDecode("0x31ee185dad1220a8c88ca5275e64cf5a5cb09cb621cb30df52c9bee8fbaaf8d7")) require.NoError(t, err) - bDomain := boostTypes.ComputeDomain(boostTypes.DomainTypeAppBuilder, [4]byte{0x02, 0x0, 0x0, 0x0}, boostTypes.Hash{}) + bDomain := ssz.ComputeDomain(ssz.DomainTypeAppBuilder, [4]byte{0x02, 0x0, 0x0, 0x0}, phase0.Root{}) testExecutableData := &engine.ExecutableData{ ParentHash: common.Hash{0x02, 0x03}, @@ -84,7 +89,8 @@ func TestOnPayloadAttributes(t *testing.T) { beaconClient: &testBeacon, limiter: nil, } - builder := NewBuilder(builderArgs) + builder, err := NewBuilder(builderArgs) + require.NoError(t, err) builder.Start() defer builder.Stop() @@ -93,43 +99,42 @@ func TestOnPayloadAttributes(t *testing.T) { time.Sleep(time.Second * 3) require.NotNil(t, testRelay.submittedMsg) - expectedProposerPubkey, err := boostTypes.HexToPubkey(testBeacon.validator.Pk.String()) + expectedProposerPubkey, err := utils.HexToPubkey(testBeacon.validator.Pk.String()) require.NoError(t, err) - expectedMessage := boostTypes.BidTrace{ + expectedMessage := apiv1.BidTrace{ Slot: uint64(25), - ParentHash: boostTypes.Hash{0x02, 0x03}, + ParentHash: phase0.Hash32{0x02, 0x03}, BuilderPubkey: builder.builderPublicKey, ProposerPubkey: expectedProposerPubkey, ProposerFeeRecipient: feeRecipient, GasLimit: uint64(50), GasUsed: uint64(100), - Value: boostTypes.U256Str{0x0a}, + Value: &uint256.Int{0x0a}, } - expectedMessage.BlockHash.FromSlice(hexutil.MustDecode("0xca4147f0d4150183ece9155068f34ee3c375448814e4ca557d482b1d40ee5407")[:]) - + copy(expectedMessage.BlockHash[:], hexutil.MustDecode("0xca4147f0d4150183ece9155068f34ee3c375448814e4ca557d482b1d40ee5407")[:]) require.Equal(t, expectedMessage, *testRelay.submittedMsg.Message) - expectedExecutionPayload := boostTypes.ExecutionPayload{ + expectedExecutionPayload := bellatrix.ExecutionPayload{ ParentHash: [32]byte(testExecutableData.ParentHash), FeeRecipient: feeRecipient, StateRoot: [32]byte(testExecutableData.StateRoot), ReceiptsRoot: [32]byte(testExecutableData.ReceiptsRoot), LogsBloom: [256]byte{}, - Random: [32]byte(testExecutableData.Random), + PrevRandao: [32]byte(testExecutableData.Random), BlockNumber: testExecutableData.Number, GasLimit: testExecutableData.GasLimit, GasUsed: testExecutableData.GasUsed, Timestamp: testExecutableData.Timestamp, ExtraData: hexutil.MustDecode("0x0042fafc"), - BaseFeePerGas: boostTypes.U256Str{0x10}, + BaseFeePerGas: uint256.NewInt(10).Bytes32(), BlockHash: expectedMessage.BlockHash, - Transactions: []hexutil.Bytes{}, + Transactions: []bellatrix.Transaction{}, } require.Equal(t, expectedExecutionPayload, *testRelay.submittedMsg.ExecutionPayload) - expectedSignature, err := boostTypes.HexToSignature("0xad09f171b1da05636acfc86778c319af69e39c79515d44bdfed616ba2ef677ffd4d155d87b3363c6bae651ce1e92786216b75f1ac91dd65f3b1d1902bf8485e742170732dd82ffdf4decb0151eeb7926dd053efa9794b2ebed1a203e62bb13e9") + expectedSignature, err := utils.HexToSignature("0xad09f171b1da05636acfc86778c319af69e39c79515d44bdfed616ba2ef677ffd4d155d87b3363c6bae651ce1e92786216b75f1ac91dd65f3b1d1902bf8485e742170732dd82ffdf4decb0151eeb7926dd053efa9794b2ebed1a203e62bb13e9") require.NoError(t, err) require.Equal(t, expectedSignature, testRelay.submittedMsg.Signature) diff --git a/builder/local_relay.go b/builder/local_relay.go index 1a5f70a399..0cf7ba7f25 100644 --- a/builder/local_relay.go +++ b/builder/local_relay.go @@ -12,11 +12,23 @@ import ( "sync" "time" - "github.com/attestantio/go-builder-client/api/capella" + "github.com/attestantio/go-builder-client/api" + bellatrixapi "github.com/attestantio/go-builder-client/api/bellatrix" + capellaapi "github.com/attestantio/go-builder-client/api/capella" + apiv1 "github.com/attestantio/go-builder-client/api/v1" + "github.com/attestantio/go-builder-client/spec" + apiv1bellatrix "github.com/attestantio/go-eth2-client/api/v1/bellatrix" + consensusspec "github.com/attestantio/go-eth2-client/spec" + "github.com/attestantio/go-eth2-client/spec/bellatrix" + "github.com/attestantio/go-eth2-client/spec/phase0" + bellatrixutil "github.com/attestantio/go-eth2-client/util/bellatrix" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/log" "github.com/flashbots/go-boost-utils/bls" - boostTypes "github.com/flashbots/go-boost-utils/types" + "github.com/flashbots/go-boost-utils/ssz" + "github.com/flashbots/go-boost-utils/utils" + "github.com/holiman/uint256" + "github.com/gorilla/mux" ) @@ -35,11 +47,11 @@ type LocalRelay struct { beaconClient IBeaconClient relaySecretKey *bls.SecretKey - relayPublicKey boostTypes.PublicKey + relayPublicKey phase0.BLSPubKey serializedRelayPubkey hexutil.Bytes - builderSigningDomain boostTypes.Domain - proposerSigningDomain boostTypes.Domain + builderSigningDomain phase0.Domain + proposerSigningDomain phase0.Domain validatorsLock sync.RWMutex validators map[PubkeyHex]FullValidatorData @@ -47,18 +59,23 @@ type LocalRelay struct { enableBeaconChecks bool bestDataLock sync.Mutex - bestHeader *boostTypes.ExecutionPayloadHeader - bestPayload *boostTypes.ExecutionPayload - profit boostTypes.U256Str + bestHeader *bellatrix.ExecutionPayloadHeader + bestPayload *bellatrix.ExecutionPayload + profit *uint256.Int indexTemplate *template.Template fd ForkData } -func NewLocalRelay(sk *bls.SecretKey, beaconClient IBeaconClient, builderSigningDomain, proposerSigningDomain boostTypes.Domain, fd ForkData, enableBeaconChecks bool) *LocalRelay { - pkBytes := bls.PublicKeyFromSecretKey(sk).Compress() - pk := boostTypes.PublicKey{} - pk.FromSlice(pkBytes) +func NewLocalRelay(sk *bls.SecretKey, beaconClient IBeaconClient, builderSigningDomain, proposerSigningDomain phase0.Domain, fd ForkData, enableBeaconChecks bool) (*LocalRelay, error) { + blsPk, err := bls.PublicKeyFromSecretKey(sk) + if err != nil { + return nil, err + } + pk, err := utils.BlsPublicKeyToPublicKey(blsPk) + if err != nil { + return nil, err + } indexTemplate, err := parseIndexTemplate() if err != nil { @@ -74,7 +91,7 @@ func NewLocalRelay(sk *bls.SecretKey, beaconClient IBeaconClient, builderSigning builderSigningDomain: builderSigningDomain, proposerSigningDomain: proposerSigningDomain, - serializedRelayPubkey: pkBytes, + serializedRelayPubkey: bls.PublicKeyToBytes(blsPk), validators: make(map[PubkeyHex]FullValidatorData), @@ -82,7 +99,7 @@ func NewLocalRelay(sk *bls.SecretKey, beaconClient IBeaconClient, builderSigning indexTemplate: indexTemplate, fd: fd, - } + }, nil } func (r *LocalRelay) Start() error { @@ -94,12 +111,12 @@ func (r *LocalRelay) Stop() { r.beaconClient.Stop() } -func (r *LocalRelay) SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest, _ ValidatorData) error { +func (r *LocalRelay) SubmitBlock(msg *bellatrixapi.SubmitBlockRequest, _ ValidatorData) error { log.Info("submitting block to local relay", "block", msg.ExecutionPayload.BlockHash.String()) return r.submitBlock(msg) } -func (r *LocalRelay) SubmitBlockCapella(msg *capella.SubmitBlockRequest, _ ValidatorData) error { +func (r *LocalRelay) SubmitBlockCapella(msg *capellaapi.SubmitBlockRequest, _ ValidatorData) error { log.Info("submitting block to local relay", "block", msg.ExecutionPayload.BlockHash.String()) return r.submitBlockCapella(msg) @@ -111,19 +128,19 @@ func (r *LocalRelay) Config() RelayConfig { } // TODO: local relay support for capella -func (r *LocalRelay) submitBlockCapella(msg *capella.SubmitBlockRequest) error { +func (r *LocalRelay) submitBlockCapella(msg *capellaapi.SubmitBlockRequest) error { return nil } -func (r *LocalRelay) submitBlock(msg *boostTypes.BuilderSubmitBlockRequest) error { - payloadHeader, err := boostTypes.PayloadToPayloadHeader(msg.ExecutionPayload) +func (r *LocalRelay) submitBlock(msg *bellatrixapi.SubmitBlockRequest) error { + header, err := PayloadToPayloadHeader(msg.ExecutionPayload) if err != nil { log.Error("could not convert payload to header", "err", err) return err } r.bestDataLock.Lock() - r.bestHeader = payloadHeader + r.bestHeader = header r.bestPayload = msg.ExecutionPayload r.profit = msg.Message.Value r.bestDataLock.Unlock() @@ -132,7 +149,7 @@ func (r *LocalRelay) submitBlock(msg *boostTypes.BuilderSubmitBlockRequest) erro } func (r *LocalRelay) handleRegisterValidator(w http.ResponseWriter, req *http.Request) { - payload := []boostTypes.SignedValidatorRegistration{} + payload := []apiv1.SignedValidatorRegistration{} if err := json.NewDecoder(req.Body).Decode(&payload); err != nil { log.Error("could not decode payload", "err", err) respondError(w, http.StatusBadRequest, "invalid payload") @@ -150,7 +167,7 @@ func (r *LocalRelay) handleRegisterValidator(w http.ResponseWriter, req *http.Re return } - ok, err := boostTypes.VerifySignature(registerRequest.Message, r.builderSigningDomain, registerRequest.Message.Pubkey[:], registerRequest.Signature[:]) + ok, err := ssz.VerifySignature(registerRequest.Message, r.builderSigningDomain, registerRequest.Message.Pubkey[:], registerRequest.Signature[:]) if !ok || err != nil { log.Error("error verifying signature", "err", err) respondError(w, http.StatusBadRequest, "invalid signature") @@ -158,7 +175,7 @@ func (r *LocalRelay) handleRegisterValidator(w http.ResponseWriter, req *http.Re } // Do not check timestamp before signature, as it would leak validator data - if registerRequest.Message.Timestamp > uint64(time.Now().Add(10*time.Second).Unix()) { + if registerRequest.Message.Timestamp.Unix() > time.Now().Add(10*time.Second).Unix() { respondError(w, http.StatusBadRequest, "invalid payload") return } @@ -178,12 +195,12 @@ func (r *LocalRelay) handleRegisterValidator(w http.ResponseWriter, req *http.Re for _, registerRequest := range payload { pubkeyHex := PubkeyHex(registerRequest.Message.Pubkey.String()) if previousValidatorData, ok := r.validators[pubkeyHex]; ok { - if registerRequest.Message.Timestamp < previousValidatorData.Timestamp { + if uint64(registerRequest.Message.Timestamp.Unix()) < previousValidatorData.Timestamp { respondError(w, http.StatusBadRequest, "invalid timestamp") return } - if registerRequest.Message.Timestamp == previousValidatorData.Timestamp && (registerRequest.Message.FeeRecipient != previousValidatorData.FeeRecipient || registerRequest.Message.GasLimit != previousValidatorData.GasLimit) { + if uint64(registerRequest.Message.Timestamp.Unix()) == previousValidatorData.Timestamp && (registerRequest.Message.FeeRecipient != previousValidatorData.FeeRecipient || registerRequest.Message.GasLimit != previousValidatorData.GasLimit) { respondError(w, http.StatusBadRequest, "invalid timestamp") return } @@ -198,7 +215,7 @@ func (r *LocalRelay) handleRegisterValidator(w http.ResponseWriter, req *http.Re FeeRecipient: registerRequest.Message.FeeRecipient, GasLimit: registerRequest.Message.GasLimit, }, - Timestamp: registerRequest.Message.Timestamp, + Timestamp: uint64(registerRequest.Message.Timestamp.Unix()), } log.Info("registered validator", "pubkey", pubkeyHex, "data", r.validators[pubkeyHex]) @@ -261,20 +278,20 @@ func (r *LocalRelay) handleGetHeader(w http.ResponseWriter, req *http.Request) { return } - bid := boostTypes.BuilderBid{ + bid := bellatrixapi.BuilderBid{ Header: bestHeader, Value: profit, Pubkey: r.relayPublicKey, } - signature, err := boostTypes.SignMessage(&bid, r.builderSigningDomain, r.relaySecretKey) + signature, err := ssz.SignMessage(&bid, r.builderSigningDomain, r.relaySecretKey) if err != nil { respondError(w, http.StatusInternalServerError, "internal server error") return } - response := &boostTypes.GetHeaderResponse{ - Version: "bellatrix", - Data: &boostTypes.SignedBuilderBid{Message: &bid, Signature: signature}, + response := &spec.VersionedSignedBuilderBid{ + Version: consensusspec.DataVersionBellatrix, + Bellatrix: &bellatrixapi.SignedBuilderBid{Message: &bid, Signature: phase0.BLSSignature(signature)}, } w.Header().Set("Content-Type", "application/json") @@ -286,7 +303,7 @@ func (r *LocalRelay) handleGetHeader(w http.ResponseWriter, req *http.Request) { } func (r *LocalRelay) handleGetPayload(w http.ResponseWriter, req *http.Request) { - payload := new(boostTypes.SignedBlindedBeaconBlock) + payload := new(apiv1bellatrix.SignedBlindedBeaconBlock) if err := json.NewDecoder(req.Body).Decode(&payload); err != nil { respondError(w, http.StatusBadRequest, "invalid payload") return @@ -297,7 +314,7 @@ func (r *LocalRelay) handleGetPayload(w http.ResponseWriter, req *http.Request) return } - nextSlotProposerPubkeyHex, err := r.beaconClient.getProposerForNextSlot(payload.Message.Slot) + nextSlotProposerPubkeyHex, err := r.beaconClient.getProposerForNextSlot(uint64(payload.Message.Slot)) if err != nil { if r.enableBeaconChecks { respondError(w, http.StatusBadRequest, "unknown validator") @@ -313,7 +330,7 @@ func (r *LocalRelay) handleGetPayload(w http.ResponseWriter, req *http.Request) } } - ok, err := boostTypes.VerifySignature(payload.Message, r.proposerSigningDomain, nextSlotProposerPubkeyBytes[:], payload.Signature[:]) + ok, err := ssz.VerifySignature(payload.Message, r.proposerSigningDomain, nextSlotProposerPubkeyBytes[:], payload.Signature[:]) if !ok || err != nil { if r.enableBeaconChecks { respondError(w, http.StatusBadRequest, "invalid signature") @@ -338,9 +355,9 @@ func (r *LocalRelay) handleGetPayload(w http.ResponseWriter, req *http.Request) return } - response := boostTypes.GetPayloadResponse{ - Version: "bellatrix", - Data: bestPayload, + response := api.VersionedExecutionPayload{ + Version: consensusspec.DataVersionBellatrix, + Bellatrix: bestPayload, } w.Header().Set("Content-Type", "application/json") @@ -411,6 +428,41 @@ func (r *LocalRelay) handleStatus(w http.ResponseWriter, req *http.Request) { w.WriteHeader(http.StatusOK) } -func ExecutionPayloadHeaderEqual(l, r *boostTypes.ExecutionPayloadHeader) bool { - return l.ParentHash == r.ParentHash && l.FeeRecipient == r.FeeRecipient && l.StateRoot == r.StateRoot && l.ReceiptsRoot == r.ReceiptsRoot && l.LogsBloom == r.LogsBloom && l.Random == r.Random && l.BlockNumber == r.BlockNumber && l.GasLimit == r.GasLimit && l.GasUsed == r.GasUsed && l.Timestamp == r.Timestamp && l.BaseFeePerGas == r.BaseFeePerGas && bytes.Equal(l.ExtraData, r.ExtraData) && l.BlockHash == r.BlockHash && l.TransactionsRoot == r.TransactionsRoot +func ExecutionPayloadHeaderEqual(l, r *bellatrix.ExecutionPayloadHeader) bool { + return l.ParentHash == r.ParentHash && l.FeeRecipient == r.FeeRecipient && l.StateRoot == r.StateRoot && l.ReceiptsRoot == r.ReceiptsRoot && l.LogsBloom == r.LogsBloom && l.PrevRandao == r.PrevRandao && l.BlockNumber == r.BlockNumber && l.GasLimit == r.GasLimit && l.GasUsed == r.GasUsed && l.Timestamp == r.Timestamp && l.BaseFeePerGas == r.BaseFeePerGas && bytes.Equal(l.ExtraData, r.ExtraData) && l.BlockHash == r.BlockHash && l.TransactionsRoot == r.TransactionsRoot +} + +// PayloadToPayloadHeader converts an ExecutionPayload to ExecutionPayloadHeader +func PayloadToPayloadHeader(p *bellatrix.ExecutionPayload) (*bellatrix.ExecutionPayloadHeader, error) { + if p == nil { + return nil, errors.New("nil payload") + } + + var txs []bellatrix.Transaction + for _, tx := range p.Transactions { + txs = append(txs, tx) + } + + transactions := bellatrixutil.ExecutionPayloadTransactions{Transactions: txs} + txroot, err := transactions.HashTreeRoot() + if err != nil { + return nil, err + } + + return &bellatrix.ExecutionPayloadHeader{ + ParentHash: p.ParentHash, + FeeRecipient: p.FeeRecipient, + StateRoot: p.StateRoot, + ReceiptsRoot: p.ReceiptsRoot, + LogsBloom: p.LogsBloom, + PrevRandao: p.PrevRandao, + BlockNumber: p.BlockNumber, + GasLimit: p.GasLimit, + GasUsed: p.GasUsed, + Timestamp: p.Timestamp, + ExtraData: p.ExtraData, + BaseFeePerGas: p.BaseFeePerGas, + BlockHash: p.BlockHash, + TransactionsRoot: txroot, + }, nil } diff --git a/builder/local_relay_test.go b/builder/local_relay_test.go index 0d936ed806..f30cddb973 100644 --- a/builder/local_relay_test.go +++ b/builder/local_relay_test.go @@ -10,14 +10,22 @@ import ( "testing" "time" + "github.com/attestantio/go-builder-client/api" + bellatrixapi "github.com/attestantio/go-builder-client/api/bellatrix" + apiv1 "github.com/attestantio/go-builder-client/api/v1" + "github.com/attestantio/go-builder-client/spec" + consensusapiv1bellatrix "github.com/attestantio/go-eth2-client/api/v1/bellatrix" + "github.com/attestantio/go-eth2-client/spec/altair" + "github.com/attestantio/go-eth2-client/spec/bellatrix" + "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/ethereum/go-ethereum/beacon/engine" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/flashbotsextra" "github.com/ethereum/go-ethereum/log" "github.com/flashbots/go-boost-utils/bls" - boostTypes "github.com/flashbots/go-boost-utils/types" + "github.com/flashbots/go-boost-utils/ssz" + "github.com/holiman/uint256" "github.com/stretchr/testify/require" "golang.org/x/time/rate" ) @@ -25,11 +33,11 @@ import ( func newTestBackend(t *testing.T, forkchoiceData *engine.ExecutableData, block *types.Block, blockValue *big.Int) (*Builder, *LocalRelay, *ValidatorPrivateData) { validator := NewRandomValidator() sk, _ := bls.GenerateRandomSecretKey() - bDomain := boostTypes.ComputeDomain(boostTypes.DomainTypeAppBuilder, [4]byte{0x02, 0x0, 0x0, 0x0}, boostTypes.Hash{}) - genesisValidatorsRoot := boostTypes.Hash(common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000")) - cDomain := boostTypes.ComputeDomain(boostTypes.DomainTypeBeaconProposer, [4]byte{0x02, 0x0, 0x0, 0x0}, genesisValidatorsRoot) + bDomain := ssz.ComputeDomain(ssz.DomainTypeAppBuilder, [4]byte{0x02, 0x0, 0x0, 0x0}, phase0.Root{}) + genesisValidatorsRoot := phase0.Root(common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000")) + cDomain := ssz.ComputeDomain(ssz.DomainTypeBeaconProposer, [4]byte{0x02, 0x0, 0x0, 0x0}, genesisValidatorsRoot) beaconClient := &testBeaconClient{validator: validator} - localRelay := NewLocalRelay(sk, beaconClient, bDomain, cDomain, ForkData{}, true) + localRelay, _ := NewLocalRelay(sk, beaconClient, bDomain, cDomain, ForkData{}, true) ethService := &testEthereumService{synced: true, testExecutableData: forkchoiceData, testBlock: block, testBlockValue: blockValue} builderArgs := BuilderArgs{ sk: sk, @@ -43,8 +51,7 @@ func newTestBackend(t *testing.T, forkchoiceData *engine.ExecutableData, block * beaconClient: beaconClient, limiter: nil, } - backend := NewBuilder(builderArgs) - // service := NewService("127.0.0.1:31545", backend) + backend, _ := NewBuilder(builderArgs) backend.limiter = rate.NewLimiter(rate.Inf, 0) @@ -79,12 +86,12 @@ func TestValidatorRegistration(t *testing.T) { rr := testRequest(t, relay, "POST", "/eth/v1/builder/validators", payload) require.Equal(t, http.StatusOK, rr.Code) require.Contains(t, relay.validators, PubkeyHex(v.Pk.String())) - require.Equal(t, FullValidatorData{ValidatorData: ValidatorData{Pubkey: PubkeyHex(v.Pk.String()), FeeRecipient: payload[0].Message.FeeRecipient, GasLimit: payload[0].Message.GasLimit}, Timestamp: payload[0].Message.Timestamp}, relay.validators[PubkeyHex(v.Pk.String())]) + require.Equal(t, FullValidatorData{ValidatorData: ValidatorData{Pubkey: PubkeyHex(v.Pk.String()), FeeRecipient: payload[0].Message.FeeRecipient, GasLimit: payload[0].Message.GasLimit}, Timestamp: uint64(payload[0].Message.Timestamp.Unix())}, relay.validators[PubkeyHex(v.Pk.String())]) rr = testRequest(t, relay, "POST", "/eth/v1/builder/validators", payload) require.Equal(t, http.StatusOK, rr.Code) - payload[0].Message.Timestamp += 1 + payload[0].Message.Timestamp.Add(time.Second) // Invalid signature payload[0].Signature[len(payload[0].Signature)-1] = 0x00 rr = testRequest(t, relay, "POST", "/eth/v1/builder/validators", payload) @@ -94,22 +101,22 @@ func TestValidatorRegistration(t *testing.T) { // TODO: cover all errors } -func prepareRegistrationMessage(t *testing.T, domain boostTypes.Domain, v *ValidatorPrivateData) ([]boostTypes.SignedValidatorRegistration, error) { - var pubkey boostTypes.PublicKey - pubkey.FromSlice(v.Pk) +func prepareRegistrationMessage(t *testing.T, domain phase0.Domain, v *ValidatorPrivateData) ([]apiv1.SignedValidatorRegistration, error) { + var pubkey phase0.BLSPubKey + copy(pubkey[:], v.Pk) require.Equal(t, []byte(v.Pk), pubkey[:]) - msg := boostTypes.RegisterValidatorRequestMessage{ - FeeRecipient: boostTypes.Address{0x42}, + msg := apiv1.ValidatorRegistration{ + FeeRecipient: bellatrix.ExecutionAddress{0x42}, GasLimit: 15_000_000, - Timestamp: uint64(time.Now().Unix()), + Timestamp: time.Now(), Pubkey: pubkey, } signature, err := v.Sign(&msg, domain) require.NoError(t, err) - return []boostTypes.SignedValidatorRegistration{{ + return []apiv1.SignedValidatorRegistration{{ Message: &msg, Signature: signature, }}, nil @@ -123,7 +130,7 @@ func registerValidator(t *testing.T, v *ValidatorPrivateData, relay *LocalRelay) rr := testRequest(t, relay, "POST", "/eth/v1/builder/validators", payload) require.Equal(t, http.StatusOK, rr.Code) require.Contains(t, relay.validators, PubkeyHex(v.Pk.String())) - require.Equal(t, FullValidatorData{ValidatorData: ValidatorData{Pubkey: PubkeyHex(v.Pk.String()), FeeRecipient: payload[0].Message.FeeRecipient, GasLimit: payload[0].Message.GasLimit}, Timestamp: payload[0].Message.Timestamp}, relay.validators[PubkeyHex(v.Pk.String())]) + require.Equal(t, FullValidatorData{ValidatorData: ValidatorData{Pubkey: PubkeyHex(v.Pk.String()), FeeRecipient: payload[0].Message.FeeRecipient, GasLimit: payload[0].Message.GasLimit}, Timestamp: uint64(payload[0].Message.Timestamp.Unix())}, relay.validators[PubkeyHex(v.Pk.String())]) } func TestGetHeader(t *testing.T) { @@ -164,25 +171,24 @@ func TestGetHeader(t *testing.T) { rr = testRequest(t, relay, "GET", path, nil) require.Equal(t, http.StatusOK, rr.Code) - bid := new(boostTypes.GetHeaderResponse) + bid := new(spec.VersionedSignedBuilderBid) err = json.Unmarshal(rr.Body.Bytes(), bid) require.NoError(t, err) executionPayload, err := executableDataToExecutionPayload(forkchoiceData) require.NoError(t, err) - expectedHeader, err := boostTypes.PayloadToPayloadHeader(executionPayload) + expectedHeader, err := PayloadToPayloadHeader(executionPayload) require.NoError(t, err) - expectedValue := new(boostTypes.U256Str) - err = expectedValue.FromBig(forkchoiceBlockProfit) - require.NoError(t, err) - require.EqualValues(t, &boostTypes.BuilderBid{ + expectedValue, ok := uint256.FromBig(forkchoiceBlockProfit) + require.True(t, ok) + require.EqualValues(t, &bellatrixapi.BuilderBid{ Header: expectedHeader, - Value: *expectedValue, + Value: expectedValue, Pubkey: backend.builderPublicKey, - }, bid.Data.Message) + }, bid.Bellatrix.Message) - require.Equal(t, forkchoiceData.ParentHash.Bytes(), bid.Data.Message.Header.ParentHash[:], "didn't build on expected parent") - ok, err := boostTypes.VerifySignature(bid.Data.Message, backend.builderSigningDomain, backend.builderPublicKey[:], bid.Data.Signature[:]) + require.Equal(t, forkchoiceData.ParentHash.Bytes(), bid.Bellatrix.Message.Header.ParentHash[:], "didn't build on expected parent") + ok, err = ssz.VerifySignature(bid.Bellatrix.Message, backend.builderSigningDomain, backend.builderPublicKey[:], bid.Bellatrix.Signature[:]) require.NoError(t, err) require.True(t, ok) @@ -213,27 +219,27 @@ func TestGetPayload(t *testing.T) { rr := testRequest(t, relay, "GET", path, nil) require.Equal(t, http.StatusOK, rr.Code) - bid := new(boostTypes.GetHeaderResponse) + bid := new(spec.VersionedSignedBuilderBid) err = json.Unmarshal(rr.Body.Bytes(), bid) require.NoError(t, err) // Create request payload - msg := &boostTypes.BlindedBeaconBlock{ + msg := &consensusapiv1bellatrix.BlindedBeaconBlock{ Slot: 1, ProposerIndex: 2, - ParentRoot: boostTypes.Root{0x03}, - StateRoot: boostTypes.Root{0x04}, - Body: &boostTypes.BlindedBeaconBlockBody{ - Eth1Data: &boostTypes.Eth1Data{ - DepositRoot: boostTypes.Root{0x05}, + ParentRoot: phase0.Root{0x03}, + StateRoot: phase0.Root{0x04}, + Body: &consensusapiv1bellatrix.BlindedBeaconBlockBody{ + ETH1Data: &phase0.ETH1Data{ + DepositRoot: phase0.Root{0x05}, DepositCount: 5, - BlockHash: boostTypes.Hash{0x06}, + BlockHash: []byte{0x06}, }, - SyncAggregate: &boostTypes.SyncAggregate{ - CommitteeBits: boostTypes.CommitteeBits{0x07}, - CommitteeSignature: boostTypes.Signature{0x08}, + SyncAggregate: &altair.SyncAggregate{ + SyncCommitteeBits: []byte{0x07}, + SyncCommitteeSignature: phase0.BLSSignature{0x08}, }, - ExecutionPayloadHeader: bid.Data.Message.Header, + ExecutionPayloadHeader: bid.Bellatrix.Message.Header, }, } @@ -242,28 +248,23 @@ func TestGetPayload(t *testing.T) { require.NoError(t, err) // Call getPayload with invalid signature - rr = testRequest(t, relay, "POST", "/eth/v1/builder/blinded_blocks", boostTypes.SignedBlindedBeaconBlock{ + rr = testRequest(t, relay, "POST", "/eth/v1/builder/blinded_blocks", consensusapiv1bellatrix.SignedBlindedBeaconBlock{ Message: msg, - Signature: boostTypes.Signature{0x09}, + Signature: phase0.BLSSignature{0x09}, }) require.Equal(t, http.StatusBadRequest, rr.Code) require.Equal(t, `{"code":400,"message":"invalid signature"}`+"\n", rr.Body.String()) // Call getPayload with correct signature - rr = testRequest(t, relay, "POST", "/eth/v1/builder/blinded_blocks", boostTypes.SignedBlindedBeaconBlock{ + rr = testRequest(t, relay, "POST", "/eth/v1/builder/blinded_blocks", consensusapiv1bellatrix.SignedBlindedBeaconBlock{ Message: msg, Signature: signature, }) // Verify getPayload response require.Equal(t, http.StatusOK, rr.Code) - getPayloadResponse := new(boostTypes.GetPayloadResponse) + getPayloadResponse := new(api.VersionedExecutionPayload) err = json.Unmarshal(rr.Body.Bytes(), getPayloadResponse) require.NoError(t, err) - require.Equal(t, bid.Data.Message.Header.BlockHash, getPayloadResponse.Data.BlockHash) -} - -func TestXxx(t *testing.T) { - sk, _ := bls.GenerateRandomSecretKey() - fmt.Println(hexutil.Encode(sk.Serialize())) + require.Equal(t, bid.Bellatrix.Message.Header.BlockHash, getPayloadResponse.Bellatrix.BlockHash) } diff --git a/builder/relay.go b/builder/relay.go index ea370aa44c..1176c2ba93 100644 --- a/builder/relay.go +++ b/builder/relay.go @@ -9,11 +9,11 @@ import ( "sync" "time" + "github.com/attestantio/go-builder-client/api/bellatrix" "github.com/attestantio/go-builder-client/api/capella" - "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/log" - boostTypes "github.com/flashbots/go-boost-utils/types" - "github.com/flashbots/mev-boost/server" + + "github.com/flashbots/go-boost-utils/utils" ) var ErrValidatorNotFound = errors.New("validator not found") @@ -135,13 +135,13 @@ func (r *RemoteRelay) Start() error { func (r *RemoteRelay) Stop() {} -func (r *RemoteRelay) SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest, _ ValidatorData) error { +func (r *RemoteRelay) SubmitBlock(msg *bellatrix.SubmitBlockRequest, _ ValidatorData) error { log.Info("submitting block to remote relay", "endpoint", r.config.Endpoint) endpoint := r.config.Endpoint + "/relay/v1/builder/blocks" if r.cancellationsEnabled { endpoint = endpoint + "?cancellations=true" } - code, err := server.SendHTTPRequest(context.TODO(), *http.DefaultClient, http.MethodPost, endpoint, msg, nil) + code, err := SendHTTPRequest(context.TODO(), *http.DefaultClient, http.MethodPost, endpoint, msg, nil) if err != nil { return fmt.Errorf("error sending http request to relay %s. err: %w", r.config.Endpoint, err) } @@ -178,7 +178,7 @@ func (r *RemoteRelay) SubmitBlockCapella(msg *capella.SubmitBlockRequest, _ Vali return fmt.Errorf("non-ok response code %d from relay %s", code, r.config.Endpoint) } } else { - code, err := server.SendHTTPRequest(context.TODO(), *http.DefaultClient, http.MethodPost, endpoint, msg, nil) + code, err := SendHTTPRequest(context.TODO(), *http.DefaultClient, http.MethodPost, endpoint, msg, nil) if err != nil { return fmt.Errorf("error sending http request to relay %s. err: %w", r.config.Endpoint, err) } @@ -196,7 +196,7 @@ func (r *RemoteRelay) SubmitBlockCapella(msg *capella.SubmitBlockRequest, _ Vali func (r *RemoteRelay) getSlotValidatorMapFromRelay() (map[uint64]ValidatorData, error) { var dst GetValidatorRelayResponse - code, err := server.SendHTTPRequest(context.TODO(), *http.DefaultClient, http.MethodGet, r.config.Endpoint+"/relay/v1/builder/validators", nil, &dst) + code, err := SendHTTPRequest(context.TODO(), *http.DefaultClient, http.MethodGet, r.config.Endpoint+"/relay/v1/builder/validators", nil, &dst) if err != nil { return nil, err } @@ -207,13 +207,11 @@ func (r *RemoteRelay) getSlotValidatorMapFromRelay() (map[uint64]ValidatorData, res := make(map[uint64]ValidatorData) for _, data := range dst { - feeRecipientBytes, err := hexutil.Decode(data.Entry.Message.FeeRecipient) + feeRecipient, err := utils.HexToAddress(data.Entry.Message.FeeRecipient) if err != nil { log.Error("Ill-formatted fee_recipient from relay", "data", data) continue } - var feeRecipient boostTypes.Address - feeRecipient.FromSlice(feeRecipientBytes[:]) pubkeyHex := PubkeyHex(strings.ToLower(data.Entry.Message.Pubkey)) diff --git a/builder/relay_aggregator.go b/builder/relay_aggregator.go index 4e16c118e4..12f6f62c13 100644 --- a/builder/relay_aggregator.go +++ b/builder/relay_aggregator.go @@ -5,9 +5,9 @@ import ( "fmt" "sync" + "github.com/attestantio/go-builder-client/api/bellatrix" "github.com/attestantio/go-builder-client/api/capella" "github.com/ethereum/go-ethereum/log" - boostTypes "github.com/flashbots/go-boost-utils/types" ) type RemoteRelayAggregator struct { @@ -41,7 +41,7 @@ func (r *RemoteRelayAggregator) Stop() { } } -func (r *RemoteRelayAggregator) SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest, registration ValidatorData) error { +func (r *RemoteRelayAggregator) SubmitBlock(msg *bellatrix.SubmitBlockRequest, registration ValidatorData) error { r.registrationsCacheLock.RLock() defer r.registrationsCacheLock.RUnlock() diff --git a/builder/relay_aggregator_test.go b/builder/relay_aggregator_test.go index 630999bc9c..d46533e49a 100644 --- a/builder/relay_aggregator_test.go +++ b/builder/relay_aggregator_test.go @@ -5,15 +5,15 @@ import ( "testing" "time" + "github.com/attestantio/go-builder-client/api/bellatrix" "github.com/attestantio/go-builder-client/api/capella" - boostTypes "github.com/flashbots/go-boost-utils/types" "github.com/stretchr/testify/require" ) /* validator ValidatorData requestedSlot uint64 - submittedMsg *boostTypes.BuilderSubmitBlockRequest + submittedMsg *bellatrix.SubmitBlockRequest */ type testRelay struct { @@ -22,8 +22,8 @@ type testRelay struct { gvsErr error requestedSlot uint64 - submittedMsg *boostTypes.BuilderSubmitBlockRequest - submittedMsgCh chan *boostTypes.BuilderSubmitBlockRequest + submittedMsg *bellatrix.SubmitBlockRequest + submittedMsgCh chan *bellatrix.SubmitBlockRequest submittedMsgCapella *capella.SubmitBlockRequest submittedMsgChCapella chan *capella.SubmitBlockRequest } @@ -46,7 +46,7 @@ func newTestRelayAggBackend(numRelay int) *testRelayAggBackend { return &testRelayAggBackend{testRelays, ragg} } -func (r *testRelay) SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest, registration ValidatorData) error { +func (r *testRelay) SubmitBlock(msg *bellatrix.SubmitBlockRequest, registration ValidatorData) error { if r.submittedMsgCh != nil { select { case r.submittedMsgCh <- msg: @@ -145,7 +145,7 @@ func TestRemoteRelayAggregator(t *testing.T) { time.Sleep(10 * time.Millisecond) // if submitting for unseen VD should error out - msg := &boostTypes.BuilderSubmitBlockRequest{} + msg := &bellatrix.SubmitBlockRequest{} err = backend.ragg.SubmitBlock(msg, ValidatorData{GasLimit: 40}) require.Error(t, err) }) @@ -166,12 +166,12 @@ func TestRemoteRelayAggregator(t *testing.T) { time.Sleep(10 * time.Millisecond) // if submitting for unseen VD should error out - msg := &boostTypes.BuilderSubmitBlockRequest{} + msg := &bellatrix.SubmitBlockRequest{} err = backend.ragg.SubmitBlock(msg, ValidatorData{GasLimit: 40}) require.Error(t, err) // should submit to the single pirmary if its the only one matching - backend.relays[0].submittedMsgCh = make(chan *boostTypes.BuilderSubmitBlockRequest, 1) + backend.relays[0].submittedMsgCh = make(chan *bellatrix.SubmitBlockRequest, 1) err = backend.ragg.SubmitBlock(msg, ValidatorData{GasLimit: 10}) require.NoError(t, err) select { @@ -212,9 +212,9 @@ func TestRemoteRelayAggregator(t *testing.T) { time.Sleep(10 * time.Millisecond) // should submit to multiple matching relays - backend.relays[0].submittedMsgCh = make(chan *boostTypes.BuilderSubmitBlockRequest, 1) - backend.relays[2].submittedMsgCh = make(chan *boostTypes.BuilderSubmitBlockRequest, 1) - msg := &boostTypes.BuilderSubmitBlockRequest{} + backend.relays[0].submittedMsgCh = make(chan *bellatrix.SubmitBlockRequest, 1) + backend.relays[2].submittedMsgCh = make(chan *bellatrix.SubmitBlockRequest, 1) + msg := &bellatrix.SubmitBlockRequest{} err = backend.ragg.SubmitBlock(msg, ValidatorData{GasLimit: 10}) require.Error(t, err) diff --git a/builder/relay_test.go b/builder/relay_test.go index 9b7b9cbf34..6c36651807 100644 --- a/builder/relay_test.go +++ b/builder/relay_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - boostTypes "github.com/flashbots/go-boost-utils/types" + "github.com/attestantio/go-eth2-client/spec/bellatrix" "github.com/gorilla/mux" "github.com/stretchr/testify/require" ) @@ -52,7 +52,7 @@ func TestRemoteRelay(t *testing.T) { require.True(t, found) expectedValidator_123 := ValidatorData{ Pubkey: "0x93247f2209abcacf57b75a51dafae777f9dd38bc7053d1af526f220a7489a6d3a2753e5f3e8b1cfe39b56f43611df74a", - FeeRecipient: boostTypes.Address{0xab, 0xcf, 0x8e, 0xd, 0x4e, 0x95, 0x87, 0x36, 0x9b, 0x23, 0x1, 0xd0, 0x79, 0x3, 0x47, 0x32, 0x3, 0x2, 0xcc, 0x9}, + FeeRecipient: bellatrix.ExecutionAddress{0xab, 0xcf, 0x8e, 0xd, 0x4e, 0x95, 0x87, 0x36, 0x9b, 0x23, 0x1, 0xd0, 0x79, 0x3, 0x47, 0x32, 0x3, 0x2, 0xcc, 0x9}, GasLimit: uint64(1), } require.Equal(t, expectedValidator_123, vd) @@ -97,13 +97,13 @@ func TestRemoteRelay(t *testing.T) { expectedValidator_155 := ValidatorData{ Pubkey: "0x93247f2209abcacf57b75a51dafae777f9dd38bc7053d1af526f220a7489a6d3a2753e5f3e8b1cfe39b56f43611df74a", - FeeRecipient: boostTypes.Address{0xab, 0xcf, 0x8e, 0xd, 0x4e, 0x95, 0x87, 0x36, 0x9b, 0x23, 0x1, 0xd0, 0x79, 0x3, 0x47, 0x32, 0x3, 0x2, 0xcc, 0x10}, + FeeRecipient: bellatrix.ExecutionAddress{0xab, 0xcf, 0x8e, 0xd, 0x4e, 0x95, 0x87, 0x36, 0x9b, 0x23, 0x1, 0xd0, 0x79, 0x3, 0x47, 0x32, 0x3, 0x2, 0xcc, 0x10}, GasLimit: uint64(1), } expectedValidator_156 := ValidatorData{ Pubkey: "0x93247f2209abcacf57b75a51dafae777f9dd38bc7053d1af526f220a7489a6d3a2753e5f3e8b1cfe39b56f43611df74a", - FeeRecipient: boostTypes.Address{0xab, 0xcf, 0x8e, 0xd, 0x4e, 0x95, 0x87, 0x36, 0x9b, 0x23, 0x1, 0xd0, 0x79, 0x3, 0x47, 0x32, 0x3, 0x2, 0xcc, 0x11}, + FeeRecipient: bellatrix.ExecutionAddress{0xab, 0xcf, 0x8e, 0xd, 0x4e, 0x95, 0x87, 0x36, 0x9b, 0x23, 0x1, 0xd0, 0x79, 0x3, 0x47, 0x32, 0x3, 0x2, 0xcc, 0x11}, GasLimit: uint64(1), } diff --git a/builder/service.go b/builder/service.go index 88a63259d1..7da670cacf 100644 --- a/builder/service.go +++ b/builder/service.go @@ -11,6 +11,7 @@ import ( "golang.org/x/time/rate" + "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" @@ -21,7 +22,7 @@ import ( "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/rpc" "github.com/flashbots/go-boost-utils/bls" - boostTypes "github.com/flashbots/go-boost-utils/types" + "github.com/flashbots/go-boost-utils/ssz" "github.com/flashbots/go-utils/httplogger" "github.com/gorilla/mux" ) @@ -141,9 +142,9 @@ func Register(stack *node.Node, backend *eth.Ethereum, cfg *Config) error { var genesisForkVersion [4]byte copy(genesisForkVersion[:], genesisForkVersionBytes[:4]) - builderSigningDomain := boostTypes.ComputeDomain(boostTypes.DomainTypeAppBuilder, genesisForkVersion, boostTypes.Root{}) + builderSigningDomain := ssz.ComputeDomain(ssz.DomainTypeAppBuilder, genesisForkVersion, phase0.Root{}) - genesisValidatorsRoot := boostTypes.Root(common.HexToHash(cfg.GenesisValidatorsRoot)) + genesisValidatorsRoot := phase0.Root(common.HexToHash(cfg.GenesisValidatorsRoot)) bellatrixForkVersionBytes, err := hexutil.Decode(cfg.BellatrixForkVersion) if err != nil { return fmt.Errorf("invalid bellatrixForkVersion: %w", err) @@ -151,7 +152,7 @@ func Register(stack *node.Node, backend *eth.Ethereum, cfg *Config) error { var bellatrixForkVersion [4]byte copy(bellatrixForkVersion[:], bellatrixForkVersionBytes[:4]) - proposerSigningDomain := boostTypes.ComputeDomain(boostTypes.DomainTypeBeaconProposer, bellatrixForkVersion, genesisValidatorsRoot) + proposerSigningDomain := ssz.ComputeDomain(ssz.DomainTypeBeaconProposer, bellatrixForkVersion, genesisValidatorsRoot) var beaconClient IBeaconClient if len(cfg.BeaconEndpoints) == 0 { @@ -174,7 +175,10 @@ func Register(stack *node.Node, backend *eth.Ethereum, cfg *Config) error { return errors.New("incorrect builder API secret key provided") } - localRelay = NewLocalRelay(relaySk, beaconClient, builderSigningDomain, proposerSigningDomain, ForkData{cfg.GenesisForkVersion, cfg.BellatrixForkVersion, cfg.GenesisValidatorsRoot}, cfg.EnableValidatorChecks) + localRelay, err = NewLocalRelay(relaySk, beaconClient, builderSigningDomain, proposerSigningDomain, ForkData{cfg.GenesisForkVersion, cfg.BellatrixForkVersion, cfg.GenesisValidatorsRoot}, cfg.EnableValidatorChecks) + if err != nil { + return fmt.Errorf("failed to create local relay: %w", err) + } } var relay IRelay @@ -279,7 +283,10 @@ func Register(stack *node.Node, backend *eth.Ethereum, cfg *Config) error { limiter: limiter, } - builderBackend := NewBuilder(builderArgs) + builderBackend, err := NewBuilder(builderArgs) + if err != nil { + return fmt.Errorf("failed to create builder backend: %w", err) + } builderService := NewService(cfg.ListenAddr, localRelay, builderBackend) stack.RegisterAPIs([]rpc.API{ diff --git a/builder/utils.go b/builder/utils.go index f5e041660a..f2383c5cc5 100644 --- a/builder/utils.go +++ b/builder/utils.go @@ -4,11 +4,17 @@ import ( "bytes" "compress/gzip" "context" + "encoding/json" + "errors" "fmt" "io" "net/http" ) +var ( + errHTTPErrorResponse = errors.New("HTTP error response") +) + // SendSSZRequest is a request to send SSZ data to a remote relay. func SendSSZRequest(ctx context.Context, client http.Client, method, url string, payload []byte, useGzip bool) (code int, err error) { var req *http.Request @@ -60,3 +66,56 @@ func SendSSZRequest(ctx context.Context, client http.Client, method, url string, } return resp.StatusCode, nil } + +// SendHTTPRequest - prepare and send HTTP request, marshaling the payload if any, and decoding the response if dst is set +func SendHTTPRequest(ctx context.Context, client http.Client, method, url string, payload, dst any) (code int, err error) { + var req *http.Request + + if payload == nil { + req, err = http.NewRequestWithContext(ctx, method, url, nil) + } else { + payloadBytes, err2 := json.Marshal(payload) + if err2 != nil { + return 0, fmt.Errorf("could not marshal request: %w", err2) + } + req, err = http.NewRequestWithContext(ctx, method, url, bytes.NewReader(payloadBytes)) + + // Set headers + req.Header.Add("Content-Type", "application/json") + } + if err != nil { + return 0, fmt.Errorf("could not prepare request: %w", err) + } + + // Execute request + resp, err := client.Do(req) + if err != nil { + return 0, err + } + defer resp.Body.Close() + + if resp.StatusCode == http.StatusNoContent { + return resp.StatusCode, nil + } + + if resp.StatusCode > 299 { + bodyBytes, err := io.ReadAll(resp.Body) + if err != nil { + return resp.StatusCode, fmt.Errorf("could not read error response body for status code %d: %w", resp.StatusCode, err) + } + return resp.StatusCode, fmt.Errorf("%w: %d / %s", errHTTPErrorResponse, resp.StatusCode, string(bodyBytes)) + } + + if dst != nil { + bodyBytes, err := io.ReadAll(resp.Body) + if err != nil { + return resp.StatusCode, fmt.Errorf("could not read response body: %w", err) + } + + if err := json.Unmarshal(bodyBytes, dst); err != nil { + return resp.StatusCode, fmt.Errorf("could not unmarshal response %s: %w", string(bodyBytes), err) + } + } + + return resp.StatusCode, nil +} diff --git a/builder/validator.go b/builder/validator.go index 22192c1943..40d8c24014 100644 --- a/builder/validator.go +++ b/builder/validator.go @@ -1,11 +1,16 @@ package builder import ( + "errors" "time" + apiv1 "github.com/attestantio/go-builder-client/api/v1" + "github.com/attestantio/go-eth2-client/spec/bellatrix" + "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/flashbots/go-boost-utils/bls" - boostTypes "github.com/flashbots/go-boost-utils/types" + "github.com/flashbots/go-boost-utils/ssz" + "github.com/flashbots/go-boost-utils/utils" ) type ValidatorPrivateData struct { @@ -18,31 +23,34 @@ func NewRandomValidator() *ValidatorPrivateData { if err != nil { return nil } - return &ValidatorPrivateData{sk, pk.Compress()} + return &ValidatorPrivateData{sk, bls.PublicKeyToBytes(pk)} } -func (v *ValidatorPrivateData) Sign(msg boostTypes.HashTreeRoot, d boostTypes.Domain) (boostTypes.Signature, error) { - return boostTypes.SignMessage(msg, d, v.sk) +func (v *ValidatorPrivateData) Sign(msg ssz.ObjWithHashTreeRoot, d phase0.Domain) (phase0.BLSSignature, error) { + return ssz.SignMessage(msg, d, v.sk) } -func (v *ValidatorPrivateData) PrepareRegistrationMessage(feeRecipientHex string) (boostTypes.SignedValidatorRegistration, error) { - address, err := boostTypes.HexToAddress(feeRecipientHex) +func (v *ValidatorPrivateData) PrepareRegistrationMessage(feeRecipientHex string) (apiv1.SignedValidatorRegistration, error) { + address, err := utils.HexToAddress(feeRecipientHex) if err != nil { - return boostTypes.SignedValidatorRegistration{}, err + return apiv1.SignedValidatorRegistration{}, err } - pubkey := boostTypes.PublicKey{} - pubkey.FromSlice(v.Pk) + if len(v.Pk) != 48 { + return apiv1.SignedValidatorRegistration{}, errors.New("invalid public key") + } + pubkey := phase0.BLSPubKey{} + copy(pubkey[:], v.Pk) - msg := &boostTypes.RegisterValidatorRequestMessage{ - FeeRecipient: address, + msg := &apiv1.ValidatorRegistration{ + FeeRecipient: bellatrix.ExecutionAddress(address), GasLimit: 1000, - Timestamp: uint64(time.Now().UnixMilli()), + Timestamp: time.Now(), Pubkey: pubkey, } - signature, err := v.Sign(msg, boostTypes.DomainBuilder) + signature, err := v.Sign(msg, ssz.DomainBuilder) if err != nil { - return boostTypes.SignedValidatorRegistration{}, err + return apiv1.SignedValidatorRegistration{}, err } - return boostTypes.SignedValidatorRegistration{Message: msg, Signature: signature}, nil + return apiv1.SignedValidatorRegistration{Message: msg, Signature: phase0.BLSSignature(signature)}, nil } diff --git a/eth/block-validation/api.go b/eth/block-validation/api.go index f452bd45f6..d2727ce945 100644 --- a/eth/block-validation/api.go +++ b/eth/block-validation/api.go @@ -7,6 +7,7 @@ import ( "math/big" "os" + bellatrixapi "github.com/attestantio/go-builder-client/api/bellatrix" capellaapi "github.com/attestantio/go-builder-client/api/capella" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/ethereum/go-ethereum/beacon/engine" @@ -18,8 +19,6 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/rpc" - - boostTypes "github.com/flashbots/go-boost-utils/types" ) type BlacklistedAddresses []common.Address @@ -126,7 +125,7 @@ func NewBlockValidationAPI(eth *eth.Ethereum, accessVerifier *AccessVerifier) *B } type BuilderBlockValidationRequest struct { - boostTypes.BuilderSubmitBlockRequest + bellatrixapi.SubmitBlockRequest RegisteredGasLimit uint64 `json:"registered_gas_limit,string"` } @@ -143,11 +142,11 @@ func (api *BlockValidationAPI) ValidateBuilderSubmissionV1(params *BuilderBlockV return err } - if params.Message.ParentHash != boostTypes.Hash(block.ParentHash()) { + if params.Message.ParentHash != phase0.Hash32(block.ParentHash()) { return fmt.Errorf("incorrect ParentHash %s, expected %s", params.Message.ParentHash.String(), block.ParentHash().String()) } - if params.Message.BlockHash != boostTypes.Hash(block.Hash()) { + if params.Message.BlockHash != phase0.Hash32(block.Hash()) { return fmt.Errorf("incorrect BlockHash %s, expected %s", params.Message.BlockHash.String(), block.Hash().String()) } @@ -160,7 +159,7 @@ func (api *BlockValidationAPI) ValidateBuilderSubmissionV1(params *BuilderBlockV } feeRecipient := common.BytesToAddress(params.Message.ProposerFeeRecipient[:]) - expectedProfit := params.Message.Value.BigInt() + expectedProfit := params.Message.Value.ToBig() var vmconfig vm.Config var tracer *logger.AccessListTracer = nil @@ -175,7 +174,7 @@ func (api *BlockValidationAPI) ValidateBuilderSubmissionV1(params *BuilderBlockV return err } isPostMerge := true // the call is PoS-native - timestamp := params.BuilderSubmitBlockRequest.ExecutionPayload.Timestamp + timestamp := params.SubmitBlockRequest.ExecutionPayload.Timestamp precompiles := vm.ActivePrecompiles(api.eth.APIBackend.ChainConfig().Rules(new(big.Int).SetUint64(params.ExecutionPayload.BlockNumber), isPostMerge, timestamp)) tracer = logger.NewAccessListTracer(nil, common.Address{}, common.Address{}, precompiles) vmconfig = vm.Config{Tracer: tracer, Debug: true} @@ -236,12 +235,6 @@ func (api *BlockValidationAPI) ValidateBuilderSubmissionV2(params *BuilderBlockV return err } - // validated at the relay - // isShanghai := api.eth.BlockChain().Config().IsShanghai(params.ExecutionPayload.Timestamp) - // if err := verifyWithdrawals(block.Withdrawals(), params.WithdrawalsRoot, isShanghai); err != nil { - // return err - // } - if params.Message.ParentHash != phase0.Hash32(block.ParentHash()) { return fmt.Errorf("incorrect ParentHash %s, expected %s", params.Message.ParentHash.String(), block.ParentHash().String()) } diff --git a/eth/block-validation/api_test.go b/eth/block-validation/api_test.go index eb3d487cf3..412fe3d29e 100644 --- a/eth/block-validation/api_test.go +++ b/eth/block-validation/api_test.go @@ -8,6 +8,7 @@ import ( "testing" "time" + bellatrixapi "github.com/attestantio/go-builder-client/api/bellatrix" capellaapi "github.com/attestantio/go-builder-client/api/capella" apiv1 "github.com/attestantio/go-builder-client/api/v1" "github.com/attestantio/go-eth2-client/spec/bellatrix" @@ -90,15 +91,15 @@ func TestValidateBuilderSubmissionV1(t *testing.T) { payload, err := ExecutableDataToExecutionPayload(execData) require.NoError(t, err) - proposerAddr := boostTypes.Address{} - proposerAddr.FromSlice(testValidatorAddr[:]) + proposerAddr := bellatrix.ExecutionAddress{} + copy(proposerAddr[:], testValidatorAddr[:]) blockRequest := &BuilderBlockValidationRequest{ - BuilderSubmitBlockRequest: boostTypes.BuilderSubmitBlockRequest{ - Signature: boostTypes.Signature{}, - Message: &boostTypes.BidTrace{ - ParentHash: boostTypes.Hash(execData.ParentHash), - BlockHash: boostTypes.Hash(execData.BlockHash), + SubmitBlockRequest: bellatrixapi.SubmitBlockRequest{ + Signature: phase0.BLSSignature{}, + Message: &apiv1.BidTrace{ + ParentHash: phase0.Hash32(execData.ParentHash), + BlockHash: phase0.Hash32(execData.BlockHash), ProposerFeeRecipient: proposerAddr, GasLimit: execData.GasLimit, GasUsed: execData.GasUsed, @@ -108,9 +109,9 @@ func TestValidateBuilderSubmissionV1(t *testing.T) { RegisteredGasLimit: execData.GasLimit, } - blockRequest.Message.Value = boostTypes.IntToU256(190526394825529) + blockRequest.Message.Value = uint256.NewInt(190526394825529) require.ErrorContains(t, api.ValidateBuilderSubmissionV1(blockRequest), "inaccurate payment") - blockRequest.Message.Value = boostTypes.IntToU256(149830884438530) + blockRequest.Message.Value = uint256.NewInt(149830884438530) require.NoError(t, api.ValidateBuilderSubmissionV1(blockRequest)) blockRequest.Message.GasLimit += 1 @@ -157,7 +158,6 @@ func TestValidateBuilderSubmissionV1(t *testing.T) { invalidPayload, err := ExecutableDataToExecutionPayload(execData) require.NoError(t, err) invalidPayload.GasUsed = execData.GasUsed - invalidPayload.LogsBloom = boostTypes.Bloom{} copy(invalidPayload.ReceiptsRoot[:], hexutil.MustDecode("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")[:32]) blockRequest.ExecutionPayload = invalidPayload updatePayloadHash(t, blockRequest) @@ -290,7 +290,6 @@ func TestValidateBuilderSubmissionV2(t *testing.T) { invalidPayload, err := ExecutableDataToExecutionPayloadV2(execData) require.NoError(t, err) invalidPayload.GasUsed = execData.GasUsed - invalidPayload.LogsBloom = boostTypes.Bloom{} copy(invalidPayload.ReceiptsRoot[:], hexutil.MustDecode("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")[:32]) blockRequest.ExecutionPayload = invalidPayload updatePayloadHashV2(t, blockRequest) @@ -436,10 +435,10 @@ func TestBlacklistLoad(t *testing.T) { require.NoError(t, av.verifyTraces(tracer)) } -func ExecutableDataToExecutionPayload(data *engine.ExecutableData) (*boostTypes.ExecutionPayload, error) { - transactionData := make([]hexutil.Bytes, len(data.Transactions)) +func ExecutableDataToExecutionPayload(data *engine.ExecutableData) (*bellatrix.ExecutionPayload, error) { + transactionData := make([]bellatrix.Transaction, len(data.Transactions)) for i, tx := range data.Transactions { - transactionData[i] = hexutil.Bytes(tx) + transactionData[i] = bellatrix.Transaction(tx) } baseFeePerGas := new(boostTypes.U256Str) @@ -448,13 +447,13 @@ func ExecutableDataToExecutionPayload(data *engine.ExecutableData) (*boostTypes. return nil, err } - return &boostTypes.ExecutionPayload{ + return &bellatrix.ExecutionPayload{ ParentHash: [32]byte(data.ParentHash), FeeRecipient: [20]byte(data.FeeRecipient), StateRoot: [32]byte(data.StateRoot), ReceiptsRoot: [32]byte(data.ReceiptsRoot), - LogsBloom: boostTypes.Bloom(types.BytesToBloom(data.LogsBloom)), - Random: [32]byte(data.Random), + LogsBloom: types.BytesToBloom(data.LogsBloom), + PrevRandao: [32]byte(data.Random), BlockNumber: data.Number, GasLimit: data.GasLimit, GasUsed: data.GasUsed, @@ -493,7 +492,7 @@ func ExecutableDataToExecutionPayloadV2(data *engine.ExecutableData) (*capella.E FeeRecipient: [20]byte(data.FeeRecipient), StateRoot: [32]byte(data.StateRoot), ReceiptsRoot: [32]byte(data.ReceiptsRoot), - LogsBloom: boostTypes.Bloom(types.BytesToBloom(data.LogsBloom)), + LogsBloom: types.BytesToBloom(data.LogsBloom), PrevRandao: [32]byte(data.Random), BlockNumber: data.Number, GasLimit: data.GasLimit, diff --git a/flashbotsextra/database.go b/flashbotsextra/database.go index 026ac0189d..6f56b8603f 100644 --- a/flashbotsextra/database.go +++ b/flashbotsextra/database.go @@ -6,10 +6,10 @@ import ( "math/big" "time" + apiv1 "github.com/attestantio/go-builder-client/api/v1" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" - boostTypes "github.com/flashbots/go-boost-utils/types" "github.com/jmoiron/sqlx" _ "github.com/lib/pq" ) @@ -172,7 +172,7 @@ func (ds *DatabaseService) getBundleIdsAndInsertMissingBundles(ctx context.Conte return bundleIdsMap, nil } -func (ds *DatabaseService) insertBuildBlock(tx *sqlx.Tx, ctx context.Context, block *types.Block, blockValue *big.Int, bidTrace *boostTypes.BidTrace, ordersClosedAt time.Time, sealedAt time.Time) (uint64, error) { +func (ds *DatabaseService) insertBuildBlock(tx *sqlx.Tx, ctx context.Context, block *types.Block, blockValue *big.Int, bidTrace *apiv1.BidTrace, ordersClosedAt time.Time, sealedAt time.Time) (uint64, error) { blockData := BuiltBlock{ BlockNumber: block.NumberU64(), Profit: new(big.Rat).SetFrac(blockValue, big.NewInt(1e18)).FloatString(18), diff --git a/flashbotsextra/database_test.go b/flashbotsextra/database_test.go index 5d0fe37e6c..cc7d3ffe23 100644 --- a/flashbotsextra/database_test.go +++ b/flashbotsextra/database_test.go @@ -6,9 +6,9 @@ import ( "testing" "time" + apiv1 "github.com/attestantio/go-builder-client/api/v1" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - boostTypes "github.com/flashbots/go-boost-utils/types" "github.com/stretchr/testify/require" ) diff --git a/go.mod b/go.mod index 0edcfeca8d..651b1a2ab6 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/cespare/cp v1.1.1 github.com/cloudflare/cloudflare-go v0.14.0 github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 - github.com/consensys/gnark-crypto v0.9.1-0.20230105202408-1a7a29904a7c + github.com/consensys/gnark-crypto v0.11.0 github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set/v2 v2.1.0 github.com/docker/docker v1.6.2 @@ -24,9 +24,8 @@ require ( github.com/fatih/color v1.13.0 github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 - github.com/flashbots/go-boost-utils v0.3.5 - github.com/flashbots/go-utils v0.4.5 - github.com/flashbots/mev-boost v0.7.3 + github.com/flashbots/go-boost-utils v1.6.1-0.20230530114823-e5d0f8730a0f + github.com/flashbots/go-utils v0.4.8 github.com/fsnotify/fsnotify v1.6.0 github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 github.com/gballet/go-verkle v0.0.0-20220902153445-097bd83b7732 @@ -66,17 +65,23 @@ require ( github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tyler-smith/go-bip39 v1.1.0 github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa - golang.org/x/crypto v0.1.0 + golang.org/x/crypto v0.7.0 golang.org/x/exp v0.0.0-20230206171751-46f607a40771 golang.org/x/sync v0.1.0 golang.org/x/sys v0.6.0 - golang.org/x/text v0.7.0 + golang.org/x/text v0.8.0 golang.org/x/time v0.0.0-20220922220347-f3bd1da661af - golang.org/x/tools v0.2.0 + golang.org/x/tools v0.6.0 gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce ) -require gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect +require ( + github.com/bits-and-blooms/bitset v1.5.0 // indirect + go.uber.org/atomic v1.10.0 // indirect + go.uber.org/multierr v1.6.0 // indirect + go.uber.org/zap v1.23.0 // indirect + gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect +) require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1 // indirect @@ -97,7 +102,7 @@ require ( github.com/consensys/bavard v0.1.13 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/crate-crypto/go-ipa v0.0.0-20220523130400-f11357ae11c7 // indirect - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect github.com/deepmap/oapi-codegen v1.8.2 // indirect github.com/dlclark/regexp2 v1.7.0 // indirect github.com/ferranbt/fastssz v0.1.3 // indirect @@ -105,7 +110,7 @@ require ( github.com/getsentry/sentry-go v0.18.0 // indirect github.com/go-ole/go-ole v1.2.1 // indirect github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect - github.com/goccy/go-yaml v1.9.2 // indirect + github.com/goccy/go-yaml v1.9.6 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097 // indirect github.com/klauspost/compress v1.15.15 // indirect @@ -134,8 +139,8 @@ require ( github.com/tklauser/go-sysconf v0.3.5 // indirect github.com/tklauser/numcpus v0.2.2 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect - golang.org/x/mod v0.6.0 // indirect - golang.org/x/net v0.4.0 // indirect + golang.org/x/mod v0.8.0 // indirect + golang.org/x/net v0.8.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index b47788aba4..c92e8bf331 100644 --- a/go.sum +++ b/go.sum @@ -71,10 +71,13 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.1.1/go.mod h1:Wi0EBZwiz/K44YliU0EKxq github.com/aws/smithy-go v1.1.0 h1:D6CSsM3gdxaGaqXnPgOBCeL6Mophqzu7KJOu7zW78sU= github.com/aws/smithy-go v1.1.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= +github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bits-and-blooms/bitset v1.5.0 h1:NpE8frKRLGHIcEzkR+gZhiioW1+WbYV6fKwD6ZIpQT8= +github.com/bits-and-blooms/bitset v1.5.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= @@ -110,8 +113,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.9.1-0.20230105202408-1a7a29904a7c h1:llSLg4o9EgH3SrXky+Q5BqEYqV76NGKo07K5Ps2pIKo= -github.com/consensys/gnark-crypto v0.9.1-0.20230105202408-1a7a29904a7c/go.mod h1:CkbdF9hbRidRJYMRzmfX8TMOr95I2pYXRHF18MzRrvA= +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/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= @@ -130,9 +133,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6dtGktsI= github.com/deckarep/golang-set/v2 v2.1.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0= -github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 h1:HbphB4TFFXpv7MNrT52FGrrgVXF1owhMVTHFZIlnvd4= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0/go.mod h1:DZGJHZMqrU4JJqFAWUS2UO1+lbSKsdiOoYi9Zzey7Fc= github.com/deepmap/oapi-codegen v1.6.0/go.mod h1:ryDa9AgbELGeB+YEXE1dR53yAjHwFvE9iAUlWl9Al3M= github.com/deepmap/oapi-codegen v1.8.2 h1:SegyeYGcdi0jLLrpbCMoJxnUUn8GBXHsvr4rbzjuhfU= github.com/deepmap/oapi-codegen v1.8.2/go.mod h1:YLgSKSDv/bZQB7N4ws6luhozi3cEdRktEqrX88CvjIw= @@ -174,12 +176,10 @@ github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c h1:CndMRAH4JIwxbW8KYq github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c/go.mod h1:AzA8Lj6YtixmJWL+wkKoBGsLWy9gFrAzi4g+5bCKwpY= github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c= github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= -github.com/flashbots/go-boost-utils v0.3.5 h1:RApwo1+8SGKhEGWH/WFIhg21pkCCW+RpO7MkZwiMI6A= -github.com/flashbots/go-boost-utils v0.3.5/go.mod h1:vEfLpq6MLgdRtfWUG0fGDBbHXu0SyRInkw6ekLJeRIU= -github.com/flashbots/go-utils v0.4.5 h1:xTrVcfxQ+qpVVPyRBWUllwZAxbAijE06d9N7e7mmmlM= -github.com/flashbots/go-utils v0.4.5/go.mod h1:3YKyfbtetVIXuWKbZ9WmK8bSF20hSFXk0wCWDNHYFvE= -github.com/flashbots/mev-boost v0.7.3 h1:AwJQACv6/CJuMQe4oGNvIgW00oKFCzzDBrb4DlJsBKE= -github.com/flashbots/mev-boost v0.7.3/go.mod h1:DOqKZloyaZnfr6eGbnQb8XGH3gtjts19ATxI1LnfcNM= +github.com/flashbots/go-boost-utils v1.6.1-0.20230530114823-e5d0f8730a0f h1:bqjiOGi7eKSRC/RDLkh5voN/D4zIPOws3+IRU9J+U/o= +github.com/flashbots/go-boost-utils v1.6.1-0.20230530114823-e5d0f8730a0f/go.mod h1:fjoQ0NT/zd6LLVSSye+mCJhBemse7GW+06m+pxECETQ= +github.com/flashbots/go-utils v0.4.8 h1:WDJXryrqShGq4HFe+p1kGjObXSqzT7Sy/+9YvFpr5tM= +github.com/flashbots/go-utils v0.4.8/go.mod h1:dBmSv4Cpqij4xKP50bdisAvFIo4/EgsY97BMpVjPzr0= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= @@ -234,8 +234,8 @@ github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= -github.com/goccy/go-yaml v1.9.2 h1:2Njwzw+0+pjU2gb805ZC1B/uBuAs2VcZ3K+ZgHwDs7w= -github.com/goccy/go-yaml v1.9.2/go.mod h1:U/jl18uSupI5rdI2jmuCswEA2htH9eXfferR3KfscvA= +github.com/goccy/go-yaml v1.9.6 h1:KhAu1zf9JXnm3vbG49aDE0E5uEBUsM4uwD31/58ZWyI= +github.com/goccy/go-yaml v1.9.6/go.mod h1:JubOolP3gh0HpiBc4BLRD4YmjEjHAmIIB2aaXKkTfoE= github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= @@ -625,8 +625,16 @@ go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= +go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= +go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.23.0 h1:OjGQ5KQDEUawVHxNwQgPpiypGHOxo2mNZsOqTak4fFY= +go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -641,8 +649,8 @@ golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= -golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= +golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -675,8 +683,8 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I= -golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI= +golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -709,8 +717,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211008194852-3b03d305991f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU= -golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= +golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -770,6 +778,7 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211020174200-9d6173849985/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -786,8 +795,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -826,8 +835,8 @@ golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.2.0 h1:G6AHpWxTMGY1KyEYoAQ5WTtIekUUvDNjan3ugu60JvE= -golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA= +golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From 9a692c20fcde56d4c77626b90d306de56c117a84 Mon Sep 17 00:00:00 2001 From: avalonche Date: Thu, 1 Jun 2023 15:44:46 +1000 Subject: [PATCH 2/4] fix tests --- builder/builder.go | 22 +++++++++++----------- builder/builder_test.go | 2 +- builder/local_relay.go | 4 +++- builder/local_relay_test.go | 19 ++++++++++++++----- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/builder/builder.go b/builder/builder.go index e223a5618a..fb6093ee95 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -62,17 +62,17 @@ type IBuilder interface { } type Builder struct { - ds flashbotsextra.IDatabaseService - relay IRelay - eth IEthereumService - dryRun bool - ignoreLatePayloadAttributes bool - validator *blockvalidation.BlockValidationAPI - beaconClient IBeaconClient - builderSecretKey *bls.SecretKey - builderPublicKey phase0.BLSPubKey - builderSigningDomain phase0.Domain - builderResubmitInterval time.Duration + ds flashbotsextra.IDatabaseService + relay IRelay + eth IEthereumService + dryRun bool + ignoreLatePayloadAttributes bool + validator *blockvalidation.BlockValidationAPI + beaconClient IBeaconClient + builderSecretKey *bls.SecretKey + builderPublicKey phase0.BLSPubKey + builderSigningDomain phase0.Domain + builderResubmitInterval time.Duration limiter *rate.Limiter diff --git a/builder/builder_test.go b/builder/builder_test.go index 6b6f03b0e4..7c8c4cca9e 100644 --- a/builder/builder_test.go +++ b/builder/builder_test.go @@ -127,7 +127,7 @@ func TestOnPayloadAttributes(t *testing.T) { GasUsed: testExecutableData.GasUsed, Timestamp: testExecutableData.Timestamp, ExtraData: hexutil.MustDecode("0x0042fafc"), - BaseFeePerGas: uint256.NewInt(10).Bytes32(), + BaseFeePerGas: [32]byte{0x10}, BlockHash: expectedMessage.BlockHash, Transactions: []bellatrix.Transaction{}, } diff --git a/builder/local_relay.go b/builder/local_relay.go index 0cf7ba7f25..e4780d9460 100644 --- a/builder/local_relay.go +++ b/builder/local_relay.go @@ -176,6 +176,7 @@ func (r *LocalRelay) handleRegisterValidator(w http.ResponseWriter, req *http.Re // Do not check timestamp before signature, as it would leak validator data if registerRequest.Message.Timestamp.Unix() > time.Now().Add(10*time.Second).Unix() { + log.Error("invalid timestamp", "timestamp", registerRequest.Message.Timestamp) respondError(w, http.StatusBadRequest, "invalid payload") return } @@ -305,6 +306,7 @@ func (r *LocalRelay) handleGetHeader(w http.ResponseWriter, req *http.Request) { func (r *LocalRelay) handleGetPayload(w http.ResponseWriter, req *http.Request) { payload := new(apiv1bellatrix.SignedBlindedBeaconBlock) if err := json.NewDecoder(req.Body).Decode(&payload); err != nil { + log.Error("failed to decode payload", "error", err) respondError(w, http.StatusBadRequest, "invalid payload") return } @@ -355,7 +357,7 @@ func (r *LocalRelay) handleGetPayload(w http.ResponseWriter, req *http.Request) return } - response := api.VersionedExecutionPayload{ + response := &api.VersionedExecutionPayload{ Version: consensusspec.DataVersionBellatrix, Bellatrix: bestPayload, } diff --git a/builder/local_relay_test.go b/builder/local_relay_test.go index f30cddb973..27af2b49cb 100644 --- a/builder/local_relay_test.go +++ b/builder/local_relay_test.go @@ -66,6 +66,7 @@ func testRequest(t *testing.T, localRelay *LocalRelay, method, path string, payl req, err = http.NewRequest(method, path, nil) } else { payloadBytes, err2 := json.Marshal(payload) + fmt.Println(string(payloadBytes)) require.NoError(t, err2) req, err = http.NewRequest(method, path, bytes.NewReader(payloadBytes)) } @@ -180,7 +181,7 @@ func TestGetHeader(t *testing.T) { expectedHeader, err := PayloadToPayloadHeader(executionPayload) require.NoError(t, err) expectedValue, ok := uint256.FromBig(forkchoiceBlockProfit) - require.True(t, ok) + require.False(t, ok) require.EqualValues(t, &bellatrixapi.BuilderBid{ Header: expectedHeader, Value: expectedValue, @@ -223,6 +224,9 @@ func TestGetPayload(t *testing.T) { err = json.Unmarshal(rr.Body.Bytes(), bid) require.NoError(t, err) + blockHash := [32]byte{0x06} + syncCommitteeBits := [64]byte{0x07} + // Create request payload msg := &consensusapiv1bellatrix.BlindedBeaconBlock{ Slot: 1, @@ -233,10 +237,15 @@ func TestGetPayload(t *testing.T) { ETH1Data: &phase0.ETH1Data{ DepositRoot: phase0.Root{0x05}, DepositCount: 5, - BlockHash: []byte{0x06}, + BlockHash: blockHash[:], }, + ProposerSlashings: []*phase0.ProposerSlashing{}, + AttesterSlashings: []*phase0.AttesterSlashing{}, + Attestations: []*phase0.Attestation{}, + Deposits: []*phase0.Deposit{}, + VoluntaryExits: []*phase0.SignedVoluntaryExit{}, SyncAggregate: &altair.SyncAggregate{ - SyncCommitteeBits: []byte{0x07}, + SyncCommitteeBits: syncCommitteeBits[:], SyncCommitteeSignature: phase0.BLSSignature{0x08}, }, ExecutionPayloadHeader: bid.Bellatrix.Message.Header, @@ -248,7 +257,7 @@ func TestGetPayload(t *testing.T) { require.NoError(t, err) // Call getPayload with invalid signature - rr = testRequest(t, relay, "POST", "/eth/v1/builder/blinded_blocks", consensusapiv1bellatrix.SignedBlindedBeaconBlock{ + rr = testRequest(t, relay, "POST", "/eth/v1/builder/blinded_blocks", &consensusapiv1bellatrix.SignedBlindedBeaconBlock{ Message: msg, Signature: phase0.BLSSignature{0x09}, }) @@ -256,7 +265,7 @@ func TestGetPayload(t *testing.T) { require.Equal(t, `{"code":400,"message":"invalid signature"}`+"\n", rr.Body.String()) // Call getPayload with correct signature - rr = testRequest(t, relay, "POST", "/eth/v1/builder/blinded_blocks", consensusapiv1bellatrix.SignedBlindedBeaconBlock{ + rr = testRequest(t, relay, "POST", "/eth/v1/builder/blinded_blocks", &consensusapiv1bellatrix.SignedBlindedBeaconBlock{ Message: msg, Signature: signature, }) From 3ea3b07bb303cb0219131a6fc6fef509930cef9f Mon Sep 17 00:00:00 2001 From: avalonche Date: Thu, 1 Jun 2023 16:00:54 +1000 Subject: [PATCH 3/4] linting --- builder/builder.go | 15 +++++++-------- builder/local_relay.go | 9 +++------ builder/local_relay_test.go | 2 +- builder/relay.go | 1 - builder/resubmit_utils.go | 28 +++++++++++++--------------- builder/service.go | 3 +-- builder/utils.go | 4 +--- builder/validator.go | 5 ++--- 8 files changed, 28 insertions(+), 39 deletions(-) diff --git a/builder/builder.go b/builder/builder.go index fb6093ee95..b78e1f57a7 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -23,11 +23,10 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/flashbots/go-boost-utils/bls" "github.com/flashbots/go-boost-utils/ssz" + boostTypes "github.com/flashbots/go-boost-utils/types" "github.com/flashbots/go-boost-utils/utils" "github.com/holiman/uint256" "golang.org/x/time/rate" - - boostTypes "github.com/flashbots/go-boost-utils/types" ) const ( @@ -245,7 +244,7 @@ func (b *Builder) submitBellatrixBlock(block *types.Block, blockValue *big.Int, } blockSubmitReq := bellatrixapi.SubmitBlockRequest{ - Signature: phase0.BLSSignature(signature), + Signature: signature, Message: &blockBidMsg, ExecutionPayload: payload, } @@ -289,9 +288,9 @@ func (b *Builder) submitCapellaBlock(block *types.Block, blockValue *big.Int, or Slot: attrs.Slot, ParentHash: payload.ParentHash, BlockHash: payload.BlockHash, - BuilderPubkey: phase0.BLSPubKey(b.builderPublicKey), - ProposerPubkey: phase0.BLSPubKey(proposerPubkey), - ProposerFeeRecipient: bellatrix.ExecutionAddress(vd.FeeRecipient), + BuilderPubkey: b.builderPublicKey, + ProposerPubkey: proposerPubkey, + ProposerFeeRecipient: vd.FeeRecipient, GasLimit: executableData.ExecutionPayload.GasLimit, GasUsed: executableData.ExecutionPayload.GasUsed, Value: value, @@ -304,7 +303,7 @@ func (b *Builder) submitCapellaBlock(block *types.Block, blockValue *big.Int, or } blockSubmitReq := capellaapi.SubmitBlockRequest{ - Signature: phase0.BLSSignature(signature), + Signature: signature, Message: &blockBidMsg, ExecutionPayload: payload, } @@ -371,7 +370,7 @@ func (b *Builder) OnPayloadAttribute(attrs *types.BuilderPayloadAttributes) erro b.slotCtx = slotCtx b.slotCtxCancel = slotCtxCancel - go b.runBuildingJob(b.slotCtx, phase0.BLSPubKey(proposerPubkey), vd, attrs) + go b.runBuildingJob(b.slotCtx, proposerPubkey, vd, attrs) return nil } diff --git a/builder/local_relay.go b/builder/local_relay.go index e4780d9460..9c2abef78c 100644 --- a/builder/local_relay.go +++ b/builder/local_relay.go @@ -27,9 +27,8 @@ import ( "github.com/flashbots/go-boost-utils/bls" "github.com/flashbots/go-boost-utils/ssz" "github.com/flashbots/go-boost-utils/utils" - "github.com/holiman/uint256" - "github.com/gorilla/mux" + "github.com/holiman/uint256" ) type ForkData struct { @@ -292,7 +291,7 @@ func (r *LocalRelay) handleGetHeader(w http.ResponseWriter, req *http.Request) { response := &spec.VersionedSignedBuilderBid{ Version: consensusspec.DataVersionBellatrix, - Bellatrix: &bellatrixapi.SignedBuilderBid{Message: &bid, Signature: phase0.BLSSignature(signature)}, + Bellatrix: &bellatrixapi.SignedBuilderBid{Message: &bid, Signature: signature}, } w.Header().Set("Content-Type", "application/json") @@ -441,9 +440,7 @@ func PayloadToPayloadHeader(p *bellatrix.ExecutionPayload) (*bellatrix.Execution } var txs []bellatrix.Transaction - for _, tx := range p.Transactions { - txs = append(txs, tx) - } + txs = append(txs, p.Transactions...) transactions := bellatrixutil.ExecutionPayloadTransactions{Transactions: txs} txroot, err := transactions.HashTreeRoot() diff --git a/builder/local_relay_test.go b/builder/local_relay_test.go index 27af2b49cb..4b6ae15630 100644 --- a/builder/local_relay_test.go +++ b/builder/local_relay_test.go @@ -92,7 +92,7 @@ func TestValidatorRegistration(t *testing.T) { rr = testRequest(t, relay, "POST", "/eth/v1/builder/validators", payload) require.Equal(t, http.StatusOK, rr.Code) - payload[0].Message.Timestamp.Add(time.Second) + payload[0].Message.Timestamp = payload[0].Message.Timestamp.Add(time.Second) // Invalid signature payload[0].Signature[len(payload[0].Signature)-1] = 0x00 rr = testRequest(t, relay, "POST", "/eth/v1/builder/validators", payload) diff --git a/builder/relay.go b/builder/relay.go index 1176c2ba93..a28fe1e71c 100644 --- a/builder/relay.go +++ b/builder/relay.go @@ -12,7 +12,6 @@ import ( "github.com/attestantio/go-builder-client/api/bellatrix" "github.com/attestantio/go-builder-client/api/capella" "github.com/ethereum/go-ethereum/log" - "github.com/flashbots/go-boost-utils/utils" ) diff --git a/builder/resubmit_utils.go b/builder/resubmit_utils.go index 46c3fcc5ca..4819287e6d 100644 --- a/builder/resubmit_utils.go +++ b/builder/resubmit_utils.go @@ -15,22 +15,20 @@ func runResubmitLoop(ctx context.Context, limiter *rate.Limiter, updateSignal <- return } - var ( - waitUntilSubmitTime = func(waitUntil time.Time) (ok bool, err error) { - now := time.Now().UTC() - if waitUntil.UTC().Before(now) { - waitUntil = now - } - sleepTime := waitUntil.UTC().Sub(now.UTC()) - select { - case <-ctx.Done(): - ok = false - case <-time.After(sleepTime): - ok = true - } - return ok && ctx.Err() == nil, ctx.Err() + waitUntilSubmitTime := func(waitUntil time.Time) (ok bool, err error) { + now := time.Now().UTC() + if waitUntil.UTC().Before(now) { + waitUntil = now } - ) + sleepTime := waitUntil.UTC().Sub(now.UTC()) + select { + case <-ctx.Done(): + ok = false + case <-time.After(sleepTime): + ok = true + } + return ok && ctx.Err() == nil, ctx.Err() + } if canContinue, err := waitUntilSubmitTime(submitTime); !canContinue { log.Warn("skipping resubmit loop - cannot continue", "error", err) diff --git a/builder/service.go b/builder/service.go index 7da670cacf..03234f9667 100644 --- a/builder/service.go +++ b/builder/service.go @@ -9,8 +9,6 @@ import ( "strings" "time" - "golang.org/x/time/rate" - "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -25,6 +23,7 @@ import ( "github.com/flashbots/go-boost-utils/ssz" "github.com/flashbots/go-utils/httplogger" "github.com/gorilla/mux" + "golang.org/x/time/rate" ) const ( diff --git a/builder/utils.go b/builder/utils.go index f2383c5cc5..284285cf4e 100644 --- a/builder/utils.go +++ b/builder/utils.go @@ -11,9 +11,7 @@ import ( "net/http" ) -var ( - errHTTPErrorResponse = errors.New("HTTP error response") -) +var errHTTPErrorResponse = errors.New("HTTP error response") // SendSSZRequest is a request to send SSZ data to a remote relay. func SendSSZRequest(ctx context.Context, client http.Client, method, url string, payload []byte, useGzip bool) (code int, err error) { diff --git a/builder/validator.go b/builder/validator.go index 40d8c24014..9adcc51493 100644 --- a/builder/validator.go +++ b/builder/validator.go @@ -5,7 +5,6 @@ import ( "time" apiv1 "github.com/attestantio/go-builder-client/api/v1" - "github.com/attestantio/go-eth2-client/spec/bellatrix" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/flashbots/go-boost-utils/bls" @@ -43,7 +42,7 @@ func (v *ValidatorPrivateData) PrepareRegistrationMessage(feeRecipientHex string copy(pubkey[:], v.Pk) msg := &apiv1.ValidatorRegistration{ - FeeRecipient: bellatrix.ExecutionAddress(address), + FeeRecipient: address, GasLimit: 1000, Timestamp: time.Now(), Pubkey: pubkey, @@ -52,5 +51,5 @@ func (v *ValidatorPrivateData) PrepareRegistrationMessage(feeRecipientHex string if err != nil { return apiv1.SignedValidatorRegistration{}, err } - return apiv1.SignedValidatorRegistration{Message: msg, Signature: phase0.BLSSignature(signature)}, nil + return apiv1.SignedValidatorRegistration{Message: msg, Signature: signature}, nil } From d5cb4bbbbb542a9658e996d13bcff4afd058fb50 Mon Sep 17 00:00:00 2001 From: avalonche Date: Thu, 8 Jun 2023 04:45:49 +1000 Subject: [PATCH 4/4] merge conflicts --- builder/builder.go | 8 ++++---- flashbotsextra/database.go | 6 +++--- flashbotsextra/database_test.go | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/builder/builder.go b/builder/builder.go index b78e1f57a7..7d59b9d0f9 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -192,7 +192,7 @@ func (b *Builder) Stop() error { func (b *Builder) onSealedBlock(block *types.Block, blockValue *big.Int, ordersClosedAt, sealedAt time.Time, commitedBundles, allBundles []types.SimulatedBundle, usedSbundles []types.UsedSBundle, - proposerPubkey boostTypes.PublicKey, vd ValidatorData, attrs *types.BuilderPayloadAttributes) error { + proposerPubkey phase0.BLSPubKey, vd ValidatorData, attrs *types.BuilderPayloadAttributes) error { if b.eth.Config().IsShanghai(block.Time()) { if err := b.submitCapellaBlock(block, blockValue, ordersClosedAt, sealedAt, commitedBundles, allBundles, usedSbundles, proposerPubkey, vd, attrs); err != nil { return err @@ -211,7 +211,7 @@ func (b *Builder) onSealedBlock(block *types.Block, blockValue *big.Int, ordersC func (b *Builder) submitBellatrixBlock(block *types.Block, blockValue *big.Int, ordersClosedAt, sealedAt time.Time, commitedBundles, allBundles []types.SimulatedBundle, usedSbundles []types.UsedSBundle, - proposerPubkey boostTypes.PublicKey, vd ValidatorData, attrs *types.BuilderPayloadAttributes) error { + proposerPubkey phase0.BLSPubKey, vd ValidatorData, attrs *types.BuilderPayloadAttributes) error { executableData := engine.BlockToExecutableData(block, blockValue) payload, err := executableDataToExecutionPayload(executableData.ExecutionPayload) if err != nil { @@ -270,7 +270,7 @@ func (b *Builder) submitBellatrixBlock(block *types.Block, blockValue *big.Int, func (b *Builder) submitCapellaBlock(block *types.Block, blockValue *big.Int, ordersClosedAt, sealedAt time.Time, commitedBundles, allBundles []types.SimulatedBundle, usedSbundles []types.UsedSBundle, - proposerPubkey boostTypes.PublicKey, vd ValidatorData, attrs *types.BuilderPayloadAttributes) error { + proposerPubkey phase0.BLSPubKey, vd ValidatorData, attrs *types.BuilderPayloadAttributes) error { executableData := engine.BlockToExecutableData(block, blockValue) payload, err := executableDataToCapellaExecutionPayload(executableData.ExecutionPayload) if err != nil { @@ -314,7 +314,7 @@ func (b *Builder) submitCapellaBlock(block *types.Block, blockValue *big.Int, or log.Error("could not validate block for capella", "err", err) } } else { - go b.ds.ConsumeBuiltBlock(block, blockValue, ordersClosedAt, sealedAt, commitedBundles, allBundles, usedSbundles, &boostBidTrace) + go b.ds.ConsumeBuiltBlock(block, blockValue, ordersClosedAt, sealedAt, commitedBundles, allBundles, usedSbundles, &blockBidMsg) err = b.relay.SubmitBlockCapella(&blockSubmitReq, vd) if err != nil { log.Error("could not submit capella block", "err", err, "#commitedBundles", len(commitedBundles)) diff --git a/flashbotsextra/database.go b/flashbotsextra/database.go index 6f56b8603f..d39274e974 100644 --- a/flashbotsextra/database.go +++ b/flashbotsextra/database.go @@ -23,14 +23,14 @@ type IDatabaseService interface { ConsumeBuiltBlock(block *types.Block, blockValue *big.Int, OrdersClosedAt time.Time, sealedAt time.Time, commitedBundles []types.SimulatedBundle, allBundles []types.SimulatedBundle, usedSbundles []types.UsedSBundle, - bidTrace *boostTypes.BidTrace) + bidTrace *apiv1.BidTrace) GetPriorityBundles(ctx context.Context, blockNum int64, isHighPrio bool) ([]DbBundle, error) GetLatestUuidBundles(ctx context.Context, blockNum int64) ([]types.LatestUuidBundle, error) } type NilDbService struct{} -func (NilDbService) ConsumeBuiltBlock(block *types.Block, _ *big.Int, _ time.Time, _ time.Time, _ []types.SimulatedBundle, _ []types.SimulatedBundle, _ []types.UsedSBundle, _ *boostTypes.BidTrace) { +func (NilDbService) ConsumeBuiltBlock(block *types.Block, _ *big.Int, _ time.Time, _ time.Time, _ []types.SimulatedBundle, _ []types.SimulatedBundle, _ []types.UsedSBundle, _ *apiv1.BidTrace) { } func (NilDbService) GetPriorityBundles(ctx context.Context, blockNum int64, isHighPrio bool) ([]DbBundle, error) { @@ -247,7 +247,7 @@ func (ds *DatabaseService) insertUsedSBundleIds(tx *sqlx.Tx, ctx context.Context func (ds *DatabaseService) ConsumeBuiltBlock(block *types.Block, blockValue *big.Int, ordersClosedAt time.Time, sealedAt time.Time, commitedBundles []types.SimulatedBundle, allBundles []types.SimulatedBundle, usedSbundles []types.UsedSBundle, - bidTrace *boostTypes.BidTrace) { + bidTrace *apiv1.BidTrace) { ctx, cancel := context.WithTimeout(context.Background(), 12*time.Second) defer cancel() diff --git a/flashbotsextra/database_test.go b/flashbotsextra/database_test.go index cc7d3ffe23..232ab4c3b1 100644 --- a/flashbotsextra/database_test.go +++ b/flashbotsextra/database_test.go @@ -120,7 +120,7 @@ func TestDatabaseBlockInsertion(t *testing.T) { Success: true, } - bidTrace := &boostTypes.BidTrace{} + bidTrace := &apiv1.BidTrace{} ocAt := time.Now().Add(-time.Hour).UTC() sealedAt := time.Now().Add(-30 * time.Minute).UTC()