Skip to content
This repository was archived by the owner on Oct 20, 2024. It is now read-only.

Commit 76cc4b7

Browse files
authored
Rename requestId to userOpHash (#44)
1 parent f4f1fd1 commit 76cc4b7

File tree

6 files changed

+46
-46
lines changed

6 files changed

+46
-46
lines changed

internal/start/private.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func PrivateMode() {
112112
"/",
113113
relayer.FilterByClientID(),
114114
jsonrpc.Controller(client.NewRpcAdapter(c)),
115-
relayer.MapRequestIDToClientID(),
115+
relayer.MapUserOpHashToClientID(),
116116
)
117117
r.Run(fmt.Sprintf(":%d", conf.Port))
118118
}

pkg/bundler/bundler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ func (i *Bundler) Run() error {
8080

8181
bat := []string{}
8282
for _, op := range ctx.Batch {
83-
bat = append(bat, op.GetRequestID(ep, i.chainID).String())
83+
bat = append(bat, op.GetUserOpHash(ep, i.chainID).String())
8484
}
85-
l = l.WithValues("batch_request_ids", bat)
85+
l = l.WithValues("batch_userop_hashes", bat)
8686

8787
drp := []string{}
8888
for _, op := range ctx.PendingRemoval {
89-
drp = append(drp, op.GetRequestID(ep, i.chainID).String())
89+
drp = append(drp, op.GetUserOpHash(ep, i.chainID).String())
9090
}
91-
l = l.WithValues("dropped_request_ids", drp)
91+
l = l.WithValues("dropped_userop_hashes", drp)
9292

9393
for k, v := range ctx.Data {
9494
l = l.WithValues(k, v)

pkg/client/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ func (i *Client) SendUserOperation(op map[string]any, ep string) (string, error)
7777
l.Error(err, "eth_sendUserOperation error")
7878
return "", err
7979
}
80-
rid := userOp.GetRequestID(epAddr, i.chainID)
81-
l = l.WithValues("request_id", rid)
80+
hash := userOp.GetUserOpHash(epAddr, i.chainID)
81+
l = l.WithValues("userop_hash", hash)
8282

8383
// Check mempool for duplicates and only replace under the following circumstances:
8484
//
@@ -127,7 +127,7 @@ func (i *Client) SendUserOperation(op map[string]any, ep string) (string, error)
127127
}
128128

129129
l.Info("eth_sendUserOperation ok")
130-
return rid.String(), nil
130+
return hash.String(), nil
131131
}
132132

133133
// SupportedEntryPoints implements the method call for eth_supportedEntryPoints. It returns the array of

pkg/modules/relay/relayer.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ func (r *Relayer) FilterByClientID() gin.HandlerFunc {
106106
}
107107
}
108108

