Skip to content

Commit

Permalink
feat: add blockHeight filter to ListDistributionRoots
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcgary committed Jan 22, 2025
1 parent a19c591 commit 84e5dc5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/DataDog/datadog-go/v5 v5.5.0
github.com/Layr-Labs/eigenlayer-contracts v0.4.1-holesky-pepe.0.20240813143901-00fc4b95e9c1
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.13
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250122190013-01d27f288892
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250122201559-ae5f5b65ce44
github.com/ethereum/go-ethereum v1.14.9
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1
github.com/google/uuid v1.6.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ github.com/Layr-Labs/protocol-apis v1.1.1-0.20250122185055-8ce2cc7afa86 h1:XfVh8
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250122185055-8ce2cc7afa86/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk=
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250122190013-01d27f288892 h1:OJs2VEsSVhdrPcS+CcX6sWr2UOIYhFY473y0+QDaq/4=
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250122190013-01d27f288892/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk=
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250122201559-ae5f5b65ce44 h1:jaWO3t0OvIKFBDP9zK6/mmwSeEA4P1FQKWqB5qdKjuU=
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250122201559-ae5f5b65ce44/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk=
github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
Expand Down
12 changes: 10 additions & 2 deletions pkg/rewards/rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,15 +790,23 @@ type DistributionRoot struct {
Disabled bool
}

func (rc *RewardsCalculator) ListDistributionRoots() ([]*DistributionRoot, error) {
// ListDistributionRoots returns a list of submitted distribution roots. If a non-zero blockHeight is provided,
// DistributionRoots for only that blockHeight will be returned
func (rc *RewardsCalculator) ListDistributionRoots(blockHeight uint64) ([]*DistributionRoot, error) {
query := `
select
sdr.*,
case when ddr.root_index is not null then true else false end as disabled
from submitted_distribution_roots as sdr
left join disabled_distribution_roots as ddr on (sdr.root_index = ddr.root_index)
order by root_index desc
`
if blockHeight > 0 {
query += `
where sdr.block_number = {{.blockHeight}}
`
}
query += ` order by root_index desc`

var submittedDistributionRoots []*DistributionRoot
res := rc.grm.Raw(query).Scan(&submittedDistributionRoots)
if res.Error != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/rpcServer/rewardsHandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ func (rpc *RpcServer) ListClaimedRewardsByBlockRange(ctx context.Context, req *r
}

func (rpc *RpcServer) ListDistributionRoots(ctx context.Context, req *rewardsV1.ListDistributionRootsRequest) (*rewardsV1.ListDistributionRootsResponse, error) {
roots, err := rpc.rewardsCalculator.ListDistributionRoots()
blockHeight := req.GetBlockHeight()
roots, err := rpc.rewardsCalculator.ListDistributionRoots(blockHeight)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
Expand Down

0 comments on commit 84e5dc5

Please sign in to comment.