Skip to content

Commit

Permalink
types(builder): align names to spec
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevbirb committed Jun 5, 2024
1 parent d6d8b43 commit 1c69d14
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
9 changes: 5 additions & 4 deletions builder/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ type Builder struct {
builderResubmitInterval time.Duration
discardRevertibleTxOnErr bool

constraintsCache *shardmap.FIFOMap[uint64, common.Constraints]
// constraintsCache is a map from slot to the constraints made by proposers
constraintsCache *shardmap.FIFOMap[uint64, common.SignedConstraintsList]

limiter *rate.Limiter
submissionOffsetFromEndOfSlot time.Duration
Expand Down Expand Up @@ -195,7 +196,7 @@ func NewBuilder(args BuilderArgs) (*Builder, error) {
discardRevertibleTxOnErr: args.discardRevertibleTxOnErr,
submissionOffsetFromEndOfSlot: args.submissionOffsetFromEndOfSlot,

constraintsCache: shardmap.NewFIFOMap[uint64, common.Constraints](64, 16, shardmap.HashUint64),
constraintsCache: shardmap.NewFIFOMap[uint64, common.SignedConstraintsList](64, 16, shardmap.HashUint64),

limiter: args.limiter,
slotCtx: slotCtx,
Expand Down Expand Up @@ -349,7 +350,7 @@ func (b *Builder) subscribeToRelayForConstraints(relayBaseEndpoint, authHeader s

// We assume the data is the JSON representation of the constraints
log.Debug("Received new constraint: %s\n", data)
constraintsSigned := make(common.Constraints, 0, 8)
constraintsSigned := make(common.SignedConstraintsList, 0, 8)
if err := json.Unmarshal([]byte(data), &constraintsSigned); err != nil {
log.Warn(fmt.Sprintf("Failed to unmarshal constraints: %v", err))
continue
Expand All @@ -365,7 +366,7 @@ func (b *Builder) subscribeToRelayForConstraints(relayBaseEndpoint, authHeader s
slotConstraints, _ := b.constraintsCache.Get(constraint.Message.Slot)
if len(slotConstraints) == 0 {
// New constraint for this slot, add it in the map and continue with the next constraint
b.constraintsCache.Put(constraint.Message.Slot, common.Constraints{constraint})
b.constraintsCache.Put(constraint.Message.Slot, common.SignedConstraintsList{constraint})
continue
}
for _, slotConstraint := range slotConstraints {
Expand Down
6 changes: 3 additions & 3 deletions builder/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,14 +670,14 @@ func sseConstraintsHandler(w http.ResponseWriter, r *http.Request) {
}
}

func generateMockConstraintsForSlot(slot uint64) common.Constraints {
func generateMockConstraintsForSlot(slot uint64) common.SignedConstraintsList {
rawTx := new(common.HexBytes)
err := rawTx.UnmarshalJSON([]byte("\"0x02f876018305da308401312d0085041f1196d2825208940c598786c88883ff5e4f461750fad64d3fae54268804b7ec32d7a2000080c080a0086f02eacec72820be3b117e1edd5bd7ed8956964b28b2d903d2cba53dd13560a06d61ec9ccce6acb31bf21878b9a844e7fdac860c5b7d684f7eb5f38a5945357c\""))
if err != nil {
fmt.Println("Failed to unmarshal rawTx: ", err)
}
return common.Constraints{
&common.ConstraintSigned{
return common.SignedConstraintsList{
&common.SignedConstraints{
Message: common.ConstraintMessage{
Constraints: []*common.Constraint{{Tx: *rawTx}}, ValidatorIndex: 0, Slot: slot,
}, Signature: phase0.BLSSignature{},
Expand Down
11 changes: 6 additions & 5 deletions builder/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,14 @@ func (v *VersionedSubmitBlockRequestWithProofs) String() string {
return string(out)
}

// Constraints are a list of proposer constraints that a builder must satisfy
// in order to produce a valid bid.
// Reference: https://chainbound.github.io/bolt-docs/api/builder-api
type Constraints = []*ConstraintSigned
// SignedConstraintsList are a list of proposer constraints that a builder must satisfy
// in order to produce a valid bid. This is not defined on the
// [spec](https://chainbound.github.io/bolt-docs/api/builder-api)
// but it's useful as an helper type
type SignedConstraintsList = []*SignedConstraints

// Reference: https://chainbound.github.io/bolt-docs/api/builder-api
type ConstraintSigned struct {
type SignedConstraints struct {
Message ConstraintMessage `json:"message"`
Signature phase0.BLSSignature `json:"signature"`
}
Expand Down

0 comments on commit 1c69d14

Please sign in to comment.