-
Notifications
You must be signed in to change notification settings - Fork 15
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
validate upstream version #527
Merged
+799
−1,058
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/io/emeraldpay/dshackle/config/context/HotConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.emeraldpay.dshackle.config.context | ||
|
||
import io.emeraldpay.dshackle.config.hot.AutoReloadbleConfig | ||
import io.emeraldpay.dshackle.config.hot.CompatibleVersionsRules | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.core.io.ClassPathResource | ||
import java.util.function.Supplier | ||
|
||
@Configuration | ||
open class HotConfig { | ||
@Bean | ||
open fun hotVersionsConfig( | ||
@Value("\${compatibility.url}") | ||
url: String, | ||
@Value("\${compatibility.enabled}") | ||
enabled: Boolean, | ||
): Supplier<CompatibleVersionsRules?> { | ||
return if (enabled) { | ||
val initialContent = | ||
ClassPathResource("public/compatible-clients.yaml").inputStream.readBytes().toString(Charsets.UTF_8) | ||
AutoReloadbleConfig(initialContent, url, CompatibleVersionsRules::class.java).also { it.start() } | ||
} else { | ||
Supplier { null } | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/kotlin/io/emeraldpay/dshackle/config/hot/AutoReloadbleConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.emeraldpay.dshackle.config.hot | ||
|
||
import io.emeraldpay.dshackle.Global | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.web.client.RestTemplate | ||
import reactor.core.publisher.Flux | ||
import java.time.Duration | ||
import java.util.concurrent.atomic.AtomicReference | ||
import java.util.function.Supplier | ||
|
||
class AutoReloadbleConfig<T>( | ||
val initialContent: String, | ||
val configUrl: String, | ||
private val type: Class<T>, | ||
) : Supplier<T?> { | ||
companion object { | ||
private val log = LoggerFactory.getLogger(AutoReloadbleConfig::class.java) | ||
} | ||
|
||
private val restTemplate = RestTemplate() | ||
private val instance = AtomicReference<T>() | ||
|
||
fun reload() { | ||
try { | ||
val response = restTemplate.getForObject(configUrl, String::class.java) | ||
if (response != null) { | ||
instance.set(parseConfig(response)) | ||
} | ||
} catch (e: Exception) { | ||
log.error("Failed to reload config from $configUrl for type $type", e) | ||
} | ||
} | ||
|
||
fun start() { | ||
instance.set(parseConfig(initialContent)) | ||
Flux.interval( | ||
Duration.ofSeconds(600), | ||
).subscribe { | ||
reload() | ||
} | ||
} | ||
|
||
private fun parseConfig(config: String): T { | ||
return Global.yamlMapper.readValue(config, type) | ||
} | ||
|
||
override fun get(): T { | ||
return instance.get() | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/io/emeraldpay/dshackle/config/hot/CompatibleVersionsRules.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.emeraldpay.dshackle.config.hot | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties | ||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class CompatibleVersionsRules( | ||
@JsonProperty("rules") | ||
val rules: List<CompatibleVersionsRule>, | ||
) | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class CompatibleVersionsRule( | ||
@JsonProperty("client") | ||
val client: String, | ||
@JsonProperty("blacklist") | ||
val blacklist: List<String>?, | ||
@JsonProperty("whitelist") | ||
val whitelist: List<String>?, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 0 additions & 94 deletions
94
src/main/kotlin/io/emeraldpay/dshackle/upstream/BasicEthUpstreamValidator.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make it configurable? It mean time interval