Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: protocol RPC implementations #190

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
6 changes: 5 additions & 1 deletion cmd/debugger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"github.com/Layr-Labs/sidecar/pkg/rewards/stakerOperators"
"github.com/Layr-Labs/sidecar/pkg/rewardsCalculatorQueue"
"github.com/Layr-Labs/sidecar/pkg/rpcServer"
"github.com/Layr-Labs/sidecar/pkg/service/protocolDataService"
"github.com/Layr-Labs/sidecar/pkg/service/rewardsDataService"
"github.com/Layr-Labs/sidecar/pkg/sidecar"
pgStorage "github.com/Layr-Labs/sidecar/pkg/storage/postgres"
"log"
Expand Down Expand Up @@ -104,6 +106,8 @@ func main() {

p := pipeline.NewPipeline(fetchr, idxr, mds, sm, msm, rc, rcq, cfg, sdc, eb, l)
rps := proofs.NewRewardsProofsStore(rc, l)
pds := protocolDataService.NewProtocolDataService(grm, l, cfg)
rds := rewardsDataService.NewRewardsDataService(grm, l, cfg, rc)

// Create new sidecar instance
// Create new sidecar instance
Expand All @@ -114,7 +118,7 @@ func main() {
rpc := rpcServer.NewRpcServer(&rpcServer.RpcServerConfig{
GrpcPort: cfg.RpcConfig.GrpcPort,
HttpPort: cfg.RpcConfig.HttpPort,
}, mds, sm, rc, rcq, eb, rps, l)
}, mds, sm, rc, rcq, eb, rps, pds, rds, l)

// RPC channel to notify the RPC server to shutdown gracefully
rpcChannel := make(chan bool)
Expand Down
7 changes: 6 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/Layr-Labs/sidecar/pkg/rewards/stakerOperators"
"github.com/Layr-Labs/sidecar/pkg/rewardsCalculatorQueue"
"github.com/Layr-Labs/sidecar/pkg/rpcServer"
"github.com/Layr-Labs/sidecar/pkg/service/protocolDataService"
"github.com/Layr-Labs/sidecar/pkg/service/rewardsDataService"
"github.com/Layr-Labs/sidecar/pkg/shutdown"
"github.com/Layr-Labs/sidecar/pkg/sidecar"
pgStorage "github.com/Layr-Labs/sidecar/pkg/storage/postgres"
Expand Down Expand Up @@ -121,6 +123,9 @@ var runCmd = &cobra.Command{

rps := proofs.NewRewardsProofsStore(rc, l)

pds := protocolDataService.NewProtocolDataService(grm, l, cfg)
rds := rewardsDataService.NewRewardsDataService(grm, l, cfg, rc)

go rcq.Process()

p := pipeline.NewPipeline(fetchr, idxr, mds, sm, msm, rc, rcq, cfg, sdc, eb, l)
Expand All @@ -133,7 +138,7 @@ var runCmd = &cobra.Command{
rpc := rpcServer.NewRpcServer(&rpcServer.RpcServerConfig{
GrpcPort: cfg.RpcConfig.GrpcPort,
HttpPort: cfg.RpcConfig.HttpPort,
}, mds, sm, rc, rcq, eb, rps, l)
}, mds, sm, rc, rcq, eb, rps, pds, rds, l)

// RPC channel to notify the RPC server to shutdown gracefully
rpcChannel := make(chan bool)
Expand Down
8 changes: 4 additions & 4 deletions examples/rewardsProofs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"context"
"crypto/tls"
"fmt"
v1 "github.com/Layr-Labs/protocol-apis/gen/protos/eigenlayer/sidecar/v1"
rewardsV1 "github.com/Layr-Labs/protocol-apis/gen/protos/eigenlayer/sidecar/v1/rewards"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"log"
"strings"
)

