Skip to content

Commit

Permalink
feat(mev-boost): add delegation action to api
Browse files Browse the repository at this point in the history
  • Loading branch information
merklefruit committed Oct 11, 2024
1 parent 601f8d6 commit 482b850
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
16 changes: 12 additions & 4 deletions mev-boost/server/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,34 @@ func (c *ConstraintsCache) FindTransactionByHash(txHash gethCommon.Hash) (*Trans
return nil, false
}

// Ref: https://docs.boltprotocol.xyz/api/builder#delegate
// SignedDelegation represents the delegation signed by the proposer pubkey to
// authorize the delegatee pubkey to submit constraints on their behalf.
//
// Specs: https://docs.boltprotocol.xyz/api/builder#delegate
type SignedDelegation struct {
Message Delegation `json:"message"`
Signature phase0.BLSSignature `json:"signature"`
}

// Ref: https://docs.boltprotocol.xyz/api/builder#delegate
// Delegation as from Specs: https://docs.boltprotocol.xyz/api/builder#delegate
type Delegation struct {
Action uint8 `json:"action"`
ValidatorPubkey phase0.BLSPubKey `json:"validator_pubkey"`
DelegateePubkey phase0.BLSPubKey `json:"delegatee_pubkey"`
}

// Ref: https://docs.boltprotocol.xyz/api/builder#revoke
// SignedRevocation represents the revocation signed by the proposer pubkey to
// revoke the delegatee pubkey's ability to submit constraints on their behalf.
//
// Specs: https://docs.boltprotocol.xyz/api/builder#revoke
type SignedRevocation struct {
Message Revocation `json:"message"`
Signature phase0.BLSSignature `json:"signature"`
}

// Ref: https://docs.boltprotocol.xyz/api/builder#revoke
// Revocation as from Specs: https://docs.boltprotocol.xyz/api/builder#revoke
type Revocation struct {
Action uint8 `json:"action"`
ValidatorPubkey phase0.BLSPubKey `json:"validator_pubkey"`
DelegateePubkey phase0.BLSPubKey `json:"delegatee_pubkey"`
}
7 changes: 7 additions & 0 deletions mev-boost/server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ func (m *BoostService) handleDelegate(w http.ResponseWriter, req *http.Request)
m.respondError(w, http.StatusBadRequest, err.Error())
return
}
if payload.Message.Action != 0 {
m.respondError(w, http.StatusBadRequest, "invalid action, expected 0 for delegate")
return
}

ua := UserAgent(req.Header.Get("User-Agent"))
log = log.WithFields(logrus.Fields{
Expand Down Expand Up @@ -407,6 +411,9 @@ func (m *BoostService) handleRevoke(w http.ResponseWriter, req *http.Request) {
m.respondError(w, http.StatusBadRequest, err.Error())
return
}
if payload.Message.Action != 1 {
m.respondError(w, http.StatusBadRequest, "invalid action, expected 1 for revoke")
}

ua := UserAgent(req.Header.Get("User-Agent"))
log = log.WithFields(logrus.Fields{
Expand Down
2 changes: 2 additions & 0 deletions mev-boost/server/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ func TestDelegate(t *testing.T) {
path := pathDelegate
delegate := SignedDelegation{
Message: Delegation{
Action: 0,
ValidatorPubkey: _HexToPubkey("0xa695ad325dfc7e1191fbc9f186f58eff42a634029731b18380ff89bf42c464a42cb8ca55b200f051f57f1e1893c68759"),
DelegateePubkey: _HexToPubkey("0xb8ba260170b9cda2ad54c321d9a8d77e4ca34517106f587eb5ec184bf78f8a0ce4fb55658301b0dc6b129d10adf62391"),
},
Expand All @@ -334,6 +335,7 @@ func TestRevoke(t *testing.T) {
path := pathRevoke
revoke := SignedRevocation{
Message: Revocation{
Action: 1,
ValidatorPubkey: _HexToPubkey("0xa695ad325dfc7e1191fbc9f186f58eff42a634029731b18380ff89bf42c464a42cb8ca55b200f051f57f1e1893c68759"),
DelegateePubkey: _HexToPubkey("0xb8ba260170b9cda2ad54c321d9a8d77e4ca34517106f587eb5ec184bf78f8a0ce4fb55658301b0dc6b129d10adf62391"),
},
Expand Down

0 comments on commit 482b850

Please sign in to comment.