Skip to content

Commit

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

Close #161

Signed-off-by: Ekaterina Pavlova <[email protected]>
  • Loading branch information
AliceInHunterland committed Apr 27, 2024
1 parent 7c1946a commit d771154
Show file tree
Hide file tree
Showing 4 changed files with 25 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
MS_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 --msPerBlock $(MS_PER_BLOCK)


# Generate transactions, dump and nodes configurations for four-nodes network
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ The following default configurations are available:
-t Request timeout.
Used for RPC requests.
Example: -t 30s
--msPerBlock Protocol setting specifying the minimal (and targeted for) time interval between blocks. Must be an integer number of milliseconds.
Example: --msPerBlock 1000
```

## Build options
Expand Down
8 changes: 8 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")
msPerBlock = flag.Int("msPerBlock", 0, "time per block in milliseconds")
)

func main() {
Expand Down Expand Up @@ -115,6 +117,9 @@ func generateGoConfig(templatePath, database, suffix string) error {
return fmt.Errorf("unable to decode node template #%d: %w", i, err)
}
template.ApplicationConfiguration.DBConfiguration.Type = database
if msPerBlock != nil && *msPerBlock > 0 {
template.ProtocolConfiguration.TimePerBlock = time.Duration(*msPerBlock) * time.Millisecond
}
var configFile string
nodeName, err := nodeNameFromSeedList(template.ApplicationConfiguration.P2P.Addresses, template.ProtocolConfiguration.SeedList)
if err != nil {
Expand Down Expand Up @@ -154,6 +159,9 @@ func generateSharpConfig(templatePath, storageEngine, suffix string) error {
return fmt.Errorf("unable to decode node template #%d: %w", i, err)
}
template.ApplicationConfiguration.Storage.Engine = storageEngine
if msPerBlock != nil && *msPerBlock > 0 {
template.ProtocolConfiguration.MillisecondsPerBlock = *msPerBlock
}
var configFile string
nodeName, err := nodeNameFromSeedList([]string{":" + strconv.Itoa(int(template.ApplicationConfiguration.P2P.Port))}, template.ProtocolConfiguration.SeedList)
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ 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}
if [ "$NEOBENCH_VALIDATOR_COUNT" -eq 1 ]; then
export MS_PER_BLOCK=${MS_PER_BLOCK:-1s}
else
export MS_PER_BLOCK=${MS_PER_BLOCK:-5s}
fi

show_help() {
echo "Usage of benchmark runner:"
Expand Down Expand Up @@ -50,6 +55,8 @@ 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 " --msPerBlock Protocol setting specifying the minimal (and targeted for) time interval between blocks. Must be an integer number of milliseconds."
echo " Example: --msPerBlock 1000"
exit 0
}

Expand Down Expand Up @@ -172,6 +179,12 @@ while test $# -gt 0; do
shift
;;

--msPerBlock)
test $# -gt 0 || fatal "time per block should be specified"
export MS_PER_BLOCK="$1"
shift
;;

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

0 comments on commit d771154

Please sign in to comment.