Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close #531: Implement configuring the "create_empty_blocks" parameter #532

Merged
merged 3 commits into from Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions cli/src/main/scala/pravda/cli/PravdaArgsParser.scala
Expand Up @@ -398,6 +398,25 @@ object PravdaArgsParser extends CommandLine[PravdaConfig] {
.Node(PravdaConfig.Node.Mode.Init(local: PravdaConfig.Node.Network.Local), _)) =>
config.copy(mode = PravdaConfig.Node.Mode.Init(local.copy(Some(coinDistribution))))
case (_, otherwise) => otherwise
},
opt[Boolean]("create-empty-blocks")
.text("If true, then a new empty block will be created even there were no committed transactions.")
.action {
case (createEmptyBlocks,
config @ PravdaConfig
.Node(PravdaConfig.Node.Mode.Init(local: PravdaConfig.Node.Network.Local), _)) =>
config.copy(mode = PravdaConfig.Node.Mode.Init(local.copy(createEmptyBlocks = createEmptyBlocks)))
case (_, otherwise) => otherwise
},
opt[Int]("create-empty-blocks-interval")
.text("The interval (in seconds) between creating a new empty blocks.")
.action {
case (createEmptyBlocksInterval,
config @ PravdaConfig
.Node(PravdaConfig.Node.Mode.Init(local: PravdaConfig.Node.Network.Local), _)) =>
config.copy(mode =
PravdaConfig.Node.Mode.Init(local.copy(createEmptyBlocksInterval = createEmptyBlocksInterval)))
case (_, otherwise) => otherwise
}
),
cmd("run")
Expand Down
12 changes: 11 additions & 1 deletion cli/src/main/scala/pravda/cli/PravdaConfig.scala
Expand Up @@ -45,6 +45,11 @@ object PravdaConfig {
val ENDPOINT = "http://localhost:8080/api/public"
val IPFS_NODE = "/ip4/127.0.0.1/tcp/5001"
}

object Node {
val createEmptyBlocks: Boolean = false
val createEmptyBlocksInterval: Int = 900 // 15 minutes
}
}

