Skip to content

Commit 14dc1de

Browse files
committed
add block range
1 parent aa9f419 commit 14dc1de

File tree

5 files changed

+31
-39
lines changed

5 files changed

+31
-39
lines changed

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.20250626210013-5bbac7665a49
9+
github.com/Layr-Labs/protocol-apis v1.16.1-0.20250630131958-e3532387fd03
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,8 @@ github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.13 h1:Blb4AE+jC/vddV71w4/MQA
2828
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.13/go.mod h1:PD/HoyzZjxDw1tAcZw3yD0yGddo+yhmwQAi+lk298r4=
2929
github.com/Layr-Labs/protobuf-libs v0.1.0 h1:hfawlutriLq1i7cI2kXH8o2N+mx02cJTVlKrwAMazBY=
3030
github.com/Layr-Labs/protobuf-libs v0.1.0/go.mod h1:Om3Qb39NrWwald+08yTIj/VexKmocIMsMXXIM/iRcW8=
31-
github.com/Layr-Labs/protocol-apis v1.16.0 h1:JXchrhqdwVjmNHXV/l70n32n9/hvzDaVxlX1bzv7V1Q=
32-
github.com/Layr-Labs/protocol-apis v1.16.0/go.mod h1:0w24becRYehW1AbwIFRF6wsfOlFJAcqBPAMAinB0y+c=
33-
github.com/Layr-Labs/protocol-apis v1.16.1-0.20250626192844-97c1494a771c h1:RXr7ENZP7UkJD97D+CpICQV3OTPITGsci0I3IjePbBw=
34-
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=
31+
github.com/Layr-Labs/protocol-apis v1.16.1-0.20250630131958-e3532387fd03 h1:FgcEfg/Y0B8x93+dCg1sb7S9sNPcKOzlgSqso0g6tIE=
32+
github.com/Layr-Labs/protocol-apis v1.16.1-0.20250630131958-e3532387fd03/go.mod h1:0w24becRYehW1AbwIFRF6wsfOlFJAcqBPAMAinB0y+c=
3733
github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
3834
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
3935
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=

pkg/rpcServer/protocolHandlers.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,28 @@ func (rpc *RpcServer) GetDelegatedStakersForOperator(ctx context.Context, reques
103103
}
104104

105105
func (rpc *RpcServer) GetStakerShares(ctx context.Context, request *protocolV1.GetStakerSharesRequest) (*protocolV1.GetStakerSharesResponse, error) {
106-
showHistorical := request.GetShowHistorical()
106+
// Validate required fields
107+
stakerAddress := request.GetStakerAddress()
108+
if stakerAddress == "" {
109+
return nil, errors.New("staker address is required")
110+
}
111+
112+
// Handle deprecated fields with warnings - these are ignored in the new implementation
113+
if request.GetBlockHeight() > 0 {
114+
rpc.Logger.Warn("block_height parameter is deprecated and ignored")
115+
}
116+
107117
startBlock := request.GetStartBlock()
108118
endBlock := request.GetEndBlock()
119+
if (startBlock > 0 && endBlock == 0) || (startBlock == 0 && endBlock > 0) {
120+
return nil, errors.New("start_block and end_block must be provided together")
121+
}
122+
if startBlock > endBlock {
123+
return nil, errors.New("start_block cannot be greater than end_block")
124+
}
109125

110-
shares, err := rpc.protocolDataService.ListStakerShares(ctx, request.GetStakerAddress(), request.GetStrategy(), request.GetBlockHeight(), showHistorical, startBlock, endBlock)
126+
// Use start_block and end_block parameters
127+
shares, err := rpc.protocolDataService.ListStakerShares(ctx, stakerAddress, request.GetStrategy(), startBlock, endBlock)
111128
if err != nil {
112129
return nil, err
113130
}
@@ -121,8 +138,7 @@ func (rpc *RpcServer) GetStakerShares(ctx context.Context, request *protocolV1.G
121138
AvsAddresses: share.AvsAddresses,
122139
}
123140

124-
// Add historical fields if requested
125-
if showHistorical {
141+
if startBlock > 0 && endBlock > 0 {
126142
stakerShare.BlockHeight = &share.BlockHeight
127143
if share.BlockTime != nil {
128144
stakerShare.BlockTime = timestamppb.New(*share.BlockTime)

pkg/service/protocolDataService/protocol.go

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -381,30 +381,16 @@ type StakerShares struct {
381381
// and the addresses of the AVSs the operator was registered to.
382382
//
383383
// If not blockHeight is provided, the most recently indexed block will be used.
384-
// If showHistorical is true, returns all historical share records; otherwise returns aggregated current state.
385384
// 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-
}
399-
400-
bh, err := pds.BaseDataService.GetCurrentBlockHeightIfNotPresent(ctx, blockHeight)
385+
func (pds *ProtocolDataService) ListStakerShares(ctx context.Context, staker string, strategy string, startBlock uint64, endBlock uint64) ([]*StakerShares, error) {
386+
bh, err := pds.BaseDataService.GetCurrentBlockHeightIfNotPresent(ctx, endBlock)
401387
if err != nil {
402388
return nil, err
403389
}
404390

405391
var query string
406392

407-
if showHistorical {
393+
if startBlock > 0 && endBlock > 0 {
408394
query = `
409395
with distinct_staker_strategies as (
410396
select
@@ -478,16 +464,10 @@ func (pds *ProtocolDataService) ListStakerShares(ctx context.Context, staker str
478464
// Prepare query parameters
479465
queryParams := []interface{}{
480466
sql.Named("staker", staker),
467+
sql.Named("strategy", strategy),
481468
sql.Named("blockHeight", bh),
482-
}
483-
484-
if strategy != "" {
485-
queryParams = append(queryParams, sql.Named("strategy", strategy))
486-
}
487-
488-
if showHistorical {
489-
queryParams = append(queryParams, sql.Named("startBlock", startBlock))
490-
queryParams = append(queryParams, sql.Named("endBlock", endBlock))
469+
sql.Named("startBlock", startBlock),
470+
sql.Named("endBlock", endBlock),
491471
}
492472

493473
res := pds.db.Raw(query, queryParams...).Scan(&shares)

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

0 commit comments

Comments
 (0)