Skip to content

Commit

Permalink
Merge pull request #4524 from ElrondNetwork/merge-rc-v1.4.0-in-multis…
Browse files Browse the repository at this point in the history
…igner

Merge rc v1.4.0 in multisigner
  • Loading branch information
iulianpascalau authored Sep 28, 2022
2 parents bb1d9a4 + a09acff commit 7430831
Show file tree
Hide file tree
Showing 632 changed files with 10,884 additions and 39,581 deletions.
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
## Description of the reasoning behind the pull request (what feature was missing / how the problem was manifesting itself / what was the motive behind the refactoring)
## Reasoning behind the pull request
-
-
-

## Proposed Changes
## Proposed changes
-
-
-
Expand Down
2 changes: 1 addition & 1 deletion .github/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
changelog:
exclude:
labels:
- ignore-for-release
- ignore-for-release-notes
categories:
- title: Breaking Changes
labels:
Expand Down
1 change: 1 addition & 0 deletions api/shared/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

var log = logger.GetOrCreate("api/shared/logging")

const thresholdMinAPICallDurationToLog = 200 * time.Millisecond

// LogAPIActionDurationIfNeeded will log the duration of an action triggered by an API call if it's above a threshold
Expand Down
89 changes: 71 additions & 18 deletions cmd/keygenerator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"crypto/rand"
"encoding/hex"
"encoding/pem"
"fmt"
Expand All @@ -19,6 +20,7 @@ import (
"github.com/ElrondNetwork/elrond-go-crypto/signing/ed25519"
"github.com/ElrondNetwork/elrond-go-crypto/signing/mcl"
logger "github.com/ElrondNetwork/elrond-go-logger"
libp2pCrypto "github.com/libp2p/go-libp2p-core/crypto"
"github.com/urfave/cli"
)

Expand All @@ -33,6 +35,7 @@ type cfg struct {

const validatorType = "validator"
const walletType = "wallet"
const p2pType = "p2p"
const bothType = "both"
const minedWalletPrefixKeys = "mined-wallet"
const nopattern = "nopattern"
Expand Down Expand Up @@ -76,9 +79,10 @@ VERSION:
keyType = cli.StringFlag{
Name: "key-type",
Usage: fmt.Sprintf(
"What kind of keys should generate. Available options: %s, %s, %s, %s",
"What kind of keys should generate. Available options: %s, %s, %s, %s, %s",
validatorType,
walletType,
p2pType,
bothType,
minedWalletPrefixKeys),
Value: "validator",
Expand Down Expand Up @@ -116,10 +120,12 @@ VERSION:

walletKeyFilenameTemplate = "walletKey%s.pem"
validatorKeyFilenameTemplate = "validatorKey%s.pem"
p2pKeyFilenameTemplate = "p2pKey%s.pem"

log = logger.GetOrCreate("keygenerator")

validatorPubKeyConverter, _ = pubkeyConverter.NewHexPubkeyConverter(blsPubkeyLen)
p2pPubKeyConverter = NewP2pConverter()
walletPubKeyConverter, _ = pubkeyConverter.NewBech32PubkeyConverter(txSignPubkeyLen, log)
)

Expand Down Expand Up @@ -157,21 +163,22 @@ func main() {
}

func process() error {
validatorKeys, walletKeys, err := generateKeys(argsConfig.keyType, argsConfig.numKeys, argsConfig.prefixPattern, argsConfig.shardIDByte)
validatorKeys, walletKeys, p2pKeys, err := generateKeys(argsConfig.keyType, argsConfig.numKeys, argsConfig.prefixPattern, argsConfig.shardIDByte)
if err != nil {
return err
}

return outputKeys(validatorKeys, walletKeys, argsConfig.consoleOut, argsConfig.noSplit)
return outputKeys(validatorKeys, walletKeys, p2pKeys, argsConfig.consoleOut, argsConfig.noSplit)
}

func generateKeys(typeKey string, numKeys int, prefix string, shardID int) ([]key, []key, error) {
func generateKeys(typeKey string, numKeys int, prefix string, shardID int) ([]key, []key, []key, error) {
if numKeys < 1 {
return nil, nil, fmt.Errorf("number of keys should be a number greater or equal to 1")
return nil, nil, nil, fmt.Errorf("number of keys should be a number greater or equal to 1")
}

validatorKeys := make([]key, 0)
walletKeys := make([]key, 0)
p2pKeys := make([]key, 0)
var err error

blockSigningGenerator := signing.NewKeyGenerator(mcl.NewSuiteBLS12())
Expand All @@ -182,35 +189,68 @@ func generateKeys(typeKey string, numKeys int, prefix string, shardID int) ([]ke
case validatorType:
validatorKeys, err = generateKey(blockSigningGenerator, validatorKeys)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
case walletType:
walletKeys, err = generateKey(txSigningGenerator, walletKeys)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
case p2pType:
p2pKeys, err = generateP2pKey(p2pKeys)
if err != nil {
return nil, nil, nil, err
}
// TODO: change this behaviour, maybe list of options instead of both type
case bothType:
validatorKeys, err = generateKey(blockSigningGenerator, validatorKeys)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}

walletKeys, err = generateKey(txSigningGenerator, walletKeys)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}

case minedWalletPrefixKeys:
walletKeys, err = generateMinedWalletKeys(txSigningGenerator, walletKeys, prefix, shardID)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
default:
return nil, nil, fmt.Errorf("unknown key type %s", argsConfig.keyType)
return nil, nil, nil, fmt.Errorf("unknown key type %s", argsConfig.keyType)
}
}

