Skip to content

Commit

Permalink
aggressive lint
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Nov 5, 2024
1 parent 10042c8 commit 03526b7
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 31 deletions.
10 changes: 4 additions & 6 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
linters:
enable-all: false
enable-all: true
disable:
- cyclop
- forbidigo
Expand Down Expand Up @@ -28,6 +28,9 @@ linters:
- exhaustruct
- depguard
- err113
- gocognit
- nakedret
- tagliatelle

#
# Disabled because of generics:
Expand Down Expand Up @@ -55,11 +58,6 @@ linters-settings:
excludes:
- G108

tagliatelle:
case:
rules:
json: snake

gofumpt:
extra-rules: true

Expand Down
2 changes: 1 addition & 1 deletion cmd/receiver-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var flags []cli.Flag = []cli.Flag{
&cli.StringFlag{
Name: "builder-confighub-endpoint",
Value: "http://127.0.0.1:14892",
Usage: "address of the builder config hub enpoint (directly or throught the cvm-proxy)",
Usage: "address of the builder config hub enpoint (directly or using the cvm-proxy)",
EnvVars: []string{"BUILDER_CONFIGHUB_ENDPOINT"},
},
&cli.StringFlag{
Expand Down
2 changes: 1 addition & 1 deletion cmd/sender-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var flags []cli.Flag = []cli.Flag{
&cli.StringFlag{
Name: "builder-confighub-endpoint",
Value: "http://127.0.0.1:14892",
Usage: "address of the builder config hub enpoint (directly or throught the cvm-proxy)",
Usage: "address of the builder config hub enpoint (directly or using the cvm-proxy)",
EnvVars: []string{"BUILDER_CONFIGHUB_ENDPOINT"},
},
&cli.StringFlag{
Expand Down
4 changes: 2 additions & 2 deletions proxy/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ type ArchiveQueue struct {
}

func (aq *ArchiveQueue) Run() {
var workers []*archiveQueueWorker
workerCount := 1
if aq.workerCount > 0 {
workerCount = aq.workerCount
}
workers := make([]*archiveQueueWorker, 0, workerCount)
workersQueue := make(chan *ParsedRequest, ArchiveWorkerQueueSize)
for w := 0; w < workerCount; w++ {
for w := range workerCount {
worker := &archiveQueueWorker{
log: aq.log.With(slog.Int("worker", w)),
archiveClient: aq.archiveClient,
Expand Down
2 changes: 1 addition & 1 deletion proxy/confighub.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (b *BuilderConfigHub) Builders(internal bool) (result []ConfighubBuilder, e
} else {
url += "/api/l1-builder/v1/builders"
}
resp, err = http.Get(url)
resp, err = http.Get(url) //nolint:gosec
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion proxy/receiver_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func NewReceiverProxy(config ReceiverProxyConfig) (*ReceiverProxy, error) {

prx.CertHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/octet-stream")
_, err := w.Write([]byte(prx.PublicCertPEM))
_, err := w.Write(prx.PublicCertPEM)
if err != nil {
prx.Log.Warn("Failed to serve certificate", slog.Any("error", err))
}
Expand Down
21 changes: 11 additions & 10 deletions proxy/receiver_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,28 @@ func StartTestOrderflowProxy(name string) (*OrderflowProxyTestSetup, error) {
localBuilderServer := ServeHTTPRequestToChan(localBuilderRequests)

proxy := createProxy(localBuilderServer.URL, name)
publicProxyServer := &http.Server{
publicProxyServer := &http.Server{ //nolint:gosec
Handler: proxy.PublicHandler,
TLSConfig: proxy.TLSConfig(),
}
publicListener, err := net.Listen("tcp", ":0")
publicListener, err := net.Listen("tcp", ":0") //nolint:gosec
if err != nil {
return nil, err
}
go publicProxyServer.ServeTLS(publicListener, "", "") //nolint: errcheck
publicServerEndpoint := fmt.Sprintf("https://localhost:%d", publicListener.Addr().(*net.TCPAddr).Port)
ip := fmt.Sprintf("127.0.0.1:%d", publicListener.Addr().(*net.TCPAddr).Port)
go publicProxyServer.ServeTLS(publicListener, "", "") //nolint: errcheck
publicServerEndpoint := fmt.Sprintf("https://localhost:%d", publicListener.Addr().(*net.TCPAddr).Port) //nolint:forcetypeassert
ip := fmt.Sprintf("127.0.0.1:%d", publicListener.Addr().(*net.TCPAddr).Port) //nolint:forcetypeassert

localProxyServer := &http.Server{
localProxyServer := &http.Server{ //nolint:gosec
Handler: proxy.LocalHandler,
TLSConfig: proxy.TLSConfig(),
}
localListener, err := net.Listen("tcp", ":0")
localListener, err := net.Listen("tcp", ":0") //nolint:gosec
if err != nil {
return nil, err
}
go localProxyServer.ServeTLS(localListener, "", "") //nolint:errcheck
localServerEndpoint := fmt.Sprintf("https://localhost:%d", localListener.Addr().(*net.TCPAddr).Port)
go localProxyServer.ServeTLS(localListener, "", "") //nolint:errcheck
localServerEndpoint := fmt.Sprintf("https://localhost:%d", localListener.Addr().(*net.TCPAddr).Port) //nolint:forcetypeassert

certProxyServer := httptest.NewServer(proxy.CertHandler)

Expand Down Expand Up @@ -160,7 +160,7 @@ func TestMain(m *testing.M) {
archiveServer = ServeHTTPRequestToChan(archiveServerRequests)
defer archiveServer.Close()

for i := 0; i < 3; i++ {
for i := range 3 {
proxy, err := StartTestOrderflowProxy(fmt.Sprintf("proxy:%d", i))
proxies = append(proxies, proxy)
if err != nil {
Expand Down Expand Up @@ -233,6 +233,7 @@ func expectNoRequest(t *testing.T, ch chan *RequestData) {
}

func proxiesUpdatePeers(t *testing.T) {
t.Helper()
for _, instance := range proxies {
err := instance.proxy.RequestNewPeers()
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions proxy/sharing.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (sq *ShareQueue) Run() {
if sq.localBuilder != nil {
builderPeer := newShareQueuePeer("local-builder", sq.localBuilder)
localBuilder = &builderPeer
for worker := 0; worker < workersPerPeer; worker += 1 {
for worker := range workersPerPeer {
go sq.proxyRequests(localBuilder, worker)
}
defer localBuilder.Close()
Expand Down Expand Up @@ -108,7 +108,7 @@ func (sq *ShareQueue) Run() {
sq.log.Info("Created client for peer", slog.String("peer", info.Name), slog.String("name", sq.name))
newPeer := newShareQueuePeer(info.Name, client)
peers = append(peers, newPeer)
for worker := 0; worker < workersPerPeer; worker += 1 {
for worker := range workersPerPeer {
go sq.proxyRequests(&newPeer, worker)
}
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func (sq *ShareQueue) proxyRequests(peer *shareQueuePeer, worker int) {
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
resp, err := peer.client.Call(ctx, method, data)
cancel()
timeShareQueuePeerRPCDuration(peer.name, int64(time.Since(start).Milliseconds()))
timeShareQueuePeerRPCDuration(peer.name, time.Since(start).Milliseconds())
if err != nil {
logger.Warn("Error while proxying request", slog.Any("error", err))
incShareQueuePeerRPCErrors(peer.name)
Expand Down
13 changes: 7 additions & 6 deletions proxy/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"net"
"net/http"
"strings"
"sync"
Expand All @@ -16,7 +16,7 @@ import (
"github.com/flashbots/go-utils/signature"
)

var DefaultOrderflowProxyPublicPort = 5544
var DefaultOrderflowProxyPublicPort = "5544"

var errCertificate = errors.New("failed to add certificate to pool")

Expand All @@ -27,7 +27,8 @@ func createTransportForSelfSignedCert(certPEM []byte) (*http.Transport, error) {
}
return &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: certPool,
RootCAs: certPool,
MinVersion: tls.VersionTLS12,
},
}, nil
}
Expand All @@ -41,7 +42,7 @@ func HTTPClientWithMaxConnections(maxOpenConnections int) *http.Client {
}
}

func RPCClientWithCertAndSigner(endpoint string, certPEM []byte, signer *signature.Signer, maxOpenConnections int) (rpcclient.RPCClient, error) {
func RPCClientWithCertAndSigner(endpoint string, certPEM []byte, signer *signature.Signer, maxOpenConnections int) (rpcclient.RPCClient, error) { //nolint:ireturn
transport, err := createTransportForSelfSignedCert(certPEM)
if err != nil {
return nil, err
Expand All @@ -59,9 +60,9 @@ func RPCClientWithCertAndSigner(endpoint string, certPEM []byte, signer *signatu

func OrderflowProxyURLFromIP(ip string) string {
if strings.Contains(ip, ":") {
return fmt.Sprintf("https://%s", ip)
return "https://" + ip
} else {
return fmt.Sprintf("https://%s:%d", ip, DefaultOrderflowProxyPublicPort)
return "https://" + net.JoinHostPort(ip, DefaultOrderflowProxyPublicPort)
}
}

Expand Down

0 comments on commit 03526b7

Please sign in to comment.