Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[feature] Optimistic v2 submission flow #524

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
28 changes: 28 additions & 0 deletions common/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"compress/gzip"
"encoding/base64"
"encoding/hex"
"encoding/json"
"io"
"os"
Expand All @@ -12,6 +13,7 @@ import (
"github.com/attestantio/go-builder-client/api/capella"
"github.com/attestantio/go-eth2-client/spec/bellatrix"
consensuscapella "github.com/attestantio/go-eth2-client/spec/capella"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/flashbots/go-boost-utils/bls"
boostTypes "github.com/flashbots/go-boost-utils/types"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -81,6 +83,32 @@ func TestBuilderSubmitBlockRequest(sk *bls.SecretKey, bid *BidTraceV2) BuilderSu
}
}

func TestBuilderSubmitBlockRequestV2(sk *bls.SecretKey, bid *BidTraceV2) *SubmitBlockRequestV2Optimistic {
signature, err := boostTypes.SignMessage(bid, boostTypes.DomainBuilder, sk)
check(err, " SignMessage: ", bid, sk)

wRoot, err := hex.DecodeString("792930bbd5baac43bcc798ee49aa8185ef76bb3b44ba62b91d86ae569e4bb535")
check(err)
return &SubmitBlockRequestV2Optimistic{
Message: &bid.BidTrace,
ExecutionPayloadHeader: &consensuscapella.ExecutionPayloadHeader{ //nolint:exhaustruct
TransactionsRoot: [32]byte{},
Timestamp: bid.Slot * 12, // 12 seconds per slot.
PrevRandao: _HexToHash("01234567890123456789012345678901"),
WithdrawalsRoot: phase0.Root(wRoot),
ExtraData: []byte{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
},
},
Signature: [96]byte(signature),
Transactions: []bellatrix.Transaction{[]byte{0x03}},
Withdrawals: []*consensuscapella.Withdrawal{},
}
}

func LoadGzippedBytes(t *testing.T, filename string) []byte {
t.Helper()
fi, err := os.Open(filename)
Expand Down
28 changes: 28 additions & 0 deletions common/types_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
utilcapella "github.com/attestantio/go-eth2-client/util/capella"
"github.com/flashbots/go-boost-utils/bls"
boostTypes "github.com/flashbots/go-boost-utils/types"
"github.com/holiman/uint256"
)

var (
Expand Down Expand Up @@ -71,6 +72,33 @@ func BuildGetHeaderResponse(payload *BuilderSubmitBlockRequest, sk *bls.SecretKe
return nil, ErrEmptyPayload
}

func BuildGetHeaderResponseHeaderOnly(value *uint256.Int, header *consensuscapella.ExecutionPayloadHeader, sk *bls.SecretKey, pubkey *boostTypes.PublicKey, domain boostTypes.Domain) (*GetHeaderResponse, error) {
builderBid := capella.BuilderBid{
Value: value,
Header: header,
Pubkey: *(*phase0.BLSPubKey)(pubkey),
}

sig, err := boostTypes.SignMessage(&builderBid, domain, sk)
if err != nil {
return nil, err
}

signedBuilderBid := &capella.SignedBuilderBid{
Message: &builderBid,
Signature: phase0.BLSSignature(sig),
}

return &GetHeaderResponse{
Capella: &spec.VersionedSignedBuilderBid{
Version: consensusspec.DataVersionCapella,
Capella: signedBuilderBid,
Bellatrix: nil,
},
Bellatrix: nil,
}, nil
}

func BuildGetPayloadResponse(payload *BuilderSubmitBlockRequest) (*GetPayloadResponse, error) {
if payload.Bellatrix != nil {
return &GetPayloadResponse{
Expand Down
13 changes: 8 additions & 5 deletions datastore/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,12 @@ func (r *RedisCache) SaveBidAndUpdateTopBid(ctx context.Context, pipeliner redis
//
// Time to save things in Redis
//
// 1. Save the execution payload
err = r.SaveExecutionPayloadCapella(ctx, pipeliner, payload.Slot(), payload.ProposerPubkey(), payload.BlockHash(), getPayloadResponse.Capella.Capella)
if err != nil {
return state, err
// 1. Save the execution payload (only if it was passed in).
if getPayloadResponse != nil {
err = r.SaveExecutionPayloadCapella(ctx, pipeliner, payload.Slot(), payload.ProposerPubkey(), payload.BlockHash(), getPayloadResponse.Capella.Capella)
if err != nil {
return state, err
}
}

// Record time needed to save payload
Expand All @@ -513,7 +515,6 @@ func (r *RedisCache) SaveBidAndUpdateTopBid(ctx context.Context, pipeliner redis
if err != nil {
return state, err
}
state.WasBidSaved = true
builderBids.bidValues[payload.BuilderPubkey().String()] = payload.Value()

// Record time needed to save bid
Expand Down Expand Up @@ -543,6 +544,8 @@ func (r *RedisCache) SaveBidAndUpdateTopBid(ctx context.Context, pipeliner redis
return state, err
}
state.IsNewTopBid = payload.Value().Cmp(state.TopBidValue) == 0
// An Exec happens in _updateTopBid.
state.WasBidSaved = true

// Record time needed to update top bid
nextTime = time.Now().UTC()
Expand Down
30 changes: 17 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ require (
github.com/bradfitz/gomemcache v0.0.0-20230124162541-5f7a7d875746
github.com/btcsuite/btcd/btcutil v1.1.2
github.com/buger/jsonparser v1.1.1
github.com/ethereum/go-ethereum v1.12.2
github.com/ethereum/go-ethereum v1.13.1
github.com/flashbots/go-boost-utils v1.6.0
github.com/flashbots/go-utils v0.4.11
github.com/flashbots/go-utils v0.5.0
github.com/go-redis/redis/v9 v9.0.0-rc.1
github.com/gorilla/mux v1.8.0
github.com/holiman/uint256 v1.2.3
Expand All @@ -35,18 +35,20 @@ require (
github.com/bits-and-blooms/bitset v1.7.0 // indirect
github.com/cockroachdb/errors v1.9.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 // indirect
github.com/cockroachdb/pebble v0.0.0-20230906160148-46873a6a7a06 // indirect
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.11.0 // indirect
github.com/crate-crypto/go-kzg-4844 v0.3.0 // indirect
github.com/ethereum/c-kzg-4844 v0.3.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/getsentry/sentry-go v0.18.0 // indirect
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
github.com/goccy/go-yaml v1.11.0 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
Expand All @@ -60,24 +62,26 @@ require (
github.com/prometheus/procfs v0.9.0 // indirect
github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/protobuf v1.28.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

require (
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VictoriaMetrics/fastcache v1.6.0 // indirect
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
github.com/btcsuite/btcd v0.23.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/ferranbt/fastssz v0.1.3
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
Expand All @@ -93,14 +97,14 @@ require (
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tdewolff/parse v2.3.4+incompatible // indirect
github.com/tdewolff/test v1.0.7 // indirect
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yuin/gopher-lua v1.1.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.23.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.25.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/sys v0.12.0 // indirect
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading
Loading