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

Fix OG panic issues #1554

Merged
merged 3 commits into from
Sep 25, 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
14 changes: 7 additions & 7 deletions go/rpc/encrypted_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,23 @@ func (c *EncRPCClient) Subscribe(ctx context.Context, result interface{}, namesp
return nil, fmt.Errorf("expected a channel of type `chan types.Log`, got %T", ch)
}
clientChannel := make(chan common.IDAndEncLog)
subscription, err := c.obscuroClient.Subscribe(ctx, nil, namespace, clientChannel, subscriptionType, encryptedParams)
subscriptionToObscuro, err := c.obscuroClient.Subscribe(ctx, nil, namespace, clientChannel, subscriptionType, encryptedParams)
if err != nil {
return nil, err
}

// We need to return the subscription ID, to allow unsubscribing. However, the client API has already converted
// from a subscription ID to a subscription object under the hood, so we can't retrieve the subscription ID.
// To hack around this, we always return the subscription ID as the first message on the newly-created subscription.
err = c.setResultToSubID(clientChannel, result, subscription)
err = c.setResultToSubID(clientChannel, result, subscriptionToObscuro)
if err != nil {
subscription.Unsubscribe()
subscriptionToObscuro.Unsubscribe()
return nil, err
}

go c.forwardLogs(clientChannel, logCh, subscription)
go c.forwardLogs(clientChannel, logCh, subscriptionToObscuro)

return subscription, nil
return subscriptionToObscuro, nil
}

func (c *EncRPCClient) forwardLogs(clientChannel chan common.IDAndEncLog, logCh chan common.IDAndLog, subscription *rpc.ClientSubscription) {
Expand Down Expand Up @@ -166,9 +166,9 @@ func (c *EncRPCClient) forwardLogs(clientChannel chan common.IDAndEncLog, logCh

case err := <-subscription.Err():
if err != nil {
c.logger.Info("subscription closed", log.ErrKey, err)
c.logger.Info("subscription to obscuro node closed with error", log.ErrKey, err)
} else {
c.logger.Trace("subscription closed")
c.logger.Info("subscription to obscuro node closed")
}
return
}
Expand Down
14 changes: 11 additions & 3 deletions tools/walletextension/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"fmt"
"regexp"

gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/ecies"
"github.com/obscuronet/go-obscuro/go/common/viewingkey"
"github.com/obscuronet/go-obscuro/go/rpc"

gethcommon "github.com/ethereum/go-ethereum/common"
gethlog "github.com/ethereum/go-ethereum/log"
)

var authenticateMessageRegex = regexp.MustCompile(MessageFormatRegex)
Expand Down Expand Up @@ -63,7 +65,13 @@ func GetUserIDbyte(userID string) ([]byte, error) {
return hex.DecodeString(userID)
}

func CreateEncClient(hostRPCBindAddr string, addressBytes []byte, privateKeyBytes []byte, signature []byte) (*rpc.EncRPCClient, error) {
func CreateEncClient(
hostRPCBindAddr string,
addressBytes []byte,
privateKeyBytes []byte,
signature []byte,
logger gethlog.Logger,
) (*rpc.EncRPCClient, error) {
privateKey, err := BytesToPrivateKey(privateKeyBytes)
if err != nil {
return nil, fmt.Errorf("unable to convert bytes to ecies private key: %w", err)
Expand All @@ -77,7 +85,7 @@ func CreateEncClient(hostRPCBindAddr string, addressBytes []byte, privateKeyByte
PublicKey: PrivateKeyToCompressedPubKey(privateKey),
Signature: signature,
}
encClient, err := rpc.NewEncNetworkClient(hostRPCBindAddr, vk, nil)
encClient, err := rpc.NewEncNetworkClient(hostRPCBindAddr, vk, logger)
if err != nil {
return nil, fmt.Errorf("unable to create EncRPCClient: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewWalletExtensionContainerFromConfig(config config.Config, logger gethlog.
logger.Error(fmt.Errorf("error getting accounts for user: %s, %w", hex.EncodeToString(user.UserID), err).Error())
}
for _, account := range accounts {
encClient, err := wecommon.CreateEncClient(hostRPCBindAddr, account.AccountAddress, user.PrivateKey, account.Signature)
encClient, err := wecommon.CreateEncClient(hostRPCBindAddr, account.AccountAddress, user.PrivateKey, account.Signature, logger)
if err != nil {
logger.Error(fmt.Errorf("error creating new client, %w", err).Error())
}
Expand Down
3 changes: 1 addition & 2 deletions tools/walletextension/storage/database/mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@ func (m *MariaDB) AddAccount(userID []byte, accountAddress []byte, signature []b
}
defer stmt.Close()

res, err := stmt.Exec(userID, accountAddress, signature)
_, err = stmt.Exec(userID, accountAddress, signature)
if err != nil {
return err
}
fmt.Println(res)

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion tools/walletextension/wallet_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (w *WalletExtension) AddAddressToUser(hexUserID string, message string, sig

accManager := w.userAccountManager.AddAndReturnAccountManager(hexUserID)

encClient, err := common.CreateEncClient(w.hostAddr, addressFromMessage.Bytes(), privateKeyBytes, signature)
encClient, err := common.CreateEncClient(w.hostAddr, addressFromMessage.Bytes(), privateKeyBytes, signature, w.Logger())
if err != nil {
w.Logger().Error(fmt.Errorf("error creating encrypted client for user: (%s), %w", hexUserID, err).Error())
}
Expand Down
Loading