Skip to content

Commit

Permalink
Implement configuring the "create_empty_blocks" parameter #531
Browse files Browse the repository at this point in the history
Tendermint has two parameters which we should be able to configure with using Pravda CLI and/or just writing a values in node.conf file.

Two new arguments in `pravda node init` command have been added:
- `--create-empty-blocks`
- `--create-empty-blocks-interval`

Also, two new ENV variables have been added:
- `PRAVDA_CREATE_EMPTY_BLOCKS`
- `PRAVDA_CREATE_EMPTY_BLOCKS_INTERVAL`
  • Loading branch information
Chicker committed Nov 5, 2019
1 parent beeeec9 commit a4bcaaa
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 11 deletions.
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
10 changes: 9 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,10 @@ object PravdaConfig {
sealed trait Network

object Network {
final case class Local(coinDistribution: Option[String]) extends Network
final case class Local(coinDistribution: Option[String],
createEmptyBlocks: Boolean = DefaultValues.Node.createEmptyBlocks,
createEmptyBlocksInterval: Int = DefaultValues.Node.createEmptyBlocksInterval)
extends Network

case object Testnet extends Network
}
Expand Down
27 changes: 19 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,10 @@ final class Node[F[_]: Monad](io: IoLanguage[F], random: RandomLanguage[F], node
| rpc-port = 46657
| proxy-app-port = 46658
| use-unix-domain-socket = false
| # If true, then a new empty block will be created even there were no committed transactions.
| create-empty-blocks = ${createEmptyBlocks.toString}
| # The interval (in seconds) between creating a new empty blocks.
| create-empty-blocks-interval = ${createEmptyBlocksInterval.toString}
| }
| data-directory = "${dataDir.replace("\\", "\\\\")}"
| coin-distribution = "${coinDistribution
Expand Down Expand Up @@ -123,15 +129,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 +155,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 +187,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
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

0 comments on commit a4bcaaa

Please sign in to comment.