Skip to content

Commit 16d3359

Browse files
Backport changes from V1 (#1559)
* Adjusted the scheduler of on-demand BEEFY relay (#1530) * Fix on-demand beefy relay * Reduce the ticker interval * Format * Add #1501 back with the delay * Fix connect with heartbeat (#1539) * Fix connecting with heartbeat * Update go-ethereum dependencies * Add heart beat log * Update go.work.sum * Add Ethereum connection heartbeat * Fix log level * Set channel length to 1 * Supress heartbeat logs * Add a timeout to the contract call * Update relayer/relays/parachain/ethereum-writer.go Co-authored-by: Alistair Singh <[email protected]> * Make params configurable * Use latest nonce * Add timeout waitForTransaction --------- Co-authored-by: Alistair Singh <[email protected]> * Fix building error * Timeout for waitForTransaction (#1545) * Allow disabling heartbeat (#1551) * Fix connect * Add timeout * Fix Ethereum relay to wait until the next block (#1560) * Wait for the next block * Fix error handling * Add logs * Remove unused * Remove from gitignore --------- Co-authored-by: Alistair Singh <[email protected]>
1 parent 3aba4b5 commit 16d3359

File tree

18 files changed

+197
-133
lines changed

18 files changed

+197
-133
lines changed

go.work.sum

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee
8888
github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI=
8989
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
9090
github.com/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w=
91-
github.com/deepmap/oapi-codegen v1.6.0 h1:w/d1ntwh91XI0b/8ja7+u5SvA4IFfM0UNNLmiDR1gg0=
92-
github.com/deepmap/oapi-codegen v1.6.0/go.mod h1:ryDa9AgbELGeB+YEXE1dR53yAjHwFvE9iAUlWl9Al3M=
9391
github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo=
9492
github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
9593
github.com/donovanhide/eventsource v0.0.0-20210830082556-c59027999da0 h1:C7t6eeMaEQVy6e8CarIhscYQlNmw5e3G36y7l7Y21Ao=
@@ -168,8 +166,6 @@ github.com/googleapis/google-cloud-go-testing v0.0.0-20210719221736-1c9a4c676720
168166
github.com/googleapis/google-cloud-go-testing v0.0.0-20210719221736-1c9a4c676720/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
169167
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
170168
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
171-
github.com/graph-gophers/graphql-go v1.3.0 h1:Eb9x/q6MFpCLz7jBCiP/WTxjSDrYLR1QY41SORZyNJ0=
172-
github.com/graph-gophers/graphql-go v1.3.0/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc=
173169
github.com/guptarohit/asciigraph v0.5.5 h1:ccFnUF8xYIOUPPY3tmdvRyHqmn1MYI9iv1pLKX+/ZkQ=
174170
github.com/guptarohit/asciigraph v0.5.5/go.mod h1:dYl5wwK4gNsnFf9Zp+l06rFiDZ5YtXM6x7SRWZ3KGag=
175171
github.com/hashicorp/consul/api v1.25.1 h1:CqrdhYzc8XZuPnhIYZWH45toM0LB9ZeYr/gvpLVI3PE=
@@ -194,12 +190,6 @@ github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
194190
github.com/hydrogen18/memlistener v1.0.0 h1:JR7eDj8HD6eXrc5fWLbSUnfcQFL06PYvCc0DKQnWfaU=
195191
github.com/hydrogen18/memlistener v1.0.0/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE=
196192
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639 h1:mV02weKRL81bEnm8A0HT1/CAelMQDBuQIfLw8n+d6xI=
197-
github.com/influxdata/influxdb-client-go/v2 v2.4.0 h1:HGBfZYStlx3Kqvsv1h2pJixbCl/jhnFtxpKFAv9Tu5k=
198-
github.com/influxdata/influxdb-client-go/v2 v2.4.0/go.mod h1:vLNHdxTJkIf2mSLvGrpj8TCcISApPoXkaxP8g9uRlW8=
199-
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c h1:qSHzRbhzK8RdXOsAdfDgO49TtqC1oZ+acxPrkfTxcCs=
200-
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
201-
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7wlPfJLvMCdtV4zPulc4uCPrlywQOmbFOhgQNU=
202-
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
203193
github.com/iris-contrib/schema v0.0.6 h1:CPSBLyx2e91H2yJzPuhGuifVRnZBBJ3pCOMbOvPZaTw=
204194
github.com/iris-contrib/schema v0.0.6/go.mod h1:iYszG0IOsuIsfzjymw1kMzTL8YQcCWlm65f3wX8J5iA=
205195
github.com/jedisct1/go-minisign v0.0.0-20230811132847-661be99b8267 h1:TMtDYDHKYY15rFihtRfck/bfFqNfvcabqvXAFQfAUpY=

relayer/chain/ethereum/connection.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/ethereum/go-ethereum/core/types"
1919
"github.com/ethereum/go-ethereum/ethclient"
2020
"github.com/sirupsen/logrus"
21+
"golang.org/x/sync/errgroup"
2122

2223
"github.com/snowfork/snowbridge/relayer/config"
2324
"github.com/snowfork/snowbridge/relayer/crypto/secp256k1"
@@ -47,7 +48,7 @@ func NewConnection(config *config.EthereumConfig, kp *secp256k1.Keypair) *Connec
4748
}
4849
}
4950

