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

feat: bolt-boost changes #11

Merged
merged 17 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mev-boost/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/DataDog/zstd v1.5.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/chainbound/shardmap v0.0.3-0.20240604113309-43d9072efe8c // 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-20230928194634-aa077af62593 // indirect
Expand Down
4 changes: 4 additions & 0 deletions mev-boost/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46f
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chainbound/shardmap v0.0.2 h1:yB1weccdm2vC6dnqzzLwPIvyAnRj7815mJWbkPybiYw=
github.com/chainbound/shardmap v0.0.2/go.mod h1:TBvIzhHyFUbt+oa3UzbijobTUh221st6xIbuki7WzPc=
github.com/chainbound/shardmap v0.0.3-0.20240604113309-43d9072efe8c h1:7GkJDinsgr9Wcr5yJZGGtYFcCAxS9WSdOBr4DXBaM7c=
github.com/chainbound/shardmap v0.0.3-0.20240604113309-43d9072efe8c/go.mod h1:TBvIzhHyFUbt+oa3UzbijobTUh221st6xIbuki7WzPc=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cockroachdb/datadriven v1.0.2/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU=
Expand Down
10 changes: 6 additions & 4 deletions mev-boost/server/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package server

const (
// Router paths
pathStatus = "/eth/v1/builder/status"
pathRegisterValidator = "/eth/v1/builder/validators"
pathGetHeader = "/eth/v1/builder/header/{slot:[0-9]+}/{parent_hash:0x[a-fA-F0-9]+}/{pubkey:0x[a-fA-F0-9]+}"
pathGetPayload = "/eth/v1/builder/blinded_blocks"
pathStatus = "/eth/v1/builder/status"
pathRegisterValidator = "/eth/v1/builder/validators"
pathSubmitConstraint = "/eth/v1/builder/constraints"
pathGetHeader = "/eth/v1/builder/header/{slot:[0-9]+}/{parent_hash:0x[a-fA-F0-9]+}/{pubkey:0x[a-fA-F0-9]+}"
pathGetHeaderWithProofs = "/eth/v1/builder/header_with_proofs/{slot:[0-9]+}/{parent_hash:0x[a-fA-F0-9]+}/{pubkey:0x[a-fA-F0-9]+}"
pathGetPayload = "/eth/v1/builder/blinded_blocks"

// // Relay Monitor paths
// pathAuctionTranscript = "/monitor/v1/transcript"
Expand Down
56 changes: 0 additions & 56 deletions mev-boost/server/boltSidecar.go

This file was deleted.

96 changes: 96 additions & 0 deletions mev-boost/server/constraints.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package server

import (
"github.com/chainbound/shardmap"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

type BatchedSignedConstraints = []*SignedConstraints

type SignedConstraints struct {
Message ConstraintsMessage `json:"message"`
Signature HexBytes `json:"signature"`
}

type ConstraintsMessage struct {
ValidatorIndex uint64
Slot uint64
Constraints []*Constraint
}

type Constraint struct {
Tx Transaction
Index *uint64
}

// ConstraintCache is a cache for constraints.
type ConstraintCache struct {
// map of slots to all constraints for that slot
constraints shardmap.FIFOMap[uint64, map[common.Hash]*Constraint]
}

// NewConstraintCache creates a new constraint cache.
// cap is the maximum number of slots to store constraints for.
func NewConstraintCache(cap int) *ConstraintCache {
return &ConstraintCache{
constraints: *shardmap.NewFIFOMap[uint64, map[common.Hash]*Constraint](int(cap), 1, shardmap.HashUint64),
}
}

// AddInclusionConstraint adds an inclusion constraint to the cache at the given slot for the given transaction.
func (c *ConstraintCache) AddInclusionConstraint(slot uint64, tx Transaction, index *uint64) error {
if _, exists := c.constraints.Get(slot); !exists {
c.constraints.Put(slot, make(map[common.Hash]*Constraint))
}

// parse transaction to get its hash and store it in the cache
// for constant time lookup later
var parsedTx = new(types.Transaction)
err := parsedTx.UnmarshalBinary(tx)
if err != nil {
return err
}

m, _ := c.constraints.Get(slot)
m[parsedTx.Hash()] = &Constraint{
Tx: tx,
Index: index,
}

return nil
}

// AddInclusionConstraints adds multiple inclusion constraints to the cache at the given slot
func (c *ConstraintCache) AddInclusionConstraints(slot uint64, constraints []*Constraint) error {
if _, exists := c.constraints.Get(slot); !exists {
c.constraints.Put(slot, make(map[common.Hash]*Constraint))
}

m, _ := c.constraints.Get(slot)
for _, constraint := range constraints {
var parsedTx = new(types.Transaction)
err := parsedTx.UnmarshalBinary(constraint.Tx)
if err != nil {
return err
}
m[parsedTx.Hash()] = constraint
}

return nil
}

// Get gets the constraints at the given slot.
func (c *ConstraintCache) Get(slot uint64) (map[common.Hash]*Constraint, bool) {
return c.constraints.Get(slot)
}

// FindTransactionByHash finds the constraint for the given transaction hash and returns it.
func (c *ConstraintCache) FindTransactionByHash(txHash common.Hash) (*Constraint, bool) {
for kv := range c.constraints.Iter() {
if constraint, exists := kv.Value[txHash]; exists {
return constraint, true
}
}
return nil, false
}
Loading