Check gas price (#494)
* add gas validation option * gas price config for chains * check gas price * add tests * fix txt * make gas price dls * fix config
This commit is contained in:
@@ -94,8 +94,9 @@ open class EthereumUpstreamValidator @JvmOverloads constructor(
|
||||
validateChain(),
|
||||
validateOldBlocks(),
|
||||
validateCallLimit(),
|
||||
validateGasPrice(),
|
||||
).map {
|
||||
listOf(it.t1, it.t2, it.t3).maxOf { it }
|
||||
listOf(it.t1, it.t2, it.t3, it.t4).maxOf { it }
|
||||
}.block() ?: ValidateUpstreamSettingsResult.UPSTREAM_SETTINGS_ERROR
|
||||
}
|
||||
|
||||
@@ -195,6 +196,31 @@ open class EthereumUpstreamValidator @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun validateGasPrice(): Mono<ValidateUpstreamSettingsResult> {
|
||||
if (!options.validateGasPrice || config.gasPriceCondition == null) {
|
||||
return Mono.just(ValidateUpstreamSettingsResult.UPSTREAM_VALID)
|
||||
}
|
||||
return upstream.getIngressReader()
|
||||
.read(ChainRequest("eth_gasPrice", ListParams()))
|
||||
.flatMap(ChainResponse::requireStringResult)
|
||||
.map { result ->
|
||||
val actualGasPrice = result.substring(2).toLong(16)
|
||||
if (!config.gasPriceCondition!!.check(actualGasPrice)) {
|
||||
log.warn(
|
||||
"Node ${upstream.getId()} has gasPrice $actualGasPrice, " +
|
||||
"but it is not equal to the required ${config.gasPriceCondition!!.rules()}",
|
||||
)
|
||||
ValidateUpstreamSettingsResult.UPSTREAM_FATAL_SETTINGS_ERROR
|
||||
} else {
|
||||
ValidateUpstreamSettingsResult.UPSTREAM_VALID
|
||||
}
|
||||
}
|
||||
.onErrorResume { err ->
|
||||
log.warn("Error during gasPrice validation", err)
|
||||
Mono.just(ValidateUpstreamSettingsResult.UPSTREAM_SETTINGS_ERROR)
|
||||
}
|
||||
}
|
||||
|
||||
private fun chainId(): Mono<String> {
|
||||
return upstream.getIngressReader()
|
||||
.read(ChainRequest("eth_chainId", ListParams()))
|
||||
|
||||
Reference in New Issue
Block a user