109-
// MapRequestIDToClientID is a custom Gin middleware used to map a userOp requestID to a clientID. This
109+
// MapUserOpHashToClientID is a custom Gin middleware used to map a userOpHash to a clientID. This
110110
// should be placed after the main method call on the RPC path.
111-
func (r *Relayer) MapRequestIDToClientID() gin.HandlerFunc {
111+
func (r *Relayer) MapUserOpHashToClientID() gin.HandlerFunc {
112112
return func(c *gin.Context) {
113-
l := r.logger.WithName("map_request_id_to_client_id")
113+
l := r.logger.WithName("map_userop_hash_to_client_id")
114114

115115
req, _ := c.Get("json-rpc-request")
116116
json := req.(map[string]any)
@@ -123,26 +123,26 @@ func (r *Relayer) MapRequestIDToClientID() gin.HandlerFunc {
123123
ep := params[1].(string)
124124
op, err := userop.New(data)
125125
if err != nil {
126-
l.Error(err, "map_request_id_to_client_id failed")
126+
l.Error(err, "map_userop_hash_to_client_id failed")
127127
c.Status(http.StatusInternalServerError)
128128
return
129129
}
130130

131-
rid := op.GetRequestID(common.HexToAddress(ep), r.chainID).String()
131+
hash := op.GetUserOpHash(common.HexToAddress(ep), r.chainID).String()
132132
cid := ginutils.GetClientIPFromXFF(c)
133133
l = l.
134-
WithValues("request_id", rid).
134+
WithValues("userop_hash", hash).
135135
WithValues("client_id", cid)
136136
err = r.db.Update(func(txn *badger.Txn) error {
137-
err := mapRequestIDToClientID(txn, rid, cid)
137+
err := mapUserOpHashToClientID(txn, hash, cid)
138138
if err != nil {
139139
return err
140140
}
141141

142142
return incrementOpsSeenByClientID(txn, cid)
143143
})
144144
if err != nil {
145-
l.Error(err, "map_request_id_to_client_id failed")
145+
l.Error(err, "map_userop_hash_to_client_id failed")
146146
c.Status(http.StatusInternalServerError)
147147
return
148148
}
@@ -154,15 +154,15 @@ func (r *Relayer) MapRequestIDToClientID() gin.HandlerFunc {
154154
// mitigate DoS attacks.
155155
func (r *Relayer) SendUserOperation() modules.BatchHandlerFunc {
156156
return func(ctx *modules.BatchHandlerCtx) error {
157-
// TODO: Increment badger nextTxnTs to read latest data from MapRequestIDToClientID.
157+
// TODO: Increment badger nextTxnTs to read latest data from MapUserOpHashToClientID.
158158
time.Sleep(time.Millisecond)
159159

160160
var del []string
161161
err := r.db.Update(func(txn *badger.Txn) error {
162162
// Delete any request ID entries from dropped userOps.
163163
if len(ctx.PendingRemoval) > 0 {
164-
rids := getRequestIDsFromOps(ctx.EntryPoint, ctx.ChainID, ctx.PendingRemoval...)
165-
if err := removeRequestIDEntries(txn, rids...); err != nil {
164+
hashes := getUserOpHashesFromOps(ctx.EntryPoint, ctx.ChainID, ctx.PendingRemoval...)
165+
if err := removeUserOpHashEntries(txn, hashes...); err != nil {
166166
return err
167167
}
168168
}
@@ -184,8 +184,8 @@ func (r *Relayer) SendUserOperation() modules.BatchHandlerFunc {
184184
} else if revert != nil {
185185
ctx.MarkOpIndexForRemoval(revert.OpIndex)
186186

187-
rids := getRequestIDsFromOps(ctx.EntryPoint, ctx.ChainID, ctx.PendingRemoval...)
188-
if err := removeRequestIDEntries(txn, rids...); err != nil {
187+
hashes := getUserOpHashesFromOps(ctx.EntryPoint, ctx.ChainID, ctx.PendingRemoval...)
188+
if err := removeUserOpHashEntries(txn, hashes...); err != nil {
189189
return err
190190
}
191191
} else {
@@ -213,8 +213,8 @@ func (r *Relayer) SendUserOperation() modules.BatchHandlerFunc {
213213
} else if revert != nil {
214214
ctx.MarkOpIndexForRemoval(revert.OpIndex)
215215

216-
rids := getRequestIDsFromOps(ctx.EntryPoint, ctx.ChainID, ctx.PendingRemoval...)
217-
if err := removeRequestIDEntries(txn, rids...); err != nil {
216+
hashes := getUserOpHashesFromOps(ctx.EntryPoint, ctx.ChainID, ctx.PendingRemoval...)
217+
if err := removeUserOpHashEntries(txn, hashes...); err != nil {
218218
return err
219219
}
220220
} else {
@@ -223,9 +223,9 @@ func (r *Relayer) SendUserOperation() modules.BatchHandlerFunc {
223223
}
224224
}
225225

226-
rids := getRequestIDsFromOps(ctx.EntryPoint, ctx.ChainID, ctx.Batch...)
227-
del = append([]string{}, rids...)
228-
return incrementOpsIncludedByRequestIDs(txn, rids...)
226+
hashes := getUserOpHashesFromOps(ctx.EntryPoint, ctx.ChainID, ctx.Batch...)
227+
del = append([]string{}, hashes...)
228+
return incrementOpsIncludedByUserOpHashes(txn, hashes...)
229229
})
230230
if err != nil {
231231
return err
@@ -234,7 +234,7 @@ func (r *Relayer) SendUserOperation() modules.BatchHandlerFunc {
234234
// Delete remaining request ID entries from submitted userOps.
235235
// Perform update in new txn to avoid db conflicts.
236236
err = r.db.Update(func(txn *badger.Txn) error {
237-
return removeRequestIDEntries(txn, del...)
237+
return removeUserOpHashEntries(txn, del...)
238238
})
239239
if err != nil {
240240
return err

pkg/modules/relay/utils.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ const timeWindow = 7 * 24 * time.Hour
1717
const separator = ":"
1818
const keyPrefix = "module" + separator + "relay"
1919
const opsCountPrefix = keyPrefix + separator + "opsCount"
20-
const requestIDPrefix = keyPrefix + separator + "requestID"
20+
const userOpHashPrefix = keyPrefix + separator + "userOpHash"
2121

2222
func getOpsCountKey(clientID string) []byte {
2323
return []byte(opsCountPrefix + separator + clientID)
2424
}
2525

26-
func getRequestIDKey(requestID string) []byte {
27-
return []byte(requestIDPrefix + separator + requestID)
26+
func getUserOpHashKey(userOpHash string) []byte {
27+
return []byte(userOpHashPrefix + separator + userOpHash)
2828
}
2929

30-
func getRequestIDsFromOps(ep common.Address, chainID *big.Int, ops ...*userop.UserOperation) []string {
31-
rids := []string{}
30+
func getUserOpHashesFromOps(ep common.Address, chainID *big.Int, ops ...*userop.UserOperation) []string {
31+
hashes := []string{}
3232
for _, op := range ops {
33-
rids = append(rids, op.GetRequestID(ep, chainID).String())
33+
hashes = append(hashes, op.GetUserOpHash(ep, chainID).String())
3434
}
3535

36-
return rids
36+
return hashes
3737
}
3838

3939
func getOpsCountByClientID(txn *badger.Txn, clientID string) (opsSeen int, opsIncluded int, err error) {
@@ -77,9 +77,9 @@ func incrementOpsSeenByClientID(txn *badger.Txn, clientID string) error {
7777
return txn.SetEntry(e)
7878
}
7979

80-
func incrementOpsIncludedByRequestIDs(txn *badger.Txn, requestIDs ...string) error {
81-
for _, rid := range requestIDs {
82-
item, err := txn.Get(getRequestIDKey(rid))
80+
func incrementOpsIncludedByUserOpHashes(txn *badger.Txn, userOpHashes ...string) error {
81+
for _, hashes := range userOpHashes {
82+
item, err := txn.Get(getUserOpHashKey(hashes))
8383
if err != nil && err == badger.ErrKeyNotFound {
8484
return nil
8585
}
@@ -119,13 +119,13 @@ func incrementOpsIncludedByRequestIDs(txn *badger.Txn, requestIDs ...string) err
119119
return nil
120120
}
121121

122-
func mapRequestIDToClientID(txn *badger.Txn, requestID string, clientID string) error {
123-
return txn.Set(getRequestIDKey(requestID), []byte(clientID))
122+
func mapUserOpHashToClientID(txn *badger.Txn, userOpHash string, clientID string) error {
123+
return txn.Set(getUserOpHashKey(userOpHash), []byte(clientID))
124124
}
125125

126-
func removeRequestIDEntries(txn *badger.Txn, requestIDs ...string) error {
127-
for _, rid := range requestIDs {
128-
err := txn.Delete(getRequestIDKey(rid))
126+
func removeUserOpHashEntries(txn *badger.Txn, userOpHashes ...string) error {
127+
for _, hashes := range userOpHashes {
128+
err := txn.Delete(getUserOpHashKey(hashes))
129129
if err != nil {
130130
return err
131131
}

pkg/userop/object.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (op *UserOperation) GetMaxPrefund() *big.Int {
7171
return big.NewInt(0).Mul(requiredGas, op.MaxFeePerGas)
7272
}
7373

74-
// Pack returns a standard message of the userOp. This cannot be used to generate a requestID.
74+
// Pack returns a standard message of the userOp. This cannot be used to generate a userOpHash.
7575
func (op *UserOperation) Pack() []byte {
7676
args := getAbiArgs()
7777
packed, _ := args.Pack(&struct {
@@ -103,7 +103,7 @@ func (op *UserOperation) Pack() []byte {
103103
return packed
104104
}
105105

106-
// PackForSignature returns a minimal message of the userOp. This can be used to generate a requestID.
106+
// PackForSignature returns a minimal message of the userOp. This can be used to generate a userOpHash.
107107
func (op *UserOperation) PackForSignature() []byte {
108108
args := getAbiArgs()
109109
packed, _ := args.Pack(&struct {
@@ -138,8 +138,8 @@ func (op *UserOperation) PackForSignature() []byte {
138138
return (hexutil.MustDecode(enc))
139139
}
140140

141-
// GetRequestID returns the hash of the userOp + entryPoint address + chainID.
142-
func (op *UserOperation) GetRequestID(entryPoint common.Address, chainID *big.Int) common.Hash {
141+
// GetUserOpHash returns the hash of the userOp + entryPoint address + chainID.
142+
func (op *UserOperation) GetUserOpHash(entryPoint common.Address, chainID *big.Int) common.Hash {
143143
return crypto.Keccak256Hash(
144144
crypto.Keccak256(op.PackForSignature()),
145145
common.LeftPadBytes(entryPoint.Bytes(), 32),

0 commit comments

Comments
 (0)