func NewSidecarClient(url string, insecureConn bool) (v1.RewardsClient, error) {
func NewSidecarClient(url string, insecureConn bool) (rewardsV1.RewardsClient, error) {
var creds grpc.DialOption
if strings.Contains(url, "localhost:") || strings.Contains(url, "127.0.0.1:") || insecureConn {
creds = grpc.WithTransportCredentials(insecure.NewCredentials())
Expand All @@ -25,7 +25,7 @@ func NewSidecarClient(url string, insecureConn bool) (v1.RewardsClient, error) {
return nil, err
}

return v1.NewRewardsClient(grpcClient), nil
return rewardsV1.NewRewardsClient(grpcClient), nil
}

func main() {
Expand All @@ -37,7 +37,7 @@ func main() {
log.Fatal(err)
}

res, err := client.GenerateClaimProof(context.Background(), &v1.GenerateClaimProofRequest{
res, err := client.GenerateClaimProof(context.Background(), &rewardsV1.GenerateClaimProofRequest{
EarnerAddress: earnerAddress,
Tokens: tokens,
})
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ 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.20250114181701-acb87ef4eeb5
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250123222616-41f0274e56d9
github.com/ethereum/go-ethereum v1.14.9
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1
github.com/google/uuid v1.6.0
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0
github.com/habx/pg-commands v0.6.1
github.com/lib/pq v1.10.9
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.0
Expand Down Expand Up @@ -53,7 +54,6 @@ require (
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/habx/pg-commands v0.6.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/uint256 v1.3.1 // indirect
github.com/iden3/go-iden3-crypto v0.0.16 // indirect
Expand Down
16 changes: 6 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,12 @@ github.com/Layr-Labs/eigenlayer-contracts v0.4.1-holesky-pepe.0.20240813143901-0
github.com/Layr-Labs/eigenlayer-contracts v0.4.1-holesky-pepe.0.20240813143901-00fc4b95e9c1/go.mod h1:Ie8YE3EQkTHqG6/tnUS0He7/UPMkXPo/3OFXwSy0iRo=
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.13 h1:Blb4AE+jC/vddV71w4/MQAPooM+8EVqv9w2bL4OytgY=
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.13/go.mod h1:PD/HoyzZjxDw1tAcZw3yD0yGddo+yhmwQAi+lk298r4=
github.com/Layr-Labs/protocol-apis v1.1.0 h1:PO6x+Y9ORiac2dkaWJayRFqhyzcvMbvRQkDIpLTNtVc=
github.com/Layr-Labs/protocol-apis v1.1.0/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk=
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250110201222-e8670ac00c32 h1:nRHAH0dn5qkQXUjdrPlGThtKLt154UKAHfzCEyMqfr0=
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250110201222-e8670ac00c32/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk=
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250110201843-c2f2cf37e910 h1:X3t1mr1kAOGDJ3paPS/lzHJchK4y+oWSJ+D/7+MgOmY=
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250110201843-c2f2cf37e910/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk=
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250114180833-6f2487a7e08c h1:kcTwHJVRDQAGqVacRJ4h6r6LKIZP6nBkxaBEJvZ9A3Q=
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250114180833-6f2487a7e08c/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk=
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250114181701-acb87ef4eeb5 h1:0PLxb8fpwdpWpfk24yhdZzETFCxVMN2yJjRDyBBf6wM=
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250114181701-acb87ef4eeb5/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk=
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250122221613-65afff84af27 h1:3jWR07FKc5qTmJR8VKlQFfHv26ZdnbwFi34CvtWuRRY=
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250122221613-65afff84af27/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk=
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250123222217-15d8d3b2f108 h1:gspRqV5XKOpdG21mFCQs5Dojg2sMA+oSI8S6D+z4fpc=
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250123222217-15d8d3b2f108/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk=
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250123222616-41f0274e56d9 h1:InnITBvNMqkNVnrbihyzMizagobMKtA2/RglLr2RpXg=
github.com/Layr-Labs/protocol-apis v1.1.1-0.20250123222616-41f0274e56d9/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
24 changes: 13 additions & 11 deletions pkg/rewards/rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"database/sql"
"errors"
"fmt"
"github.com/Layr-Labs/sidecar/pkg/rewards/rewardsTypes"
"time"

"sync/atomic"
Expand Down Expand Up @@ -482,15 +483,8 @@ func (rc *RewardsCalculator) DeleteCorruptedRewardsFromBlockHeight(blockHeight u
return nil
}

type Reward struct {
Earner string
Token string
Snapshot string
CumulativeAmount string
}

func (rc *RewardsCalculator) FetchRewardsForSnapshot(snapshotDate string) ([]*Reward, error) {
var goldRows []*Reward
func (rc *RewardsCalculator) FetchRewardsForSnapshot(snapshotDate string) ([]*rewardsTypes.Reward, error) {
var goldRows []*rewardsTypes.Reward
query, err := rewardsUtils.RenderQueryTemplate(`
select
earner,
Expand Down Expand Up @@ -796,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
8 changes: 8 additions & 0 deletions pkg/rewards/rewardsTypes/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package rewardsTypes

type Reward struct {
Earner string
Token string
Snapshot string
CumulativeAmount string
}
2 changes: 1 addition & 1 deletion pkg/rpcServer/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package rpcServer
import (
"context"

sidecarV1 "github.com/Layr-Labs/protocol-apis/gen/protos/eigenlayer/sidecar/v1"
sidecarV1 "github.com/Layr-Labs/protocol-apis/gen/protos/eigenlayer/sidecar/v1/sidecar"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand Down
12 changes: 6 additions & 6 deletions pkg/rpcServer/healthHandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package rpcServer

import (
"context"
sidecarV1 "github.com/Layr-Labs/protocol-apis/gen/protos/eigenlayer/sidecar/v1"
healthV1 "github.com/Layr-Labs/protocol-apis/gen/protos/eigenlayer/sidecar/v1/health"
)

func (rpc *RpcServer) HealthCheck(ctx context.Context, req *sidecarV1.HealthCheckRequest) (*sidecarV1.HealthCheckResponse, error) {
return &sidecarV1.HealthCheckResponse{
Status: sidecarV1.HealthCheckResponse_SERVING,
func (rpc *RpcServer) HealthCheck(ctx context.Context, req *healthV1.HealthCheckRequest) (*healthV1.HealthCheckResponse, error) {
return &healthV1.HealthCheckResponse{
Status: healthV1.HealthCheckResponse_SERVING,
}, nil
}

func (rpc *RpcServer) ReadyCheck(ctx context.Context, req *sidecarV1.ReadyRequest) (*sidecarV1.ReadyResponse, error) {
return &sidecarV1.ReadyResponse{
func (rpc *RpcServer) ReadyCheck(ctx context.Context, req *healthV1.ReadyRequest) (*healthV1.ReadyResponse, error) {
return &healthV1.ReadyResponse{
Ready: true,
}, nil
}
16 changes: 8 additions & 8 deletions pkg/rpcServer/proofsHandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ package rpcServer
import (
"context"
"github.com/Layr-Labs/eigenlayer-rewards-proofs/pkg/claimgen"
sidecarV1 "github.com/Layr-Labs/protocol-apis/gen/protos/eigenlayer/sidecar/v1"
rewardsV1 "github.com/Layr-Labs/protocol-apis/gen/protos/eigenlayer/sidecar/v1/rewards"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func convertClaimProofToRPCResponse(solidityProof *claimgen.IRewardsCoordinatorRewardsMerkleClaimStrings) *sidecarV1.Proof {
tokenLeaves := make([]*sidecarV1.TokenLeaf, 0)
func convertClaimProofToRPCResponse(solidityProof *claimgen.IRewardsCoordinatorRewardsMerkleClaimStrings) *rewardsV1.Proof {
tokenLeaves := make([]*rewardsV1.TokenLeaf, 0)

for _, l := range solidityProof.TokenLeaves {
tokenLeaves = append(tokenLeaves, &sidecarV1.TokenLeaf{
tokenLeaves = append(tokenLeaves, &rewardsV1.TokenLeaf{
Token: l.Token.String(),
CumulativeEarnings: l.CumulativeEarnings,
})
}

return &sidecarV1.Proof{
return &rewardsV1.Proof{
Root: solidityProof.Root,
RootIndex: solidityProof.RootIndex,
EarnerIndex: solidityProof.EarnerIndex,
EarnerTreeProof: solidityProof.EarnerTreeProof,
EarnerLeaf: &sidecarV1.EarnerLeaf{
EarnerLeaf: &rewardsV1.EarnerLeaf{
Earner: solidityProof.EarnerLeaf.Earner.String(),
EarnerTokenRoot: solidityProof.EarnerLeaf.EarnerTokenRoot,
},
Expand All @@ -33,7 +33,7 @@ func convertClaimProofToRPCResponse(solidityProof *claimgen.IRewardsCoordinatorR
}
}

func (rpc *RpcServer) GenerateClaimProof(ctx context.Context, req *sidecarV1.GenerateClaimProofRequest) (*sidecarV1.GenerateClaimProofResponse, error) {
func (rpc *RpcServer) GenerateClaimProof(ctx context.Context, req *rewardsV1.GenerateClaimProofRequest) (*rewardsV1.GenerateClaimProofResponse, error) {
earner := req.GetEarnerAddress()
tokens := req.GetTokens()
rootIndex := req.GetRootIndex()
Expand All @@ -52,7 +52,7 @@ func (rpc *RpcServer) GenerateClaimProof(ctx context.Context, req *sidecarV1.Gen

solidityClaim := claimgen.FormatProofForSolidity(root, claim)

return &sidecarV1.GenerateClaimProofResponse{
return &rewardsV1.GenerateClaimProofResponse{
Proof: convertClaimProofToRPCResponse(solidityClaim),
}, nil
}
Loading
Loading