Skip to content

Commit

Permalink
fix panic in pod
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Aug 5, 2024
1 parent 4728821 commit a106b14
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
28 changes: 16 additions & 12 deletions nodebuilder/p2p/tls.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package p2p

import (
cfg "crypto/tls"
"crypto/tls"
"os"
"path/filepath"

"github.com/libp2p/go-libp2p"
ws "github.com/libp2p/go-libp2p/p2p/transport/websocket"
Expand All @@ -11,28 +12,31 @@ import (
)

const (
cert = "/cert.pem"
key = "/key.pem"
cert = "cert.pem"
key = "key.pem"
)

var tlsPath = "TLS_PATH"

// enableWss checks whether `tlsPath` is not empty and creates a certificates
// to enable a websocket transport.
func enableWss() (libp2p.Option, bool, error) {
path := os.Getenv(tlsPath)
exist := utils.Exists(path+cert) && utils.Exists(path+key)
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
}

var certificates []cfg.Certificate
if path != "" {
cert, err := cfg.LoadX509KeyPair(path+cert, path+key)
if err != nil {
return nil, false, err
}
certificates = append(certificates, cert)
var certificates []tls.Certificate
cert, err := tls.LoadX509KeyPair(certPath, keyPath)
if err != nil {
return nil, false, err
}
config := &cfg.Config{MinVersion: cfg.VersionTLS12, Certificates: certificates}
certificates = append(certificates, cert)
config := &tls.Config{MinVersion: tls.VersionTLS12, Certificates: certificates}

return libp2p.Transport(ws.New, ws.WithTLSConfig(config)), true, nil
}
3 changes: 2 additions & 1 deletion state/core_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ 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 Expand Up @@ -594,7 +595,7 @@ func (ca *CoreAccessor) setupTxClient(ctx context.Context, keyName string) (*use
}
ca.defaultSignerAddress = addr
return user.SetupTxClient(ctx, ca.keyring, ca.coreConn, encCfg,
user.WithDefaultAccount(keyName), user.WithDefaultAddress(addr),
user.WithDefaultAccount(keyName),
)
}

Expand Down

0 comments on commit a106b14

Please sign in to comment.