Skip to content

Commit

Permalink
add pubkey filter to el_consolidations & el_withdrawals pages
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Dec 2, 2024
1 parent db66236 commit 5e45147
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
23 changes: 15 additions & 8 deletions handlers/el_consolidations.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func ElConsolidations(w http.ResponseWriter, r *http.Request) {
var minTgtIndex uint64
var maxTgtIndex uint64
var tgtVName string
var withOrphaned uint64
var withOrphaned uint64 = 1
var pubkey string

if urlArgs.Has("f") {
if urlArgs.Has("f.mins") {
Expand Down Expand Up @@ -83,13 +84,14 @@ func ElConsolidations(w http.ResponseWriter, r *http.Request) {
if urlArgs.Has("f.orphaned") {
withOrphaned, _ = strconv.ParseUint(urlArgs.Get("f.orphaned"), 10, 64)
}
} else {
withOrphaned = 1
if urlArgs.Has("f.pubkey") {
pubkey = urlArgs.Get("f.pubkey")
}
}
var pageError error
pageError = services.GlobalCallRateLimiter.CheckCallLimit(r, 2)
if pageError == nil {
data.Data, pageError = getFilteredElConsolidationsPageData(pageIdx, pageSize, minSlot, maxSlot, sourceAddr, minSrcIndex, maxSrcIndex, srcVName, minTgtIndex, maxTgtIndex, tgtVName, uint8(withOrphaned))
data.Data, pageError = getFilteredElConsolidationsPageData(pageIdx, pageSize, minSlot, maxSlot, sourceAddr, minSrcIndex, maxSrcIndex, srcVName, minTgtIndex, maxTgtIndex, tgtVName, uint8(withOrphaned), pubkey)
}
if pageError != nil {
handlePageError(w, r, pageError)
Expand All @@ -101,11 +103,11 @@ func ElConsolidations(w http.ResponseWriter, r *http.Request) {
}
}

func getFilteredElConsolidationsPageData(pageIdx uint64, pageSize uint64, minSlot uint64, maxSlot uint64, sourceAddr string, minSrcIndex uint64, maxSrcIndex uint64, srcVName string, minTgtIndex uint64, maxTgtIndex uint64, tgtVName string, withOrphaned uint8) (*models.ElConsolidationsPageData, error) {
func getFilteredElConsolidationsPageData(pageIdx uint64, pageSize uint64, minSlot uint64, maxSlot uint64, sourceAddr string, minSrcIndex uint64, maxSrcIndex uint64, srcVName string, minTgtIndex uint64, maxTgtIndex uint64, tgtVName string, withOrphaned uint8, pubkey string) (*models.ElConsolidationsPageData, error) {
pageData := &models.ElConsolidationsPageData{}
pageCacheKey := fmt.Sprintf("el_consolidations:%v:%v:%v:%v:%v:%v:%v:%v:%v:%v:%v:%v", pageIdx, pageSize, minSlot, maxSlot, sourceAddr, minSrcIndex, maxSrcIndex, srcVName, minTgtIndex, maxTgtIndex, tgtVName, withOrphaned)
pageCacheKey := fmt.Sprintf("el_consolidations:%v:%v:%v:%v:%v:%v:%v:%v:%v:%v:%v:%v:%v", pageIdx, pageSize, minSlot, maxSlot, sourceAddr, minSrcIndex, maxSrcIndex, srcVName, minTgtIndex, maxTgtIndex, tgtVName, withOrphaned, pubkey)
pageRes, pageErr := services.GlobalFrontendCache.ProcessCachedPage(pageCacheKey, true, pageData, func(_ *services.FrontendCacheProcessingPage) interface{} {
return buildFilteredElConsolidationsPageData(pageIdx, pageSize, minSlot, maxSlot, sourceAddr, minSrcIndex, maxSrcIndex, srcVName, minTgtIndex, maxTgtIndex, tgtVName, withOrphaned)
return buildFilteredElConsolidationsPageData(pageIdx, pageSize, minSlot, maxSlot, sourceAddr, minSrcIndex, maxSrcIndex, srcVName, minTgtIndex, maxTgtIndex, tgtVName, withOrphaned, pubkey)
})
if pageErr == nil && pageRes != nil {
resData, resOk := pageRes.(*models.ElConsolidationsPageData)
Expand All @@ -117,7 +119,7 @@ func getFilteredElConsolidationsPageData(pageIdx uint64, pageSize uint64, minSlo
return pageData, pageErr
}

func buildFilteredElConsolidationsPageData(pageIdx uint64, pageSize uint64, minSlot uint64, maxSlot uint64, sourceAddr string, minSrcIndex uint64, maxSrcIndex uint64, srcVName string, minTgtIndex uint64, maxTgtIndex uint64, tgtVName string, withOrphaned uint8) *models.ElConsolidationsPageData {
func buildFilteredElConsolidationsPageData(pageIdx uint64, pageSize uint64, minSlot uint64, maxSlot uint64, sourceAddr string, minSrcIndex uint64, maxSrcIndex uint64, srcVName string, minTgtIndex uint64, maxTgtIndex uint64, tgtVName string, withOrphaned uint8, pubkey string) *models.ElConsolidationsPageData {
filterArgs := url.Values{}
if minSlot != 0 {
filterArgs.Add("f.mins", fmt.Sprintf("%v", minSlot))
Expand Down Expand Up @@ -149,6 +151,9 @@ func buildFilteredElConsolidationsPageData(pageIdx uint64, pageSize uint64, minS
if withOrphaned != 0 {
filterArgs.Add("f.orphaned", fmt.Sprintf("%v", withOrphaned))
}
if pubkey != "" {
filterArgs.Add("f.pubkey", pubkey)
}

pageData := &models.ElConsolidationsPageData{
FilterAddress: sourceAddr,
Expand All @@ -161,6 +166,7 @@ func buildFilteredElConsolidationsPageData(pageIdx uint64, pageSize uint64, minS
FilterMaxTgtIndex: maxTgtIndex,
FilterTgtValidatorName: tgtVName,
FilterWithOrphaned: withOrphaned,
FilterPublicKey: pubkey,
}
logrus.Debugf("el_consolidations page called: %v:%v [%v,%v,%v,%v,%v,%v,%v,%v]", pageIdx, pageSize, minSlot, maxSlot, minSrcIndex, maxSrcIndex, srcVName, minTgtIndex, maxTgtIndex, tgtVName)
if pageIdx == 1 {
Expand Down Expand Up @@ -189,6 +195,7 @@ func buildFilteredElConsolidationsPageData(pageIdx uint64, pageSize uint64, minS
MaxTgtIndex: maxTgtIndex,
TgtValidatorName: tgtVName,
WithOrphaned: withOrphaned,
PublicKey: common.FromHex(pubkey),
}

dbElConsolidations, totalRows := services.GlobalBeaconService.GetConsolidationRequestsByFilter(consolidationRequestFilter, pageIdx-1, uint32(pageSize))
Expand Down
19 changes: 14 additions & 5 deletions handlers/el_withdrawals.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func ElWithdrawals(w http.ResponseWriter, r *http.Request) {
var vname string
var withOrphaned uint64
var withType uint64
var pubkey string

if urlArgs.Has("f") {
if urlArgs.Has("f.mins") {
Expand All @@ -75,13 +76,16 @@ func ElWithdrawals(w http.ResponseWriter, r *http.Request) {
if urlArgs.Has("f.type") {
withType, _ = strconv.ParseUint(urlArgs.Get("f.type"), 10, 64)
}
if urlArgs.Has("f.pubkey") {
pubkey = urlArgs.Get("f.pubkey")
}
} else {
withOrphaned = 1
}
var pageError error
pageError = services.GlobalCallRateLimiter.CheckCallLimit(r, 2)
if pageError == nil {
data.Data, pageError = getFilteredElWithdrawalsPageData(pageIdx, pageSize, minSlot, maxSlot, sourceAddr, minIndex, maxIndex, vname, uint8(withOrphaned), uint8(withType))
data.Data, pageError = getFilteredElWithdrawalsPageData(pageIdx, pageSize, minSlot, maxSlot, sourceAddr, minIndex, maxIndex, vname, uint8(withOrphaned), uint8(withType), pubkey)
}
if pageError != nil {
handlePageError(w, r, pageError)
Expand All @@ -93,11 +97,11 @@ func ElWithdrawals(w http.ResponseWriter, r *http.Request) {
}
}

func getFilteredElWithdrawalsPageData(pageIdx uint64, pageSize uint64, minSlot uint64, maxSlot uint64, sourceAddr string, minIndex uint64, maxIndex uint64, vname string, withOrphaned uint8, withType uint8) (*models.ElWithdrawalsPageData, error) {
func getFilteredElWithdrawalsPageData(pageIdx uint64, pageSize uint64, minSlot uint64, maxSlot uint64, sourceAddr string, minIndex uint64, maxIndex uint64, vname string, withOrphaned uint8, withType uint8, pubkey string) (*models.ElWithdrawalsPageData, error) {
pageData := &models.ElWithdrawalsPageData{}
pageCacheKey := fmt.Sprintf("el_withdrawals:%v:%v:%v:%v:%v:%v:%v:%v:%v:%v", pageIdx, pageSize, minSlot, maxSlot, sourceAddr, minIndex, maxIndex, vname, withOrphaned, withType)
pageCacheKey := fmt.Sprintf("el_withdrawals:%v:%v:%v:%v:%v:%v:%v:%v:%v:%v:%v", pageIdx, pageSize, minSlot, maxSlot, sourceAddr, minIndex, maxIndex, vname, withOrphaned, withType, pubkey)
pageRes, pageErr := services.GlobalFrontendCache.ProcessCachedPage(pageCacheKey, true, pageData, func(_ *services.FrontendCacheProcessingPage) interface{} {
return buildFilteredElWithdrawalsPageData(pageIdx, pageSize, minSlot, maxSlot, sourceAddr, minIndex, maxIndex, vname, withOrphaned, withType)
return buildFilteredElWithdrawalsPageData(pageIdx, pageSize, minSlot, maxSlot, sourceAddr, minIndex, maxIndex, vname, withOrphaned, withType, pubkey)
})
if pageErr == nil && pageRes != nil {
resData, resOk := pageRes.(*models.ElWithdrawalsPageData)
Expand All @@ -109,7 +113,7 @@ func getFilteredElWithdrawalsPageData(pageIdx uint64, pageSize uint64, minSlot u
return pageData, pageErr
}

func buildFilteredElWithdrawalsPageData(pageIdx uint64, pageSize uint64, minSlot uint64, maxSlot uint64, sourceAddr string, minIndex uint64, maxIndex uint64, vname string, withOrphaned uint8, withType uint8) *models.ElWithdrawalsPageData {
func buildFilteredElWithdrawalsPageData(pageIdx uint64, pageSize uint64, minSlot uint64, maxSlot uint64, sourceAddr string, minIndex uint64, maxIndex uint64, vname string, withOrphaned uint8, withType uint8, pubkey string) *models.ElWithdrawalsPageData {
filterArgs := url.Values{}
if minSlot != 0 {
filterArgs.Add("f.mins", fmt.Sprintf("%v", minSlot))
Expand All @@ -135,6 +139,9 @@ func buildFilteredElWithdrawalsPageData(pageIdx uint64, pageSize uint64, minSlot
if withType != 0 {
filterArgs.Add("f.type", fmt.Sprintf("%v", withType))
}
if pubkey != "" {
filterArgs.Add("f.pubkey", pubkey)
}

pageData := &models.ElWithdrawalsPageData{
FilterAddress: sourceAddr,
Expand All @@ -145,6 +152,7 @@ func buildFilteredElWithdrawalsPageData(pageIdx uint64, pageSize uint64, minSlot
FilterValidatorName: vname,
FilterWithOrphaned: withOrphaned,
FilterWithType: withType,
FilterPublicKey: pubkey,
}
logrus.Debugf("el_withdrawals page called: %v:%v [%v,%v,%v,%v,%v]", pageIdx, pageSize, minSlot, maxSlot, minIndex, maxIndex, vname)
if pageIdx == 1 {
Expand All @@ -170,6 +178,7 @@ func buildFilteredElWithdrawalsPageData(pageIdx uint64, pageSize uint64, minSlot
MaxIndex: maxIndex,
ValidatorName: vname,
WithOrphaned: withOrphaned,
PublicKey: common.FromHex(pubkey),
}

switch withType {
Expand Down
9 changes: 9 additions & 0 deletions templates/el_consolidations/el_consolidations.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ <h1 class="h4 mb-1 mb-md-0">
<input name="f.svname" type="text" class="form-control" placeholder="Source Validator Name" aria-label="Source Validator Name" aria-describedby="basic-addon1" value="{{ .FilterSrcValidatorName }}">
</div>
</div>
<div class="row mt-1">
<div class="col-sm-12 col-md-6 col-lg-4">
Public Key
<i class="fa fa-info-circle text-muted ms-2" role="button" data-bs-toggle="tooltip" data-bs-placement="right" title="This filter matches either source or target validator public keys"></i>
</div>
<div class="col-sm-12 col-md-6 col-lg-8">
<input name="f.pubkey" type="text" class="form-control" placeholder="Public Key (source or target)" aria-label="Public Key" aria-describedby="basic-addon1" value="{{ .FilterPublicKey }}">
</div>
</div>
</div>
</div>
<div class="col-sm-12 col-md-6">
Expand Down
8 changes: 8 additions & 0 deletions templates/el_withdrawals/el_withdrawals.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ <h1 class="h4 mb-1 mb-md-0">
<input name="f.vname" type="text" class="form-control" placeholder="Validator Name" aria-label="Validator Name" aria-describedby="basic-addon1" value="{{ .FilterValidatorName }}">
</div>
</div>
<div class="row mt-1">
<div class="col-sm-12 col-md-6 col-lg-4">
Public Key
</div>
<div class="col-sm-12 col-md-6 col-lg-8">
<input name="f.pubkey" type="text" class="form-control" placeholder="Public Key" aria-label="Public Key" aria-describedby="basic-addon1" value="{{ .FilterPublicKey }}">
</div>
</div>
</div>
</div>
<div class="col-sm-12 col-md-6">
Expand Down
1 change: 1 addition & 0 deletions types/models/el_consolidations.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type ElConsolidationsPageData struct {
FilterMinSlot uint64 `json:"filter_mins"`
FilterMaxSlot uint64 `json:"filter_maxs"`
FilterAddress string `json:"filter_address"`
FilterPublicKey string `json:"filter_pubkey"`
FilterMinSrcIndex uint64 `json:"filter_minsi"`
FilterMaxSrcIndex uint64 `json:"filter_maxsi"`
FilterSrcValidatorName string `json:"filter_svname"`
Expand Down
1 change: 1 addition & 0 deletions types/models/el_withdrawals.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type ElWithdrawalsPageData struct {
FilterValidatorName string `json:"filter_vname"`
FilterWithOrphaned uint8 `json:"filter_orphaned"`
FilterWithType uint8 `json:"filter_type"`
FilterPublicKey string `json:"filter_pubkey"`

ElRequests []*ElWithdrawalsPageDataWithdrawal `json:"withdrawals"`
RequestCount uint64 `json:"request_count"`
Expand Down

0 comments on commit 5e45147

Please sign in to comment.