Skip to content

Commit

Permalink
groom log reports
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelkrolevets committed Sep 27, 2023
1 parent c00be40 commit 2495c75
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 148 deletions.
8 changes: 4 additions & 4 deletions cli/initiator/generate_initiator_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var GenerateInitiatorKeysCmd = &cobra.Command{
if err != nil {
logger.Fatal("Failed to generate operator keys", zap.Error(err))
}
logger.Info("generated public key (base64)", zap.String("pk", base64.StdEncoding.EncodeToString(pk)))
logger.Info("Generated public key (base64)", zap.String("pk", base64.StdEncoding.EncodeToString(pk)))

if password != "" {
encryptedData, err := keystorev4.New().Encrypt(sk, password)
Expand All @@ -53,10 +53,10 @@ var GenerateInitiatorKeysCmd = &cobra.Command{
logger.Fatal("Failed to write encrypted private key to file", zap.Error(err))
}

logger.Info("private key encrypted and stored in encrypted_private_key.json")
logger.Info("Private key encrypted and stored in encrypted_private_key.json")
} else {
logger.Info("generated public key (base64)", zap.String("pk", base64.StdEncoding.EncodeToString(pk)))
logger.Info("generated private key (base64)", zap.String("sk", base64.StdEncoding.EncodeToString(sk)))
logger.Info("Generated public key (base64)", zap.String("pk", base64.StdEncoding.EncodeToString(pk)))
logger.Info("Generated private key (base64)", zap.String("sk", base64.StdEncoding.EncodeToString(sk)))
}
},
}
50 changes: 25 additions & 25 deletions cli/initiator/initiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,62 +120,62 @@ var StartDKG = &cobra.Command{
// Check paths for results
depositResultsPath := viper.GetString("depositResultsPath")
if depositResultsPath == "" {
logger.Fatal("failed to get deposit result path flag value", zap.Error(err))
logger.Fatal("😥 Failed to get deposit result path flag value: ", zap.Error(err))
}
_, err = os.Stat(depositResultsPath)
if os.IsNotExist(err) {
logger.Fatal("Folder to store deposit file does not exist", zap.Error(err))
logger.Fatal("😥 Folder to store deposit file does not exist: ", zap.Error(err))
}
// Check paths for results
ssvPayloadResultsPath := viper.GetString("ssvPayloadResultsPath")
if ssvPayloadResultsPath == "" {
logger.Fatal("failed to get ssv payload path flag value", zap.Error(err))
logger.Fatal("😥 Failed to get ssv payload path flag value: ", zap.Error(err))
}
_, err = os.Stat(ssvPayloadResultsPath)
if os.IsNotExist(err) {
logger.Fatal("Folder to store SSV payload file does not exist", zap.Error(err))
logger.Fatal("😥 Folder to store SSV payload file does not exist: ", zap.Error(err))
}
// Load operators TODO: add more sources.
operatorFile := viper.GetString("operatorsInfoPath")
if operatorFile == "" {
logger.Fatal("failed to get operator info file path flag value", zap.Error(err))
logger.Fatal("😥 Failed to get operator info file path flag value: ", zap.Error(err))
}

opsfile, err := os.ReadFile(operatorFile)
if err != nil {
logger.Fatal("failed to read operator info file", zap.Error(err))
logger.Fatal("😥 Failed to read operator info file: ", zap.Error(err))
}

opMap, err := initiator.LoadOperatorsJson(opsfile)
if err != nil {
logger.Fatal("Failed to load operators: ", zap.Error(err))
logger.Fatal("😥 Failed to load operators: ", zap.Error(err))
}
participants := viper.GetStringSlice("operatorIDs")
if participants == nil {
logger.Fatal("failed to get operator IDs flag value", zap.Error(err))
logger.Fatal("😥 Failed to get operator IDs flag value: ", zap.Error(err))
}
parts, err := loadParticipants(participants)
if err != nil {
logger.Fatal("failed: ", zap.Error(err))
logger.Fatal("😥 Failed to load participants: ", zap.Error(err))
}
privKeyPath := viper.GetString("initiatorPrivKey")
if privKeyPath == "" {
logger.Fatal("failed to get initiator key flag value", zap.Error(err))
logger.Fatal("😥 Failed to get initiator key flag value", zap.Error(err))
}
var privateKey *rsa.PrivateKey
pass := viper.GetString("initiatorPrivKeyPassword")
if pass != "" {
// check if a password string a valid path, then read password from the file
if _, err := os.Stat(pass); err != nil {
logger.Fatal("Cant read password file", zap.Error(err))
logger.Fatal("😥 Password file: ", zap.Error(err))
}
keyStorePassword, err := os.ReadFile(pass)
if err != nil {
logger.Fatal("Error reading Password file", zap.Error(err))
logger.Fatal("😥 Error reading password file: ", zap.Error(err))
}
encryptedJSON, err := os.ReadFile(privKeyPath)
if err != nil {
logger.Fatal("cant read operator`s key file", zap.Error(err))
logger.Fatal("😥 Cant read operator`s key file", zap.Error(err))
}
privateKey, err = crypto.ConvertEncryptedPemToPrivateKey(encryptedJSON, string(keyStorePassword))
if err != nil {
Expand All @@ -191,11 +191,11 @@ var StartDKG = &cobra.Command{
dkgInitiator := initiator.New(privateKey, opMap, logger)
withdrawAddr := viper.GetString("withdrawAddress")
if withdrawAddr == "" {
logger.Fatal("failed to get withdrawal address flag value", zap.Error(err))
logger.Fatal("😥 Failed to get withdrawal address flag value: ", zap.Error(err))
}
fork := viper.GetString("fork")
if fork == "" {
logger.Fatal("failed to get fork version flag value", zap.Error(err))
logger.Fatal("😥 Failed to get fork version flag value: ", zap.Error(err))
}
var forkHEX [4]byte
switch fork {
Expand All @@ -206,35 +206,35 @@ var StartDKG = &cobra.Command{
case "now_test_network":
forkHEX = [4]byte{0x99, 0x99, 0x99, 0x99}
default:
logger.Fatal("please provide a valid fork name: mainnet, prater, or now_test_network")
logger.Fatal("😥 Please provide a valid fork name: mainnet, prater, or now_test_network")
}
owner := viper.GetString("owner")
if owner == "" {
logger.Fatal("failed to get owner address flag value", zap.Error(err))
logger.Fatal("😥 Failed to get owner address flag value: ", zap.Error(err))
}
nonce := viper.GetUint64("nonce")
withdrawPubKey, err := hex.DecodeString(withdrawAddr)
if err != nil {
logger.Fatal("failed to decode withdrawal public key", zap.Error(err))
logger.Fatal("😥 Failed to decode withdrawal public key: ", zap.Error(err))
}
id := dkgInitiator.NewID()
depositData, keyShares, err := dkgInitiator.StartDKG(id, withdrawPubKey, parts, forkHEX, fork, common.HexToAddress(owner), nonce)
if err != nil {
logger.Fatal("failed to initiate DKG ceremony", zap.Error(err))
logger.Fatal("😥 Failed to initiate DKG ceremony: ", zap.Error(err))
}
// Save deposit file
logger.Info("🎯 all data is validated.")
logger.Info("🎯 All data is validated.")
depositFinalPath := fmt.Sprintf("%s/deposit_%s.json", depositResultsPath, depositData.PubKey)
logger.Info("💾 writing deposit data json to file", zap.String("path", depositFinalPath))
logger.Info("💾 Writing deposit data json to file", zap.String("path", depositFinalPath))
err = utils.WriteJSON(depositFinalPath, []initiator.DepositDataJson{*depositData})
if err != nil {
logger.Warn("Failed writing deposit data file", zap.Error(err))
logger.Warn("Failed writing deposit data file: ", zap.Error(err))
}
payloadFinalPath := fmt.Sprintf("%s/payload_%v.json", ssvPayloadResultsPath, depositData.PubKey)
logger.Info("💾 writing keyshares payload to file", zap.String("path", payloadFinalPath))
logger.Info("💾 Writing keyshares payload to file", zap.String("path", payloadFinalPath))
err = utils.WriteJSON(payloadFinalPath, keyShares)
if err != nil {
logger.Warn("Failed writing keyshares file", zap.Error(err))
logger.Warn("Failed writing keyshares file: ", zap.Error(err))
}

fmt.Println(`
Expand Down Expand Up @@ -262,7 +262,7 @@ func loadParticipants(flagdata []string) ([]uint64, error) {
for i := 0; i < len(flagdata); i++ {
opid, err := strconv.ParseUint(flagdata[i], 10, strconv.IntSize)
if err != nil {
return nil, fmt.Errorf("cant load operator err: %v , data: %v, ", err, flagdata[i])
return nil, fmt.Errorf("😥 cant load operator err: %v , data: %v, ", err, flagdata[i])
}
partsarr = append(partsarr, opid)
}
Expand Down
18 changes: 9 additions & 9 deletions cli/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,50 +90,50 @@ var StartDKGOperator = &cobra.Command{
}
logger := zap.L().Named("dkg-operator")
if err != nil {
logger.Warn("couldn't find config file, its ok if you are using cli params")
logger.Warn("Couldn't find config file, its ok if you are using cli params")
}
privKeyPath := viper.GetString("privKey")
if privKeyPath == "" {
logger.Fatal("failed to get operator private key flag value", zap.Error(err))
logger.Fatal("😥 Failed to get operator private key flag value: ", zap.Error(err))
}
var privateKey *rsa.PrivateKey
pass := viper.GetString("password")
if pass != "" {
// check if a password string a valid path, then read password from the file
if _, err := os.Stat(pass); err != nil {
logger.Fatal("Cant read password file", zap.Error(err))
logger.Fatal("Password file: ", zap.Error(err))
}
keyStorePassword, err := os.ReadFile(pass)
if err != nil {
logger.Fatal("Error reading Password file", zap.Error(err))
logger.Fatal("😥 Error reading password file: ", zap.Error(err))
return err
}
encryptedJSON, err := os.ReadFile(privKeyPath)
if err != nil {
logger.Fatal("cant read operator`s key file", zap.Error(err))
logger.Fatal("😥 Cant read operator`s key file: ", zap.Error(err))
return err
}
privateKey, err = crypto.ConvertEncryptedPemToPrivateKey(encryptedJSON, string(keyStorePassword))
if err != nil {
logger.Fatal("cant read operator`s key file", zap.Error(err))
logger.Fatal("😥 Cant read operator`s key file: ", zap.Error(err))
return err
}
} else {
logger.Fatal("please provide password string or path to password file", zap.Error(err))
logger.Fatal("😥 Please provide password string or path to password file: ", zap.Error(err))
return err
}
srv := operator.New(privateKey, logger)
port := viper.GetUint64("port")
if port == 0 {
logger.Fatal("failed to get operator info file path flag value", zap.Error(err))
logger.Fatal("😥 Failed to get operator info file path flag value: ", zap.Error(err))
return err
}
pubKey, err := crypto.EncodePublicKey(&privateKey.PublicKey)
if err != nil {
logger.Fatal(err.Error())
return err
}
logger.Info("starting DKG operator", zap.Uint64("port", port), zap.String("public key", string(pubKey)))
logger.Info("🚀 Starting DKG operator", zap.Uint64("port", port), zap.String("public key", string(pubKey)))
if err := srv.Start(uint16(port)); err != nil {
log.Fatalf("Error in operator %v", err)
return err
Expand Down
6 changes: 3 additions & 3 deletions pkgs/board/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewBoard(
}

func (b *Board) PushDeals(bundle *dkg.DealBundle) {
b.logger.Debug("pushing deal bundle")
b.logger.Debug("Pushing deal bundle: ", zap.Int("num of deals", len(bundle.Deals)))

byts, err := wire2.EncodeDealBundle(bundle)
if err != nil {
Expand All @@ -53,7 +53,7 @@ func (b *Board) IncomingDeal() <-chan dkg.DealBundle {
}

func (b *Board) PushResponses(bundle *dkg.ResponseBundle) {
b.logger.Info("pushing response bundle")
b.logger.Info("Pushing response bundle: ", zap.Int("num of responses", len(bundle.Responses)))

byts, err := wire2.EncodeResponseBundle(bundle)
if err != nil {
Expand All @@ -77,7 +77,7 @@ func (b *Board) IncomingResponse() <-chan dkg.ResponseBundle {
}

func (b *Board) PushJustifications(bundle *dkg.JustificationBundle) {
b.logger.Info("pushing justification bundle")
b.logger.Info("Pushing justification bundle: ", zap.Int("num of responses", len(bundle.Justifications)))

byts, err := wire2.EncodeJustificationBundle(bundle)
if err != nil {
Expand Down
Loading

0 comments on commit 2495c75

Please sign in to comment.