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

Remove finalization checkpoint #40

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func GetPeriodFromEpoch(epoch int64) int64 {
return epoch / EPOCHS_PER_SYNC_COMMITTEE_PERIOD
}

func GetEpochFromSlot(slot int64) int64 {
return slot / SLOTS_PER_EPOCH
}

func ConnectToChain(ctx context.Context, url string, key *ecdsa.PrivateKey) (*ethclient.Client, *bind.TransactOpts, error) {
client, err := ethclient.Dial(url)
if err != nil {
Expand Down
38 changes: 23 additions & 15 deletions internal/to_tara/event_processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"net/http"
"relayer/internal/common"
"strconv"
"strings"
)
Expand All @@ -15,7 +16,7 @@ func (r *Relayer) startEventProcessing(ctx context.Context) {
client := &http.Client{}

// Construct the request to the Ethereum 2.0 node's event stream
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/eth/v1/events?topics=finalized_checkpoint", r.beaconNodeEndpoint), nil)
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/eth/v1/events?topics=head", r.beaconNodeEndpoint), nil)
if err != nil {
r.log.Fatalf("Failed to create request: %v", err)
}
Expand Down Expand Up @@ -51,20 +52,27 @@ func (r *Relayer) processSSEStream(stream io.ReadCloser) {
continue
}

switch epoch := subscriptionData["epoch"].(type) {
case float64:
// JSON numbers are decoded into float64 by default
r.onFinalizedEpoch <- int64(epoch)
case int:
// Handle int if by any chance it's parsed as such
r.onFinalizedEpoch <- int64(epoch)
case string:
// If "epoch" is provided as a string, parse it to an integer
if epochVal, err := strconv.ParseUint(epoch, 10, 64); err == nil {
r.onFinalizedEpoch <- int64(epochVal)
r.log.WithField("epoch", epochVal).Debug("Epoch value")
} else {
r.log.WithError(err).Error("Error converting epoch from string to uint64")
switch epoch_transition := subscriptionData["epoch_transition"].(type) {
case bool:
if epoch_transition {
switch slot := subscriptionData["slot"].(type) {
case float64:
// JSON numbers are decoded into float64 by default
r.onFinalizedEpoch <- common.GetEpochFromSlot(int64(slot))
case int:
// Handle int if by any chance it's parsed as such
r.onFinalizedEpoch <- common.GetEpochFromSlot(int64(slot))
case string:
// If "epoch" is provided as a string, parse it to an integer
if slotVal, err := strconv.ParseUint(slot, 10, 64); err == nil {
r.onFinalizedEpoch <- common.GetEpochFromSlot(int64(slotVal))
r.log.WithField("slot", slotVal).Debug("Slot value")
} else {
r.log.WithError(err).Error("Error converting epoch from string to uint64")
}
default:
r.log.WithField("data", subscriptionData).Warn("Epoch value is of an unrecognized type")
}
Comment on lines +58 to +75
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this convertion to a separate method and leave something like r.onFinalizedEpoch <- common.ToInt64(slot) here?

}
default:
r.log.WithField("data", subscriptionData).Warn("Epoch value is of an unrecognized type")
Expand Down
Loading