Check gas price multiply conditions (#496)

* multiply conditions

* update doc
This commit is contained in:
Anton
2024-06-03 12:51:50 +03:00
committed by GitHub
parent 724e9be98a
commit 753b7d8503
6 changed files with 87 additions and 33 deletions

View File

@@ -197,7 +197,7 @@ open class EthereumUpstreamValidator @JvmOverloads constructor(
}
private fun validateGasPrice(): Mono<ValidateUpstreamSettingsResult> {
if (!options.validateGasPrice || config.gasPriceCondition == null) {
if (!options.validateGasPrice) {
return Mono.just(ValidateUpstreamSettingsResult.UPSTREAM_VALID)
}
return upstream.getIngressReader()
@@ -205,10 +205,10 @@ open class EthereumUpstreamValidator @JvmOverloads constructor(
.flatMap(ChainResponse::requireStringResult)
.map { result ->
val actualGasPrice = result.substring(2).toLong(16)
if (!config.gasPriceCondition!!.check(actualGasPrice)) {
if (!config.gasPriceCondition.check(actualGasPrice)) {
log.warn(
"Node ${upstream.getId()} has gasPrice $actualGasPrice, " +
"but it is not equal to the required ${config.gasPriceCondition!!.rules()}",
"but it is not equal to the required ${config.gasPriceCondition.rules()}",
)
ValidateUpstreamSettingsResult.UPSTREAM_FATAL_SETTINGS_ERROR
} else {

View File

@@ -351,7 +351,7 @@ class EthereumUpstreamValidatorSpec extends Specification {
it.validateChain = false
it.validateCallLimit = false
}.buildOptions()
def conf = ChainConfig.defaultWithGasPriceCondition("ne 3000000000")
def conf = ChainConfig.defaultWithGasPriceCondition(["ne 3000000000", "ne 5000000000"])
def up = Mock(Upstream) {
3 * getIngressReader() >>
Mock(Reader) {
@@ -374,7 +374,7 @@ class EthereumUpstreamValidatorSpec extends Specification {
it.validateChain = false
it.validateCallLimit = false
}.buildOptions()
def conf = ChainConfig.defaultWithGasPriceCondition("eq 1000000000")
def conf = ChainConfig.defaultWithGasPriceCondition(["eq 1000000000"])
def up = Mock(Upstream) {
3 * getIngressReader() >>
Mock(Reader) {
@@ -395,6 +395,7 @@ class EthereumUpstreamValidatorSpec extends Specification {
setup:
def options = ChainOptions.PartialOptions.getDefaults().tap {
it.validateCallLimit = false
it.validateGasPrice = false
}.buildOptions()
def up = Mock(Upstream) {
4 * getIngressReader() >> Mock(Reader) {
@@ -417,6 +418,7 @@ class EthereumUpstreamValidatorSpec extends Specification {
setup:
def options = ChainOptions.PartialOptions.getDefaults().tap {
it.validateCallLimit = false
it.validateGasPrice = false
}.buildOptions()
def up = Mock(Upstream) {
4 * getIngressReader() >> Mock(Reader) {
@@ -437,7 +439,9 @@ class EthereumUpstreamValidatorSpec extends Specification {
def "Upstream is valid if all setting are valid"() {
setup:
def options = ChainOptions.PartialOptions.getDefaults().buildOptions()
def options = ChainOptions.PartialOptions.getDefaults().tap{
it.validateGasPrice = false
}.buildOptions()
def up = Mock(Upstream) {
5 * getIngressReader() >> Mock(Reader) {
1 * read(new ChainRequest("eth_chainId", new ListParams())) >> Mono.just(new ChainResponse('"0x1"'.getBytes(), null))
@@ -461,7 +465,9 @@ class EthereumUpstreamValidatorSpec extends Specification {
def "Upstream is not valid if there are errors"() {
setup:
def options = ChainOptions.PartialOptions.getDefaults().buildOptions()
def options = ChainOptions.PartialOptions.getDefaults().tap {
it.validateGasPrice = false
}.buildOptions()
def up = Mock(Upstream) {
5 * getIngressReader() >> Mock(Reader) {
1 * read(new ChainRequest("eth_chainId", new ListParams())) >> Mono.just(new ChainResponse(null, new ChainCallError(1, "Too long")))