Skip to content

Commit aa9f419

Browse files
committed
add start/end block number for historical results
1 parent dc7c08a commit aa9f419

File tree

8 files changed

+62
-16
lines changed

8 files changed

+62
-16
lines changed

docs/docs/public-api/schemas/getstakersharesrequest.schema.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebar_label: "GetStakerSharesRequest"
66
hide_title: true
77
hide_table_of_contents: true
88
schema: true
9-
sample: {"blockHeight":0,"stakerAddress":"string"}
9+
sample: {"blockHeight":0,"stakerAddress":"string","strategy":"string","showHistorical":false,"startBlock":0,"endBlock":0}
1010
custom_edit_url: null
1111
---
1212

@@ -25,7 +25,7 @@ import Heading from "@theme/Heading";
2525

2626

2727
<Schema
28-
schema={{"type":"object","properties":{"blockHeight":{"type":"integer","format":"uint64"},"stakerAddress":{"type":"string"}},"required":["block_height"],"title":"GetStakerSharesRequest"}}
28+
schema={{"type":"object","properties":{"blockHeight":{"type":"integer","format":"uint64"},"stakerAddress":{"type":"string"},"strategy":{"type":"string"},"showHistorical":{"type":"boolean"},"startBlock":{"type":"integer","format":"uint64"},"endBlock":{"type":"integer","format":"uint64"}},"title":"GetStakerSharesRequest"}}
2929
schemaType={"response"}
3030
>
3131