final case class GenAddress(output: Option[String] = None) extends PravdaConfig
Expand Down Expand Up @@ -106,7 +111,12 @@ object PravdaConfig {
sealed trait Network

object Network {
final case class Local(coinDistribution: Option[String]) extends Network
final case class Local(coinDistribution: Option[String],
// If true, then a new empty block will be created even there were no committed transactions.
createEmptyBlocks: Boolean = DefaultValues.Node.createEmptyBlocks,
// The interval (in seconds) between creating a new empty blocks.
createEmptyBlocksInterval: Int = DefaultValues.Node.createEmptyBlocksInterval)
extends Network

case object Testnet extends Network
}
Expand Down
25 changes: 17 additions & 8 deletions cli/src/main/scala/pravda/cli/programs/Node.scala
Expand Up @@ -42,7 +42,9 @@ final class Node[F[_]: Monad](io: IoLanguage[F], random: RandomLanguage[F], node
paymentWallet: Validator,
validators: Seq[String],
coinDistribution: Seq[CoinDistributionMember],
seeds: Seq[(String, Int)]) =
seeds: Seq[(String, Int)],
createEmptyBlocks: Boolean,
createEmptyBlocksInterval: Int) =
s"""pravda {
| network-address-cache {
| ttl = 60
Expand All @@ -57,6 +59,8 @@ final class Node[F[_]: Monad](io: IoLanguage[F], random: RandomLanguage[F], node
| rpc-port = 46657
| proxy-app-port = 46658
| use-unix-domain-socket = false
| create-empty-blocks = ${createEmptyBlocks.toString}
| create-empty-blocks-interval = ${createEmptyBlocksInterval.toString}
| }
| data-directory = "${dataDir.replace("\\", "\\\\")}"
| coin-distribution = "${coinDistribution
Expand Down Expand Up @@ -123,15 +127,17 @@ final class Node[F[_]: Monad](io: IoLanguage[F], random: RandomLanguage[F], node
)

config = network match {
case Network.Local(_) =>
case Network.Local(_, createEmptyBlocks, createEmptyBlocksInterval) =>
applicationConfig(
isValidator = true,
chainId = "local",
dataDir = dataDir,
paymentWallet = paymentWallet,
coinDistribution = initialDistribution,
validators = List(s"me:10:${bytes.byteString2hex(pub)}"),
seeds = Nil
seeds = Nil,
createEmptyBlocks = createEmptyBlocks,
createEmptyBlocksInterval = createEmptyBlocksInterval
)
case Network.Testnet =>
val pkey = "c77f81ae0c37ea3742e16b5cf15563ca6cc063bc5e88ff55a74dc0e52bd7d632"
Expand All @@ -147,7 +153,10 @@ final class Node[F[_]: Monad](io: IoLanguage[F], random: RandomLanguage[F], node
NativeCoin @@ 1000000000L
)
),
Seq("35.234.141.154" -> 30001)
Seq("35.234.141.154" -> 30001),
// For non-validator nodes these settings doesn't make sense.
createEmptyBlocks = false,
createEmptyBlocksInterval = 0
)
}
_ <- EitherT[F, String, Unit](io.writeToFile(configPath, ByteString.copyFromUtf8(config)).map(Right.apply))
Expand Down Expand Up @@ -176,10 +185,10 @@ final class Node[F[_]: Monad](io: IoLanguage[F], random: RandomLanguage[F], node
}
_ <- EitherT[F, String, Unit] {
config.mode match {
case Mode.Nope => Monad[F].pure(Left(s"[init|run] subcommand required."))
case Mode.Init(network @ Network.Local(cd)) => init(dataDir, network, cd)
case Mode.Init(network) => init(dataDir, network, None)
case Mode.Run => mkConfigPath(dataDir).flatMap(node.launch).map(Right.apply)
case Mode.Nope => Monad[F].pure(Left(s"[init|run] subcommand required."))
case Mode.Init(network @ Network.Local(cd, _, _)) => init(dataDir, network, cd)
case Mode.Init(network) => init(dataDir, network, None)
case Mode.Run => mkConfigPath(dataDir).flatMap(node.launch).map(Right.apply)
}
}
} yield ()
Expand Down
4 changes: 3 additions & 1 deletion doc/CLI/pravda-node-init.md
Expand Up @@ -2,7 +2,7 @@
THIS FILE IS GENERATED. DO NOT EDIT MANUALLY!
-->

```pravda node init --data-dir <file> --local --testnet --coin-distribution <string>```
```pravda node init --data-dir <file> --local --testnet --coin-distribution <string> --create-empty-blocks <boolean> --create-empty-blocks-interval <int>```

## Description
Create a data directory and configuration for the new node.
Expand All @@ -14,3 +14,5 @@ Create a data directory and configuration for the new node.
|`--local`|Initialize the local node with self-validation.
|`--testnet`|Initialize the node connected to the official testnet.
|`--coin-distribution`|Initialize the local node with the addresses that has a certain amount of coins at the initial state. JSON file. The format is as follows: [{"address":<public key in hex>,"amount":<number>}]
|`--create-empty-blocks`|If true, then a new empty block will be created even there were no committed transactions.
|`--create-empty-blocks-interval`|The interval (in seconds) between creating a new empty blocks.
6 changes: 6 additions & 0 deletions node/src/main/resources/application.conf
Expand Up @@ -20,6 +20,12 @@ pravda {
proxy-app-port = ${?PRAVDA_ABCI_PORT}
use-unix-domain-socket = false
use-unix-domain-socket = ${?PRAVDA_USE_UNIX_SOCKET}
# If true, then a new empty block will be created even there were no committed transactions.
create-empty-blocks = false
create-empty-blocks = ${?PRAVDA_CREATE_EMPTY_BLOCKS}
# The interval (in seconds) between creating a new empty blocks.
create-empty-blocks-interval = 900
create-empty-blocks-interval = ${?PRAVDA_CREATE_EMPTY_BLOCKS_INTERVAL}
}
is-validator = ${?PRAVDA_IS_VALIDATOR}
data-directory = ${?PRAVDA_DATA}
Expand Down
4 changes: 3 additions & 1 deletion node/src/main/scala/pravda/node/data/PravdaConfig.scala
Expand Up @@ -65,6 +65,8 @@ object PravdaConfig {
peerPort: Int,
rpcPort: Int,
proxyAppPort: Int,
useUnixDomainSocket: Boolean
useUnixDomainSocket: Boolean,
createEmptyBlocks: Boolean = false,
createEmptyBlocksInterval: Int = 900
)
}
3 changes: 2 additions & 1 deletion node/src/main/scala/pravda/node/tendermint.scala
Expand Up @@ -181,7 +181,8 @@ object tendermint {
|abci = "socket"
|proxy_app = "$proxyAppAddr"
|[consensus]
|create_empty_blocks = false
|create_empty_blocks = ${config.tendermint.createEmptyBlocks.toString}
|create_empty_blocks_interval = "${config.tendermint.createEmptyBlocksInterval.toString}s"
|[p2p]
|addr_book_strict = false
|seeds="${config.seeds}"
Expand Down
9 changes: 6 additions & 3 deletions project/Dependencies.scala
@@ -1,9 +1,12 @@
import sbt._

object Dependencies {
lazy val akkaHttp = "com.typesafe.akka" %% "akka-http" % "10.1.7"
lazy val akkaActor = "com.typesafe.akka" %% "akka-actor" % "2.5.19"
lazy val akkaStream = "com.typesafe.akka" %% "akka-stream" % "2.5.19"
lazy val `akka-version` = "2.5.25"
lazy val `akka-http-version` = "10.1.8"

lazy val akkaHttp = "com.typesafe.akka" %% "akka-http" % `akka-http-version`
lazy val akkaActor = "com.typesafe.akka" %% "akka-actor" % `akka-version`
lazy val akkaStream = "com.typesafe.akka" %% "akka-stream" % `akka-version`
lazy val logbackClassic = "ch.qos.logback" % "logback-classic" % "1.2.3"
lazy val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.14.0"
lazy val catsCore = "org.typelevel" %% "cats-core" % "1.5.0"
Expand Down