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
10 changes: 6 additions & 4 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 Down
Loading