Skip to content

Commit

Permalink
config: Add --time flag
Browse files Browse the repository at this point in the history
--time added to runner.sh and `time-per-block` is used in generation
config files.

Close #161

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
  • Loading branch information
AliceInHunterland committed Apr 17, 2024
1 parent 2694b14 commit 40a9983
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ BUILD_DIR=.docker/build
NEOBENCH_TYPE ?= NEO
NEOBENCH_FROM_COUNT ?= 1
NEOBENCH_TO_COUNT ?= 1
TIME_PER_BLOCK ?= 1000

.PHONY: help

Expand Down Expand Up @@ -112,7 +113,7 @@ config:
@echo "=> Generate configurations for single-node and four-nodes networks from templates"
@set -x \
&& cd ./cmd \
&& go run ./config/ --go-template go.protocol.template.yml --go-db leveldb --sharp-template sharp.protocol.template.yml --sharp-db LevelDBStore
&& go run ./config/ --go-template go.protocol.template.yml --go-db leveldb --sharp-template sharp.protocol.template.yml --sharp-db LevelDBStore --time-per-block $(TIME_PER_BLOCK)


# Generate transactions, dump and nodes configurations for four-nodes network
Expand Down
4 changes: 4 additions & 0 deletions cmd/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"strconv"
"strings"
"time"

"github.com/k14s/ytt/pkg/cmd/template"
"github.com/nspcc-dev/neo-go/pkg/config"
Expand All @@ -29,6 +30,7 @@ var (
goDB = flag.String("go-db", "leveldb", "database for Go node")
sharpTemplateFile = flag.String("sharp-template", "", "configuration template file for C# node")
sharpDB = flag.String("sharp-db", "LevelDBStore", "database for C# node")
timePerBlock = flag.Int("time-per-block", 5000, "Time per block in milliseconds")
)

func main() {
Expand Down Expand Up @@ -115,6 +117,7 @@ func generateGoConfig(templatePath, database, suffix string) error {
return fmt.Errorf("unable to decode node template #%d: %w", i, err)
}
template.ApplicationConfiguration.DBConfiguration.Type = database
template.ProtocolConfiguration.TimePerBlock = time.Duration(*timePerBlock) * time.Millisecond
var configFile string
nodeName, err := nodeNameFromSeedList(template.ApplicationConfiguration.P2P.Addresses, template.ProtocolConfiguration.SeedList)
if err != nil {
Expand Down Expand Up @@ -154,6 +157,7 @@ func generateSharpConfig(templatePath, storageEngine, suffix string) error {
return fmt.Errorf("unable to decode node template #%d: %w", i, err)
}
template.ApplicationConfiguration.Storage.Engine = storageEngine
template.ProtocolConfiguration.MillisecondsPerBlock = *timePerBlock
var configFile string
nodeName, err := nodeNameFromSeedList([]string{":" + strconv.Itoa(int(template.ApplicationConfiguration.P2P.Port))}, template.ProtocolConfiguration.SeedList)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export NEOBENCH_FROM_COUNT=${NEOBENCH_FROM_COUNT:-1}
export NEOBENCH_TC=${NEOBENCH_TC:-}
export NEOBENCH_TO_COUNT=${NEOBENCH_TO_COUNT:-1}
export NEOBENCH_VALIDATOR_COUNT=${NEOBENCH_VALIDATOR_COUNT:-4}
export TIME_PER_BLOCK=${TIME_PER_BLOCK:-}

show_help() {
echo "Usage of benchmark runner:"
Expand Down Expand Up @@ -50,6 +51,7 @@ show_help() {
echo " -l, --log Enable logging on consensus nodes."
echo " --tc Arguments to pass to 'tc qdisc netem' inside the container."
echo " Example: 'delay 100ms'"
echo " --time Set the time per block (in milliseconds)."
exit 0
}

Expand Down Expand Up @@ -171,6 +173,11 @@ while test $# -gt 0; do
export NEOBENCH_TC="$1"
shift
;;
--time)
test $# -gt 0 || fatal "Time per block should be specified."
export TIME_PER_BLOCK="$1"
shift
;;

*) fatal "Unknown option: $_opt" ;;
esac
Expand Down

0 comments on commit 40a9983

Please sign in to comment.