Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Provide multi addresses instead of p2p peer ids to the manifest file (#…
Browse files Browse the repository at this point in the history
…1272)

* Provide multi addresses instead of p2p peer ids to the manifest file

* Update README

* Set trimmed address and BLS key to validator account
  • Loading branch information
Stefan-Ethernal authored Mar 8, 2023
1 parent 0ea8874 commit 39dc415
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 32 deletions.
3 changes: 1 addition & 2 deletions command/genesis/polybft_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ func (p *genesisParams) generatePolyBftChainConfig() error {

// set genesis validators as boot nodes if boot nodes not provided via CLI
if len(p.bootnodes) == 0 {
bootNodeMultiAddr := fmt.Sprintf("/ip4/%s/tcp/%d/p2p/%s", "127.0.0.1", bootnodePortStart+i, validator.NodeID)
chainConfig.Bootnodes = append(chainConfig.Bootnodes, bootNodeMultiAddr)
chainConfig.Bootnodes = append(chainConfig.Bootnodes, validator.MultiAddr)
}
}

Expand Down
2 changes: 1 addition & 1 deletion command/genesis/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func ReadValidatorsByPrefix(dir, prefix string) ([]*polybft.Validator, error) {
BlsPrivateKey: account.Bls,
BlsKey: hex.EncodeToString(account.Bls.PublicKey().Marshal()),
BlsSignature: blsSignature,
NodeID: nodeID,
MultiAddr: fmt.Sprintf("/ip4/%s/tcp/%d/p2p/%s", "127.0.0.1", bootnodePortStart+int64(i), nodeID),
}
}

Expand Down
29 changes: 15 additions & 14 deletions command/polybftmanifest/manifest_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/0xPolygon/polygon-edge/command/genesis"
"github.com/0xPolygon/polygon-edge/consensus/polybft"
"github.com/0xPolygon/polygon-edge/types"
"github.com/multiformats/go-multiaddr"
"github.com/spf13/cobra"
)

