Skip to content

Commit

Permalink
Set WS heartbeat to 30s for all relayers (#1306)
Browse files Browse the repository at this point in the history
  • Loading branch information
vgeddes authored Oct 9, 2024
1 parent 2a03817 commit ce6b1c1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
28 changes: 28 additions & 0 deletions relayer/chain/relaychain/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"sort"
"time"

gsrpc "github.com/snowfork/go-substrate-rpc-client/v4"
"github.com/snowfork/go-substrate-rpc-client/v4/types"
Expand Down Expand Up @@ -65,6 +66,33 @@ func (co *Connection) Connect(_ context.Context) error {
return nil
}

func (co *Connection) ConnectWithHeartBeat(ctx context.Context, heartBeat time.Duration) error {
err := co.Connect(ctx)
if err != nil {
return err
}

ticker := time.NewTicker(heartBeat)

go func() {
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
_, err := co.API().RPC.System.Version()
if err != nil {
log.WithField("endpoint", co.endpoint).Error("Connection heartbeat failed")
return
}
}
}
}()

return nil
}

func (co *Connection) Close() {
// TODO: Fix design issue in GSRPC preventing on-demand closing of connections
}
Expand Down
2 changes: 1 addition & 1 deletion relayer/relays/beacon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (r *Relay) Start(ctx context.Context, eg *errgroup.Group) error {

paraconn := parachain.NewConnection(r.config.Sink.Parachain.Endpoint, r.keypair.AsKeyringPair())

err := paraconn.ConnectWithHeartBeat(ctx, 60*time.Second)
err := paraconn.ConnectWithHeartBeat(ctx, 30*time.Second)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion relayer/relays/beefy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package beefy
import (
"context"
"fmt"
"time"

"golang.org/x/sync/errgroup"

Expand Down Expand Up @@ -44,7 +45,7 @@ func NewRelay(config *Config, ethereumKeypair *secp256k1.Keypair) (*Relay, error
}

func (relay *Relay) Start(ctx context.Context, eg *errgroup.Group) error {
err := relay.relaychainConn.Connect(ctx)
err := relay.relaychainConn.ConnectWithHeartBeat(ctx, 30*time.Second)
if err != nil {
return fmt.Errorf("create relaychain connection: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion relayer/relays/execution/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (r *Relay) Start(ctx context.Context, eg *errgroup.Group) error {
paraconn := parachain.NewConnection(r.config.Sink.Parachain.Endpoint, r.keypair.AsKeyringPair())
ethconn := ethereum.NewConnection(&r.config.Source.Ethereum, nil)

err := paraconn.ConnectWithHeartBeat(ctx, 20*time.Second)
err := paraconn.ConnectWithHeartBeat(ctx, 30*time.Second)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion relayer/relays/parachain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package parachain
import (
"context"
"fmt"
"time"

"golang.org/x/sync/errgroup"

Expand Down Expand Up @@ -66,7 +67,7 @@ func NewRelay(config *Config, keypair *secp256k1.Keypair) (*Relay, error) {
}

func (relay *Relay) Start(ctx context.Context, eg *errgroup.Group) error {
err := relay.parachainConn.Connect(ctx)
err := relay.parachainConn.ConnectWithHeartBeat(ctx, 30*time.Second)
if err != nil {
return err
}
Expand Down

0 comments on commit ce6b1c1

Please sign in to comment.