From 10f4c6b5fb082a0fa0ff4c3f571f1685eae5a3d3 Mon Sep 17 00:00:00 2001 From: Mike Sizov Date: Fri, 14 Jun 2024 20:35:03 +0700 Subject: [PATCH 1/4] Process arbitrum nitro eth_syncing message --- .../arbitrum/json/NitroSyncingJson.java | 47 +++++++++++++++++++ .../json/NitroSyncingJsonDeserializer.java | 28 +++++++++++ .../json/NitroSyncingJsonSerializer.java | 25 ++++++++++ .../ethereum/EthereumUpstreamValidator.kt | 9 +++- 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJson.java create mode 100644 src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJsonDeserializer.java create mode 100644 src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJsonSerializer.java diff --git a/src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJson.java b/src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJson.java new file mode 100644 index 000000000..9b27acba0 --- /dev/null +++ b/src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJson.java @@ -0,0 +1,47 @@ +package io.emeraldpay.dshackle.upstream.arbitrum.json; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +@JsonDeserialize(using = NitroSyncingJsonDeserializer.class) +@JsonSerialize(using = NitroSyncingJsonSerializer.class) +public class NitroSyncingJson { + + private boolean syncing; + + private Long syncTargetMsgCount; + private Long feedPendingMessageCount; + private Long msgCount; + + public boolean isSyncing() { + return syncing; + } + + public void setSyncing(boolean syncing) { + this.syncing = syncing; + } + + public Long getSyncTargetMsgCount() { + return syncTargetMsgCount; + } + + public void setSyncTargetMsgCount(Long syncTargetMsgCount) { + this.syncTargetMsgCount = syncTargetMsgCount; + } + + public Long getFeedPendingMessageCount() { + return feedPendingMessageCount; + } + + public void setFeedPendingMessageCount(Long feedPendingMessageCount) { + this.feedPendingMessageCount = feedPendingMessageCount; + } + + public Long getMsgCount() { + return msgCount; + } + + public void setMsgCount(Long msgCount) { + this.msgCount = msgCount; + } +} diff --git a/src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJsonDeserializer.java b/src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJsonDeserializer.java new file mode 100644 index 000000000..7bcbcfebf --- /dev/null +++ b/src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJsonDeserializer.java @@ -0,0 +1,28 @@ +package io.emeraldpay.dshackle.upstream.arbitrum.json; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonNode; +import io.emeraldpay.dshackle.upstream.arbitrum.json.NitroSyncingJson; +import io.emeraldpay.dshackle.upstream.ethereum.json.EtherJsonDeserializer; + +import java.io.IOException; + +public class NitroSyncingJsonDeserializer extends EtherJsonDeserializer { + + @Override + public NitroSyncingJson deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { + JsonNode node = jp.readValueAsTree(); + NitroSyncingJson resp = new NitroSyncingJson(); + if (node.isBoolean()) { + resp.setSyncing(node.asBoolean()); + } else { + resp.setSyncing(true); + resp.setSyncTargetMsgCount(getLong(node, "syncTargetMsgCount")); + resp.setFeedPendingMessageCount(getLong(node, "feedPendingMessageCount")); + resp.setMsgCount(getLong(node, "msgCount")); + } + return resp; + } +} diff --git a/src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJsonSerializer.java b/src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJsonSerializer.java new file mode 100644 index 000000000..be63c51c4 --- /dev/null +++ b/src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJsonSerializer.java @@ -0,0 +1,25 @@ +package io.emeraldpay.dshackle.upstream.arbitrum.json; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import io.emeraldpay.dshackle.upstream.ethereum.json.EtherJsonSerializer; + +import java.io.IOException; + +public class NitroSyncingJsonSerializer extends EtherJsonSerializer { + + @Override + public void serialize(NitroSyncingJson value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + if (value == null) { + gen.writeNull(); + } else if (value.isSyncing()) { + gen.writeStartObject(); + writeField(gen, "syncTargetMsgCount", value.getSyncTargetMsgCount()); + writeField(gen, "feedPendingMessageCount", value.getFeedPendingMessageCount()); + writeField(gen, "msgCount", value.getMsgCount()); + gen.writeEndObject(); + } else { + gen.writeBoolean(false); + } + } +} diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamValidator.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamValidator.kt index c46fad378..956fd5dd2 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamValidator.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamValidator.kt @@ -28,6 +28,7 @@ import io.emeraldpay.dshackle.upstream.ChainResponse import io.emeraldpay.dshackle.upstream.Upstream import io.emeraldpay.dshackle.upstream.UpstreamAvailability import io.emeraldpay.dshackle.upstream.ValidateUpstreamSettingsResult +import io.emeraldpay.dshackle.upstream.arbitrum.json.NitroSyncingJson import io.emeraldpay.dshackle.upstream.ethereum.domain.Address import io.emeraldpay.dshackle.upstream.ethereum.hex.HexData import io.emeraldpay.dshackle.upstream.ethereum.json.SyncingJson @@ -58,7 +59,13 @@ open class EthereumUpstreamValidator @JvmOverloads constructor( override fun validateSyncingRequest(): ValidateSyncingRequest { return ValidateSyncingRequest( ChainRequest("eth_syncing", ListParams()), - ) { bytes -> objectMapper.readValue(bytes, SyncingJson::class.java).isSyncing } + ) { bytes -> + if (listOf(Chain.ARBITRUM__MAINNET, Chain.ARBITRUM__SEPOLIA, Chain.ARBITRUM_NOVA__MAINNET).contains(chain)) { + objectMapper.readValue(bytes, NitroSyncingJson::class.java).isSyncing + } else { + objectMapper.readValue(bytes, SyncingJson::class.java).isSyncing + } + } } override fun validatePeersRequest(): ValidatePeersRequest { From 880b200775c1a84dfb11bed265a1b7da593cb82d Mon Sep 17 00:00:00 2001 From: Mike Sizov Date: Fri, 14 Jun 2024 21:52:08 +0700 Subject: [PATCH 2/4] Simplify eth_syncing check --- .../arbitrum/json/NitroSyncingJson.java | 47 -------------- .../json/NitroSyncingJsonDeserializer.java | 28 --------- .../json/NitroSyncingJsonSerializer.java | 25 -------- .../upstream/ethereum/json/SyncingJson.java | 62 ------------------- .../json/SyncingJsonDeserializer.java | 41 ------------ .../ethereum/json/SyncingJsonSerializer.java | 39 ------------ .../ethereum/EthereumUpstreamValidator.kt | 10 +-- 7 files changed, 5 insertions(+), 247 deletions(-) delete mode 100644 src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJson.java delete mode 100644 src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJsonDeserializer.java delete mode 100644 src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJsonSerializer.java delete mode 100644 src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/SyncingJson.java delete mode 100644 src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/SyncingJsonDeserializer.java delete mode 100644 src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/SyncingJsonSerializer.java diff --git a/src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJson.java b/src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJson.java deleted file mode 100644 index 9b27acba0..000000000 --- a/src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJson.java +++ /dev/null @@ -1,47 +0,0 @@ -package io.emeraldpay.dshackle.upstream.arbitrum.json; - -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -@JsonDeserialize(using = NitroSyncingJsonDeserializer.class) -@JsonSerialize(using = NitroSyncingJsonSerializer.class) -public class NitroSyncingJson { - - private boolean syncing; - - private Long syncTargetMsgCount; - private Long feedPendingMessageCount; - private Long msgCount; - - public boolean isSyncing() { - return syncing; - } - - public void setSyncing(boolean syncing) { - this.syncing = syncing; - } - - public Long getSyncTargetMsgCount() { - return syncTargetMsgCount; - } - - public void setSyncTargetMsgCount(Long syncTargetMsgCount) { - this.syncTargetMsgCount = syncTargetMsgCount; - } - - public Long getFeedPendingMessageCount() { - return feedPendingMessageCount; - } - - public void setFeedPendingMessageCount(Long feedPendingMessageCount) { - this.feedPendingMessageCount = feedPendingMessageCount; - } - - public Long getMsgCount() { - return msgCount; - } - - public void setMsgCount(Long msgCount) { - this.msgCount = msgCount; - } -} diff --git a/src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJsonDeserializer.java b/src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJsonDeserializer.java deleted file mode 100644 index 7bcbcfebf..000000000 --- a/src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJsonDeserializer.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.emeraldpay.dshackle.upstream.arbitrum.json; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonNode; -import io.emeraldpay.dshackle.upstream.arbitrum.json.NitroSyncingJson; -import io.emeraldpay.dshackle.upstream.ethereum.json.EtherJsonDeserializer; - -import java.io.IOException; - -public class NitroSyncingJsonDeserializer extends EtherJsonDeserializer { - - @Override - public NitroSyncingJson deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { - JsonNode node = jp.readValueAsTree(); - NitroSyncingJson resp = new NitroSyncingJson(); - if (node.isBoolean()) { - resp.setSyncing(node.asBoolean()); - } else { - resp.setSyncing(true); - resp.setSyncTargetMsgCount(getLong(node, "syncTargetMsgCount")); - resp.setFeedPendingMessageCount(getLong(node, "feedPendingMessageCount")); - resp.setMsgCount(getLong(node, "msgCount")); - } - return resp; - } -} diff --git a/src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJsonSerializer.java b/src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJsonSerializer.java deleted file mode 100644 index be63c51c4..000000000 --- a/src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJsonSerializer.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.emeraldpay.dshackle.upstream.arbitrum.json; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.SerializerProvider; -import io.emeraldpay.dshackle.upstream.ethereum.json.EtherJsonSerializer; - -import java.io.IOException; - -public class NitroSyncingJsonSerializer extends EtherJsonSerializer { - - @Override - public void serialize(NitroSyncingJson value, JsonGenerator gen, SerializerProvider serializers) throws IOException { - if (value == null) { - gen.writeNull(); - } else if (value.isSyncing()) { - gen.writeStartObject(); - writeField(gen, "syncTargetMsgCount", value.getSyncTargetMsgCount()); - writeField(gen, "feedPendingMessageCount", value.getFeedPendingMessageCount()); - writeField(gen, "msgCount", value.getMsgCount()); - gen.writeEndObject(); - } else { - gen.writeBoolean(false); - } - } -} diff --git a/src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/SyncingJson.java b/src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/SyncingJson.java deleted file mode 100644 index ed6b3ffaa..000000000 --- a/src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/SyncingJson.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2016-2019 Igor Artamonov, All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.emeraldpay.dshackle.upstream.ethereum.json; - -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -@JsonDeserialize(using = SyncingJsonDeserializer.class) -@JsonSerialize(using = SyncingJsonSerializer.class) -public class SyncingJson { - - private boolean syncing; - - private Long startingBlock; - private Long currentBlock; - private Long highestBlock; - - public boolean isSyncing() { - return syncing; - } - - public void setSyncing(boolean syncing) { - this.syncing = syncing; - } - - public Long getStartingBlock() { - return startingBlock; - } - - public void setStartingBlock(Long startingBlock) { - this.startingBlock = startingBlock; - } - - public Long getCurrentBlock() { - return currentBlock; - } - - public void setCurrentBlock(Long currentBlock) { - this.currentBlock = currentBlock; - } - - public Long getHighestBlock() { - return highestBlock; - } - - public void setHighestBlock(Long highestBlock) { - this.highestBlock = highestBlock; - } -} diff --git a/src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/SyncingJsonDeserializer.java b/src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/SyncingJsonDeserializer.java deleted file mode 100644 index f146f7808..000000000 --- a/src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/SyncingJsonDeserializer.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2016-2019 Igor Artamonov, All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.emeraldpay.dshackle.upstream.ethereum.json; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonNode; - -import java.io.IOException; - -public class SyncingJsonDeserializer extends EtherJsonDeserializer { - - @Override - public SyncingJson deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { - JsonNode node = jp.readValueAsTree(); - SyncingJson resp = new SyncingJson(); - if (node.isBoolean()) { - resp.setSyncing(node.asBoolean()); - } else { - resp.setSyncing(true); - resp.setStartingBlock(getLong(node, "startingBlock")); - resp.setCurrentBlock(getLong(node, "currentBlock")); - resp.setHighestBlock(getLong(node, "highestBlock")); - } - return resp; - } -} diff --git a/src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/SyncingJsonSerializer.java b/src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/SyncingJsonSerializer.java deleted file mode 100644 index 09e3d7d63..000000000 --- a/src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/SyncingJsonSerializer.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2016-2019 Igor Artamonov, All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.emeraldpay.dshackle.upstream.ethereum.json; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.SerializerProvider; - -import java.io.IOException; - -public class SyncingJsonSerializer extends EtherJsonSerializer { - - @Override - public void serialize(SyncingJson value, JsonGenerator gen, SerializerProvider serializers) throws IOException { - if (value == null) { - gen.writeNull(); - } else if (value.isSyncing()) { - gen.writeStartObject(); - writeField(gen, "startingBlock", value.getStartingBlock()); - writeField(gen, "currentBlock", value.getCurrentBlock()); - writeField(gen, "highestBlock", value.getHighestBlock()); - gen.writeEndObject(); - } else { - gen.writeBoolean(false); - } - } -} diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamValidator.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamValidator.kt index 956fd5dd2..204c35565 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamValidator.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamValidator.kt @@ -28,10 +28,8 @@ import io.emeraldpay.dshackle.upstream.ChainResponse import io.emeraldpay.dshackle.upstream.Upstream import io.emeraldpay.dshackle.upstream.UpstreamAvailability import io.emeraldpay.dshackle.upstream.ValidateUpstreamSettingsResult -import io.emeraldpay.dshackle.upstream.arbitrum.json.NitroSyncingJson import io.emeraldpay.dshackle.upstream.ethereum.domain.Address import io.emeraldpay.dshackle.upstream.ethereum.hex.HexData -import io.emeraldpay.dshackle.upstream.ethereum.json.SyncingJson import io.emeraldpay.dshackle.upstream.ethereum.json.TransactionCallJson import io.emeraldpay.dshackle.upstream.rpcclient.ListParams import org.springframework.scheduling.concurrent.CustomizableThreadFactory @@ -60,10 +58,12 @@ open class EthereumUpstreamValidator @JvmOverloads constructor( return ValidateSyncingRequest( ChainRequest("eth_syncing", ListParams()), ) { bytes -> - if (listOf(Chain.ARBITRUM__MAINNET, Chain.ARBITRUM__SEPOLIA, Chain.ARBITRUM_NOVA__MAINNET).contains(chain)) { - objectMapper.readValue(bytes, NitroSyncingJson::class.java).isSyncing + val raw = Global.objectMapper.readTree(bytes) + if (raw.isBoolean) { + raw.asBoolean() } else { - objectMapper.readValue(bytes, SyncingJson::class.java).isSyncing + log.warn("Received syncing object ${raw.toPrettyString()} for upstream ${upstream.getId()}") + true } } } From 58646812594aa5bb1af5c26c88b123f8c878eb2a Mon Sep 17 00:00:00 2001 From: Mike Sizov Date: Fri, 14 Jun 2024 21:56:22 +0700 Subject: [PATCH 3/4] enable syncing validation --- foundation/src/main/resources/chains.yaml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/foundation/src/main/resources/chains.yaml b/foundation/src/main/resources/chains.yaml index b9de05b02..0aa651b82 100644 --- a/foundation/src/main/resources/chains.yaml +++ b/foundation/src/main/resources/chains.yaml @@ -213,8 +213,6 @@ chain-settings: settings: expected-block-time: 2.7s allow-pruning-requirement: true - options: - disable-validation: true lags: syncing: 40 lagging: 20 @@ -240,8 +238,6 @@ chain-settings: settings: expected-block-time: 260ms allow-pruning-requirement: true - options: - disable-validation: true lags: syncing: 40 lagging: 20 @@ -358,7 +354,7 @@ chain-settings: allow-pruning-requirement: true options: validate-peers: false - validate-syncing: false + validate-syncing: true lags: syncing: 10 lagging: 5 @@ -1271,7 +1267,7 @@ chain-settings: settings: options: validate-peers: false - validate-syncing: false + validate-syncing: true fork-choice: quorum expected-block-time: 300ms lags: From 08ddd3197ddcfafe3c5be344936f8ce184c85354 Mon Sep 17 00:00:00 2001 From: Mike Sizov Date: Fri, 14 Jun 2024 22:13:43 +0700 Subject: [PATCH 4/4] remove extra lines --- foundation/src/main/resources/chains.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/foundation/src/main/resources/chains.yaml b/foundation/src/main/resources/chains.yaml index 0aa651b82..abc8e44d5 100644 --- a/foundation/src/main/resources/chains.yaml +++ b/foundation/src/main/resources/chains.yaml @@ -354,7 +354,6 @@ chain-settings: allow-pruning-requirement: true options: validate-peers: false - validate-syncing: true lags: syncing: 10 lagging: 5 @@ -1267,7 +1266,6 @@ chain-settings: settings: options: validate-peers: false - validate-syncing: true fork-choice: quorum expected-block-time: 300ms lags: