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 `msPerBlock` is used in
generation config files.

Close #161

Signed-off-by: Ekaterina Pavlova <[email protected]>
  • Loading branch information
AliceInHunterland committed May 4, 2024
1 parent 7a39b3f commit 924e1bb
Show file tree
Hide file tree
Showing 4 changed files with 22 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 ?= 0

.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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ The following default configurations are available:
Example: -l journald -l syslog -l json-file
--tc Arguments to pass to 'tc qdisc netem' inside the container.
Example: 'delay 100ms'
--msPerBlock Protocol setting specifying the minimal (and targeted for) time interval between blocks. Must be an integer number of milliseconds.
The default value is set in configuration templates and is 1s and 5s for single node and multinode setup respectively.
Example: --msPerBlock 3000
```

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
9 changes: 9 additions & 0 deletions runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ show_help() {
echo " Example: -l journald -l syslog -l json-file"
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 " The default value is set in configuration templates and is 1s and 5s for single node and multinode setup respectively."
echo " Example: --msPerBlock 1000"
exit 0
}

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

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

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

0 comments on commit 924e1bb

Please sign in to comment.