Skip to content

Commit

Permalink
refactor: Rename resubInterval to logResubInterval
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyodar committed May 23, 2024
1 parent b8b63a5 commit 6715e95
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions core/safeclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
)

const (
BLOCK_CHUNK_SIZE = 2000
BLOCK_MAX_RANGE = 10000
RESUB_INTERVAL = 5 * time.Minute
HEADER_TIMEOUT = 1 * time.Minute
BLOCK_CHUNK_SIZE = 2000
BLOCK_MAX_RANGE = 10000
LOG_RESUB_INTERVAL = 5 * time.Minute
HEADER_TIMEOUT = 1 * time.Minute
)

type SafeClient interface {
Expand All @@ -30,29 +30,29 @@ type SafeClient interface {
type SafeEthClient struct {
eth.Client

wg sync.WaitGroup
logger logging.Logger
rpcUrl string
closeC chan struct{}
closed bool
headerTimeout time.Duration
resubInterval time.Duration
blockChunkSize uint64
blockMaxRange uint64
wg sync.WaitGroup
logger logging.Logger
rpcUrl string
closeC chan struct{}
closed bool
headerTimeout time.Duration
logResubInterval time.Duration
blockChunkSize uint64
blockMaxRange uint64

createClient func(string, logging.Logger) (eth.Client, error)
}

func NewSafeEthClient(rpcUrl string, logger logging.Logger, opts ...SafeEthClientOption) (*SafeEthClient, error) {
safeClient := &SafeEthClient{
logger: logger,
rpcUrl: rpcUrl,
resubInterval: RESUB_INTERVAL,
headerTimeout: HEADER_TIMEOUT,
blockChunkSize: BLOCK_CHUNK_SIZE,
blockMaxRange: BLOCK_MAX_RANGE,
closeC: make(chan struct{}),
createClient: createDefaultClient,
logger: logger,
rpcUrl: rpcUrl,
logResubInterval: LOG_RESUB_INTERVAL,
headerTimeout: HEADER_TIMEOUT,
blockChunkSize: BLOCK_CHUNK_SIZE,
blockMaxRange: BLOCK_MAX_RANGE,
closeC: make(chan struct{}),
createClient: createDefaultClient,
}

for _, opt := range opts {
Expand All @@ -72,9 +72,9 @@ func NewSafeEthClient(rpcUrl string, logger logging.Logger, opts ...SafeEthClien

type SafeEthClientOption func(*SafeEthClient)

func WithResubInterval(interval time.Duration) SafeEthClientOption {
func WithLogResubInterval(interval time.Duration) SafeEthClientOption {
return func(c *SafeEthClient) {
c.resubInterval = interval
c.logResubInterval = interval
}
}

Expand Down Expand Up @@ -234,14 +234,14 @@ func (c *SafeEthClient) SubscribeFilterLogs(ctx context.Context, q ethereum.Filt
go func() {
defer c.wg.Done()

ticker := time.NewTicker(c.resubInterval)
ticker := time.NewTicker(c.logResubInterval)
defer ticker.Stop()

handleResub := func() {
err := resub()
if err != nil {
c.logger.Error("Failed to resubscribe to logs", "err", err)
ticker.Reset(c.resubInterval)
ticker.Reset(c.logResubInterval)
} else {
ticker.Stop()
}
Expand Down

0 comments on commit 6715e95

Please sign in to comment.