mirror of
https://github.com/corda/corda.git
synced 2025-02-01 00:45:59 +00:00
Added exclude whitelist to Network Bootstrapper to enable fine grained testing (#2666)
* Added exclude whitelist to Network Bootstrapper to enable fine grained testing. * code review change
This commit is contained in:
parent
57067065f4
commit
d4f9b10469
@ -53,6 +53,7 @@ class NetworkBootstrapper {
|
|||||||
|
|
||||||
private const val LOGS_DIR_NAME = "logs"
|
private const val LOGS_DIR_NAME = "logs"
|
||||||
private const val WHITELIST_FILE_NAME = "whitelist.txt"
|
private const val WHITELIST_FILE_NAME = "whitelist.txt"
|
||||||
|
private const val EXCLUDE_WHITELIST_FILE_NAME = "exclude_whitelist.txt"
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
@ -80,7 +81,7 @@ class NetworkBootstrapper {
|
|||||||
println("Gathering notary identities")
|
println("Gathering notary identities")
|
||||||
val notaryInfos = gatherNotaryInfos(nodeInfoFiles)
|
val notaryInfos = gatherNotaryInfos(nodeInfoFiles)
|
||||||
println("Notary identities to be used in network-parameters file: ${notaryInfos.joinToString("; ") { it.prettyPrint() }}")
|
println("Notary identities to be used in network-parameters file: ${notaryInfos.joinToString("; ") { it.prettyPrint() }}")
|
||||||
val mergedWhiteList = generateWhitelist(directory / WHITELIST_FILE_NAME, cordapps)
|
val mergedWhiteList = generateWhitelist(directory / WHITELIST_FILE_NAME, directory / EXCLUDE_WHITELIST_FILE_NAME, cordapps)
|
||||||
println("Updating whitelist.")
|
println("Updating whitelist.")
|
||||||
overwriteWhitelist(directory / WHITELIST_FILE_NAME, mergedWhiteList)
|
overwriteWhitelist(directory / WHITELIST_FILE_NAME, mergedWhiteList)
|
||||||
installNetworkParameters(notaryInfos, nodeDirs, mergedWhiteList)
|
installNetworkParameters(notaryInfos, nodeDirs, mergedWhiteList)
|
||||||
@ -186,17 +187,19 @@ class NetworkBootstrapper {
|
|||||||
nodeDirs.forEach { copier.install(it) }
|
nodeDirs.forEach { copier.install(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateWhitelist(whitelistFile: Path, cordapps: List<String>?): Map<String, List<AttachmentId>> {
|
private fun generateWhitelist(whitelistFile: Path, excludeWhitelistFile: Path, cordapps: List<String>?): Map<String, List<AttachmentId>> {
|
||||||
val existingWhitelist = if (whitelistFile.exists()) readContractWhitelist(whitelistFile) else emptyMap()
|
val existingWhitelist = if (whitelistFile.exists()) readContractWhitelist(whitelistFile) else emptyMap()
|
||||||
|
|
||||||
println("Found existing whitelist: $existingWhitelist")
|
println("Found existing whitelist: $existingWhitelist")
|
||||||
|
|
||||||
|
val excludeContracts = if (excludeWhitelistFile.exists()) readExcludeWhitelist(excludeWhitelistFile) else emptyList()
|
||||||
|
println("Exclude Contracts from whitelist: $excludeContracts")
|
||||||
|
|
||||||
val newWhiteList = cordapps?.flatMap { cordappJarPath ->
|
val newWhiteList = cordapps?.flatMap { cordappJarPath ->
|
||||||
val jarHash = getJarHash(cordappJarPath)
|
val jarHash = getJarHash(cordappJarPath)
|
||||||
scanJarForContracts(cordappJarPath).map { contract ->
|
scanJarForContracts(cordappJarPath).map { contract ->
|
||||||
contract to jarHash
|
contract to jarHash
|
||||||
}
|
}
|
||||||
}?.toMap() ?: emptyMap()
|
}?.filter { (contractClassName, _) -> contractClassName !in excludeContracts }?.toMap() ?: emptyMap()
|
||||||
|
|
||||||
println("Calculating whitelist for current cordapps: $newWhiteList")
|
println("Calculating whitelist for current cordapps: $newWhiteList")
|
||||||
|
|
||||||
@ -213,7 +216,7 @@ class NetworkBootstrapper {
|
|||||||
|
|
||||||
private fun overwriteWhitelist(whitelistFile: Path, mergedWhiteList: Map<String, List<AttachmentId>>) {
|
private fun overwriteWhitelist(whitelistFile: Path, mergedWhiteList: Map<String, List<AttachmentId>>) {
|
||||||
PrintStream(whitelistFile.toFile().outputStream()).use { out ->
|
PrintStream(whitelistFile.toFile().outputStream()).use { out ->
|
||||||
mergedWhiteList.forEach { (contract, attachments )->
|
mergedWhiteList.forEach { (contract, attachments) ->
|
||||||
out.println("${contract}:${attachments.joinToString(",")}")
|
out.println("${contract}:${attachments.joinToString(",")}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,12 +228,14 @@ class NetworkBootstrapper {
|
|||||||
SecureHash.SHA256(hs.hash().asBytes())
|
SecureHash.SHA256(hs.hash().asBytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun readContractWhitelist(file: Path): Map<String, List<AttachmentId>> = file.toFile().readLines()
|
private fun readContractWhitelist(file: Path): Map<String, List<AttachmentId>> = file.readAllLines()
|
||||||
.map { line -> line.split(":") }
|
.map { line -> line.split(":") }
|
||||||
.map { (contract, attachmentIds) ->
|
.map { (contract, attachmentIds) ->
|
||||||
contract to (attachmentIds.split(",").map(::parse))
|
contract to (attachmentIds.split(",").map(::parse))
|
||||||
}.toMap()
|
}.toMap()
|
||||||
|
|
||||||
|
private fun readExcludeWhitelist(file: Path): List<String> = file.readAllLines().map(String::trim)
|
||||||
|
|
||||||
private fun NotaryInfo.prettyPrint(): String = "${identity.name} (${if (validating) "" else "non-"}validating)"
|
private fun NotaryInfo.prettyPrint(): String = "${identity.name} (${if (validating) "" else "non-"}validating)"
|
||||||
|
|
||||||
private fun NodeInfo.notaryIdentity(): Party {
|
private fun NodeInfo.notaryIdentity(): Party {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user