Return limit zksync (#459)
* validateCallLimit with limit param * add call-validate-contract to zksync * update reader * fix error message * rm disable-validation for testnets/sepolia * fix tests * split CallLimitValidator implementations for zksync and other eth * add callLimitBlockNumber param * mv callLimitBlockNumber to options * upd docs * rm callLimitBlockNumber options param and hardcode it add zskync call limit validator check for debug_traceBlockByNumber is available * zksync limit check only for mainnet
This commit is contained in:
@@ -120,31 +120,19 @@ open class EthereumUpstreamValidator @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
private fun validateCallLimit(): Mono<ValidateUpstreamSettingsResult> {
|
||||
if (!options.validateCallLimit || config.callLimitContract == null) {
|
||||
val validator = callLimitValidatorFactory(upstream, options, config, chain)
|
||||
if (!validator.isEnabled()) {
|
||||
return Mono.just(ValidateUpstreamSettingsResult.UPSTREAM_VALID)
|
||||
}
|
||||
return upstream.getIngressReader()
|
||||
.read(
|
||||
ChainRequest(
|
||||
"eth_call",
|
||||
ListParams(
|
||||
TransactionCallJson(
|
||||
Address.from(config.callLimitContract),
|
||||
// calling contract with param 200_000, meaning it will generate 200k symbols or response
|
||||
// f4240 + metadata — ~1 million
|
||||
HexData.from("0xd8a26e3a00000000000000000000000000000000000000000000000000000000000f4240"),
|
||||
),
|
||||
"latest",
|
||||
),
|
||||
),
|
||||
)
|
||||
.read(validator.createRequest())
|
||||
.flatMap(ChainResponse::requireResult)
|
||||
.map { ValidateUpstreamSettingsResult.UPSTREAM_VALID }
|
||||
.onErrorResume {
|
||||
if (it.message != null && it.message!!.contains("rpc.returndata.limit")) {
|
||||
if (validator.isLimitError(it)) {
|
||||
log.warn(
|
||||
"Error: ${it.message}. Node ${upstream.getId()} is probably incorrectly configured. " +
|
||||
"You need to set up your return limit to at least 1_100_000. " +
|
||||
"You need to set up your return limit to at least ${options.callLimitSize}. " +
|
||||
"Erigon config example: https://github.com/ledgerwatch/erigon/blob/d014da4dc039ea97caf04ed29feb2af92b7b129d/cmd/utils/flags.go#L369",
|
||||
)
|
||||
Mono.just(ValidateUpstreamSettingsResult.UPSTREAM_FATAL_SETTINGS_ERROR)
|
||||
@@ -221,3 +209,63 @@ open class EthereumUpstreamValidator @JvmOverloads constructor(
|
||||
.flatMap(ChainResponse::requireStringResult)
|
||||
}
|
||||
}
|
||||
|
||||
interface CallLimitValidator {
|
||||
fun isEnabled(): Boolean
|
||||
fun createRequest(): ChainRequest
|
||||
fun isLimitError(err: Throwable): Boolean
|
||||
}
|
||||
|
||||
class EthCallLimitValidator(
|
||||
private val options: ChainOptions.Options,
|
||||
private val config: ChainConfig,
|
||||
) : CallLimitValidator {
|
||||
override fun isEnabled() = options.validateCallLimit && config.callLimitContract != null
|
||||
|
||||
override fun createRequest() = ChainRequest(
|
||||
"eth_call",
|
||||
ListParams(
|
||||
TransactionCallJson(
|
||||
Address.from(config.callLimitContract),
|
||||
// contract like https://github.com/p2p-org/dshackle/pull/246
|
||||
// meta + size in hex
|
||||
HexData.from("0xd8a26e3a" + options.callLimitSize.toString(16).padStart(64, '0')),
|
||||
),
|
||||
"latest",
|
||||
),
|
||||
)
|
||||
|
||||
override fun isLimitError(err: Throwable): Boolean =
|
||||
err.message != null && err.message!!.contains("rpc.returndata.limit")
|
||||
}
|
||||
|
||||
class ZkSyncCallLimitValidator(
|
||||
private val upstream: Upstream,
|
||||
private val options: ChainOptions.Options,
|
||||
) : CallLimitValidator {
|
||||
private val method = "debug_traceBlockByNumber"
|
||||
|
||||
override fun isEnabled() =
|
||||
options.validateCallLimit && upstream.getMethods().getSupportedMethods().contains(method)
|
||||
|
||||
override fun createRequest() = ChainRequest(
|
||||
method,
|
||||
ListParams("0x1b73b2b", mapOf("tracer" to "callTracer")),
|
||||
)
|
||||
|
||||
override fun isLimitError(err: Throwable): Boolean =
|
||||
err.message != null && err.message!!.contains("response size should not greater than")
|
||||
}
|
||||
|
||||
fun callLimitValidatorFactory(
|
||||
upstream: Upstream,
|
||||
options: ChainOptions.Options,
|
||||
config: ChainConfig,
|
||||
chain: Chain,
|
||||
): CallLimitValidator {
|
||||
return if (listOf(Chain.ZKSYNC__MAINNET).contains(chain)) {
|
||||
ZkSyncCallLimitValidator(upstream, options)
|
||||
} else {
|
||||
EthCallLimitValidator(options, config)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
id == "local"
|
||||
chain == "ethereum"
|
||||
connection instanceof UpstreamsConfig.RpcConnection
|
||||
with((UpstreamsConfig.RpcConnection)connection) {
|
||||
with((UpstreamsConfig.RpcConnection) connection) {
|
||||
rpc != null
|
||||
rpc.url == new URI("http://localhost:8545")
|
||||
ws != null
|
||||
@@ -62,7 +62,7 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
id == "infura"
|
||||
chain == "ethereum"
|
||||
connection instanceof UpstreamsConfig.RpcConnection
|
||||
with((UpstreamsConfig.RpcConnection)connection) {
|
||||
with((UpstreamsConfig.RpcConnection) connection) {
|
||||
rpc.url == new URI("https://mainnet.infura.io/v3/fa28c968191849c1aff541ad1d8511f2")
|
||||
rpc.basicAuth != null
|
||||
with((AuthConfig.ClientBasicAuth) rpc.basicAuth) {
|
||||
@@ -215,7 +215,7 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
with(act.upstreams.get(0)) {
|
||||
id == "remote"
|
||||
connection instanceof UpstreamsConfig.GrpcConnection
|
||||
with((UpstreamsConfig.GrpcConnection)connection) {
|
||||
with((UpstreamsConfig.GrpcConnection) connection) {
|
||||
host == "10.2.0.15"
|
||||
auth != null
|
||||
with(auth) {
|
||||
@@ -279,7 +279,7 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
id == "local"
|
||||
chain == "ethereum"
|
||||
connection instanceof UpstreamsConfig.RpcConnection
|
||||
with((UpstreamsConfig.RpcConnection)connection) {
|
||||
with((UpstreamsConfig.RpcConnection) connection) {
|
||||
rpc != null
|
||||
rpc.url == new URI("http://localhost:8545")
|
||||
ws == null
|
||||
@@ -451,13 +451,13 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
disableValidation == false
|
||||
validateSyncing == true
|
||||
validatePeers == false
|
||||
validateCalllimit == true
|
||||
validateCallLimit == true
|
||||
}
|
||||
with(act.upstreams.get(1).options) {
|
||||
disableValidation == false
|
||||
validateSyncing == false
|
||||
validatePeers == false
|
||||
validateCalllimit == false
|
||||
validateCallLimit == false
|
||||
}
|
||||
with(act.upstreams.get(2).options) {
|
||||
disableValidation == true
|
||||
@@ -496,18 +496,18 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
result.disableValidation == exp
|
||||
|
||||
where:
|
||||
base | overwrite | exp
|
||||
true | true | true
|
||||
true | false | false
|
||||
true | null | true
|
||||
base | overwrite | exp
|
||||
true | true | true
|
||||
true | false | false
|
||||
true | null | true
|
||||
|
||||
false | true | true
|
||||
false | false | false
|
||||
false | null | false
|
||||
false | true | true
|
||||
false | false | false
|
||||
false | null | false
|
||||
|
||||
null | true | true
|
||||
null | false | false
|
||||
null | null | false
|
||||
null | true | true
|
||||
null | false | false
|
||||
null | null | false
|
||||
}
|
||||
|
||||
def "Merge options for providesBalance"() {
|
||||
@@ -518,18 +518,18 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
result.providesBalance == exp
|
||||
|
||||
where:
|
||||
base | overwrite | exp
|
||||
true | true | true
|
||||
true | false | false
|
||||
true | null | true
|
||||
base | overwrite | exp
|
||||
true | true | true
|
||||
true | false | false
|
||||
true | null | true
|
||||
|
||||
false | true | true
|
||||
false | false | false
|
||||
false | null | false
|
||||
false | true | true
|
||||
false | false | false
|
||||
false | null | false
|
||||
|
||||
null | true | true
|
||||
null | false | false
|
||||
null | null | null
|
||||
null | true | true
|
||||
null | false | false
|
||||
null | null | null
|
||||
}
|
||||
|
||||
def "Merge options for validatePeers"() {
|
||||
@@ -540,18 +540,18 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
result.validatePeers == exp
|
||||
|
||||
where:
|
||||
base | overwrite | exp
|
||||
true | true | true
|
||||
true | false | false
|
||||
true | null | true
|
||||
base | overwrite | exp
|
||||
true | true | true
|
||||
true | false | false
|
||||
true | null | true
|
||||
|
||||
false | true | true
|
||||
false | false | false
|
||||
false | null | false
|
||||
false | true | true
|
||||
false | false | false
|
||||
false | null | false
|
||||
|
||||
null | true | true
|
||||
null | false | false
|
||||
null | null | true
|
||||
null | true | true
|
||||
null | false | false
|
||||
null | null | true
|
||||
}
|
||||
|
||||
def "Merge options for validateSyncing"() {
|
||||
@@ -562,18 +562,18 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
result.validateSyncing == exp
|
||||
|
||||
where:
|
||||
base | overwrite | exp
|
||||
true | true | true
|
||||
true | false | false
|
||||
true | null | true
|
||||
base | overwrite | exp
|
||||
true | true | true
|
||||
true | false | false
|
||||
true | null | true
|
||||
|
||||
false | true | true
|
||||
false | false | false
|
||||
false | null | false
|
||||
false | true | true
|
||||
false | false | false
|
||||
false | null | false
|
||||
|
||||
null | true | true
|
||||
null | false | false
|
||||
null | null | true
|
||||
null | true | true
|
||||
null | false | false
|
||||
null | null | true
|
||||
}
|
||||
|
||||
def "Merge options for timeout"() {
|
||||
@@ -589,12 +589,12 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
result.timeout == expValue
|
||||
|
||||
where:
|
||||
base | overwrite | exp
|
||||
1 | 2 | 2
|
||||
3 | 4 | 4
|
||||
5 | null | 5
|
||||
null | 6 | 6
|
||||
null | null | null
|
||||
base | overwrite | exp
|
||||
1 | 2 | 2
|
||||
3 | 4 | 4
|
||||
5 | null | 5
|
||||
null | 6 | 6
|
||||
null | null | null
|
||||
}
|
||||
|
||||
def "Merge options for minPeers"() {
|
||||
@@ -605,12 +605,12 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
result.minPeers == exp
|
||||
|
||||
where:
|
||||
base | overwrite | exp
|
||||
1 | 2 | 2
|
||||
3 | 4 | 4
|
||||
5 | null | 5
|
||||
null | 6 | 6
|
||||
null | null | 1
|
||||
base | overwrite | exp
|
||||
1 | 2 | 2
|
||||
3 | 4 | 4
|
||||
5 | null | 5
|
||||
null | 6 | 6
|
||||
null | null | 1
|
||||
}
|
||||
|
||||
def "Merge options for validationInterval"() {
|
||||
@@ -621,12 +621,12 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
result.validationInterval == exp
|
||||
|
||||
where:
|
||||
base | overwrite | exp
|
||||
1 | 2 | 2
|
||||
3 | 4 | 4
|
||||
5 | null | 5
|
||||
null | 6 | 6
|
||||
null | null | 30
|
||||
base | overwrite | exp
|
||||
1 | 2 | 2
|
||||
3 | 4 | 4
|
||||
5 | null | 5
|
||||
null | 6 | 6
|
||||
null | null | 30
|
||||
}
|
||||
|
||||
def "Options with default values"() {
|
||||
@@ -636,7 +636,7 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
def options = partialOptions.buildOptions()
|
||||
then:
|
||||
options == new ChainOptions.Options(
|
||||
false, false, 30, Duration.ofSeconds(60), null, true, 1, true, true, true
|
||||
false, false, 30, Duration.ofSeconds(60), null, true, 1, true, true, true, 1_000_000
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ class EthereumUpstreamValidatorSpec extends Specification {
|
||||
def "Doesnt validate chan and callLimit when disabled"() {
|
||||
setup:
|
||||
def options = ChainOptions.PartialOptions.getDefaults().tap {
|
||||
it.validateCalllimit = false
|
||||
it.validateCallLimit = false
|
||||
it.validateChain = false
|
||||
}.buildOptions()
|
||||
def up = Mock(Upstream) {
|
||||
@@ -344,7 +344,7 @@ class EthereumUpstreamValidatorSpec extends Specification {
|
||||
def "Upstream is valid if chain settings are valid"() {
|
||||
setup:
|
||||
def options = ChainOptions.PartialOptions.getDefaults().tap {
|
||||
it.validateCalllimit = false
|
||||
it.validateCallLimit = false
|
||||
}.buildOptions()
|
||||
def up = Mock(Upstream) {
|
||||
4 * getIngressReader() >> Mock(Reader) {
|
||||
@@ -366,7 +366,7 @@ class EthereumUpstreamValidatorSpec extends Specification {
|
||||
def "Upstream is not valid - specified optimism but got ethereum"() {
|
||||
setup:
|
||||
def options = ChainOptions.PartialOptions.getDefaults().tap {
|
||||
it.validateCalllimit = false
|
||||
it.validateCallLimit = false
|
||||
}.buildOptions()
|
||||
def up = Mock(Upstream) {
|
||||
4 * getIngressReader() >> Mock(Reader) {
|
||||
|
||||
Reference in New Issue
Block a user