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

Speedup Makefile Deployment and Restore Targets #6869

Merged
merged 6 commits into from
Sep 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Regtest: Bypass recursive Gradle invocations
alvasw committed Sep 12, 2023

Verified

This commit was signed with the committer’s verified signature.
alvasw Alva Swanson
commit f872d41d30435ec316ebd8766b39e95ec6576184
Original file line number Diff line number Diff line change
@@ -2,9 +2,16 @@ package bisq.gradle.regtest_plugin

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.file.RegularFile
import org.gradle.api.provider.Provider
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaToolchainService
import org.gradle.jvm.toolchain.JvmImplementation
import org.gradle.jvm.toolchain.JvmVendorSpec
import org.gradle.kotlin.dsl.register
import javax.inject.Inject

class RegtestPlugin : Plugin<Project> {
class RegtestPlugin @Inject constructor(private val javaToolchainService: JavaToolchainService) : Plugin<Project> {

companion object {
const val RPC_USER = "bisqdao"
@@ -28,15 +35,17 @@ class RegtestPlugin : Plugin<Project> {
val startFirstSeedNodeTask = project.tasks.register<StartBisqTask>("startRegtestFirstSeednode") {
dependsOn(startBitcoindTask)

pidFile.set(project.layout.projectDirectory.file(".localnet/seednode_1.pid"))
startScriptFile.set(project.layout.projectDirectory.file("bisq-seednode"))
workingDirectory.set(project.layout.projectDirectory)
javaExecutable.set(getJavaExecutable())
libsDir.set(project.layout.projectDirectory.dir("seednode/build/app/lib"))

mainClass.set("bisq.seednode.SeedNodeMain")
arguments.set(
createSeedNodeArgs(5120, 2002, "seednode")
createSeedNodeArgs(5120, 2002, "seednode")
)

workingDirectory.set(project.layout.projectDirectory)
logFile.set(project.layout.projectDirectory.file(".localnet/seednode_1_shell.log"))
pidFile.set(project.layout.projectDirectory.file(".localnet/seednode_1.pid"))
}

val stopFirstSeedNodeTask = project.tasks.register<KillTask>("stopRegtestFirstSeednode") {
@@ -47,15 +56,17 @@ class RegtestPlugin : Plugin<Project> {
dependsOn(startBitcoindTask)
dependsOn(startFirstSeedNodeTask)

pidFile.set(project.layout.projectDirectory.file(".localnet/seednode_2.pid"))
startScriptFile.set(project.layout.projectDirectory.file("bisq-seednode"))
workingDirectory.set(project.layout.projectDirectory)
javaExecutable.set(getJavaExecutable())
libsDir.set(project.layout.projectDirectory.dir("seednode/build/app/lib"))

mainClass.set("bisq.seednode.SeedNodeMain")
arguments.set(
createSeedNodeArgs(5121, 3002, "seednode2")
createSeedNodeArgs(5121, 3002, "seednode2")
)

workingDirectory.set(project.layout.projectDirectory)
logFile.set(project.layout.projectDirectory.file(".localnet/seednode_2_shell.log"))
pidFile.set(project.layout.projectDirectory.file(".localnet/seednode_2.pid"))
}

val stopSeedNodeTask = project.tasks.register<KillTask>("stopRegtestSecondSeednode") {
@@ -66,15 +77,17 @@ class RegtestPlugin : Plugin<Project> {
dependsOn(startFirstSeedNodeTask)
dependsOn(startSecondSeedNodeTask)

pidFile.set(project.layout.projectDirectory.file(".localnet/mediator.pid"))
startScriptFile.set(project.layout.projectDirectory.file("bisq-desktop"))
workingDirectory.set(project.layout.projectDirectory)
javaExecutable.set(getJavaExecutable())
libsDir.set(project.layout.projectDirectory.dir("desktop/build/app/lib"))

mainClass.set("bisq.desktop.app.BisqAppMain")
arguments.set(
createBisqUserArgs(4444, ".localnet/mediator", "Mediator")
createBisqUserArgs(4444, ".localnet/mediator", "Mediator")
)

workingDirectory.set(project.layout.projectDirectory)
logFile.set(project.layout.projectDirectory.file(".localnet/mediator_shell.log"))
pidFile.set(project.layout.projectDirectory.file(".localnet/mediator.pid"))
}

val stopMediatorTask = project.tasks.register<KillTask>("stopRegtestMediator") {
@@ -85,23 +98,26 @@ class RegtestPlugin : Plugin<Project> {
dependsOn(startFirstSeedNodeTask)
dependsOn(startSecondSeedNodeTask)

pidFile.set(project.layout.projectDirectory.file(".localnet/alice.pid"))
startScriptFile.set(project.layout.projectDirectory.file("bisq-desktop"))
workingDirectory.set(project.layout.projectDirectory)
javaExecutable.set(getJavaExecutable())
libsDir.set(project.layout.projectDirectory.dir("desktop/build/app/lib"))

mainClass.set("bisq.desktop.app.BisqAppMain")

val additionalArgs = listOf(
"--fullDaoNode=true",
"--rpcUser=bisqdao",
"--rpcPassword=bsq",
"--rpcBlockNotificationPort=5122",
"--genesisBlockHeight=111",
"--genesisTxId=30af0050040befd8af25068cc697e418e09c2d8ebd8d411d2240591b9ec203cf"
"--fullDaoNode=true",
"--rpcUser=bisqdao",
"--rpcPassword=bsq",
"--rpcBlockNotificationPort=5122",
"--genesisBlockHeight=111",
"--genesisTxId=30af0050040befd8af25068cc697e418e09c2d8ebd8d411d2240591b9ec203cf"
)
arguments.set(
createBisqUserArgs(5555, ".localnet/alice", "Alice", additionalArgs)
createBisqUserArgs(5555, ".localnet/alice", "Alice", additionalArgs)
)

workingDirectory.set(project.layout.projectDirectory)
logFile.set(project.layout.projectDirectory.file(".localnet/alice_shell.log"))
pidFile.set(project.layout.projectDirectory.file(".localnet/alice.pid"))
}

val stopAliceTask = project.tasks.register<KillTask>("stopRegtestAlice") {
@@ -112,15 +128,17 @@ class RegtestPlugin : Plugin<Project> {
dependsOn(startMediatorTask)
dependsOn(startAliceTask)

pidFile.set(project.layout.projectDirectory.file(".localnet/bob.pid"))
startScriptFile.set(project.layout.projectDirectory.file("bisq-desktop"))
workingDirectory.set(project.layout.projectDirectory)
javaExecutable.set(getJavaExecutable())
libsDir.set(project.layout.projectDirectory.dir("desktop/build/app/lib"))

mainClass.set("bisq.desktop.app.BisqAppMain")
arguments.set(
createBisqUserArgs(6666, ".localnet/bob", "Bob")
createBisqUserArgs(6666, ".localnet/bob", "Bob")
)

workingDirectory.set(project.layout.projectDirectory)
logFile.set(project.layout.projectDirectory.file(".localnet/bob_shell.log"))
pidFile.set(project.layout.projectDirectory.file(".localnet/bob.pid"))
}

project.tasks.register<KillTask>("stopRegtest") {
@@ -136,34 +154,43 @@ class RegtestPlugin : Plugin<Project> {
}
}

private fun createBisqUserArgs(nodePort: Int,
dataDir: String,
appName: String,
additionalArgs: List<String> = emptyList()): List<String> =
createBisqCommonArgs(nodePort) +
listOf(
"--appDataDir=$dataDir",
"--appName=$appName"
) + additionalArgs
private fun getJavaExecutable(): Provider<RegularFile> =
javaToolchainService.launcherFor {
languageVersion.set(JavaLanguageVersion.of(11))
vendor.set(JvmVendorSpec.AZUL)
implementation.set(JvmImplementation.VENDOR_SPECIFIC)
}.map { it.executablePath }

private fun createBisqUserArgs(
nodePort: Int,
dataDir: String,
appName: String,
additionalArgs: List<String> = emptyList()
): List<String> =
createBisqCommonArgs(nodePort) +
listOf(
"--appDataDir=$dataDir",
"--appName=$appName"
) + additionalArgs

private fun createSeedNodeArgs(blockNotificationPort: Int, nodePort: Int, appName: String): List<String> =
createBisqCommonArgs(nodePort) +
listOf(
"--fullDaoNode=true",
createBisqCommonArgs(nodePort) +
listOf(
"--fullDaoNode=true",

"--rpcUser=${RPC_USER}",
"--rpcPassword=${RPC_PASSWORD}",
"--rpcBlockNotificationPort=$blockNotificationPort",
"--rpcUser=${RPC_USER}",
"--rpcPassword=${RPC_PASSWORD}",
"--rpcBlockNotificationPort=$blockNotificationPort",

"--userDataDir=.localnet",
"--appName=$appName"
)
"--userDataDir=.localnet",
"--appName=$appName"
)

private fun createBisqCommonArgs(nodePort: Int): List<String> =
listOf(
"--baseCurrencyNetwork=BTC_REGTEST",
"--useLocalhostForP2P=true",
"--useDevPrivilegeKeys=true",
"--nodePort=$nodePort"
)
listOf(
"--baseCurrencyNetwork=BTC_REGTEST",
"--useLocalhostForP2P=true",
"--useDevPrivilegeKeys=true",
"--nodePort=$nodePort"
)
}
Original file line number Diff line number Diff line change
@@ -4,22 +4,25 @@ import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.ListProperty
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*

abstract class StartBisqTask : DefaultTask() {

@get:InputDirectory
abstract val workingDirectory: DirectoryProperty

@get:InputFile
abstract val startScriptFile: RegularFileProperty
abstract val javaExecutable: RegularFileProperty

@get:InputDirectory
abstract val libsDir: DirectoryProperty

@get:Input
abstract val arguments: ListProperty<String>
abstract val mainClass: Property<String>

@get:InputDirectory
abstract val workingDirectory: DirectoryProperty
@get:Input
abstract val arguments: ListProperty<String>

@get:Internal
abstract val logFile: RegularFileProperty
@@ -30,15 +33,29 @@ abstract class StartBisqTask : DefaultTask() {
@TaskAction
fun run() {
ProcessKiller(pidFile.asFile.get())
.kill()
.kill()

// Wait until process stopped
Thread.sleep(5000)

val processBuilder = ProcessBuilder(
"bash", startScriptFile.asFile.get().absolutePath, arguments.get().joinToString(" ")
javaExecutable.asFile.get().absolutePath,

"-XX:MaxRAM=8g",
"-Xss1280k",
"-XX:+UseG1GC",
"-XX:MaxHeapFreeRatio=10",
"-XX:MinHeapFreeRatio=5",
"-XX:+UseStringDeduplication",
"-Djava.net.preferIPv4Stack=true",

"-classpath", createClassPath(),
mainClass.get(),
)

processBuilder.command()
.addAll(arguments.get())

processBuilder.directory(workingDirectory.asFile.get())
processBuilder.redirectErrorStream(true)
processBuilder.redirectOutput(logFile.asFile.get())
@@ -47,7 +64,12 @@ abstract class StartBisqTask : DefaultTask() {
val pid = process.pid()

pidFile.asFile
.get()
.writeText(pid.toString())
.get()
.writeText(pid.toString())
}

private fun createClassPath(): String {
val libsDirFile = libsDir.asFile.get()
return libsDirFile.listFiles()!!.joinToString(separator = ":") { it.absolutePath }
}
}