docs/openapi/api.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,11 +2631,22 @@
26312631
},
26322632
"stakerAddress": {
26332633
"type": "string"
2634+
},
2635+
"strategy": {
2636+
"type": "string"
2637+
},
2638+
"showHistorical": {
2639+
"type": "boolean"
2640+
},
2641+
"startBlock": {
2642+
"type": "integer",
2643+
"format": "uint64"
2644+
},
2645+
"endBlock": {
2646+
"type": "integer",
2647+
"format": "uint64"
26342648
}
2635-
},
2636-
"required": [
2637-
"block_height"
2638-
]
2649+
}
26392650
},
26402651
"GetStakerSharesResponse": {
26412652
"type": "object",

docs/openapi/api.public.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -896,11 +896,22 @@
896896
},
897897
"stakerAddress": {
898898
"type": "string"
899+
},
900+
"strategy": {
901+
"type": "string"
902+
},
903+
"showHistorical": {
904+
"type": "boolean"
905+
},
906+
"startBlock": {
907+
"type": "integer",
908+
"format": "uint64"
909+
},
910+
"endBlock": {
911+
"type": "integer",
912+
"format": "uint64"
899913
}
900-
},
901-
"required": [
902-
"block_height"
903-
]
914+
}
904915
},
905916
"GetStakerSharesResponse": {
906917
"type": "object",

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/DataDog/datadog-go/v5 v5.6.0
77
github.com/Layr-Labs/eigenlayer-contracts v0.4.1-holesky-pepe.0.20240813143901-00fc4b95e9c1
88
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.13
9-
github.com/Layr-Labs/protocol-apis v1.16.1-0.20250626192844-97c1494a771c
9+
github.com/Layr-Labs/protocol-apis v1.16.1-0.20250626210013-5bbac7665a49
1010
github.com/ProtonMail/go-crypto v1.1.6
1111
github.com/agiledragon/gomonkey/v2 v2.13.0
1212
github.com/akuity/grpc-gateway-client v0.0.0-20240912082144-55a48e8b4b89

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ github.com/Layr-Labs/protocol-apis v1.16.0 h1:JXchrhqdwVjmNHXV/l70n32n9/hvzDaVxl
3232
github.com/Layr-Labs/protocol-apis v1.16.0/go.mod h1:0w24becRYehW1AbwIFRF6wsfOlFJAcqBPAMAinB0y+c=
3333
github.com/Layr-Labs/protocol-apis v1.16.1-0.20250626192844-97c1494a771c h1:RXr7ENZP7UkJD97D+CpICQV3OTPITGsci0I3IjePbBw=
3434
github.com/Layr-Labs/protocol-apis v1.16.1-0.20250626192844-97c1494a771c/go.mod h1:0w24becRYehW1AbwIFRF6wsfOlFJAcqBPAMAinB0y+c=
35+
github.com/Layr-Labs/protocol-apis v1.16.1-0.20250626210013-5bbac7665a49 h1:c/He01yN3KvfT+FJ8b+piOO7TKZeqP5dIBoJ5NI+0tw=
36+
github.com/Layr-Labs/protocol-apis v1.16.1-0.20250626210013-5bbac7665a49/go.mod h1:0w24becRYehW1AbwIFRF6wsfOlFJAcqBPAMAinB0y+c=
3537
github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
3638
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
3739
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=

pkg/rpcServer/protocolHandlers.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ func (rpc *RpcServer) GetDelegatedStakersForOperator(ctx context.Context, reques
104104

105105
func (rpc *RpcServer) GetStakerShares(ctx context.Context, request *protocolV1.GetStakerSharesRequest) (*protocolV1.GetStakerSharesResponse, error) {
106106
showHistorical := request.GetShowHistorical()
107-
shares, err := rpc.protocolDataService.ListStakerShares(ctx, request.GetStakerAddress(), request.GetStrategy(), request.GetBlockHeight(), showHistorical)
107+
startBlock := request.GetStartBlock()
108+
endBlock := request.GetEndBlock()
109+
110+
shares, err := rpc.protocolDataService.ListStakerShares(ctx, request.GetStakerAddress(), request.GetStrategy(), request.GetBlockHeight(), showHistorical, startBlock, endBlock)
108111
if err != nil {
109112
return nil, err
110113
}

pkg/service/protocolDataService/protocol.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,20 @@ type StakerShares struct {
382382
//
383383
// If not blockHeight is provided, the most recently indexed block will be used.
384384
// If showHistorical is true, returns all historical share records; otherwise returns aggregated current state.
385-
func (pds *ProtocolDataService) ListStakerShares(ctx context.Context, staker string, strategy string, blockHeight uint64, showHistorical bool) ([]*StakerShares, error) {
385+
// For historical results, startBlock and endBlock can be used to filter the block range.
386+
func (pds *ProtocolDataService) ListStakerShares(ctx context.Context, staker string, strategy string, blockHeight uint64, showHistorical bool, startBlock uint64, endBlock uint64) ([]*StakerShares, error) {
387+
// Validate that start and end blocks are required when historical is true
388+
if showHistorical {
389+
if startBlock == 0 {
390+
return nil, errors.New("startBlock is required when showHistorical is true")
391+
}
392+
if endBlock == 0 {
393+
return nil, errors.New("endBlock is required when showHistorical is true")
394+
}
395+
if startBlock > endBlock {
396+
return nil, errors.New("startBlock cannot be greater than endBlock")
397+
}
398+
}
386399

387400
bh, err := pds.BaseDataService.GetCurrentBlockHeightIfNotPresent(ctx, blockHeight)
388401
if err != nil {
@@ -403,7 +416,8 @@ func (pds *ProtocolDataService) ListStakerShares(ctx context.Context, staker str
403416
ssd.transaction_hash,
404417
ssd.log_index
405418
from staker_share_deltas as ssd
406-
where ssd.block_number <= @blockHeight
419+
where ssd.block_number >= @startBlock
420+
and ssd.block_number <= @endBlock
407421
`
408422
if strategy != "" {
409423
query += `
@@ -471,6 +485,11 @@ func (pds *ProtocolDataService) ListStakerShares(ctx context.Context, staker str
471485
queryParams = append(queryParams, sql.Named("strategy", strategy))
472486
}
473487

488+
if showHistorical {
489+
queryParams = append(queryParams, sql.Named("startBlock", startBlock))
490+
queryParams = append(queryParams, sql.Named("endBlock", endBlock))
491+
}
492+
474493
res := pds.db.Raw(query, queryParams...).Scan(&shares)
475494
if res.Error != nil {
476495
return nil, res.Error

pkg/service/protocolDataService/protocol_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func Test_ProtocolDataService(t *testing.T) {
118118
staker := "0x130c646e1224d979ff23523308abb6012ce04b0a"
119119
blockNumber := uint64(3204391)
120120

121-
shares, err := pds.ListStakerShares(context.Background(), staker, "", blockNumber, false)
121+
shares, err := pds.ListStakerShares(context.Background(), staker, "", blockNumber, false, 0, 0)
122122
assert.Nil(t, err)
123123
assert.True(t, len(shares) > 0)
124124
for _, share := range shares {
@@ -129,7 +129,7 @@ func Test_ProtocolDataService(t *testing.T) {
129129
staker := "0xbc9dec48f305167bb8ee593e44893acf65ad3f36"
130130
blockNumber := uint64(3240224)
131131

132-
shares, err := pds.ListStakerShares(context.Background(), staker, "", blockNumber, false)
132+
shares, err := pds.ListStakerShares(context.Background(), staker, "", blockNumber, false, 0, 0)
133133
assert.Nil(t, err)
134134
assert.True(t, len(shares) > 0)
135135
for _, share := range shares {

0 commit comments

Comments
 (0)