return validatorKeys, walletKeys, nil
return validatorKeys, walletKeys, p2pKeys, nil
}

func generateP2pKey(list []key) ([]key, error) {
privateKey, publicKey, err := libp2pCrypto.GenerateSecp256k1Key(rand.Reader)
if err != nil {
return nil, err
}

skBytes, err := privateKey.Raw()
if err != nil {
return nil, err
}

pkBytes, err := publicKey.Raw()
if err != nil {
return nil, err
}

list = append(
list,
key{
skBytes: skBytes,
pkBytes: pkBytes,
},
)

return list, nil
}

func generateKey(keyGen crypto.KeyGenerator, list []key) ([]key, error) {
Expand Down Expand Up @@ -284,18 +324,19 @@ func keyInShard(keyBytes []byte, shardID byte) bool {
func outputKeys(
validatorKeys []key,
walletKeys []key,
p2pKeys []key,
consoleOut bool,
noSplit bool,
) error {
if consoleOut {
return printKeys(validatorKeys, walletKeys)
return printKeys(validatorKeys, walletKeys, p2pKeys)
}

return saveKeys(validatorKeys, walletKeys, noSplit)
return saveKeys(validatorKeys, walletKeys, p2pKeys, noSplit)
}

func printKeys(validatorKeys []key, walletKeys []key) error {
if len(validatorKeys)+len(walletKeys) == 0 {
func printKeys(validatorKeys, walletKeys, p2pKeys []key) error {
if len(validatorKeys)+len(walletKeys)+len(p2pKeys) == 0 {
return fmt.Errorf("internal error: no keys to print")
}

Expand All @@ -312,6 +353,12 @@ func printKeys(validatorKeys []key, walletKeys []key) error {
errFound = err
}
}
if len(p2pKeys) > 0 {
err := printSliceKeys("P2p keys:", p2pKeys, p2pPubKeyConverter)
if err != nil {
errFound = err
}
}

return errFound
}
Expand Down Expand Up @@ -348,8 +395,8 @@ func writeKeyToStream(writer io.Writer, key key, pubkeyConverter core.PubkeyConv
return pem.Encode(writer, &blk)
}

func saveKeys(validatorKeys []key, walletKeys []key, noSplit bool) error {
if len(validatorKeys)+len(walletKeys) == 0 {
func saveKeys(validatorKeys, walletKeys, p2pKeys []key, noSplit bool) error {
if len(validatorKeys)+len(walletKeys)+len(p2pKeys) == 0 {
return fmt.Errorf("internal error: no keys to save")
}

Expand All @@ -366,6 +413,12 @@ func saveKeys(validatorKeys []key, walletKeys []key, noSplit bool) error {
errFound = err
}
}
if len(p2pKeys) > 0 {
err := saveSliceKeys(p2pKeyFilenameTemplate, p2pKeys, p2pPubKeyConverter, noSplit)
if err != nil {
errFound = err
}
}

return errFound
}
Expand Down
45 changes: 45 additions & 0 deletions cmd/keygenerator/p2pConverter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"fmt"

libp2pCrypto "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer"
)

type p2pConverter struct{}

// NewP2pConverter creates a new instance of p2p converter
func NewP2pConverter() *p2pConverter {
return &p2pConverter{}
}

// Len return zero
func (p *p2pConverter) Len() int {
return 0
}

// Decode does nothing
func (p *p2pConverter) Decode(humanReadable string) ([]byte, error) {
return nil, fmt.Errorf("not implemented")
}

// Encode encodes a byte array representing public key as peer ID string
func (p *p2pConverter) Encode(pkBytes []byte) string {
pubKey, err := libp2pCrypto.UnmarshalSecp256k1PublicKey(pkBytes)
if err != nil {
return ""
}

id, err := peer.IDFromPublicKey(pubKey)
if err != nil {
return ""
}

return id.Pretty()
}

// IsInterfaceNil returns true if there is no value under the interface
func (p *p2pConverter) IsInterfaceNil() bool {
return p == nil
}
5 changes: 5 additions & 0 deletions cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,11 @@
[Debug.EpochStart]
GoRoutineAnalyserEnabled = true
ProcessDataTrieOnCommitEpoch = true
[Debug.Process]
Enabled = true
DebuggingLogLevel = "*:DEBUG,p2p:TRACE,debug:DEBUG,process:TRACE,intercept:TRACE"
GoRoutinesDump = true
PollingTimeInSeconds = 240 # 4 minutes

[Health]
IntervalVerifyMemoryInSeconds = 30
Expand Down
15 changes: 12 additions & 3 deletions cmd/node/config/enableEpochs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,29 @@
CheckExecuteOnReadOnlyEnableEpoch = 1

# ESDTMetadataContinuousCleanupEnableEpoch represents the epoch when esdt metadata is automatically deleted according to inshard liquidity
ESDTMetadataContinuousCleanupEnableEpoch = 4
ESDTMetadataContinuousCleanupEnableEpoch = 1

# HeartbeatDisableEpoch represents the epoch when heartbeat v1 messages stop being sent and processed
HeartbeatDisableEpoch = 2
HeartbeatDisableEpoch = 1

# MiniBlockPartialExecutionEnableEpoch represents the epoch when mini block partial execution will be enabled
MiniBlockPartialExecutionEnableEpoch = 3
MiniBlockPartialExecutionEnableEpoch = 1

# FixAsyncCallBackArgsListEnableEpoch represents the epoch when the async callback arguments lists fix will be enabled
FixAsyncCallBackArgsListEnableEpoch = 1

# SetSenderInEeiOutputTransferEnableEpoch represents the epoch when setting the sender in eei output transfers will be enabled
SetSenderInEeiOutputTransferEnableEpoch = 4

# RefactorPeersMiniBlocksEnableEpoch represents the epoch when refactor of the peers mini blocks will be enabled
RefactorPeersMiniBlocksEnableEpoch = 5

# BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers
BLSMultiSignerEnableEpoch = [
{ EnableEpoch = 0, Type = "no-KOSK"},
{ EnableEpoch = 3, Type = "KOSK"}
]

# MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch
MaxNodesChangeEnableEpoch = [
{ EpochEnable = 0, MaxNumNodes = 36, NodesToShufflePerShard = 4 },
Expand Down
3 changes: 3 additions & 0 deletions cmd/node/config/external.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
# Password is used to authorize an observer to push event data
Password = ""

# RequestTimeoutSec defines the timeout in seconds for the http client
RequestTimeoutSec = 60

# CovalentConnector defines settings related to covalent indexer
[CovalentConnector]
# This flag shall only be used for observer nodes
Expand Down
14 changes: 0 additions & 14 deletions cmd/node/config/p2p.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@
#If the port = 0, the node will search for a free port on the machine and use it
Port = "37373-38383"

#Seed represents the seed string generator for p2p identity (used during authentication and message passing).
#An empty Seed value will mean that the identity will be generated randomly in a secure cryptographically manner.
#The seed provided in this string can be of any length.
#########################################################################################
# WARNING! FOR SECURITY REASONS, ONE MIGHT USE A GENERATED STRING AS LONG AS POSSIBLE! #
# IT IS RECOMMENDED THAT THE SEED FIELD SHOULD REMAIN EMPTY (NO CHARACTERS BETWEEN "") #
# THIS SEED WILL BE USED FOR P2P'S PRIVATE KEY GENERATION. SAME SEED USED WILL LEAD TO #
# THE GENERATION OF THE SAME P2P IDENTITY. #
# SPECIFY A SEED VALUE IF YOU KNOW WHAT YOU ARE DOING! #
#########################################################################################
#The seed provided will be hashed using SHA256 and the resulting 32 byte length byte array will be used in
#p2p identity generation
Seed = ""

#ThresholdMinConnectedPeers represents the minimum number of connections a node should have before it can start
#the sync and consensus mechanisms
ThresholdMinConnectedPeers = 3
Expand Down
9 changes: 9 additions & 0 deletions cmd/node/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@ var (
Usage: "Boolean flag for enabling the node to generate a signing key when it starts (if the validatorKey.pem" +
" file is present, setting this flag to true will overwrite the BLS key used by the node)",
}

// p2pKeyPemFile defines the flag for the path to the key pem file used for p2p signing
p2pKeyPemFile = cli.StringFlag{
Name: "p2p-key-pem-file",
Usage: "The `filepath` for the PEM file which contains the secret keys for the p2p key. If this is not specified a new key will be generated (internally) by default.",
Value: "./config/p2pKey.pem",
}
)

func getFlags() []cli.Flag {
Expand Down Expand Up @@ -397,6 +404,7 @@ func getFlags() []cli.Flag {
disableConsensusWatchdog,
serializeSnapshots,
noKey,
p2pKeyPemFile,
}
}

Expand Down Expand Up @@ -434,6 +442,7 @@ func applyFlags(ctx *cli.Context, cfgs *config.Configs, flagsConfig *config.Cont
cfgs.ConfigurationPathsHolder.GasScheduleDirectoryName = ctx.GlobalString(gasScheduleConfigurationDirectory.Name)
cfgs.ConfigurationPathsHolder.SmartContracts = ctx.GlobalString(smartContractsFile.Name)
cfgs.ConfigurationPathsHolder.ValidatorKey = ctx.GlobalString(validatorKeyPemFile.Name)
cfgs.ConfigurationPathsHolder.P2pKey = ctx.GlobalString(p2pKeyPemFile.Name)

if ctx.IsSet(startInEpoch.Name) {
log.Debug("start in epoch is enabled")
Expand Down
Loading

0 comments on commit 7430831

Please sign in to comment.