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

Merge v1.4.0 feat/p2p-separate-repo #4503

Merged
merged 82 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
1728715
factory: refactor into subpackages
AdoAdoAdo Jul 15, 2022
3036288
factory: add test exported
AdoAdoAdo Jul 15, 2022
03b9ebf
factory: add mocks for components
AdoAdoAdo Jul 15, 2022
d394ce1
add a multi signer container for versioned multisigner
AdoAdoAdo Jul 19, 2022
03ce699
move MultiSignerContainer interface to common and fix tests
AdoAdoAdo Jul 20, 2022
f96f3c7
create a bootstrap components test implementation
AdoAdoAdo Jul 21, 2022
bdeee82
Merge pull request #4298 from ElrondNetwork/refactor-factory
AdoAdoAdo Jul 21, 2022
811288a
added signing component for consensus:
ssd04 Jul 22, 2022
379055d
consensus signing: unit tests for aggSig and verifyAggSig
ssd04 Jul 22, 2022
7116ec6
integrate refactored stateless multisigner
AdoAdoAdo Jul 22, 2022
4cb32fc
consensus: added signature handler interface
ssd04 Jul 22, 2022
2791efc
consensus: fix unit tests after multisigner integration
AdoAdoAdo Jul 22, 2022
66a6576
factory: fix integration tests
AdoAdoAdo Jul 22, 2022
8709e7f
signature holder component: renamings and comment updates
ssd04 Jul 22, 2022
36d9dbc
unit tests and mocks fixes
ssd04 Jul 22, 2022
1cfff4e
Merge branch 'feat/kosk-bls-multisigner' into update-bls-multisigner
AdoAdoAdo Jul 25, 2022
93ca11b
update signature handler interface; remove own index from signatures …
ssd04 Jul 25, 2022
e7a4f5f
factory: add unit tests for multisig container
AdoAdoAdo Jul 25, 2022
7c5aa28
factory: removed from argument list unnecessary crypto params, fixed …
AdoAdoAdo Jul 26, 2022
a2f8e2c
factory: update comments
AdoAdoAdo Jul 26, 2022
bb6e447
fixes after review: nil checks and errors updates
ssd04 Jul 28, 2022
9f378a5
factory crypto: error and comments updates
ssd04 Jul 29, 2022
1e94967
Merge pull request #4318 from ElrondNetwork/update-bls-multisigner
ssd04 Jul 29, 2022
e525002
Merge branch 'feat/kosk-bls-multisigner' into signatures-holder-compo…
ssd04 Jul 29, 2022
a7c0c9d
integrate multisigner container; fix unit tests
ssd04 Aug 1, 2022
cd57cd1
fix multisigner mutex on set + unit tests
ssd04 Aug 1, 2022
d9473b0
create signature handler component for consensus
ssd04 Aug 1, 2022
f248531
remove single signer since it's not being used
ssd04 Aug 1, 2022
12f2d8d
add multi signer container stub
ssd04 Aug 1, 2022
f6cb500
consensus signing: remove multi signer set from signature handler, re…
ssd04 Aug 1, 2022
5b1e898
fixes after review:
ssd04 Aug 1, 2022
3be0b7e
fixes after review: renamings, removed TODO comment
ssd04 Aug 1, 2022
323d3f9
fixes after review: better checks for invalid input
ssd04 Aug 1, 2022
60b05ff
fixes after review: renamings, change mutex to read when applicable
ssd04 Aug 1, 2022
aac70c1
fix linter issues: return bool variable directly
ssd04 Aug 1, 2022
67ed8dd
unit tests for get current multi signer fail
ssd04 Aug 2, 2022
5969f45
fix after review: better slice allocation
ssd04 Aug 2, 2022
a7ab265
Merge pull request #4316 from ElrondNetwork/signatures-holder-component
AdoAdoAdo Aug 2, 2022
b8b0369
Merge branch 'rc/2022-july' into merge-rc-july-into-feat-kosk-bls-mul…
ssd04 Aug 2, 2022
ca40a0a
conflicts fix after merge
ssd04 Aug 2, 2022
9c1b662
factory: remove old network components test file
ssd04 Aug 2, 2022
f8fd0c7
Merge pull request #4337 from ElrondNetwork/merge-rc-july-into-feat-k…
ssd04 Aug 2, 2022
e099ad4
consensus endround: remove unused function
ssd04 Aug 2, 2022
5880e80
Merge pull request #4339 from ElrondNetwork/consensus-subround-fix-li…
ssd04 Aug 3, 2022
39e6f1a
Merge branch 'rc/2022-july' into update-kosk-bls-multisigner-rc-july
ssd04 Aug 29, 2022
2768eb7
fix merge conflicts
ssd04 Aug 29, 2022
d424b06
remove duplicate test file; fix factory api resolver unit test
ssd04 Aug 29, 2022
749e202
Merge pull request #4405 from ElrondNetwork/update-kosk-bls-multisign…
ssd04 Aug 30, 2022
b6da3f1
Merge branch 'rc/2022-july' into feat/kosk-bls-multisigner
AdoAdoAdo Sep 1, 2022
b0ee408
Merge pull request #4430 from ElrondNetwork/merge-rc-july-feat-kosk
AdoAdoAdo Sep 2, 2022
a0442ea
load pem file for p2p key as byte array
ssd04 Sep 19, 2022
12149cc
fix integration test: added p2p key path
ssd04 Sep 19, 2022
d4a9180
added p2p key option in keygenerator
ssd04 Sep 19, 2022
cd21c73
fix factory network components test
ssd04 Sep 19, 2022
9566e28
refactor to use libp2p crypto.PrivKey interface
ssd04 Sep 19, 2022
e4fc932
refactor get pk from p2p key in order to remove duplicated code
ssd04 Sep 19, 2022
a068c83
seednode: revert default value for p2pkeyfilename flag
ssd04 Sep 19, 2022
1d22b38
removed p2p rand package as it is not being used anymore
ssd04 Sep 19, 2022
6eebc53
keygenerator: added a separate converter for p2p encoding
ssd04 Sep 19, 2022
349b6f3
fixes after review: more logging + added more unit tests
ssd04 Sep 20, 2022
6cc8a00
Merge branch 'rc/v1.4.0' into load-private-key-for-p2p
ssd04 Sep 20, 2022
a0ad600
cleanup: remove seed referencies from config
ssd04 Sep 20, 2022
fa3ed86
cleanup: remove seed referencies from config - fix integration test
ssd04 Sep 20, 2022
1097ca4
Merge branch 'rc/v1.4.0' into merge-v1.4-feat-kosk
AdoAdoAdo Sep 20, 2022
bde1072
fixes after merge
AdoAdoAdo Sep 20, 2022
92fa342
Merge pull request #4487 from ElrondNetwork/merge-v1.4-feat-kosk
gabi-vuls Sep 21, 2022
b6a2105
Merge branch 'rc/v1.4.0' into merge-v1.4.0-feat-kosk-210922
AdoAdoAdo Sep 21, 2022
20b7aa7
fix signer mock
AdoAdoAdo Sep 21, 2022
1e290d8
remove logging in integration test
AdoAdoAdo Sep 21, 2022
94b10b3
Merge pull request #4494 from ElrondNetwork/merge-v1.4.0-feat-kosk-21…
AdoAdoAdo Sep 22, 2022
534f082
Merge pull request #4314 from ElrondNetwork/feat/kosk-bls-multisigner
AdoAdoAdo Sep 22, 2022
97aeb57
- updated crypto repo version
iulianpascalau Sep 22, 2022
4562f8e
Merge branch 'rc/v1.4.0' into merge-v1.4.0-load-private-key-for-p2p
ssd04 Sep 22, 2022
b2e134a
fix testscommon components: remove seed parameter
ssd04 Sep 22, 2022
8dd305e
removed network components test file from factory folder
ssd04 Sep 22, 2022
a0af5ab
Merge pull request #4502 from ElrondNetwork/merge-v1.4.0-load-private…
ssd04 Sep 22, 2022
c414b68
Merge pull request #4478 from ElrondNetwork/load-private-key-for-p2p
iulianpascalau Sep 22, 2022
1e30493
Merge branch 'rc/v1.4.0' into update-crypto-repo-version
iulianpascalau Sep 22, 2022
45b3e87
Merge pull request #4497 from ElrondNetwork/update-crypto-repo-version
gabi-vuls Sep 22, 2022
14792e2
Merge branch 'rc/v1.4.0' into feat/p2p-separate-repo
iulianpascalau Sep 22, 2022
67c8853
- fixes after merge
iulianpascalau Sep 22, 2022
07c3fb0
- fixed memory footprint tests
iulianpascalau Sep 22, 2022
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
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
}
6 changes: 6 additions & 0 deletions cmd/node/config/enableEpochs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@
# 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
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
14 changes: 0 additions & 14 deletions cmd/seednode/config/p2p.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@
#Can use single values such as 0, 10230, 15670 or a range such as 5000-10000
Port = "10000"

#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 = "seed"

# The maximum peers that will connect to this node
MaximumExpectedPeerCount = 1024

Expand Down
Loading