From de71b973717020245020d4dffd6c2ed1fa5d6841 Mon Sep 17 00:00:00 2001 From: Chalith Desaman Date: Tue, 1 Dec 2020 14:23:28 +0530 Subject: [PATCH] Stopped skipping self pub key from the config unl (#179) --- src/conf.cpp | 9 +++++---- test/local-cluster/cluster-create.sh | 13 ++++++++++--- test/vm-cluster/cluster.sh | 13 ++++++++++--- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/conf.cpp b/src/conf.cpp index c0b2d9db..26abd151 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -91,6 +91,9 @@ namespace conf crypto::generate_signing_keys(cfg.pubkey, cfg.seckey); binpair_to_hex(cfg); + //Add self pubkey to the unl. + cfg.unl.emplace(cfg.pubkey); + cfg.operating_mode = OPERATING_MODE::PROPOSER; cfg.peerport = 22860; cfg.roundtime = 1000; @@ -364,8 +367,7 @@ namespace conf reinterpret_cast(nodepk.data()), nodepk.length()); - if (hex_pubkey != cfg.pubkeyhex) - unl.push_back(hex_pubkey); // We do not save our own pubkey in config file. + unl.push_back(hex_pubkey); } d.insert_or_assign("unl", unl); @@ -450,8 +452,7 @@ namespace conf return -1; } - // Populate unl. - cfg.unl.emplace(cfg.pubkey); // Add self pubkey to unl. + // Populate unl. unl::init(cfg.unl); // Populate runtime contract execution args. diff --git a/test/local-cluster/cluster-create.sh b/test/local-cluster/cluster-create.sh index 3da3bc25..d301cbb3 100755 --- a/test/local-cluster/cluster-create.sh +++ b/test/local-cluster/cluster-create.sh @@ -102,11 +102,17 @@ function joinarr { arr=("${!arrname}") skip=$2 + let prevlast=$ncount-2 + # Resetting prevlast if nothing is given to skip. + if [ $skip -lt 0 ] + then + let prevlast=prevlast+1 + fi + j=0 str="[" for (( i=0; i<$ncount; i++ )) do - let prevlast=$ncount-2 if [ "$i" != "$skip" ] then str="$str'${arr[i]}'" @@ -123,12 +129,13 @@ function joinarr { echo $str } -# Loop through all nodes hp.cfg and inject peer and unl lists (skip self node). +# Loop through all nodes hp.cfg and inject peer and unl lists (skip self node for peers). for (( j=0; j<$ncount; j++ )) do let n=$j+1 mypeers=$(joinarr peers $j) - myunl=$(joinarr pubkeys $j) + # Skip param is passed as -1 to stop skipping self pubkey. + myunl=$(joinarr pubkeys -1) pushd ./node$n/cfg > /dev/null 2>&1 mv hp.cfg tmp.json # nodejs needs file extension to be .json diff --git a/test/vm-cluster/cluster.sh b/test/vm-cluster/cluster.sh index 5241f898..f9eced57 100755 --- a/test/vm-cluster/cluster.sh +++ b/test/vm-cluster/cluster.sh @@ -307,11 +307,17 @@ function joinarr { arr=("${!arrname}") skip=$2 + let prevlast=$ncount-2 + # Resetting prevlast if nothing is given to skip. + if [ $skip -lt 0 ] + then + let prevlast=prevlast+1 + fi + j=0 str="[" for (( i=0; i<$vmcount; i++ )) do - let prevlast=$vmcount-2 if [ "$i" != "$skip" ] then str="$str\"${arr[i]}\"" @@ -333,9 +339,10 @@ for (( j=0; j<$vmcount; j++ )) do let n=$j+1 - # Prepare peer and unl lists (skip self node). + # Prepare peer and unl lists (skip self node for peers). mypeers=$(joinarr peers $j) - myunl=$(joinarr pubkeys $j) + # Skip param is passed as -1 to stop skipping self pubkey. + myunl=$(joinarr pubkeys -1) # Merge json contents to produce final contract config. echo "$(cat ./cfg/node$n.cfg)" \