Skip to content

Commit

Permalink
fix(server): Wrap cannon errors (#346)
Browse files Browse the repository at this point in the history
* refactor: Improve error handling in Cannon location and Coordinator client functions

* Yeet epoch

* style: Change log level from Info to Debug
  • Loading branch information
samcm authored Jul 8, 2024
1 parent ec94902 commit cf83d6e
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 203 deletions.
2 changes: 1 addition & 1 deletion pkg/cannon/iterator/backfilling_checkpoint_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (c *BackfillingCheckpoint) Next(ctx context.Context) (rsp *BackFillingCheck
"next_epoch": rsp.Next,
"direction": rsp.Direction,
"look_aheads": rsp.LookAheads,
}).Info("Returning next epoch")
}).Debug("Returning next epoch")

span.SetAttributes(attribute.Int64("next_epoch", int64(rsp.Next)))
span.SetAttributes(attribute.String("direction", string(rsp.Direction)))
Expand Down
221 changes: 70 additions & 151 deletions pkg/proto/xatu/coordinator.pb.go

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions pkg/proto/xatu/coordinator.proto
Original file line number Diff line number Diff line change
Expand Up @@ -109,42 +109,42 @@ message BackfillingCheckpointMarker {
}

message CannonLocationEthV2BeaconBlockVoluntaryExit {
uint64 epoch = 1; // Marked for deprecation
reserved 1;
BackfillingCheckpointMarker backfilling_checkpoint_marker = 2;
}

message CannonLocationEthV2BeaconBlockProposerSlashing{
uint64 epoch = 1; // Marked for deprecation
reserved 1;
BackfillingCheckpointMarker backfilling_checkpoint_marker = 2;
}

message CannonLocationEthV2BeaconBlockDeposit {
uint64 epoch = 1; // Marked for deprecation
reserved 1;
BackfillingCheckpointMarker backfilling_checkpoint_marker = 2;
}

message CannonLocationEthV2BeaconBlockAttesterSlashing {
uint64 epoch = 1; // Marked for deprecation
reserved 1;
BackfillingCheckpointMarker backfilling_checkpoint_marker = 2;
}

message CannonLocationEthV2BeaconBlockBlsToExecutionChange {
uint64 epoch = 1; // Marked for deprecation
reserved 1;
BackfillingCheckpointMarker backfilling_checkpoint_marker = 2;
}

message CannonLocationEthV2BeaconBlockExecutionTransaction {
uint64 epoch = 1; // Marked for deprecation
reserved 1;
BackfillingCheckpointMarker backfilling_checkpoint_marker = 2;
}

message CannonLocationEthV2BeaconBlockWithdrawal {
uint64 epoch = 1; // Marked for deprecation
reserved 1;
BackfillingCheckpointMarker backfilling_checkpoint_marker = 2;
}

message CannonLocationEthV2BeaconBlock {
uint64 epoch = 1; // Marked for deprecation
reserved 1;
BackfillingCheckpointMarker backfilling_checkpoint_marker = 2;
}

Expand All @@ -154,7 +154,7 @@ message CannonLocationBlockprintBlockClassification {
}

message CannonLocationEthV1BeaconBlobSidecar {
uint64 epoch = 1; // Marked for deprecation
reserved 1;
BackfillingCheckpointMarker backfilling_checkpoint_marker = 2;
}

Expand Down
58 changes: 32 additions & 26 deletions pkg/server/persistence/cannon/location.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cannon

