Skip to content

Commit b3b56f6

Browse files
committed
Moved subscription backoff max and alert threshold to subscribe opts
Instead of defining those values per-contract we defined them only one time now.
1 parent f5ebf3c commit b3b56f6

File tree

5 files changed

+22
-36
lines changed

5 files changed

+22
-36
lines changed

pkg/chain/ethereum/ethutil/subscribe_opts.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ const (
1313
// pulled from the chain by the subscription monitoring mechanism if no
1414
// other value is provided in SubscribeOpts when creating the subscription.
1515
DefaultSubscribeOptsPastBlocks = 100
16+
17+
// SubscriptionBackoffMax is the maximum backoff time between event
18+
// resubscription attempts.
19+
SubscriptionBackoffMax = 2 * time.Minute
20+
21+
// SubscriptionAlertThreshold is time threshold below which event
22+
// resubscription emits an error to the logs.
23+
// WS connection can be dropped at any moment and event resubscription will
24+
// follow. However, if WS connection for event subscription is getting
25+
// dropped too often, it may indicate something is wrong with Ethereum
26+
// client. This constant defines the minimum lifetime of an event
27+
// subscription required before the subscription failure happens and
28+
// resubscription follows so that the resubscription does not emit an error
29+
// to the logs alerting about potential problems with Ethereum client
30+
// connection.
31+
SubscriptionAlertThreshold = 15 * time.Minute
1632
)
1733

1834
// SubscribeOpts specifies optional configuration options that can be passed

tools/generators/ethereum/contract.go.tmpl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,6 @@ import (
2626
// included or excluded from logging at startup by name.
2727
var {{.ShortVar}}Logger = log.Logger("keep-contract-{{.Class}}")
2828

29-
const (
30-
// Maximum backoff time between event resubscription attempts.
31-
{{.ShortVar}}SubscriptionBackoffMax = 2 * time.Minute
32-
33-
// Threshold below which event resubscription emits an error to the logs.
34-
// WS connection can be dropped at any moment and event resubscription will
35-
// follow. However, if WS connection for event subscription is getting
36-
// dropped too often, it may indicate something is wrong with Ethereum
37-
// client. This constant defines the minimum lifetime of an event
38-
// subscription required before the subscription failure happens and
39-
// resubscription follows so that the resubscription does not emit an error
40-
// to the logs alerting about potential problems with Ethereum client.
41-
{{.ShortVar}}SubscriptionAlertThreshold = 15 * time.Minute
42-
)
43-
4429
type {{.Class}} struct {
4530
contract *abi.{{.AbiClass}}
4631
contractAddress common.Address

tools/generators/ethereum/contract_events.go.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ func ({{$contract.ShortVar}} *{{$contract.Class}}) watch{{$event.CapsName}}(
150150
)
151151
}
152152

153-
sub := ethutil.WithResubscription(
154-
{{$contract.ShortVar}}SubscriptionBackoffMax,
153+
return ethutil.WithResubscription(
154+
ethutil.SubscriptionBackoffMax,
155155
subscribeFn,
156-
{{$contract.ShortVar}}SubscriptionAlertThreshold,
156+
ethutil.SubscriptionAlertThreshold,
157157
thresholdViolatedFn,
158158
subscriptionFailedFn,
159159
)

tools/generators/ethereum/contract_events_template_content.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ func ({{$contract.ShortVar}} *{{$contract.Class}}) watch{{$event.CapsName}}(
153153
)
154154
}
155155
156-
sub := ethutil.WithResubscription(
157-
{{$contract.ShortVar}}SubscriptionBackoffMax,
156+
return ethutil.WithResubscription(
157+
ethutil.SubscriptionBackoffMax,
158158
subscribeFn,
159-
{{$contract.ShortVar}}SubscriptionAlertThreshold,
159+
ethutil.SubscriptionAlertThreshold,
160160
thresholdViolatedFn,
161161
subscriptionFailedFn,
162162
)

tools/generators/ethereum/contract_template_content.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,6 @@ import (
2929
// included or excluded from logging at startup by name.
3030
var {{.ShortVar}}Logger = log.Logger("keep-contract-{{.Class}}")
3131
32-
const (
33-
// Maximum backoff time between event resubscription attempts.
34-
{{.ShortVar}}SubscriptionBackoffMax = 2 * time.Minute
35-
36-
// Threshold below which event resubscription emits an error to the logs.
37-
// WS connection can be dropped at any moment and event resubscription will
38-
// follow. However, if WS connection for event subscription is getting
39-
// dropped too often, it may indicate something is wrong with Ethereum
40-
// client. This constant defines the minimum lifetime of an event
41-
// subscription required before the subscription failure happens and
42-
// resubscription follows so that the resubscription does not emit an error
43-
// to the logs alerting about potential problems with Ethereum client.
44-
{{.ShortVar}}SubscriptionAlertThreshold = 15 * time.Minute
45-
)
46-
4732
type {{.Class}} struct {
4833
contract *abi.{{.AbiClass}}
4934
contractAddress common.Address

0 commit comments

Comments
 (0)