Skip to content

Commit

Permalink
rework enableWss
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Aug 5, 2024
1 parent a106b14 commit 29837d0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions nodebuilder/p2p/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (ua *UserAgent) String() string {
func host(params hostParams) (HostBase, error) {
ua := newUserAgent().WithNetwork(params.Net).WithNodeType(params.Tp)

wss, isEnabled, err := enableWss()
tlsCfg, isEnabled, err := tlsEnabled()
if err != nil {
return nil, err
}
Expand All @@ -95,7 +95,7 @@ func host(params hostParams) (HostBase, error) {
libp2p.Transport(tcp.NewTCPTransport),
libp2p.Transport(quic.NewTransport),
libp2p.Transport(webtransport.New),
wss,
wsTransport(tlsCfg),
),
// to clearly define what defaults we rely upon
libp2p.DefaultSecurity,
Expand Down
23 changes: 16 additions & 7 deletions nodebuilder/p2p/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ const (
key = "key.pem"
)

var tlsPath = "TLS_PATH"
var tlsPath = "CELESTIA_TLS_PATH"

// enableWss checks whether `tlsPath` is not empty and creates a certificates
// to enable a websocket transport.
func enableWss() (libp2p.Option, bool, error) {
// tlsEnabled checks whether `tlsPath` is not empty and creates a certificates.
// it returns the cfg itself, the bool flag that specifies whether the config was created
// and an error.
func tlsEnabled() (*tls.Config, bool, error) {
path := os.Getenv(tlsPath)
certPath := filepath.Join(path, cert)
keyPath := filepath.Join(path, key)

exist := utils.Exists(certPath) && utils.Exists(keyPath)
if !exist {
return libp2p.Transport(ws.New), exist, nil
return nil, false, nil
}

var certificates []tls.Certificate
Expand All @@ -36,7 +37,15 @@ func enableWss() (libp2p.Option, bool, error) {
return nil, false, err
}
certificates = append(certificates, cert)
config := &tls.Config{MinVersion: tls.VersionTLS12, Certificates: certificates}
return &tls.Config{MinVersion: tls.VersionTLS12, Certificates: certificates}, true, nil
}

return libp2p.Transport(ws.New, ws.WithTLSConfig(config)), true, nil
// wsTransport enables a support for the secure websocket connection
// using the passed tls config. The connection will be insecure in case
// config is empty.
func wsTransport(config *tls.Config) libp2p.Option {
if config == nil {
return libp2p.Transport(ws.New)
}
return libp2p.Transport(ws.New, ws.WithTLSConfig(config))
}
1 change: 0 additions & 1 deletion state/core_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ func (ca *CoreAccessor) SubmitPayForBlob(
if response != nil && response.Code != 0 {
err = errors.Join(err, sdkErrors.ABCIError(response.Codespace, response.Code, response.Logs.String()))
}
fmt.Println("TX HASH ", response.TxHash)
return unsetTx(response), err
}
return nil, fmt.Errorf("failed to submit blobs after %d attempts: %w", maxRetries, lastErr)
Expand Down

0 comments on commit 29837d0

Please sign in to comment.