@@ -8,13 +8,16 @@ import (
88 "encoding/json"
99 "fmt"
1010 "log"
11+ "net/http"
1112 "os"
1213 "path/filepath"
1314 "sync"
1415 "time"
1516
1617 "github.com/ethereum/go-ethereum/crypto"
18+ "github.com/urfave/cli/v2"
1719 "github.com/yetanotherco/aligned_layer/operator/risc_zero"
20+ "golang.org/x/crypto/sha3"
1821
1922 "github.com/prometheus/client_golang/prometheus"
2023 "github.com/yetanotherco/aligned_layer/metrics"
@@ -590,3 +593,65 @@ func (o *Operator) SignTaskResponse(batchIdentifierHash [32]byte) *bls.Signature
590593 responseSignature := * o .Config .BlsConfig .KeyPair .SignMessage (batchIdentifierHash )
591594 return & responseSignature
592595}
596+
597+ func (o * Operator ) SendTelemetryData (ctx * cli.Context ) error {
598+ // hash version
599+ hash := sha3 .NewLegacyKeccak256 ()
600+ hash .Write ([]byte (ctx .App .Version ))
601+
602+ // get hash
603+ version := hash .Sum (nil )
604+
605+ // sign version
606+ signature , err := crypto .Sign (version [:], o .Config .EcdsaConfig .PrivateKey )
607+ if err != nil {
608+ return err
609+ }
610+ ethRpcUrl , err := BaseUrlOnly (o .Config .BaseConfig .EthRpcUrl )
611+ if err != nil {
612+ return err
613+ }
614+ ethRpcUrlFallback , err := BaseUrlOnly (o .Config .BaseConfig .EthRpcUrlFallback )
615+ if err != nil {
616+ return err
617+ }
618+ ethWsUrl , err := BaseUrlOnly (o .Config .BaseConfig .EthWsUrl )
619+ if err != nil {
620+ return err
621+ }
622+ ethWsUrlFallback , err := BaseUrlOnly (o .Config .BaseConfig .EthWsUrlFallback )
623+ if err != nil {
624+ return err
625+ }
626+
627+ body := map [string ]interface {}{
628+ "version" : ctx .App .Version ,
629+ "signature" : signature ,
630+ "eth_rpc_url" : ethRpcUrl ,
631+ "eth_rpc_url_fallback" : ethRpcUrlFallback ,
632+ "eth_ws_url" : ethWsUrl ,
633+ "eth_ws_url_fallback" : ethWsUrlFallback ,
634+ }
635+
636+ bodyBuffer := new (bytes.Buffer )
637+
638+ bodyReader := json .NewEncoder (bodyBuffer )
639+ err = bodyReader .Encode (body )
640+ if err != nil {
641+ return err
642+ }
643+
644+ // send version to operator tracker server
645+ endpoint := o .Config .Operator .OperatorTrackerIpPortAddress + "/versions"
646+ o .Logger .Info ("Sending version to operator tracker server: " , "endpoint" , endpoint )
647+
648+ res , err := http .Post (endpoint , "application/json" , bodyBuffer )
649+ if err != nil {
650+ // Dont prevent operator from starting if operator tracker server is down
651+ o .Logger .Warn ("Error sending version to metrics server: " , "err" , err )
652+ } else if res .StatusCode != http .StatusCreated && res .StatusCode != http .StatusNoContent {
653+ o .Logger .Warn ("Error sending version to operator tracker server: " , "status_code" , res .StatusCode )
654+ }
655+
656+ return nil
657+ }
0 commit comments