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

Use 1-second timeout when initializing msg sender #280

Merged
merged 1 commit into from
Dec 14, 2023
Merged
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/sourcegraph/conc v0.3.0
github.com/stretchr/testify v1.8.4
github.com/tonkeeper/scam_backoffice_rules v0.0.0-20231207072018-fb6051191f8e
github.com/tonkeeper/tongo v1.4.2-0.20231213140948-5149f5e93a2b
github.com/tonkeeper/tongo v1.4.2-0.20231214105758-5913463ccac7
go.opentelemetry.io/otel v1.19.0
go.opentelemetry.io/otel/metric v1.19.0
go.opentelemetry.io/otel/trace v1.19.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tonkeeper/scam_backoffice_rules v0.0.0-20231207072018-fb6051191f8e h1:Av1unDqMPNWHKw1pqJpngDJhr0MfVzAHrH4UZtwK1Y4=
github.com/tonkeeper/scam_backoffice_rules v0.0.0-20231207072018-fb6051191f8e/go.mod h1:SqZXYO9vbID8ku+xnnaKXeNGmehxigODGrk5V1KqbRA=
github.com/tonkeeper/tongo v1.4.2-0.20231213140948-5149f5e93a2b h1:/nBh5AAUS8TgmH7hOQWmcZxYNslqGqkXA7yi+HVRn90=
github.com/tonkeeper/tongo v1.4.2-0.20231213140948-5149f5e93a2b/go.mod h1:LdOBjpUz6vLp1EdX3E0XLNks9YI5XMSqaQahfOMrBEY=
github.com/tonkeeper/tongo v1.4.2-0.20231214105758-5913463ccac7 h1:H7hJTBX+mcKeMiZ/u/H6u0fUhmnhrumRzyFbmBaPmNc=
github.com/tonkeeper/tongo v1.4.2-0.20231214105758-5913463ccac7/go.mod h1:LdOBjpUz6vLp1EdX3E0XLNks9YI5XMSqaQahfOMrBEY=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
Expand Down
22 changes: 16 additions & 6 deletions pkg/blockchain/msg_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package blockchain
import (
"context"
"fmt"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"math/rand"
"sync"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/sourcegraph/conc/iter"

"github.com/tonkeeper/tongo"
"github.com/tonkeeper/tongo/config"
"github.com/tonkeeper/tongo/liteapi"
Expand Down Expand Up @@ -70,12 +72,20 @@ func NewMsgSender(logger *zap.Logger, servers []config.LiteServer, receivers map
}
clients = append(clients, client)
} else {
for _, s := range servers {
c, err := liteapi.NewClient(liteapi.WithLiteServers([]config.LiteServer{s}))
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()

tmpClients := iter.Map[config.LiteServer, *liteapi.Client](servers, func(s *config.LiteServer) *liteapi.Client {
c, err := liteapi.NewClient(liteapi.WithInitializationContext(ctx), liteapi.WithLiteServers([]config.LiteServer{*s}))
if err != nil {
continue
return nil
}
return c
})
for _, cli := range tmpClients {
if cli != nil {
clients = append(clients, cli)
}
clients = append(clients, c)
}
}
if len(clients) == 0 {
Expand Down
Loading