-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add script to run testnet + run node + config node
- Loading branch information
1 parent
221749d
commit 74e33a4
Showing
3 changed files
with
161 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package node | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
|
||
"chainspace.io/blockmania/config" | ||
) | ||
|
||
func LoadConfiguration(networkName, configRoot, runtimeRoot string, nodeID uint64) (*Config, error) { | ||
_, err := os.Stat(configRoot) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
return nil, fmt.Errorf( | ||
"Could not find the blockmania root directory `%v`", configRoot) | ||
} | ||
return nil, fmt.Errorf("Unable to access the blockmania root directory `%v`, %v", configRoot, err) | ||
} | ||
|
||
netPath := filepath.Join(configRoot, networkName) | ||
netCfg, err := config.LoadNetwork(filepath.Join(netPath, "network.yaml")) | ||
if err != nil { | ||
return nil, fmt.Errorf("Could not load network.yaml, %v", err) | ||
} | ||
|
||
nodeDir := "node-" + strconv.FormatUint(nodeID, 10) | ||
nodePath := filepath.Join(netPath, nodeDir) | ||
nodeCfg, err := config.LoadNode(filepath.Join(nodePath, "node.yaml")) | ||
if err != nil { | ||
return nil, fmt.Errorf("Could not load node.yaml, %v", err) | ||
} | ||
|
||
keys, err := config.LoadKeys(filepath.Join(nodePath, "keys.yaml")) | ||
if err != nil { | ||
return nil, fmt.Errorf("Could not load keys.yaml, %v", err) | ||
} | ||
|
||
root := configRoot | ||
if len(runtimeRoot) != 0 { | ||
root = os.ExpandEnv(runtimeRoot) | ||
} | ||
|
||
cfg := &Config{ | ||
Directory: filepath.Join(root, networkName, nodeDir), | ||
Keys: keys, | ||
Network: netCfg, | ||
NetworkName: networkName, | ||
NodeID: nodeID, | ||
Node: nodeCfg, | ||
} | ||
|
||
return cfg, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
|
||
if (( $# != 1 )); then | ||
echo "missing nodes count"; | ||
exit 1; | ||
fi | ||
|
||
# session / network name | ||
session=testnet-blockmania-${1} | ||
|
||
# destroy session if exists | ||
tmux kill-session -t ${session} | ||
pkill blockmania | ||
fuser 8080/tcp | ||
|
||
# remove existing conf | ||
rm -rf ~/.blockmania/${session} | ||
|
||
# inializes the network | ||
blockmania init -network-name ${session} -node-count ${1} | ||
|
||
echo ">> Setting up tmux session ${session}" | ||
tmux new-session -d -s ${session} | ||
|
||
tot="${1}"; | ||
for i in $(seq 1 $tot) | ||
do | ||
tmux send-keys "blockmania run -network-name ${session} -node-id ${i} -file-log info" "C-l" "C-m" | ||
if (( ${i} != $tot )); then | ||
tmux split-window | ||
tmux select-layout tiled | ||
fi | ||
|
||
done | ||
|
||
tmux attach-session -t $session |