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

create a separate func implementation for sending blockchain messages #484

Closed
wants to merge 2 commits into from
Closed
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 cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

msgSender, err := blockchain.NewMsgSender(log, cfg.App.LiteServers, map[string]chan<- blockchain.ExtInMsgCopy{
"mempool": mempoolCh,
})
}, nil)

Check failure on line 65 in cmd/api/main.go

View workflow job for this annotation

GitHub Actions / unit-tests

too many arguments in call to blockchain.NewMsgSender
if err != nil {
log.Fatal("failed to create msg sender", zap.Error(err))
}
Expand Down
18 changes: 8 additions & 10 deletions pkg/blockchain/msg_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import (
"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 @@ -50,10 +47,6 @@ type ExtInMsgCopy struct {
Accounts map[tongo.AccountID]struct{}
}

var liteserverMessageSendMc = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "liteserver_message_send",
}, []string{"server", "result", "iteration"})

func (m *ExtInMsgCopy) IsEmulation() bool {
return len(m.Accounts) > 0
}
Expand Down Expand Up @@ -91,7 +84,6 @@ func NewMsgSender(logger *zap.Logger, servers []config.LiteServer, receivers map
if len(clients) == 0 {
return nil, fmt.Errorf("no lite clients available")
}

msgSender := &MsgSender{
sendingClients: clients,
logger: logger,
Expand Down Expand Up @@ -161,10 +153,8 @@ func (ms *MsgSender) send(ctx context.Context, payload []byte) error {
c := ms.sendingClients[serverNumber]
_, err = c.SendMessage(ctx, payload)
if err == nil {
liteserverMessageSendMc.WithLabelValues(fmt.Sprintf("%d", serverNumber), "success", fmt.Sprintf("%d", i)).Inc()
return nil
}
liteserverMessageSendMc.WithLabelValues(fmt.Sprintf("%d", serverNumber), "error", fmt.Sprintf("%d", i)).Inc()
}
return err
}
Expand Down Expand Up @@ -197,3 +187,11 @@ func (ms *MsgSender) SendMultipleMessages(ctx context.Context, copies []ExtInMsg
func (ms *MsgSender) SendingClientsNumber() int {
return len(ms.sendingClients)
}

func (ms *MsgSender) GetReceivers() map[string]chan<- ExtInMsgCopy {
return ms.receivers
}

func (ms *MsgSender) GetClients() []*liteapi.Client {
return ms.sendingClients
}
Loading