diff --git a/go.mod b/go.mod index 81c1f47e..932ecec8 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,6 @@ require ( github.com/wealdtech/go-merkletree/v2 v2.6.0 github.com/wk8/go-ordered-map/v2 v2.1.8 go.uber.org/zap v1.27.0 - golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 google.golang.org/grpc v1.65.0 gorm.io/driver/postgres v1.5.9 gorm.io/gorm v1.25.10 @@ -87,12 +86,12 @@ require ( github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect go.uber.org/multierr v1.10.0 // indirect - golang.org/x/crypto v0.24.0 // indirect + golang.org/x/crypto v0.31.0 // indirect golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect golang.org/x/net v0.26.0 // indirect - golang.org/x/sync v0.8.0 // indirect - golang.org/x/sys v0.22.0 // indirect - golang.org/x/text v0.17.0 // indirect + golang.org/x/sync v0.10.0 // indirect + golang.org/x/sys v0.28.0 // indirect + golang.org/x/text v0.21.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect google.golang.org/protobuf v1.35.1 // indirect diff --git a/go.sum b/go.sum index 5b63fbc3..c09d6acd 100644 --- a/go.sum +++ b/go.sum @@ -41,30 +41,6 @@ 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 v0.1.0-beta.3.0.20241122223729-1734c60ac737 h1:I/0YAw2ue150YuLNavErIQ4t7yoTDuH3nqZkOS7RTjg= -github.com/Layr-Labs/protocol-apis v0.1.0-beta.3.0.20241122223729-1734c60ac737/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk= -github.com/Layr-Labs/protocol-apis v0.1.0-beta.3.0.20241203213718-bda8083a30b9 h1:tvBtFPGqMw1Hwp++cGP/otFTC2OQrJMtVjkH/vNbttE= -github.com/Layr-Labs/protocol-apis v0.1.0-beta.3.0.20241203213718-bda8083a30b9/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk= -github.com/Layr-Labs/protocol-apis v0.1.0-beta.3.0.20241203213920-e35bed7723dc h1:P7S3ijgAQ4Xdpdocfl7rGgaTsPAurHsSCYHfhWm9au4= -github.com/Layr-Labs/protocol-apis v0.1.0-beta.3.0.20241203213920-e35bed7723dc/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk= -github.com/Layr-Labs/protocol-apis v0.1.0-beta.3.0.20241203214053-44b580f4ea84 h1:BLF8GHMmXSC1YtjlqBRC7pVBDVK0QwEJpwXYjZO7t1w= -github.com/Layr-Labs/protocol-apis v0.1.0-beta.3.0.20241203214053-44b580f4ea84/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk= -github.com/Layr-Labs/protocol-apis v1.0.0-rc.1 h1:N3OAsdZ5V/QVAjsJbJa1kruocoi50jfLquyVk4bL9HQ= -github.com/Layr-Labs/protocol-apis v1.0.0-rc.1/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk= -github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20241203225729-619c724a75e3 h1:kc3jPZzgTsXWTPDzEi9iB9DAc2+soPHsGd41KTVhC04= -github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20241203225729-619c724a75e3/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk= -github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20241204030420-83d31161930e h1:h6ptdsDTKiTldAyel+XXfbusrarpF2+arhPlaFUeq7M= -github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20241204030420-83d31161930e/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk= -github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20241204194134-d3c82f365d7a h1:KgeRP8HuUI6OR7v3oe8l4vXbhBiZfu4htao4yiHlbsk= -github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20241204194134-d3c82f365d7a/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk= -github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20241205194457-0df3820dae69 h1:OIdv/BZIDU8Olkpo80aOZGZ9TpgLYdKYcU8BicMD61M= -github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20241205194457-0df3820dae69/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk= -github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20241206170231-3505e222b408 h1:yUA+KbV/uZUkwf6EjlmOvyp1FA3tYOgtwp9NqoZra7w= -github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20241206170231-3505e222b408/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk= -github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20241206170400-42069f3d8ad6 h1:W7jhyGCXRs4OK+MkbzQhGlj0E+O6+rJi74VPyikNaDQ= -github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20241206170400-42069f3d8ad6/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk= -github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20241206171033-dc9bce2085c6 h1:Qg6fhCB2no7QWuPAZEIX1GwnX2ayDbgCqenYAQxaA6U= -github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20241206171033-dc9bce2085c6/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk= github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20241206171209-6484d433345c h1:m9xRDJR9ItBQmiOBhsx64Bemi4W5/2pkXru75evpEGI= github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20241206171209-6484d433345c/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk= github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= @@ -486,8 +462,8 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= -golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= +golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -574,8 +550,8 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= -golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -630,8 +606,8 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -639,8 +615,8 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3 golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= -golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -694,8 +670,6 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= -golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= diff --git a/pkg/clients/ethereum/client.go b/pkg/clients/ethereum/client.go index ab6f2c9a..8ec149a1 100644 --- a/pkg/clients/ethereum/client.go +++ b/pkg/clients/ethereum/client.go @@ -17,7 +17,6 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethclient" "go.uber.org/zap" - "golang.org/x/xerrors" ) const ( @@ -292,7 +291,7 @@ func (c *Client) batchCall(ctx context.Context, requests []*RPCRequest) ([]*RPCR } requestBody, err := json.Marshal(requests) if err != nil { - return nil, xerrors.Errorf("Failed to marshal requests: %s", err) + return nil, fmt.Errorf("Failed to marshal requests: %s", err) } ctx, cancel := context.WithTimeout(ctx, time.Second*20) @@ -300,7 +299,7 @@ func (c *Client) batchCall(ctx context.Context, requests []*RPCRequest) ([]*RPCR request, err := http.NewRequestWithContext(ctx, http.MethodPost, c.clientConfig.BaseUrl, bytes.NewReader(requestBody)) if err != nil { - return nil, xerrors.Errorf("Failed to make request: %s", err) + return nil, fmt.Errorf("Failed to make request: %s", err) } request.Header.Set("Content-Type", "application/json") @@ -308,16 +307,16 @@ func (c *Client) batchCall(ctx context.Context, requests []*RPCRequest) ([]*RPCR response, err := c.httpClient.Do(request) if err != nil { - return nil, xerrors.Errorf("Request failed %v", err) + return nil, fmt.Errorf("Request failed %v", err) } responseBody, err := io.ReadAll(response.Body) if err != nil { - return nil, xerrors.Errorf("Failed to read body %v", err) + return nil, fmt.Errorf("Failed to read body %v", err) } if response.StatusCode != http.StatusOK { - return nil, xerrors.Errorf("received http error code %+v", response.StatusCode) + return nil, fmt.Errorf("received http error code %+v", response.StatusCode) } destination := []*RPCResponse{} @@ -325,13 +324,13 @@ func (c *Client) batchCall(ctx context.Context, requests []*RPCRequest) ([]*RPCR if strings.HasPrefix(string(responseBody), "{") { errorResponse := RPCResponse{} if err := json.Unmarshal(responseBody, &errorResponse); err != nil { - return nil, xerrors.Errorf("failed to unmarshal error response: %s", err) + return nil, fmt.Errorf("failed to unmarshal error response: %s", err) } c.Logger.Sugar().Debugw("Error payload returned from batch call", zap.String("error", string(responseBody)), ) if errorResponse.Error.Message != "empty batch" { - return nil, xerrors.Errorf("Error payload returned from batch call: %s", string(responseBody)) + return nil, fmt.Errorf("Error payload returned from batch call: %s", string(responseBody)) } } else { if err := json.Unmarshal(responseBody, &destination); err != nil { @@ -339,7 +338,7 @@ func (c *Client) batchCall(ctx context.Context, requests []*RPCRequest) ([]*RPCR zap.Error(err), zap.String("response", string(responseBody)), ) - return nil, xerrors.Errorf("failed to unmarshal response: %s", err) + return nil, fmt.Errorf("failed to unmarshal response: %s", err) } } response.Body.Close() @@ -492,7 +491,7 @@ func (c *Client) chunkedBatchCall(ctx context.Context, requests []*RPCRequest) ( } if len(allResults) != len(requests) { - return nil, xerrors.Errorf("Failed to fetch results for all requests. Expected %d, got %d", len(requests), len(allResults)) + return nil, fmt.Errorf("Failed to fetch results for all requests. Expected %d, got %d", len(requests), len(allResults)) } return allResults, nil } @@ -517,7 +516,7 @@ func (c *Client) call(ctx context.Context, rpcRequest *RPCRequest) (*RPCResponse request, err := http.NewRequestWithContext(ctx, http.MethodPost, c.clientConfig.BaseUrl, bytes.NewReader(requestBody)) if err != nil { - return nil, xerrors.Errorf("Failed to make request %s", err) + return nil, fmt.Errorf("Failed to make request %s", err) } request.Header.Set("Content-Type", "application/json") @@ -525,24 +524,24 @@ func (c *Client) call(ctx context.Context, rpcRequest *RPCRequest) (*RPCResponse response, err := c.httpClient.Do(request) if err != nil { - return nil, xerrors.Errorf("Request failed %s", err) + return nil, fmt.Errorf("Request failed %s", err) } responseBody, err := io.ReadAll(response.Body) if err != nil { - return nil, xerrors.Errorf("Failed to read body %s", err) + return nil, fmt.Errorf("Failed to read body %s", err) } if response.StatusCode != http.StatusOK { - return nil, xerrors.Errorf("received http error code %+v", response.StatusCode) + return nil, fmt.Errorf("received http error code %+v", response.StatusCode) } destination := &RPCResponse{} if err := json.Unmarshal(responseBody, destination); err != nil { - return nil, xerrors.Errorf("failed to unmarshal response: %s", err) + return nil, fmt.Errorf("failed to unmarshal response: %s", err) } if destination.Error != nil { - return nil, xerrors.Errorf("received error response: %+v", destination.Error) + return nil, fmt.Errorf("received error response: %+v", destination.Error) } response.Body.Close() @@ -572,5 +571,5 @@ func (c *Client) Call(ctx context.Context, rpcRequest *RPCRequest) (*RPCResponse time.Sleep(time.Second * time.Duration(backoff)) } c.Logger.Sugar().Errorw("Exceeded retries for Call", zap.Any("rpcRequest", rpcRequest)) - return nil, xerrors.Errorf("Exceeded retries for Call") + return nil, fmt.Errorf("Exceeded retries for Call") } diff --git a/pkg/clients/ethereum/types.go b/pkg/clients/ethereum/types.go index b0917c77..0231d06f 100644 --- a/pkg/clients/ethereum/types.go +++ b/pkg/clients/ethereum/types.go @@ -8,7 +8,6 @@ import ( "strings" "github.com/ethereum/go-ethereum/common/hexutil" - "golang.org/x/xerrors" ) type ( @@ -158,7 +157,7 @@ func (v EthereumHexString) MarshalJSON() ([]byte, error) { func (v *EthereumHexString) UnmarshalJSON(input []byte) error { var s string if err := json.Unmarshal(input, &s); err != nil { - return xerrors.Errorf("failed to unmarshal EthereumHexString: %w", err) + return fmt.Errorf("failed to unmarshal EthereumHexString: %w", err) } s = strings.ToLower(s) @@ -179,7 +178,7 @@ func (v *EthereumQuantity) UnmarshalJSON(input []byte) error { if len(input) > 0 && input[0] != '"' { var i uint64 if err := json.Unmarshal(input, &i); err != nil { - return xerrors.Errorf("failed to unmarshal EthereumQuantity into uint64: %w", err) + return fmt.Errorf("failed to unmarshal EthereumQuantity into uint64: %w", err) } *v = EthereumQuantity(i) @@ -188,7 +187,7 @@ func (v *EthereumQuantity) UnmarshalJSON(input []byte) error { var s string if err := json.Unmarshal(input, &s); err != nil { - return xerrors.Errorf("failed to unmarshal EthereumQuantity into string: %w", err) + return fmt.Errorf("failed to unmarshal EthereumQuantity into string: %w", err) } if s == "" { @@ -198,7 +197,7 @@ func (v *EthereumQuantity) UnmarshalJSON(input []byte) error { i, err := hexutil.DecodeUint64(s) if err != nil { - return xerrors.Errorf("failed to decode EthereumQuantity %v: %w", s, err) + return fmt.Errorf("failed to decode EthereumQuantity %v: %w", s, err) } *v = EthereumQuantity(i) @@ -222,7 +221,7 @@ func (v EthereumBigQuantity) MarshalJSON() ([]byte, error) { func (v *EthereumBigQuantity) UnmarshalJSON(input []byte) error { var s string if err := json.Unmarshal(input, &s); err != nil { - return xerrors.Errorf("failed to unmarshal EthereumBigQuantity: %w", err) + return fmt.Errorf("failed to unmarshal EthereumBigQuantity: %w", err) } if s == "" { @@ -232,7 +231,7 @@ func (v *EthereumBigQuantity) UnmarshalJSON(input []byte) error { i, err := hexutil.DecodeBig(s) if err != nil { - return xerrors.Errorf("failed to decode EthereumBigQuantity %v: %w", s, err) + return fmt.Errorf("failed to decode EthereumBigQuantity %v: %w", s, err) } *v = EthereumBigQuantity(*i) @@ -247,7 +246,7 @@ func (v EthereumBigQuantity) Value() string { func (v EthereumBigQuantity) Uint64() (uint64, error) { i := big.Int(v) if !i.IsUint64() { - return 0, xerrors.Errorf("failed to parse EthereumBigQuantity to uint64 %v", v.Value()) + return 0, fmt.Errorf("failed to parse EthereumBigQuantity to uint64 %v", v.Value()) } return i.Uint64(), nil } @@ -261,7 +260,7 @@ func (v EthereumBigFloat) MarshalJSON() ([]byte, error) { func (v *EthereumBigFloat) UnmarshalJSON(input []byte) error { var s string if err := json.Unmarshal(input, &s); err != nil { - return xerrors.Errorf("failed to unmarshal EthereumBigFloat: %w", err) + return fmt.Errorf("failed to unmarshal EthereumBigFloat: %w", err) } if s == "" { @@ -272,7 +271,7 @@ func (v *EthereumBigFloat) UnmarshalJSON(input []byte) error { scalar := new(big.Float) scalar, ok := scalar.SetString(s) if !ok { - return xerrors.Errorf("cannot parse EthereumBigFloat") + return fmt.Errorf("cannot parse EthereumBigFloat") } *v = EthereumBigFloat(*scalar) diff --git a/pkg/contractStore/postgresContractStore/postgresContractStore.go b/pkg/contractStore/postgresContractStore/postgresContractStore.go index c55aabc9..7a62b918 100644 --- a/pkg/contractStore/postgresContractStore/postgresContractStore.go +++ b/pkg/contractStore/postgresContractStore/postgresContractStore.go @@ -11,7 +11,6 @@ import ( "github.com/Layr-Labs/sidecar/internal/config" "go.uber.org/zap" - "golang.org/x/xerrors" "gorm.io/gorm" "gorm.io/gorm/clause" ) @@ -198,18 +197,18 @@ func (s *PostgresContractStore) loadContractData() (*contractStore.CoreContracts case config.Chain_Preprod: filename = "preprod.json" default: - return nil, xerrors.Errorf("Unknown environment.") + return nil, fmt.Errorf("Unknown environment.") } jsonData, err := contractStore.CoreContracts.ReadFile(fmt.Sprintf("coreContracts/%s", filename)) if err != nil { - return nil, xerrors.Errorf("Failed to open core contracts file: %w", err) + return nil, fmt.Errorf("Failed to open core contracts file: %w", err) } // read entire file and marshal it into a CoreContractsData struct data := &contractStore.CoreContractsData{} err = json.Unmarshal(jsonData, &data) if err != nil { - return nil, xerrors.Errorf("Failed to decode core contracts data: %w", err) + return nil, fmt.Errorf("Failed to decode core contracts data: %w", err) } return data, nil } @@ -217,13 +216,13 @@ func (s *PostgresContractStore) loadContractData() (*contractStore.CoreContracts func (s *PostgresContractStore) InitializeCoreContracts() error { coreContracts, err := s.loadContractData() if err != nil { - return xerrors.Errorf("Failed to load core contracts: %w", err) + return fmt.Errorf("Failed to load core contracts: %w", err) } contracts := make([]*contractStore.Contract, 0) res := s.Db.Find(&contracts) if res.Error != nil { - return xerrors.Errorf("Failed to fetch contracts: %w", res.Error) + return fmt.Errorf("Failed to fetch contracts: %w", res.Error) } for _, contract := range coreContracts.CoreContracts { @@ -236,7 +235,7 @@ func (s *PostgresContractStore) InitializeCoreContracts() error { true, ) if err != nil { - return xerrors.Errorf("Failed to create core contract: %w", err) + return fmt.Errorf("Failed to create core contract: %w", err) } if found { s.Logger.Sugar().Infow("Contract already exists", zap.String("contractAddress", contract.ContractAddress)) @@ -245,7 +244,7 @@ func (s *PostgresContractStore) InitializeCoreContracts() error { _, err = s.SetContractCheckedForProxy(contract.ContractAddress) if err != nil { - return xerrors.Errorf("Failed to create core contract: %w", err) + return fmt.Errorf("Failed to create core contract: %w", err) } s.Logger.Sugar().Infow("Created core contract", zap.String("contractAddress", contract.ContractAddress)) } @@ -256,7 +255,7 @@ func (s *PostgresContractStore) InitializeCoreContracts() error { proxy.ProxyContractAddress, ) if err != nil { - return xerrors.Errorf("Failed to create core proxy contract: %w", err) + return fmt.Errorf("Failed to create core proxy contract: %w", err) } if found { s.Logger.Sugar().Infow("Proxy contract already exists", diff --git a/pkg/eigenState/avsOperators/avsOperators.go b/pkg/eigenState/avsOperators/avsOperators.go index 5f395f68..d3921bd7 100644 --- a/pkg/eigenState/avsOperators/avsOperators.go +++ b/pkg/eigenState/avsOperators/avsOperators.go @@ -9,7 +9,6 @@ import ( "github.com/Layr-Labs/sidecar/pkg/eigenState/types" "github.com/Layr-Labs/sidecar/pkg/storage" "go.uber.org/zap" - "golang.org/x/xerrors" "gorm.io/gorm" "gorm.io/gorm/clause" "slices" @@ -86,7 +85,7 @@ func (a *AvsOperatorsModel) GetStateTransitions() (types.StateTransitions[*AvsOp // Sanity check to make sure we've got an initialized accumulator map for the block if _, ok := a.stateAccumulator[log.BlockNumber]; !ok { - return nil, xerrors.Errorf("No state accumulator found for block %d", log.BlockNumber) + return nil, fmt.Errorf("No state accumulator found for block %d", log.BlockNumber) } operator := strings.ToLower(arguments[0].Value.(string)) @@ -180,7 +179,7 @@ func (a *AvsOperatorsModel) HandleStateChange(log *storage.TransactionLog) (inte func (a *AvsOperatorsModel) prepareState(blockNumber uint64) ([]*AvsOperatorStateChange, error) { accumulatedState, ok := a.stateAccumulator[blockNumber] if !ok { - err := xerrors.Errorf("No accumulated state found for block %d", blockNumber) + err := fmt.Errorf("No accumulated state found for block %d", blockNumber) a.logger.Sugar().Errorw(err.Error(), zap.Error(err), zap.Uint64("blockNumber", blockNumber)) return nil, err } diff --git a/pkg/eigenState/base/baseEigenState.go b/pkg/eigenState/base/baseEigenState.go index 1e33b5d7..2e753a2c 100644 --- a/pkg/eigenState/base/baseEigenState.go +++ b/pkg/eigenState/base/baseEigenState.go @@ -2,6 +2,7 @@ package base import ( "database/sql" + "encoding/binary" "encoding/json" "errors" "fmt" @@ -56,10 +57,8 @@ func (b *BaseEigenState) ParseLogOutput(log *storage.TransactionLog) (map[string // 1. Ensures that the tree is always different for different blocks // 2. Allows us to have at least 1 value if there are no model changes for a block. func (b *BaseEigenState) InitializeMerkleTreeBaseStateWithBlock(blockNumber uint64) [][]byte { - blockNumberByte := []byte(fmt.Sprintf("%d", blockNumber)) return [][]byte{ - types.MerkleLeafPrefix_EigenStateBlock, - blockNumberByte, + append(types.MerkleLeafPrefix_EigenStateBlock, binary.BigEndian.AppendUint64([]byte{}, blockNumber)...), } } @@ -146,7 +145,7 @@ func NewSlotID(txHash string, logIndex uint64) types.SlotID { } func NewSlotIDWithSuffix(txHash string, logIndex uint64, suffix string) types.SlotID { - baseSlotId := fmt.Sprintf("%s_%d", txHash, logIndex) + baseSlotId := fmt.Sprintf("%s_%016x", txHash, logIndex) if suffix != "" { baseSlotId = fmt.Sprintf("%s_%s", baseSlotId, suffix) } diff --git a/pkg/eigenState/disabledDistributionRoots/disabledDistributionRoots.go b/pkg/eigenState/disabledDistributionRoots/disabledDistributionRoots.go index 7b717845..83dbcd67 100644 --- a/pkg/eigenState/disabledDistributionRoots/disabledDistributionRoots.go +++ b/pkg/eigenState/disabledDistributionRoots/disabledDistributionRoots.go @@ -8,7 +8,6 @@ import ( "github.com/Layr-Labs/sidecar/pkg/eigenState/types" "github.com/Layr-Labs/sidecar/pkg/storage" "go.uber.org/zap" - "golang.org/x/xerrors" "gorm.io/gorm" "gorm.io/gorm/clause" "slices" @@ -63,7 +62,7 @@ func (ddr *DisabledDistributionRootsModel) GetStateTransitions() (types.StateTra } // Sanity check to make sure we've got an initialized accumulator map for the block if _, ok := ddr.stateAccumulator[log.BlockNumber]; !ok { - return nil, xerrors.Errorf("No state accumulator found for block %d", log.BlockNumber) + return nil, fmt.Errorf("No state accumulator found for block %d", log.BlockNumber) } // json numbers are float64s but we want a uint64 @@ -72,7 +71,7 @@ func (ddr *DisabledDistributionRootsModel) GetStateTransitions() (types.StateTra slotId := base.NewSlotID(log.TransactionHash, log.LogIndex) _, ok := ddr.stateAccumulator[log.BlockNumber][slotId] if ok { - err := xerrors.Errorf("Duplicate disabledDistributionRoot for slot %s at block %d", slotId, log.BlockNumber) + err := fmt.Errorf("Duplicate disabledDistributionRoot for slot %s at block %d", slotId, log.BlockNumber) ddr.logger.Sugar().Errorw("Duplicate disabledDistributionRoot", zap.Error(err)) return nil, err } @@ -152,7 +151,7 @@ func (ddr *DisabledDistributionRootsModel) prepareState(blockNumber uint64) ([]* accumulatedState, ok := ddr.stateAccumulator[blockNumber] if !ok { - err := xerrors.Errorf("No accumulated state found for block %d", blockNumber) + err := fmt.Errorf("No accumulated state found for block %d", blockNumber) ddr.logger.Sugar().Errorw(err.Error(), zap.Error(err), zap.Uint64("blockNumber", blockNumber)) return nil, err } diff --git a/pkg/eigenState/operatorShares/operatorShares.go b/pkg/eigenState/operatorShares/operatorShares.go index 61e76a20..919aca74 100644 --- a/pkg/eigenState/operatorShares/operatorShares.go +++ b/pkg/eigenState/operatorShares/operatorShares.go @@ -17,7 +17,6 @@ import ( "github.com/Layr-Labs/sidecar/pkg/eigenState/stateManager" "github.com/Layr-Labs/sidecar/pkg/eigenState/types" "go.uber.org/zap" - "golang.org/x/xerrors" "gorm.io/gorm" "gorm.io/gorm/clause" ) @@ -132,7 +131,7 @@ func (osm *OperatorSharesModel) GetStateTransitions() (types.StateTransitions[*O // Sanity check to make sure we've got an initialized accumulator map for the block if _, ok := osm.stateAccumulator[log.BlockNumber]; !ok { - return nil, xerrors.Errorf("No state accumulator found for block %d", log.BlockNumber) + return nil, fmt.Errorf("No state accumulator found for block %d", log.BlockNumber) } operator := strings.ToLower(arguments[0].Value.(string)) @@ -145,7 +144,7 @@ func (osm *OperatorSharesModel) GetStateTransitions() (types.StateTransitions[*O zap.Uint64("transactionIndex", log.TransactionIndex), zap.Uint64("blockNumber", log.BlockNumber), ) - return nil, xerrors.Errorf("Failed to convert shares to big.Int: %s", sharesStr) + return nil, fmt.Errorf("Failed to convert shares to big.Int: %s", sharesStr) } // All shares are emitted as ABS(shares), so we need to negate the shares if the event is a decrease diff --git a/pkg/eigenState/rewardSubmissions/rewardSubmissions.go b/pkg/eigenState/rewardSubmissions/rewardSubmissions.go index 2b33486d..6e2a6cbf 100644 --- a/pkg/eigenState/rewardSubmissions/rewardSubmissions.go +++ b/pkg/eigenState/rewardSubmissions/rewardSubmissions.go @@ -15,7 +15,6 @@ import ( "github.com/Layr-Labs/sidecar/pkg/eigenState/stateManager" "github.com/Layr-Labs/sidecar/pkg/eigenState/types" "go.uber.org/zap" - "golang.org/x/xerrors" "gorm.io/gorm" "gorm.io/gorm/clause" ) @@ -38,7 +37,7 @@ type RewardSubmission struct { } func NewSlotID(transactionHash string, logIndex uint64, rewardHash string, strategyIndex uint64) types.SlotID { - return base.NewSlotIDWithSuffix(transactionHash, logIndex, fmt.Sprintf("%s_%d", rewardHash, strategyIndex)) + return base.NewSlotIDWithSuffix(transactionHash, logIndex, fmt.Sprintf("%s_%016x", rewardHash, strategyIndex)) } type RewardSubmissionsModel struct { @@ -79,13 +78,13 @@ func (rs *RewardSubmissionsModel) GetModelName() string { } type genericRewardPaymentData struct { - Token string - Amount json.Number - StartTimestamp uint64 - Duration uint64 + Token string `json:"token"` + Amount json.Number `json:"amount"` + StartTimestamp uint64 `json:"startTimestamp"` + Duration uint64 `json:"duration"` StrategiesAndMultipliers []struct { - Strategy string - Multiplier json.Number + Strategy string `json:"strategy"` + Multiplier json.Number `json:"multiplier"` } `json:"strategiesAndMultipliers"` } @@ -133,12 +132,12 @@ func (rs *RewardSubmissionsModel) handleRewardSubmissionCreatedEvent(log *storag amountBig, success := numbers.NewBig257().SetString(actualOuputData.Amount.String(), 10) if !success { - return nil, xerrors.Errorf("Failed to parse amount to Big257: %s", actualOuputData.Amount.String()) + return nil, fmt.Errorf("Failed to parse amount to Big257: %s", actualOuputData.Amount.String()) } multiplierBig, success := numbers.NewBig257().SetString(strategyAndMultiplier.Multiplier.String(), 10) if !success { - return nil, xerrors.Errorf("Failed to parse multiplier to Big257: %s", actualOuputData.Amount.String()) + return nil, fmt.Errorf("Failed to parse multiplier to Big257: %s", actualOuputData.Amount.String()) } var rewardType string @@ -149,7 +148,7 @@ func (rs *RewardSubmissionsModel) handleRewardSubmissionCreatedEvent(log *storag } else if log.EventName == "RewardsSubmissionForAllEarnersCreated" { rewardType = "all_earners" } else { - return nil, xerrors.Errorf("Unknown event name: %s", log.EventName) + return nil, fmt.Errorf("Unknown event name: %s", log.EventName) } rewardSubmission := &RewardSubmission{ @@ -189,7 +188,7 @@ func (rs *RewardSubmissionsModel) GetStateTransitions() (types.StateTransitions[ _, ok := rs.stateAccumulator[log.BlockNumber][slotId] if ok { fmt.Printf("Submissions: %+v\n", rs.stateAccumulator[log.BlockNumber]) - err := xerrors.Errorf("Duplicate distribution root submitted for slot %s at block %d", slotId, log.BlockNumber) + err := fmt.Errorf("Duplicate distribution root submitted for slot %s at block %d", slotId, log.BlockNumber) rs.logger.Sugar().Errorw("Duplicate distribution root submitted", zap.Error(err)) return nil, err } @@ -265,7 +264,7 @@ func (rs *RewardSubmissionsModel) HandleStateChange(log *storage.TransactionLog) func (rs *RewardSubmissionsModel) prepareState(blockNumber uint64) ([]*RewardSubmission, error) { accumulatedState, ok := rs.stateAccumulator[blockNumber] if !ok { - err := xerrors.Errorf("No accumulated state found for block %d", blockNumber) + err := fmt.Errorf("No accumulated state found for block %d", blockNumber) rs.logger.Sugar().Errorw(err.Error(), zap.Error(err), zap.Uint64("blockNumber", blockNumber)) return nil, err } diff --git a/pkg/eigenState/stakerDelegations/stakerDelegations.go b/pkg/eigenState/stakerDelegations/stakerDelegations.go index 35551b28..ae3df748 100644 --- a/pkg/eigenState/stakerDelegations/stakerDelegations.go +++ b/pkg/eigenState/stakerDelegations/stakerDelegations.go @@ -9,7 +9,6 @@ import ( "github.com/Layr-Labs/sidecar/pkg/eigenState/types" "github.com/Layr-Labs/sidecar/pkg/storage" "go.uber.org/zap" - "golang.org/x/xerrors" "gorm.io/gorm" "gorm.io/gorm/clause" "slices" @@ -79,7 +78,7 @@ func (s *StakerDelegationsModel) GetStateTransitions() (types.StateTransitions[* // Sanity check to make sure we've got an initialized accumulator map for the block if _, ok := s.stateAccumulator[log.BlockNumber]; !ok { - return nil, xerrors.Errorf("No state accumulator found for block %d", log.BlockNumber) + return nil, fmt.Errorf("No state accumulator found for block %d", log.BlockNumber) } staker := strings.ToLower(arguments[0].Value.(string)) @@ -168,7 +167,7 @@ func (s *StakerDelegationsModel) HandleStateChange(log *storage.TransactionLog) func (s *StakerDelegationsModel) prepareState(blockNumber uint64) ([]*StakerDelegationChange, error) { deltas, ok := s.stateAccumulator[blockNumber] if !ok { - err := xerrors.Errorf("No accumulated state found for block %d", blockNumber) + err := fmt.Errorf("No accumulated state found for block %d", blockNumber) s.logger.Sugar().Errorw(err.Error(), zap.Error(err), zap.Uint64("blockNumber", blockNumber)) return nil, err } diff --git a/pkg/eigenState/stakerShares/stakerShares.go b/pkg/eigenState/stakerShares/stakerShares.go index 80bb7faf..e318997f 100644 --- a/pkg/eigenState/stakerShares/stakerShares.go +++ b/pkg/eigenState/stakerShares/stakerShares.go @@ -19,7 +19,6 @@ import ( "github.com/Layr-Labs/sidecar/pkg/eigenState/stateManager" "github.com/Layr-Labs/sidecar/pkg/eigenState/types" "go.uber.org/zap" - "golang.org/x/xerrors" "gorm.io/gorm" "gorm.io/gorm/clause" ) @@ -46,7 +45,7 @@ type StakerShareDeltas struct { } func NewSlotID(transactionHash string, logIndex uint64, staker string, strategy string, strategyIndex uint64) types.SlotID { - return base.NewSlotIDWithSuffix(transactionHash, logIndex, fmt.Sprintf("%s_%s_%d", staker, strategy, strategyIndex)) + return base.NewSlotIDWithSuffix(transactionHash, logIndex, fmt.Sprintf("%s_%s_%016x", staker, strategy, strategyIndex)) } type StakerSharesModel struct { @@ -123,12 +122,12 @@ func (ss *StakerSharesModel) handleStakerDepositEvent(log *storage.TransactionLo } if stakerAddress == "" { - return nil, xerrors.Errorf("No staker address found in event") + return nil, fmt.Errorf("No staker address found in event") } shares, success := numbers.NewBig257().SetString(outputData.Shares.String(), 10) if !success { - return nil, xerrors.Errorf("Failed to convert shares to big.Int: %s", outputData.Shares) + return nil, fmt.Errorf("Failed to convert shares to big.Int: %s", outputData.Shares) } return &StakerShareDeltas{ @@ -174,7 +173,7 @@ func (ss *StakerSharesModel) handlePodSharesUpdatedEvent(log *storage.Transactio sharesDelta, success := numbers.NewBig257().SetString(sharesDeltaStr, 10) if !success { - return nil, xerrors.Errorf("Failed to convert shares to big.Int: %s", sharesDelta) + return nil, fmt.Errorf("Failed to convert shares to big.Int: %s", sharesDelta) } return &StakerShareDeltas{ @@ -203,12 +202,12 @@ func (ss *StakerSharesModel) handleM1StakerWithdrawals(log *storage.TransactionL } if stakerAddress == "" { - return nil, xerrors.Errorf("No staker address found in event") + return nil, fmt.Errorf("No staker address found in event") } shares, success := numbers.NewBig257().SetString(outputData.Shares.String(), 10) if !success { - return nil, xerrors.Errorf("Failed to convert shares to big.Int: %s", outputData.Shares) + return nil, fmt.Errorf("Failed to convert shares to big.Int: %s", outputData.Shares) } return &StakerShareDeltas{ @@ -339,7 +338,7 @@ func (ss *StakerSharesModel) handleM2QueuedWithdrawal(log *storage.TransactionLo for i, strategy := range outputData.Withdrawal.Strategies { shares, success := numbers.NewBig257().SetString(outputData.Withdrawal.Shares[i].String(), 10) if !success { - return nil, xerrors.Errorf("Failed to convert shares to big.Int: %s", outputData.Withdrawal.Shares[i]) + return nil, fmt.Errorf("Failed to convert shares to big.Int: %s", outputData.Withdrawal.Shares[i]) } r := &StakerShareDeltas{ Staker: outputData.Withdrawal.Staker, diff --git a/pkg/eigenState/stateManager/stateManager.go b/pkg/eigenState/stateManager/stateManager.go index e60358a4..caf6d09f 100644 --- a/pkg/eigenState/stateManager/stateManager.go +++ b/pkg/eigenState/stateManager/stateManager.go @@ -1,10 +1,11 @@ package stateManager import ( + "encoding/binary" "errors" - "fmt" "github.com/Layr-Labs/sidecar/pkg/storage" "github.com/Layr-Labs/sidecar/pkg/utils" + "github.com/ethereum/go-ethereum/common" "slices" "time" @@ -102,10 +103,10 @@ func (e *EigenStateManager) CleanupProcessedStateForBlock(blockNumber uint64) er func (e *EigenStateManager) GenerateStateRoot(blockNumber uint64, blockHash string) (types.StateRoot, error) { sortedIndexes := e.GetSortedModelIndexes() + common.FromHex(blockHash) roots := [][]byte{ - types.MerkleLeafPrefix_Block, - []byte(fmt.Sprintf("%d", blockNumber)), - []byte(blockHash), + append(types.MerkleLeafPrefix_Block, binary.BigEndian.AppendUint64([]byte{}, blockNumber)...), + append(types.MerkleLeafPrefix_BlockHash, common.FromHex(blockHash)...), } for _, state := range sortedIndexes { diff --git a/pkg/eigenState/submittedDistributionRoots/submittedDistributionRoots.go b/pkg/eigenState/submittedDistributionRoots/submittedDistributionRoots.go index 24b42ab4..7f884d5d 100644 --- a/pkg/eigenState/submittedDistributionRoots/submittedDistributionRoots.go +++ b/pkg/eigenState/submittedDistributionRoots/submittedDistributionRoots.go @@ -2,6 +2,7 @@ package submittedDistributionRoots import ( "encoding/json" + "fmt" "github.com/Layr-Labs/sidecar/pkg/storage" "reflect" "slices" @@ -15,7 +16,6 @@ import ( "github.com/Layr-Labs/sidecar/pkg/eigenState/stateManager" "github.com/Layr-Labs/sidecar/pkg/eigenState/types" "go.uber.org/zap" - "golang.org/x/xerrors" "gorm.io/gorm" "gorm.io/gorm/clause" ) @@ -88,7 +88,7 @@ func (sdr *SubmittedDistributionRootsModel) GetStateTransitions() (types.StateTr // Sanity check to make sure we've got an initialized accumulator map for the block if _, ok := sdr.stateAccumulator[log.BlockNumber]; !ok { - return nil, xerrors.Errorf("No state accumulator found for block %d", log.BlockNumber) + return nil, fmt.Errorf("No state accumulator found for block %d", log.BlockNumber) } var rootIndex uint64 @@ -103,12 +103,12 @@ func (sdr *SubmittedDistributionRootsModel) GetStateTransitions() (types.StateTr withoutPrefix := strings.TrimPrefix(arguments[0].Value.(string), "0x") rootIndex, err = strconv.ParseUint(withoutPrefix, 16, 32) if err != nil { - return nil, xerrors.Errorf("Failed to decode rootIndex: %v", err) + return nil, fmt.Errorf("Failed to decode rootIndex: %v", err) } case reflect.Float64: rootIndex = uint64(arguments[0].Value.(float64)) default: - return nil, xerrors.Errorf("Invalid type for rootIndex: %s", t.Kind()) + return nil, fmt.Errorf("Invalid type for rootIndex: %s", t.Kind()) } root := arguments[1].Value.(string) @@ -120,13 +120,13 @@ func (sdr *SubmittedDistributionRootsModel) GetStateTransitions() (types.StateTr withoutPrefix := strings.TrimPrefix(arguments[2].Value.(string), "0x") decoded, err := strconv.ParseUint(withoutPrefix, 16, 32) if err != nil { - return nil, xerrors.Errorf("Failed to decode rewardsCalculationEnd: %v", err) + return nil, fmt.Errorf("Failed to decode rewardsCalculationEnd: %v", err) } rewardsCalculationEnd = int64(decoded) case reflect.Float64: rewardsCalculationEnd = int64(arguments[2].Value.(float64)) default: - return nil, xerrors.Errorf("Invalid type for rewardsCalculationEnd: %s", calcualtionEndType.Kind()) + return nil, fmt.Errorf("Invalid type for rewardsCalculationEnd: %s", calcualtionEndType.Kind()) } activatedAt := outputData.ActivatedAt @@ -134,7 +134,7 @@ func (sdr *SubmittedDistributionRootsModel) GetStateTransitions() (types.StateTr slotId := base.NewSlotID(log.TransactionHash, log.LogIndex) _, ok := sdr.stateAccumulator[log.BlockNumber][slotId] if ok { - err := xerrors.Errorf("Duplicate distribution root submitted for slot %s at block %d", slotId, log.BlockNumber) + err := fmt.Errorf("Duplicate distribution root submitted for slot %s at block %d", slotId, log.BlockNumber) sdr.logger.Sugar().Errorw("Duplicate distribution root submitted", zap.Error(err)) return nil, err } @@ -220,7 +220,7 @@ func (sdr *SubmittedDistributionRootsModel) prepareState(blockNumber uint64) ([] accumulatedState, ok := sdr.stateAccumulator[blockNumber] if !ok { - err := xerrors.Errorf("No accumulated state found for block %d", blockNumber) + err := fmt.Errorf("No accumulated state found for block %d", blockNumber) sdr.logger.Sugar().Errorw(err.Error(), zap.Error(err), zap.Uint64("blockNumber", blockNumber)) return nil, err } diff --git a/pkg/eigenState/types/types.go b/pkg/eigenState/types/types.go index 12e881a9..937a51c7 100644 --- a/pkg/eigenState/types/types.go +++ b/pkg/eigenState/types/types.go @@ -55,7 +55,8 @@ type MerkleLeafPrefix []byte var ( MerkleLeafPrefix_Block MerkleLeafPrefix = []byte("0x00") - MerkleLeafPrefix_EigenStateRoot MerkleLeafPrefix = []byte("0x01") - MerkleLeafPrefix_EigenStateBlock MerkleLeafPrefix = []byte("0x02") - MerkleLeafPrefix_EigenStateChange MerkleLeafPrefix = []byte("0x03") + MerkleLeafPrefix_BlockHash MerkleLeafPrefix = []byte("0x01") + MerkleLeafPrefix_EigenStateRoot MerkleLeafPrefix = []byte("0x02") + MerkleLeafPrefix_EigenStateBlock MerkleLeafPrefix = []byte("0x03") + MerkleLeafPrefix_EigenStateChange MerkleLeafPrefix = []byte("0x04") ) diff --git a/pkg/indexer/indexer.go b/pkg/indexer/indexer.go index 97d2df67..9fed8f9e 100644 --- a/pkg/indexer/indexer.go +++ b/pkg/indexer/indexer.go @@ -12,10 +12,10 @@ import ( "github.com/Layr-Labs/sidecar/pkg/storage" "gorm.io/gorm" "slices" + "strings" "github.com/Layr-Labs/sidecar/internal/config" "go.uber.org/zap" - "golang.org/x/xerrors" ) type Indexer struct { @@ -38,6 +38,8 @@ const ( IndexError_FailedToCombineAbis IndexErrorType = 3 IndexError_FailedToFindContract IndexErrorType = 4 IndexError_FailedToParseAbi IndexErrorType = 5 + IndexError_EmptyAbi IndexErrorType = 6 + IndexError_FailedToDecodeLog IndexErrorType = 7 ) type IndexError struct { @@ -45,7 +47,7 @@ type IndexError struct { Err error BlockNumber uint64 TransactionHash string - LogIndex int + LogIndex uint64 Metadata map[string]interface{} Message string } @@ -72,7 +74,7 @@ func (e *IndexError) WithTransactionHash(txHash string) *IndexError { return e } -func (e *IndexError) WithLogIndex(logIndex int) *IndexError { +func (e *IndexError) WithLogIndex(logIndex uint64) *IndexError { e.LogIndex = logIndex return e } @@ -119,7 +121,7 @@ func (idx *Indexer) ParseInterestingTransactionsAndLogs(ctx context.Context, fet zap.String("txHash", tx.Hash.Value()), zap.Uint64("block", tx.BlockNumber.Value()), ) - return nil, NewIndexError(IndexError_ReceiptNotFound, xerrors.Errorf("receipt not found for transaction")). + return nil, NewIndexError(IndexError_ReceiptNotFound, fmt.Errorf("receipt not found for transaction")). WithBlockNumber(tx.BlockNumber.Value()). WithTransactionHash(tx.Hash.Value()) } @@ -154,51 +156,6 @@ func (idx *Indexer) ParseInterestingTransactionsAndLogs(ctx context.Context, fet return parsedTransactions, nil } -func (idx *Indexer) ParseAndIndexTransactionLogs(ctx context.Context, fetchedBlock *fetcher.FetchedBlock) *IndexError { - for i, tx := range fetchedBlock.Block.Transactions { - txReceipt, ok := fetchedBlock.TxReceipts[tx.Hash.Value()] - if !ok { - idx.Logger.Sugar().Errorw("Receipt not found for transaction", - zap.String("txHash", tx.Hash.Value()), - zap.Uint64("block", tx.BlockNumber.Value()), - ) - return NewIndexError(IndexError_ReceiptNotFound, xerrors.Errorf("receipt not found for transaction")). - WithBlockNumber(tx.BlockNumber.Value()). - WithTransactionHash(tx.Hash.Value()) - } - - parsedTransactionLogs, err := idx.ParseTransactionLogs(tx, txReceipt) - if err != nil { - idx.Logger.Sugar().Errorw("failed to process transaction logs", - zap.Error(err.Err), - zap.String("txHash", tx.Hash.Value()), - zap.Uint64("block", tx.BlockNumber.Value()), - ) - continue - } - if parsedTransactionLogs == nil { - idx.Logger.Sugar().Debugw("Log line is nil", - zap.String("txHash", tx.Hash.Value()), - zap.Uint64("block", tx.BlockNumber.Value()), - zap.Int("logIndex", i), - ) - continue - } - - for _, log := range parsedTransactionLogs.Logs { - _, err := idx.IndexLog(ctx, fetchedBlock.Block.Number.Value(), tx.Hash.Value(), tx.Index.Value(), log) - if err != nil { - idx.Logger.Sugar().Errorw("failed to index log", - zap.Error(err), - zap.String("txHash", tx.Hash.Value()), - zap.Uint64("block", tx.BlockNumber.Value()), - ) - } - } - } - return nil -} - func (idx *Indexer) IndexFetchedBlock(fetchedBlock *fetcher.FetchedBlock) (*storage.Block, bool, error) { blockNumber := fetchedBlock.Block.Number.Value() blockHash := fetchedBlock.Block.Hash.Value() @@ -235,7 +192,7 @@ func (idx *Indexer) IsInterestingAddress(addr string) bool { if addr == "" { return false } - return slices.Contains(idx.Config.GetInterestingAddressForConfigEnv(), addr) + return slices.Contains(idx.Config.GetInterestingAddressForConfigEnv(), strings.ToLower(addr)) } func (idx *Indexer) IsInterestingTransaction(txn *ethereum.EthereumTransaction, receipt *ethereum.EthereumTransactionReceipt) bool { diff --git a/pkg/indexer/transactionLogs.go b/pkg/indexer/transactionLogs.go index b571ef0f..dbcf3302 100644 --- a/pkg/indexer/transactionLogs.go +++ b/pkg/indexer/transactionLogs.go @@ -22,6 +22,7 @@ func (idx *Indexer) getAbi(json string) (*abi.ABI, error) { if err != nil { foundMatch := false + // patterns that we're fine to ignore and not treat as an error patterns := []*regexp.Regexp{ regexp.MustCompile(`only single receive is allowed`), regexp.MustCompile(`only single fallback is allowed`), @@ -33,9 +34,11 @@ func (idx *Indexer) getAbi(json string) (*abi.ABI, error) { break } } - // Ignore really common compilation error + + // If the error isnt one that we can ignore, return it if !foundMatch { idx.Logger.Sugar().Warnw("Error unmarshaling abi json", zap.Error(err)) + return nil, err } } @@ -54,6 +57,8 @@ func (idx *Indexer) ParseTransactionLogs( } contractAddress := receipt.GetTargetAddress() + // when the contractAddress is empty, we can skip the transaction since it wont have any logs associated with it. + // this is pretty typical of a transaction that simply sends ETH from one address to another without interacting with a contract if contractAddress.Value() == "" { idx.Logger.Sugar().Debugw("No contract address found in receipt, skipping", zap.String("hash", transaction.Hash.Value())) return nil, nil @@ -74,23 +79,26 @@ func (idx *Indexer) ParseTransactionLogs( WithMetadata("contractAddress", contractAddress.Value()) } + // if the contract is interesting but not found, throw an error to stop processing if contract == nil { - idx.Logger.Sugar().Debugw("No contract found for address", zap.String("hash", transaction.Hash.Value())) - return nil, nil + idx.Logger.Sugar().Errorw("No contract found for address", zap.String("hash", transaction.Hash.Value())) + return nil, NewIndexError(IndexError_FailedToFindContract, err). + WithMessage("No contract found for address"). + WithBlockNumber(transaction.BlockNumber.Value()). + WithTransactionHash(transaction.Hash.Value()). + WithMetadata("contractAddress", contractAddress.Value()) } contractAbi := contract.CombineAbis() - if err != nil { - idx.Logger.Sugar().Errorw("Failed to combine ABIs") - return nil, NewIndexError(IndexError_FailedToCombineAbis, err). - WithMessage("Failed to combine ABIs"). - WithBlockNumber(transaction.BlockNumber.Value()). - WithTransactionHash(transaction.Hash.Value()) - } + // If the ABI is empty, return an error if contractAbi == "" { - idx.Logger.Sugar().Debugw("No ABI found for contract", zap.String("hash", transaction.Hash.Value())) - return parsedTransaction, nil + idx.Logger.Sugar().Errorw("No ABI found for contract", zap.String("hash", transaction.Hash.Value())) + return nil, NewIndexError(IndexError_EmptyAbi, err). + WithMessage("No ABI found for contract"). + WithBlockNumber(transaction.BlockNumber.Value()). + WithTransactionHash(transaction.Hash.Value()). + WithMetadata("contractAddress", contractAddress.Value()) } a, err = idx.getAbi(contractAbi) if err != nil { @@ -109,18 +117,33 @@ func (idx *Indexer) ParseTransactionLogs( decodedSig, err := hex.DecodeString(txInput[2:10]) if err != nil { idx.Logger.Sugar().Errorw("Failed to decode signature") + return nil, NewIndexError(IndexError_FailedToParseTransaction, err). + WithMessage("Failed to decode signature"). + WithBlockNumber(transaction.BlockNumber.Value()). + WithTransactionHash(transaction.Hash.Value()). + WithMetadata("contractAddress", contractAddress.Value()) } if len(decodedSig) > 0 { method, err = a.MethodById(decodedSig) if err != nil { - idx.Logger.Sugar().Debugw(fmt.Sprintf("Failed to find method by ID '%s'", common.BytesToHash(decodedSig).String())) - parsedTransaction.MethodName = "unknown" + msg := fmt.Sprintf("Failed to find method by ID '%s'", common.BytesToHash(decodedSig).String()) + idx.Logger.Sugar().Debugw(msg) + return nil, NewIndexError(IndexError_FailedToParseTransaction, err). + WithMessage(msg). + WithBlockNumber(transaction.BlockNumber.Value()). + WithTransactionHash(transaction.Hash.Value()). + WithMetadata("contractAddress", contractAddress.Value()) } else { parsedTransaction.MethodName = method.RawName decodedData, err := hex.DecodeString(txInput[10:]) if err != nil { - idx.Logger.Sugar().Errorw("Failed to decode input data") + idx.Logger.Sugar().Errorw("Failed to decode transaction input data") + return nil, NewIndexError(IndexError_FailedToParseTransaction, err). + WithMessage("Failed to decode transaction input data"). + WithBlockNumber(transaction.BlockNumber.Value()). + WithTransactionHash(transaction.Hash.Value()). + WithMetadata("contractAddress", contractAddress.Value()) } else { callMap := map[string]interface{}{} if err := method.Inputs.UnpackIntoMap(callMap, decodedData); err != nil { @@ -129,10 +152,20 @@ func (idx *Indexer) ParseTransactionLogs( zap.String("transactionHash", transaction.Hash.Value()), zap.Uint64("blockNumber", transaction.BlockNumber.Value()), ) + return nil, NewIndexError(IndexError_FailedToParseTransaction, err). + WithMessage("Failed to unpack data"). + WithBlockNumber(transaction.BlockNumber.Value()). + WithTransactionHash(transaction.Hash.Value()). + WithMetadata("contractAddress", contractAddress.Value()) } callMapBytes, err := json.Marshal(callMap) if err != nil { idx.Logger.Sugar().Errorw("Failed to marshal callMap data", zap.String("hash", transaction.Hash.Value())) + return nil, NewIndexError(IndexError_FailedToParseTransaction, err). + WithMessage("Failed to marshal callMap data"). + WithBlockNumber(transaction.BlockNumber.Value()). + WithTransactionHash(transaction.Hash.Value()). + WithMetadata("contractAddress", contractAddress.Value()) } parsedTransaction.DecodedData = string(callMapBytes) } @@ -156,7 +189,14 @@ func (idx *Indexer) ParseTransactionLogs( } decodedLog, err := idx.DecodeLogWithAbi(a, receipt, lg) if err != nil { - idx.Logger.Sugar().Debugw(fmt.Sprintf("Error decoding log - index: '%d' - '%s'", i, transaction.Hash.Value()), zap.Error(err)) + msg := fmt.Sprintf("Error decoding log - index: '%d' - '%s'", i, transaction.Hash.Value()) + idx.Logger.Sugar().Debugw(msg, zap.Error(err)) + return nil, NewIndexError(IndexError_FailedToDecodeLog, err). + WithMessage(msg). + WithBlockNumber(transaction.BlockNumber.Value()). + WithTransactionHash(transaction.Hash.Value()). + WithMetadata("contractAddress", contractAddress.Value()). + WithLogIndex(lg.LogIndex.Value()) } else { idx.Logger.Sugar().Debugw(fmt.Sprintf("Decoded log - index: '%d' - '%s'", i, transaction.Hash.Value()), zap.Any("decodedLog", decodedLog)) } @@ -243,9 +283,10 @@ func (idx *Indexer) DecodeLog(a *abi.ABI, lg *ethereum.EthereumEventLog) (*parse } if a == nil { - idx.Logger.Sugar().Debugw(fmt.Sprintf("No ABI provided, using topic hash as event name '%s'", logAddress.String())) - decodedLog.EventName = topicHash.String() - return decodedLog, nil + idx.Logger.Sugar().Errorw("No ABI provided for decoding log", + zap.String("address", logAddress.String()), + ) + return nil, errors.New("no ABI provided for decoding log") } event, err := a.EventByID(topicHash) @@ -287,13 +328,14 @@ func (idx *Indexer) DecodeLog(a *abi.ABI, lg *ethereum.EthereumEventLog) (*parse outputDataMap := make(map[string]interface{}) err = a.UnpackIntoMap(outputDataMap, event.Name, byteData) if err != nil { - idx.Logger.Sugar().Errorw("Failed to unpack data: ", + idx.Logger.Sugar().Errorw("Failed to unpack data", zap.Error(err), zap.String("hash", lg.TransactionHash.Value()), zap.String("address", lg.Address.Value()), zap.String("eventName", event.Name), zap.String("transactionHash", lg.TransactionHash.Value()), ) + return nil, errors.New("failed to unpack data") } decodedLog.OutputData = outputDataMap diff --git a/pkg/pipeline/pipeline.go b/pkg/pipeline/pipeline.go index a13a6160..957cdcaf 100644 --- a/pkg/pipeline/pipeline.go +++ b/pkg/pipeline/pipeline.go @@ -299,6 +299,7 @@ func (p *Pipeline) RunForFetchedBlock(ctx context.Context, block *fetcher.Fetche sr, err := p.stateManager.WriteStateRoot(blockNumber, block.Block.Hash.Value(), stateRoot) if err != nil { p.Logger.Sugar().Errorw("Failed to write state root", zap.Uint64("blockNumber", blockNumber), zap.Error(err)) + return err } else { p.Logger.Sugar().Debugw("Wrote state root", zap.Uint64("blockNumber", blockNumber), zap.Any("stateRoot", sr)) } diff --git a/pkg/postgres/postgres.go b/pkg/postgres/postgres.go index 0b81cc70..44df42d4 100644 --- a/pkg/postgres/postgres.go +++ b/pkg/postgres/postgres.go @@ -8,7 +8,6 @@ import ( "github.com/Layr-Labs/sidecar/pkg/postgres/migrations" _ "github.com/lib/pq" "go.uber.org/zap" - "golang.org/x/xerrors" "gorm.io/driver/postgres" "gorm.io/gorm" "gorm.io/gorm/logger" @@ -156,14 +155,14 @@ func CreateDatabaseIfNotExists(cfg *PostgresConfig) error { func NewPostgres(cfg *PostgresConfig) (*Postgres, error) { if cfg.CreateDbIfNotExists { if err := CreateDatabaseIfNotExists(cfg); err != nil { - return nil, xerrors.Errorf("Failed to create database if not exists %+v", err) + return nil, fmt.Errorf("Failed to create database if not exists %+v", err) } } connectString := getPostgresConnectionString(cfg) db, err := sql.Open("postgres", connectString) if err != nil { - return nil, xerrors.Errorf("Failed to setup database %+v", err) + return nil, fmt.Errorf("Failed to setup database %+v", err) } return &Postgres{ @@ -178,7 +177,7 @@ func NewGormFromPostgresConnection(pgDb *sql.DB) (*gorm.DB, error) { Logger: logger.Default.LogMode(logger.Silent), }) if err != nil { - return nil, xerrors.Errorf("Failed to setup database %+v", err) + return nil, fmt.Errorf("Failed to setup database %+v", err) } return db, nil diff --git a/pkg/sidecar/blockIndexer.go b/pkg/sidecar/blockIndexer.go index a759042b..189b58f7 100644 --- a/pkg/sidecar/blockIndexer.go +++ b/pkg/sidecar/blockIndexer.go @@ -91,7 +91,7 @@ func (s *Sidecar) ProcessNewBlocks(ctx context.Context) error { } func (s *Sidecar) IndexFromCurrentToTip(ctx context.Context) error { - latestBlock, err := s.GetLastIndexedBlock() + lastIndexedBlock, err := s.GetLastIndexedBlock() if err != nil { return err } @@ -104,32 +104,21 @@ func (s *Sidecar) IndexFromCurrentToTip(ctx context.Context) error { if latestStateRoot == nil { s.Logger.Sugar().Infow("No state roots found, starting from EL genesis") - latestBlock = 0 + lastIndexedBlock = 0 } - if latestBlock == 0 { + if lastIndexedBlock == 0 { s.Logger.Sugar().Infow("No blocks indexed, starting from genesis block", zap.Uint64("genesisBlock", s.Config.GenesisBlockNumber)) - latestBlock = int64(s.Config.GenesisBlockNumber) + lastIndexedBlock = int64(s.Config.GenesisBlockNumber) } else { - s.Logger.Sugar().Infow("Comparing latest block and latest state root", - zap.Int64("latestBlock", latestBlock), - zap.Uint64("latestStateRootBlock", latestStateRoot.EthBlockNumber), - ) - if latestStateRoot.EthBlockNumber == uint64(latestBlock) { - s.Logger.Sugar().Infow("Latest block and latest state root are in sync, starting from latest block + 1", - zap.Int64("latestBlock", latestBlock), - zap.Uint64("latestStateRootBlock", latestStateRoot.EthBlockNumber), - ) - return nil - } // if the latest state root is behind the latest block, delete the corrupted state and set the // latest block to the latest state root + 1 - if latestStateRoot != nil && latestStateRoot.EthBlockNumber < uint64(latestBlock) { + if latestStateRoot != nil && latestStateRoot.EthBlockNumber < uint64(lastIndexedBlock) { s.Logger.Sugar().Infow("Latest state root is behind latest block, deleting corrupted state", zap.Uint64("latestStateRoot", latestStateRoot.EthBlockNumber), - zap.Int64("latestBlock", latestBlock), + zap.Int64("lastIndexedBlock", lastIndexedBlock), ) - if err := s.StateManager.DeleteCorruptedState(latestStateRoot.EthBlockNumber+1, uint64(latestBlock)); err != nil { + if err := s.StateManager.DeleteCorruptedState(latestStateRoot.EthBlockNumber+1, uint64(lastIndexedBlock)); err != nil { s.Logger.Sugar().Errorw("Failed to delete corrupted state", zap.Error(err)) return err } @@ -137,45 +126,65 @@ func (s *Sidecar) IndexFromCurrentToTip(ctx context.Context) error { s.Logger.Sugar().Errorw("Failed to purge corrupted rewards", zap.Error(err)) return err } - if err := s.Storage.DeleteCorruptedState(uint64(latestStateRoot.EthBlockNumber+1), uint64(latestBlock)); err != nil { + if err := s.Storage.DeleteCorruptedState(uint64(latestStateRoot.EthBlockNumber+1), uint64(lastIndexedBlock)); err != nil { s.Logger.Sugar().Errorw("Failed to delete corrupted state", zap.Error(err)) return err } - latestBlock = int64(latestStateRoot.EthBlockNumber + 1) + lastIndexedBlock = int64(latestStateRoot.EthBlockNumber + 1) s.Logger.Sugar().Infow("Deleted corrupted state, starting from latest state root + 1", zap.Uint64("latestStateRoot", latestStateRoot.EthBlockNumber), - zap.Int64("latestBlock", latestBlock), + zap.Int64("lastIndexedBlock", lastIndexedBlock), ) } else { - // otherwise, start from the latest block + 1 - latestBlock++ + // This should tehcnically never happen, but if the latest state root is ahead of the latest block, + // something is very wrong and we should fail. + if latestStateRoot.EthBlockNumber > uint64(lastIndexedBlock) { + return fmt.Errorf("Latest state root (%d) is ahead of latest stored block (%d), which should never happen, so something is very wrong", latestStateRoot.EthBlockNumber, lastIndexedBlock) + } + if latestStateRoot.EthBlockNumber == uint64(lastIndexedBlock) { + s.Logger.Sugar().Infow("Latest block and latest state root are in sync, starting from latest block + 1", + zap.Int64("latestBlock", lastIndexedBlock), + zap.Uint64("latestStateRootBlock", latestStateRoot.EthBlockNumber), + ) + } + lastIndexedBlock++ } } - // Get the latest safe block as a starting point - blockNumber, err := s.EthereumClient.GetLatestSafeBlock(ctx) - if err != nil { - s.Logger.Sugar().Fatalw("Failed to get current tip", zap.Error(err)) - } + retryCount := 0 + var latestSafeBlockNumber uint64 - s.Logger.Sugar().Infow("Starting indexing process", - zap.Int64("latestBlock", latestBlock), - zap.Uint64("currentTip", blockNumber), - ) + for retryCount < 3 { + // Get the latest safe block as a starting point + latestSafeBlockNumber, err := s.EthereumClient.GetLatestSafeBlock(ctx) + if err != nil { + s.Logger.Sugar().Fatalw("Failed to get current tip", zap.Error(err)) + } + + s.Logger.Sugar().Infow("Starting indexing process", + zap.Int64("latestBlock", lastIndexedBlock), + zap.Uint64("currentTip", latestSafeBlockNumber), + ) - if blockNumber < uint64(latestBlock) { - return errors.New("Current tip is less than latest block. Please make sure your node is synced to tip.") + if latestSafeBlockNumber < uint64(lastIndexedBlock) { + if retryCount == 2 { + s.Logger.Sugar().Fatalw("Current tip is less than latest block, but retry count is 2, exiting") + return errors.New("Current tip is less than latest block, but retry count is 2, exiting") + } + s.Logger.Sugar().Infow("Current tip is less than latest block sleeping for 7 minutes to allow for the node to catch up") + time.Sleep(7 * time.Minute) + } } s.Logger.Sugar().Infow("Indexing from current to tip", - zap.Uint64("currentTip", blockNumber), - zap.Int64("latestBlock", latestBlock), - zap.Uint64("difference", blockNumber-uint64(latestBlock)), + zap.Uint64("currentTip", latestSafeBlockNumber), + zap.Int64("lastIndexedBlock", lastIndexedBlock), + zap.Uint64("difference", latestSafeBlockNumber-uint64(lastIndexedBlock)), ) // Use an atomic variable to track the current tip currentTip := atomic.Uint64{} - currentTip.Store(blockNumber) + currentTip.Store(latestSafeBlockNumber) indexComplete := atomic.Bool{} indexComplete.Store(false) @@ -215,20 +224,20 @@ func (s *Sidecar) IndexFromCurrentToTip(ctx context.Context) error { runningAvg := float64(0) totalDurationMs := int64(0) - originalStartBlock := latestBlock + originalStartBlock := lastIndexedBlock //nolint:all - lastBlockParsed := latestBlock + currentBlock := lastIndexedBlock - s.Logger.Sugar().Infow("Starting indexing process", zap.Int64("latestBlock", latestBlock), zap.Uint64("currentTip", currentTip.Load())) + s.Logger.Sugar().Infow("Starting indexing process", zap.Int64("currentBlock", currentBlock), zap.Uint64("currentTip", currentTip.Load())) - for uint64(latestBlock) <= currentTip.Load() { + for uint64(currentBlock) <= currentTip.Load() { if s.shouldShutdown.Load() { s.Logger.Sugar().Infow("Shutting down block processor") return nil } tip := currentTip.Load() - blocksRemaining := tip - uint64(latestBlock) + blocksRemaining := tip - uint64(currentBlock) totalBlocksToProcess := tip - uint64(originalStartBlock) var pctComplete float64 @@ -240,34 +249,38 @@ func (s *Sidecar) IndexFromCurrentToTip(ctx context.Context) error { estTimeRemainingHours := float64(estTimeRemainingMs) / 1000 / 60 / 60 startTime := time.Now() - endBlock := int64(latestBlock + 100) + endBlock := int64(currentBlock + 100) if endBlock > int64(tip) { endBlock = int64(tip) } - if err := s.Pipeline.RunForBlockBatch(ctx, uint64(latestBlock), uint64(endBlock), true); err != nil { + if err := s.Pipeline.RunForBlockBatch(ctx, uint64(currentBlock), uint64(endBlock), true); err != nil { s.Logger.Sugar().Errorw("Failed to run pipeline for block batch", zap.Error(err), - zap.Uint64("startBlock", uint64(latestBlock)), + zap.Uint64("startBlock", uint64(currentBlock)), zap.Int64("endBlock", endBlock), ) return err } - lastBlockParsed = int64(endBlock) + currentBlock = int64(endBlock) delta := time.Since(startTime).Milliseconds() - blocksProcessed += (endBlock - latestBlock) + blocksProcessed += (endBlock - currentBlock) totalDurationMs += delta - runningAvg = float64(totalDurationMs / blocksProcessed) + if blocksProcessed == 0 { + runningAvg = 0 + } else { + runningAvg = float64(totalDurationMs / blocksProcessed) + } s.Logger.Sugar().Infow("Progress", zap.String("percentComplete", fmt.Sprintf("%.2f", pctComplete)), zap.Uint64("blocksRemaining", blocksRemaining), zap.Float64("estimatedTimeRemaining (hrs)", estTimeRemainingHours), zap.Float64("avgBlockProcessTime (ms)", float64(runningAvg)), - zap.Uint64("lastBlockParsed", uint64(lastBlockParsed)), + zap.Uint64("currentBlock", uint64(currentBlock)), ) - latestBlock = endBlock + 1 + currentBlock = endBlock + 1 } return nil diff --git a/pkg/sidecar/sidecar.go b/pkg/sidecar/sidecar.go index 892cc060..9690aab9 100644 --- a/pkg/sidecar/sidecar.go +++ b/pkg/sidecar/sidecar.go @@ -24,7 +24,6 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" "github.com/rs/cors" "go.uber.org/zap" - "golang.org/x/xerrors" "google.golang.org/grpc" "google.golang.org/grpc/reflection" ) @@ -144,7 +143,7 @@ func (s *Sidecar) WithRpcServer( grpcLis, err := net.Listen("tcp", fmt.Sprintf(":%d", grpcPort)) if err != nil { s.Logger.Sugar().Errorw("Failed to listen", zap.Error(err), zap.Int("port", grpcPort)) - return xerrors.Errorf("failed to listen: %w", err) + return fmt.Errorf("failed to listen: %w", err) } grpcServer := grpc.NewServer( diff --git a/pkg/storage/postgres/storage.go b/pkg/storage/postgres/storage.go index e4197035..d4261c1a 100644 --- a/pkg/storage/postgres/storage.go +++ b/pkg/storage/postgres/storage.go @@ -12,7 +12,6 @@ import ( "github.com/Layr-Labs/sidecar/internal/config" "go.uber.org/zap" - "golang.org/x/xerrors" "gorm.io/gorm" "gorm.io/gorm/clause" ) @@ -81,7 +80,7 @@ func (s *PostgresBlockStore) InsertBlockTransaction( result := s.Db.Model(&storage.Transaction{}).Clauses(clause.Returning{}).Create(&tx) if result.Error != nil { - return nil, xerrors.Errorf("Failed to insert block transaction '%d' - '%s': %w", blockNumber, txHash, result.Error) + return nil, fmt.Errorf("Failed to insert block transaction '%d' - '%s': %w", blockNumber, txHash, result.Error) } return tx, nil } @@ -116,7 +115,7 @@ func (s *PostgresBlockStore) InsertTransactionLog( result := s.Db.Model(&storage.TransactionLog{}).Clauses(clause.Returning{}).Create(&txLog) if result.Error != nil { - return nil, xerrors.Errorf("Failed to insert transaction log: %w - %+v", result.Error, txLog) + return nil, fmt.Errorf("Failed to insert transaction log: %w - %+v", result.Error, txLog) } return txLog, nil } @@ -133,7 +132,7 @@ func (s *PostgresBlockStore) GetLatestBlock() (*storage.Block, error) { result := s.Db.Model(&storage.Block{}).Raw(query).Scan(&block) if result.Error != nil { - return nil, xerrors.Errorf("Failed to get latest block: %w", result.Error) + return nil, fmt.Errorf("Failed to get latest block: %w", result.Error) } return block, nil } @@ -171,7 +170,7 @@ func (s *PostgresBlockStore) InsertOperatorRestakedStrategies( result := s.Db.Model(&storage.OperatorRestakedStrategies{}).Clauses(clause.Returning{}).Create(&ors) if result.Error != nil { - return nil, xerrors.Errorf("Failed to insert operator restaked strategies: %w", result.Error) + return nil, fmt.Errorf("Failed to insert operator restaked strategies: %w", result.Error) } return ors, nil } @@ -190,7 +189,7 @@ func (s *PostgresBlockStore) BulkInsertOperatorRestakedStrategies( }, ).Create(&operatorRestakedStrategies) if res.Error != nil { - return nil, xerrors.Errorf("Failed to insert operator restaked strategies: %w", res.Error) + return nil, fmt.Errorf("Failed to insert operator restaked strategies: %w", res.Error) } return operatorRestakedStrategies, nil } @@ -218,7 +217,7 @@ func (s *PostgresBlockStore) GetLatestActiveAvsOperators(blockNumber uint64, avs ` result := s.Db.Raw(query, avsDirectoryAddress, blockNumber).Scan(&rows) if result.Error != nil { - return nil, xerrors.Errorf("Failed to get latest active AVS operators: %w", result.Error) + return nil, fmt.Errorf("Failed to get latest active AVS operators: %w", result.Error) } return rows, nil } @@ -254,7 +253,7 @@ func (s *PostgresBlockStore) DeleteCorruptedState(startBlockNumber uint64, endBl sql.Named("endBlockNumber", endBlockNumber), ) if res.Error != nil { - return xerrors.Errorf("Failed to delete corrupted state from table '%s': %w", tableName, res.Error) + return fmt.Errorf("Failed to delete corrupted state from table '%s': %w", tableName, res.Error) } } blocksQuery := ` @@ -269,7 +268,7 @@ func (s *PostgresBlockStore) DeleteCorruptedState(startBlockNumber uint64, endBl sql.Named("endBlockNumber", endBlockNumber), ) if res.Error != nil { - return xerrors.Errorf("Failed to delete corrupted state from table 'blocks': %w", res.Error) + return fmt.Errorf("Failed to delete corrupted state from table 'blocks': %w", res.Error) } return nil }