import (
"errors"
"fmt"
"time"

Expand All @@ -23,6 +24,11 @@ type Location struct {
Value string `json:"value" db:"value"`
}

var (
ErrFailedToMarshal = errors.New("failed to marshal location")
ErrFailedToUnmarshal = errors.New("failed to unmarshal location")
)

// MarshalValueFromProto marshals a proto message into the Value field.
func (l *Location) Marshal(msg *xatu.CannonLocation) error {
l.NetworkID = msg.NetworkId
Expand All @@ -35,7 +41,7 @@ func (l *Location) Marshal(msg *xatu.CannonLocation) error {

b, err := protojson.Marshal(data)
if err != nil {
return err
return fmt.Errorf("%w: %s", ErrFailedToMarshal, err)
}

l.Value = string(b)
Expand All @@ -46,7 +52,7 @@ func (l *Location) Marshal(msg *xatu.CannonLocation) error {

b, err := protojson.Marshal(data)
if err != nil {
return err
return fmt.Errorf("%w: %s", ErrFailedToMarshal, err)
}

l.Value = string(b)
Expand All @@ -57,7 +63,7 @@ func (l *Location) Marshal(msg *xatu.CannonLocation) error {

b, err := protojson.Marshal(data)
if err != nil {
return err
return fmt.Errorf("%w: %s", ErrFailedToMarshal, err)
}

l.Value = string(b)
Expand All @@ -68,7 +74,7 @@ func (l *Location) Marshal(msg *xatu.CannonLocation) error {

b, err := protojson.Marshal(data)
if err != nil {
return err
return fmt.Errorf("%w: %s", ErrFailedToMarshal, err)
}

l.Value = string(b)
Expand All @@ -80,7 +86,7 @@ func (l *Location) Marshal(msg *xatu.CannonLocation) error {

b, err := protojson.Marshal(data)
if err != nil {
return err
return fmt.Errorf("%w: %s", ErrFailedToMarshal, err)
}

l.Value = string(b)
Expand All @@ -92,7 +98,7 @@ func (l *Location) Marshal(msg *xatu.CannonLocation) error {

b, err := protojson.Marshal(data)
if err != nil {
return err
return fmt.Errorf("%w: %s", ErrFailedToMarshal, err)
}

l.Value = string(b)
Expand All @@ -103,7 +109,7 @@ func (l *Location) Marshal(msg *xatu.CannonLocation) error {

b, err := protojson.Marshal(data)
if err != nil {
return err
return fmt.Errorf("%w: %s", ErrFailedToMarshal, err)
}

l.Value = string(b)
Expand All @@ -115,7 +121,7 @@ func (l *Location) Marshal(msg *xatu.CannonLocation) error {

b, err := protojson.Marshal(data)
if err != nil {
return err
return fmt.Errorf("%w: %s", ErrFailedToMarshal, err)
}

l.Value = string(b)
Expand All @@ -127,7 +133,7 @@ func (l *Location) Marshal(msg *xatu.CannonLocation) error {

b, err := protojson.Marshal(data)
if err != nil {
return err
return fmt.Errorf("%w: %s", ErrFailedToMarshal, err)
}

l.Value = string(b)
Expand All @@ -139,7 +145,7 @@ func (l *Location) Marshal(msg *xatu.CannonLocation) error {

b, err := protojson.Marshal(data)
if err != nil {
return err
return fmt.Errorf("%w: %s", ErrFailedToMarshal, err)
}

l.Value = string(b)
Expand All @@ -150,7 +156,7 @@ func (l *Location) Marshal(msg *xatu.CannonLocation) error {

b, err := protojson.Marshal(data)
if err != nil {
return err
return fmt.Errorf("%w: %s", ErrFailedToMarshal, err)
}

l.Value = string(b)
Expand All @@ -161,7 +167,7 @@ func (l *Location) Marshal(msg *xatu.CannonLocation) error {

b, err := protojson.Marshal(data)
if err != nil {
return err
return fmt.Errorf("%w: %s", ErrFailedToMarshal, err)
}

l.Value = string(b)
Expand All @@ -172,7 +178,7 @@ func (l *Location) Marshal(msg *xatu.CannonLocation) error {

b, err := protojson.Marshal(data)
if err != nil {
return err
return fmt.Errorf("%w: %s", ErrFailedToMarshal, err)
}

l.Value = string(b)
Expand All @@ -196,7 +202,7 @@ func (l *Location) Unmarshal() (*xatu.CannonLocation, error) {

err := protojson.Unmarshal([]byte(l.Value), data)
if err != nil {
return nil, err
return nil, fmt.Errorf("%w: %s", ErrFailedToUnmarshal, err)
}

msg.Data = &xatu.CannonLocation_EthV2BeaconBlockVoluntaryExit{
Expand All @@ -209,7 +215,7 @@ func (l *Location) Unmarshal() (*xatu.CannonLocation, error) {

err := protojson.Unmarshal([]byte(l.Value), data)
if err != nil {
return nil, err
return nil, fmt.Errorf("%w: %s", ErrFailedToUnmarshal, err)
}

msg.Data = &xatu.CannonLocation_EthV2BeaconBlockProposerSlashing{
Expand All @@ -222,7 +228,7 @@ func (l *Location) Unmarshal() (*xatu.CannonLocation, error) {

err := protojson.Unmarshal([]byte(l.Value), data)
if err != nil {
return nil, err
return nil, fmt.Errorf("%w: %s", ErrFailedToUnmarshal, err)
}

msg.Data = &xatu.CannonLocation_EthV2BeaconBlockDeposit{
Expand All @@ -235,7 +241,7 @@ func (l *Location) Unmarshal() (*xatu.CannonLocation, error) {

err := protojson.Unmarshal([]byte(l.Value), data)
if err != nil {
return nil, err
return nil, fmt.Errorf("%w: %s", ErrFailedToUnmarshal, err)
}

msg.Data = &xatu.CannonLocation_EthV2BeaconBlockAttesterSlashing{
Expand All @@ -249,7 +255,7 @@ func (l *Location) Unmarshal() (*xatu.CannonLocation, error) {

err := protojson.Unmarshal([]byte(l.Value), data)
if err != nil {
return nil, err
return nil, fmt.Errorf("%w: %s", ErrFailedToUnmarshal, err)
}

msg.Data = &xatu.CannonLocation_EthV2BeaconBlockExecutionTransaction{
Expand All @@ -263,7 +269,7 @@ func (l *Location) Unmarshal() (*xatu.CannonLocation, error) {

err := protojson.Unmarshal([]byte(l.Value), data)
if err != nil {
return nil, err
return nil, fmt.Errorf("%w: %s", ErrFailedToUnmarshal, err)
}

msg.Data = &xatu.CannonLocation_EthV2BeaconBlockBlsToExecutionChange{
Expand All @@ -277,7 +283,7 @@ func (l *Location) Unmarshal() (*xatu.CannonLocation, error) {

err := protojson.Unmarshal([]byte(l.Value), data)
if err != nil {
return nil, err
return nil, fmt.Errorf("%w: %s", ErrFailedToUnmarshal, err)
}

msg.Data = &xatu.CannonLocation_EthV2BeaconBlockWithdrawal{
Expand All @@ -290,7 +296,7 @@ func (l *Location) Unmarshal() (*xatu.CannonLocation, error) {

err := protojson.Unmarshal([]byte(l.Value), data)
if err != nil {
return nil, err
return nil, fmt.Errorf("%w: %s", ErrFailedToUnmarshal, err)
}

msg.Data = &xatu.CannonLocation_EthV2BeaconBlock{
Expand All @@ -303,7 +309,7 @@ func (l *Location) Unmarshal() (*xatu.CannonLocation, error) {

err := protojson.Unmarshal([]byte(l.Value), data)
if err != nil {
return nil, err
return nil, fmt.Errorf("%w: %s", ErrFailedToUnmarshal, err)
}

msg.Data = &xatu.CannonLocation_BlockprintBlockClassification{
Expand All @@ -316,7 +322,7 @@ func (l *Location) Unmarshal() (*xatu.CannonLocation, error) {

err := protojson.Unmarshal([]byte(l.Value), data)
if err != nil {
return nil, err
return nil, fmt.Errorf("%w: %s", ErrFailedToUnmarshal, err)
}

msg.Data = &xatu.CannonLocation_EthV1BeaconBlobSidecar{
Expand All @@ -329,7 +335,7 @@ func (l *Location) Unmarshal() (*xatu.CannonLocation, error) {

err := protojson.Unmarshal([]byte(l.Value), data)
if err != nil {
return nil, err
return nil, fmt.Errorf("%w: %s", ErrFailedToUnmarshal, err)
}

msg.Data = &xatu.CannonLocation_EthV1BeaconProposerDuty{
Expand All @@ -342,7 +348,7 @@ func (l *Location) Unmarshal() (*xatu.CannonLocation, error) {

err := protojson.Unmarshal([]byte(l.Value), data)
if err != nil {
return nil, err
return nil, fmt.Errorf("%w: %s", ErrFailedToUnmarshal, err)
}

msg.Data = &xatu.CannonLocation_EthV2BeaconBlockElaboratedAttestation{
Expand All @@ -355,7 +361,7 @@ func (l *Location) Unmarshal() (*xatu.CannonLocation, error) {

err := protojson.Unmarshal([]byte(l.Value), data)
if err != nil {
return nil, err
return nil, fmt.Errorf("%w: %s", ErrFailedToUnmarshal, err)
}

msg.Data = &xatu.CannonLocation_EthV1BeaconValidators{
Expand Down
10 changes: 6 additions & 4 deletions pkg/server/persistence/cannon_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"errors"
"time"

perrors "github.com/pkg/errors"

"github.com/ethpandaops/xatu/pkg/server/persistence/cannon"
"github.com/huandu/go-sqlbuilder"
)
Expand Down Expand Up @@ -41,7 +43,7 @@ func (c *Client) GetCannonLocationByID(ctx context.Context, id int64) (*cannon.L

rows, err := c.db.QueryContext(ctx, sql, args...)
if err != nil {
return nil, err
return nil, perrors.Wrap(err, "db query failed")
}

defer rows.Close()
Expand All @@ -53,7 +55,7 @@ func (c *Client) GetCannonLocationByID(ctx context.Context, id int64) (*cannon.L

err = rows.Scan(cannonLocationStruct.Addr(&location)...)
if err != nil {
return nil, err
return nil, perrors.Wrap(err, "db scan failed")
}

locations = append(locations, &location)
Expand All @@ -76,7 +78,7 @@ func (c *Client) GetCannonLocationByNetworkIDAndType(ctx context.Context, networ

rows, err := c.db.QueryContext(ctx, sql, args...)
if err != nil {
return nil, err
return nil, perrors.Wrap(err, "db query failed")
}

defer rows.Close()
Expand All @@ -88,7 +90,7 @@ func (c *Client) GetCannonLocationByNetworkIDAndType(ctx context.Context, networ

err = rows.Scan(cannonLocationStruct.Addr(&location)...)
if err != nil {
return nil, err
return nil, perrors.Wrap(err, "db scan failed")
}

locations = append(locations, &location)
Expand Down
Loading

0 comments on commit cf83d6e

Please sign in to comment.