50-
func (co *Connection) Connect(ctx context.Context) error {
51+
func (co *Connection) ConnectWithHeartBeat(ctx context.Context, eg *errgroup.Group, heartBeat time.Duration) error {
5152
client, err := ethclient.Dial(co.endpoint)
5253
if err != nil {
5354
return err
@@ -66,6 +67,27 @@ func (co *Connection) Connect(ctx context.Context) error {
6667
co.client = client
6768
co.chainID = chainID
6869

70+
if heartBeat.Abs() > 0 {
71+
ticker := time.NewTicker(heartBeat)
72+
73+
eg.Go(func() error {
74+
defer ticker.Stop()
75+
for {
76+
select {
77+
case <-ctx.Done():
78+
return ctx.Err()
79+
case <-ticker.C:
80+
_, err := client.NetworkID(ctx)
81+
if err != nil {
82+
log.WithField("endpoint", co.endpoint).Error("Connection heartbeat failed")
83+
return err
84+
}
85+
log.WithField("endpoint", co.endpoint).Info("Connection heartbeat received")
86+
}
87+
}
88+
})
89+
}
90+
6991
return nil
7092
}
7193

@@ -127,6 +149,7 @@ func (co *Connection) queryFailingError(ctx context.Context, hash common.Hash) e
127149
}
128150

129151
func (co *Connection) waitForTransaction(ctx context.Context, tx *types.Transaction, confirmations uint64) (*types.Receipt, error) {
152+
var cnt uint64
130153
for {
131154
receipt, err := co.pollTransaction(ctx, tx, confirmations)
132155
if err != nil {
@@ -141,6 +164,13 @@ func (co *Connection) waitForTransaction(ctx context.Context, tx *types.Transact
141164
case <-ctx.Done():
142165
return nil, ctx.Err()
143166
case <-time.After(6 * time.Second):
167+
if co.config.PendingTxTimeoutSecs > 0 {
168+
cnt++
169+
log.Info(fmt.Sprintf("waiting for receipt: %d seconds elapsed", cnt*6))
170+
if cnt*6 > co.config.PendingTxTimeoutSecs {
171+
return nil, fmt.Errorf("wait receipt timeout")
172+
}
173+
}
144174
}
145175
}
146176
}

relayer/chain/parachain/connection.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/sirupsen/logrus"
11+
"golang.org/x/sync/errgroup"
1112

1213
gsrpc "github.com/snowfork/go-substrate-rpc-client/v4"
1314
"github.com/snowfork/go-substrate-rpc-client/v4/signature"
@@ -73,29 +74,31 @@ func (co *Connection) Connect(_ context.Context) error {
7374
return nil
7475
}
7576

76-
func (co *Connection) ConnectWithHeartBeat(ctx context.Context, heartBeat time.Duration) error {
77+
func (co *Connection) ConnectWithHeartBeat(ctx context.Context, eg *errgroup.Group, heartBeat time.Duration) error {
7778
err := co.Connect(ctx)
7879
if err != nil {
7980
return err
8081
}
8182

82-
ticker := time.NewTicker(heartBeat)
83-
84-
go func() {
85-
defer ticker.Stop()
86-
for {
87-
select {
88-
case <-ctx.Done():
89-
return
90-
case <-ticker.C:
91-
_, err := co.API().RPC.System.Version()
92-
if err != nil {
93-
log.WithField("endpoint", co.endpoint).Error("Connection heartbeat failed")
94-
return
83+
if heartBeat.Abs() > 0 {
84+
ticker := time.NewTicker(heartBeat)
85+
86+
eg.Go(func() error {
87+
defer ticker.Stop()
88+
for {
89+
select {
90+
case <-ctx.Done():
91+
return ctx.Err()
92+
case <-ticker.C:
93+
_, err := co.API().RPC.System.Version()
94+
if err != nil {
95+
log.WithField("endpoint", co.endpoint).Error("Connection heartbeat failed")
96+
return err
97+
}
9598
}
9699
}
97-
}
98-
}()
100+
})
101+
}
99102

100103
return nil
101104
}

relayer/chain/parachain/writer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewParachainWriter(
4949
}
5050

5151
func (wr *ParachainWriter) Start(ctx context.Context, eg *errgroup.Group) error {
52-
err := wr.conn.ConnectWithHeartBeat(ctx, 30*time.Second)
52+
err := wr.conn.ConnectWithHeartBeat(ctx, eg, time.Second*60)
5353
if err != nil {
5454
return err
5555
}

relayer/chain/relaychain/connection.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
gsrpc "github.com/snowfork/go-substrate-rpc-client/v4"
1313
"github.com/snowfork/go-substrate-rpc-client/v4/types"
14+
"golang.org/x/sync/errgroup"
1415

1516
log "github.com/sirupsen/logrus"
1617
)
@@ -66,29 +67,31 @@ func (co *Connection) Connect(_ context.Context) error {
6667
return nil
6768
}
6869

69-
func (co *Connection) ConnectWithHeartBeat(ctx context.Context, heartBeat time.Duration) error {
70+
func (co *Connection) ConnectWithHeartBeat(ctx context.Context, eg *errgroup.Group, heartBeat time.Duration) error {
7071
err := co.Connect(ctx)
7172
if err != nil {
7273
return err
7374
}
7475

75-
ticker := time.NewTicker(heartBeat)
76-
77-
go func() {
78-
defer ticker.Stop()
79-
for {
80-
select {
81-
case <-ctx.Done():
82-
return
83-
case <-ticker.C:
84-
_, err := co.API().RPC.System.Version()
85-
if err != nil {
86-
log.WithField("endpoint", co.endpoint).Error("Connection heartbeat failed")
87-
return
76+
if heartBeat.Abs() > 0 {
77+
ticker := time.NewTicker(heartBeat)
78+
79+
eg.Go(func() error {
80+
defer ticker.Stop()
81+
for {
82+
select {
83+
case <-ctx.Done():
84+
return ctx.Err()
85+
case <-ticker.C:
86+
_, err := co.API().RPC.System.Version()
87+
if err != nil {
88+
log.WithField("endpoint", co.endpoint).Error("Connection heartbeat failed")
89+
return err
90+
}
8891
}
8992
}
90-
}
91-
}()
93+
})
94+
}
9295

9396
return nil
9497
}

relayer/cmd/generate_beacon_data.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/snowfork/snowbridge/relayer/relays/beacon/protocol"
2525
"github.com/snowfork/snowbridge/relayer/relays/beacon/store"
2626
executionConf "github.com/snowfork/snowbridge/relayer/relays/execution"
27+
"golang.org/x/sync/errgroup"
2728

2829
"github.com/cbroglie/mustache"
2930
"github.com/ethereum/go-ethereum/accounts/abi/bind"
@@ -235,7 +236,8 @@ func generateBeaconTestFixture(cmd *cobra.Command, _ []string) error {
235236
}
236237

237238
ethconn := ethereum.NewConnection(&executionConfig.Source.Ethereum, nil)
238-
err = ethconn.Connect(ctx)
239+
eg, ctx := errgroup.WithContext(ctx)
240+
err = ethconn.ConnectWithHeartBeat(ctx, eg, 30*time.Second)
239241
if err != nil {
240242
return err
241243
}
@@ -791,7 +793,8 @@ func generateInboundFixture(cmd *cobra.Command, _ []string) error {
791793
}
792794

793795
ethconn := ethereum.NewConnection(&executionConf.Source.Ethereum, nil)
794-
err = ethconn.Connect(ctx)
796+
eg, ctx := errgroup.WithContext(ctx)
797+
err = ethconn.ConnectWithHeartBeat(ctx, eg, 30*time.Second)
795798
if err != nil {
796799
return err
797800
}
@@ -966,7 +969,8 @@ func generateDeliveryProofFixture(cmd *cobra.Command, _ []string) error {
966969
}
967970

968971
ethconn := ethereum.NewConnection(&executionConf.Source.Ethereum, nil)
969-
err = ethconn.Connect(ctx)
972+
eg, ctx := errgroup.WithContext(ctx)
973+
err = ethconn.ConnectWithHeartBeat(ctx, eg, 30*time.Second)
970974
if err != nil {
971975
return err
972976
}

relayer/cmd/run/beefy/command.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,12 @@ func run(_ *cobra.Command, _ []string) error {
101101
return err
102102
}
103103

104-
eg.Go(func() error {
105-
err = relay.Start(ctx)
104+
err = relay.Start(ctx, eg)
105+
if err != nil {
106+
logrus.WithError(err).Fatal("Unhandled error")
107+
cancel()
106108
return err
107-
})
109+
}
108110
}
109111

110112
err = eg.Wait()

relayer/config/config.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@ package config
33
import "errors"
44

55
type PolkadotConfig struct {
6-
Endpoint string `mapstructure:"endpoint"`
6+
Endpoint string `mapstructure:"endpoint"`
7+
HeartbeatSecs uint64 `mapstructure:"heartbeat-secs"`
78
}
89

910
type ParachainConfig struct {
10-
Endpoint string `mapstructure:"endpoint"`
11+
Endpoint string `mapstructure:"endpoint"`
12+
HeartbeatSecs uint64 `mapstructure:"heartbeat-secs"`
1113
}
1214

1315
type EthereumConfig struct {
14-
Endpoint string `mapstructure:"endpoint"`
15-
GasFeeCap uint64 `mapstructure:"gas-fee-cap"`
16-
GasTipCap uint64 `mapstructure:"gas-tip-cap"`
17-
GasLimit uint64 `mapstructure:"gas-limit"`
16+
Endpoint string `mapstructure:"endpoint"`
17+
GasFeeCap uint64 `mapstructure:"gas-fee-cap"`
18+
GasTipCap uint64 `mapstructure:"gas-tip-cap"`
19+
GasLimit uint64 `mapstructure:"gas-limit"`
20+
HeartbeatSecs uint64 `mapstructure:"heartbeat-secs"`
21+
PendingTxTimeoutSecs uint64 `mapstructure:"pending-tx-timeout-secs"`
1822
}
1923

2024
type OFACConfig struct {

relayer/go.mod

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ module github.com/snowfork/snowbridge/relayer
22

33
go 1.23.0
44

5-
toolchain go1.23.2
5+
toolchain go1.23.4
66

77
require (
88
github.com/aws/aws-sdk-go-v2 v1.27.2
99
github.com/aws/aws-sdk-go-v2/config v1.27.18
1010
github.com/cbroglie/mustache v1.4.0
11-
github.com/ethereum/go-ethereum v1.15.5
11+
github.com/ethereum/go-ethereum v1.15.11
1212
github.com/ferranbt/fastssz v0.1.3
1313
github.com/holiman/uint256 v1.3.2
1414
github.com/magefile/mage v1.15.0
@@ -20,7 +20,7 @@ require (
2020
github.com/spf13/viper v1.18.2
2121
github.com/stretchr/testify v1.10.0
2222
golang.org/x/exp v0.0.0-20240110193028-0dcbfd608b1e
23-
golang.org/x/sync v0.10.0
23+
golang.org/x/sync v0.11.0
2424
)
2525

2626
require (
@@ -35,6 +35,8 @@ require (
3535
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.5 // indirect
3636
github.com/aws/aws-sdk-go-v2/service/sts v1.28.12 // indirect
3737
github.com/aws/smithy-go v1.20.2 // indirect
38+
github.com/crate-crypto/go-eth-kzg v1.3.0 // indirect
39+
github.com/ethereum/c-kzg-4844/v2 v2.1.0 // indirect
3840
github.com/ethereum/go-verkle v0.2.2 // indirect
3941
github.com/google/go-cmp v0.6.0 // indirect
4042
)
@@ -46,20 +48,18 @@ require (
4648
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
4749
github.com/allegro/bigcache v1.2.1 // indirect
4850
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.29.3
49-
github.com/bits-and-blooms/bitset v1.17.0 // indirect
51+
github.com/bits-and-blooms/bitset v1.20.0 // indirect
5052
github.com/cespare/xxhash/v2 v2.3.0 // indirect
51-
github.com/consensys/bavard v0.1.22 // indirect
52-
github.com/consensys/gnark-crypto v0.14.0 // indirect
53+
github.com/consensys/bavard v0.1.27 // indirect
54+
github.com/consensys/gnark-crypto v0.16.0 // indirect
5355
github.com/cosmos/go-bip39 v1.0.0 // indirect
5456
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
55-
github.com/crate-crypto/go-kzg-4844 v1.1.0 // indirect
5657
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
5758
github.com/deckarep/golang-set v1.8.0 // indirect
5859
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
5960
github.com/decred/base58 v1.0.5
6061
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
6162
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
62-
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
6363
github.com/fsnotify/fsnotify v1.7.0 // indirect
6464
github.com/go-ole/go-ole v1.3.0 // indirect
6565
github.com/gofrs/flock v0.8.1 // indirect
@@ -100,10 +100,10 @@ require (
100100
github.com/vedhavyas/go-subkey v1.0.3 // indirect
101101
github.com/yusufpapurcu/wmi v1.2.3 // indirect
102102
go.uber.org/multierr v1.11.0 // indirect
103-
golang.org/x/crypto v0.32.0
104-
golang.org/x/net v0.34.0 // indirect
105-
golang.org/x/sys v0.29.0 // indirect
106-
golang.org/x/text v0.21.0 // indirect
103+
golang.org/x/crypto v0.35.0
104+
golang.org/x/net v0.36.0 // indirect
105+
golang.org/x/sys v0.30.0 // indirect
106+
golang.org/x/text v0.22.0 // indirect
107107
gopkg.in/ini.v1 v1.67.0 // indirect
108108
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
109109
gopkg.in/yaml.v2 v2.4.0 // indirect

0 commit comments

Comments
 (0)