Expand All @@ -26,7 +27,6 @@ const (
defaultValidatorPrefixPath = "test-chain-"
defaultManifestPath = "./manifest.json"

nodeIDLength = 53
ecdsaAddressLength = 40
blsKeyLength = 256
blsSignatureLength = 128
Expand Down Expand Up @@ -79,7 +79,7 @@ func setFlags(cmd *cobra.Command) {
&params.validators,
validatorsFlag,
[]string{},
"validators defined by user (format: <node id>:<ECDSA address>:<public BLS key>:<BLS signature>)",
"validators defined by user (format: <P2P multi address>:<ECDSA address>:<public BLS key>:<BLS signature>)",
)

cmd.Flags().StringVar(
Expand Down Expand Up @@ -153,33 +153,34 @@ func (p *manifestInitParams) getValidatorAccounts() ([]*polybft.Validator, error
validators := make([]*polybft.Validator, len(p.validators))
for i, validator := range p.validators {
parts := strings.Split(validator, ":")

if len(parts) != 4 {
return nil, fmt.Errorf("expected 4 parts provided in the following format "+
"<nodeId:ECDSA address:blsKey:blsSignature>, but got %d part(s)",
"<P2P multi address:ECDSA address:public BLS key:BLS signature>, but got %d part(s)",
len(parts))
}

if len(parts[0]) != nodeIDLength {
return nil, fmt.Errorf("invalid node id: %s", parts[0])
if _, err := multiaddr.NewMultiaddr(parts[0]); err != nil {
return nil, fmt.Errorf("invalid P2P multi address '%s' provided: %w ", parts[0], err)
}

if len(parts[1]) != ecdsaAddressLength {
return nil, fmt.Errorf("invalid address: %s", parts[1])
trimmedAddress := strings.TrimPrefix(parts[1], "0x")
if len(trimmedAddress) != ecdsaAddressLength {
return nil, fmt.Errorf("invalid ECDSA address: %s", parts[1])
}

if len(strings.TrimPrefix(parts[2], "0x")) != blsKeyLength {
return nil, fmt.Errorf("invalid bls key: %s", parts[2])
trimmedBLSKey := strings.TrimPrefix(parts[2], "0x")
if len(trimmedBLSKey) != blsKeyLength {
return nil, fmt.Errorf("invalid BLS key: %s", parts[2])
}

if len(parts[3]) != blsSignatureLength {
return nil, fmt.Errorf("invalid bls signature: %s", parts[3])
return nil, fmt.Errorf("invalid BLS signature: %s", parts[3])
}

validators[i] = &polybft.Validator{
NodeID: parts[0],
Address: types.StringToAddress(parts[1]),
BlsKey: parts[2],
MultiAddr: parts[0],
Address: types.StringToAddress(trimmedAddress),
BlsKey: trimmedBLSKey,
BlsSignature: parts[3],
Balance: balance,
}
Expand Down
9 changes: 5 additions & 4 deletions consensus/polybft/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ In order to do so, run `make compile-core-contracts`.
go build -o polygon-edge .
```

2. Init secrets - this command is used to generate private keys (ECDSA, BLS as well as P2P networking node id). `--data-dir` denotes folder prefix names and `--num` how many accounts need to be created. **This command is for testing purposes only.**
2. Init secrets - this command is used to generate account secrets (ECDSA, BLS as well as P2P networking node id). `--data-dir` denotes folder prefix names and `--num` how many accounts need to be created. **This command is for testing purposes only.**

```bash
polygon-edge polybft-secrets --data-dir test-chain- --num 4
Expand All @@ -42,12 +42,13 @@ In order to do so, run `make compile-core-contracts`.
```

- validators information are scafollded on multiple hosts and therefore necessary information are supplied using `--validators` flag. Validator information needs to be supplied in the strictly following format:
`<p2p node id>:<public ECDSA address>:<public BLS key>:<BLS signature>`.
`<multi address>:<public ECDSA address>:<public BLS key>:<BLS signature>`.
**Note:** when specifying validators via validators flag, entire multi address must be specified.

```bash
polygon-edge manifest
--validators 16Uiu2HAmTkqGixWVxshMbbgtXhTUP8zLCZZiG1UyCNtxLhCkZJuv:0xDcBe0024206ec42b0Ef4214Ac7B71aeae1A11af0:1cf134e02c6b2afb2ceda50bf2c9a01da367ac48f7783ee6c55444e1cab418ec0f52837b90a4d8cf944814073fc6f2bd96f35366a3846a8393e3cb0b19197cde23e2b40c6401fa27ff7d0c36779d9d097d1393cab6fc1d332f92fb3df850b78703b2989d567d1344e219f0667a1863f52f7663092276770cf513f9704b5351c4:11b18bde524f4b02258a8d196b687f8d8e9490d536718666dc7babca14eccb631c238fb79aa2b44a5a4dceccad2dd797f537008dda185d952226a814c1acf7c2
[--validators 16Uiu2HAm1kVEh4uVw41WuhDfreCaVuj3kiWZy44kbnJrZnwnMKDW:0x2da750eD4AE1D5A7F7c996Faec592F3d44060e90:088d92c25b5f278750534e8a902da604a1aa39b524b4511f5f47c3a386374ca3031b667beb424faef068a01cee3428a1bc8c1c8bab826f30a1ee03fbe90cb5f01abcf4abd7af3bbe83eaed6f82179b9cbdc417aad65d919b802d91c2e1aaefec27ba747158bc18a0556e39bfc9175c099dd77517a85731894bbea3d191a622bc:08dc3006352fdc01b331907fd3a68d4d68ed40329032598c1c0faa260421d66720965ace3ba29c6d6608ec1facdbf4624bca72df36c34afd4bdd753c4dfe049c]
--validators /ip4/127.0.0.1/tcp/30301/p2p/16Uiu2HAmV5hqAp77untfJRorxqKmyUxgaVn8YHFjBJm9gKMms3mr:0xDcBe0024206ec42b0Ef4214Ac7B71aeae1A11af0:1cf134e02c6b2afb2ceda50bf2c9a01da367ac48f7783ee6c55444e1cab418ec0f52837b90a4d8cf944814073fc6f2bd96f35366a3846a8393e3cb0b19197cde23e2b40c6401fa27ff7d0c36779d9d097d1393cab6fc1d332f92fb3df850b78703b2989d567d1344e219f0667a1863f52f7663092276770cf513f9704b5351c4:11b18bde524f4b02258a8d196b687f8d8e9490d536718666dc7babca14eccb631c238fb79aa2b44a5a4dceccad2dd797f537008dda185d952226a814c1acf7c2
[--validators /ip4/127.0.0.1/tcp/30302/p2p/16Uiu2HAmGmidRQY5BGJPGVRF8p1pYFdfzuf1StHzXGLDizuxJxex:0x2da750eD4AE1D5A7F7c996Faec592F3d44060e90:088d92c25b5f278750534e8a902da604a1aa39b524b4511f5f47c3a386374ca3031b667beb424faef068a01cee3428a1bc8c1c8bab826f30a1ee03fbe90cb5f01abcf4abd7af3bbe83eaed6f82179b9cbdc417aad65d919b802d91c2e1aaefec27ba747158bc18a0556e39bfc9175c099dd77517a85731894bbea3d191a622bc:08dc3006352fdc01b331907fd3a68d4d68ed40329032598c1c0faa260421d66720965ace3ba29c6d6608ec1facdbf4624bca72df36c34afd4bdd753c4dfe049c]
[--path ./manifest.json] [--premine-validators 100]
```

Expand Down
8 changes: 4 additions & 4 deletions consensus/polybft/polybft_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@ type Validator struct {
BlsKey string
BlsSignature string
Balance *big.Int
NodeID string
MultiAddr string
}

type validatorRaw struct {
Address types.Address `json:"address"`
BlsKey string `json:"blsKey"`
BlsSignature string `json:"blsSignature"`
Balance *string `json:"balance"`
NodeID string `json:"nodeId"`
MultiAddr string `json:"multiAddr"`
}

func (v *Validator) MarshalJSON() ([]byte, error) {
raw := &validatorRaw{Address: v.Address, BlsKey: v.BlsKey, NodeID: v.NodeID, BlsSignature: v.BlsSignature}
raw := &validatorRaw{Address: v.Address, BlsKey: v.BlsKey, MultiAddr: v.MultiAddr, BlsSignature: v.BlsSignature}
raw.Balance = types.EncodeBigInt(v.Balance)

return json.Marshal(raw)
Expand All @@ -112,7 +112,7 @@ func (v *Validator) UnmarshalJSON(data []byte) error {
v.Address = raw.Address
v.BlsKey = raw.BlsKey
v.BlsSignature = raw.BlsSignature
v.NodeID = raw.NodeID
v.MultiAddr = raw.MultiAddr
v.Balance, err = types.ParseUint256orHex(raw.Balance)

if err != nil {
Expand Down
12 changes: 5 additions & 7 deletions e2e-polybft/framework/test-cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,13 @@ func NewTestCluster(t *testing.T, validatorsCount int, opts ...ClusterOption) *T
require.NoError(t, err)

if cluster.Config.BootnodeCount > 0 {
cnt := cluster.Config.BootnodeCount
if len(validators) < cnt {
cnt = len(validators)
bootNodesCnt := cluster.Config.BootnodeCount
if len(validators) < bootNodesCnt {
bootNodesCnt = len(validators)
}

for i := 0; i < cnt; i++ {
maddr := fmt.Sprintf("/ip4/%s/tcp/%d/p2p/%s",
"127.0.0.1", cluster.initialPort+int64(i+1), validators[i].NodeID)
args = append(args, "--bootnode", maddr)
for i := 0; i < bootNodesCnt; i++ {
args = append(args, "--bootnode", validators[i].MultiAddr)
}
}

Expand Down

0 comments on commit 39dc415

Please sign in to comment.