Skip to content

Commit 49c39fe

Browse files
committed
problem: same check coded in different places
1 parent c568f71 commit 49c39fe

File tree

3 files changed

+49
-38
lines changed

3 files changed

+49
-38
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Copyright (c) 2025 EmeraldPay Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.emeraldpay.dshackle
17+
18+
import io.emeraldpay.api.Chain
19+
20+
class ChainOptions {
21+
companion object {
22+
fun supportsEIP1559(chain: Chain): Boolean =
23+
when (chain) {
24+
Chain.ETHEREUM,
25+
Chain.TESTNET_GOERLI,
26+
Chain.TESTNET_HOLESKY,
27+
Chain.TESTNET_SEPOLIA,
28+
Chain.TESTNET_HOODI,
29+
-> true
30+
else -> false
31+
}
32+
33+
fun isPos(chain: Chain): Boolean =
34+
when (chain) {
35+
Chain.ETHEREUM,
36+
Chain.TESTNET_GOERLI,
37+
Chain.TESTNET_HOLESKY,
38+
Chain.TESTNET_HOODI,
39+
Chain.TESTNET_SEPOLIA,
40+
-> true
41+
else -> false
42+
}
43+
}
44+
}

src/main/kotlin/io/emeraldpay/dshackle/upstream/ForkWatchFactory.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package io.emeraldpay.dshackle.upstream
1717

1818
import io.emeraldpay.api.Chain
19+
import io.emeraldpay.dshackle.ChainOptions
1920
import org.slf4j.LoggerFactory
2021
import org.springframework.beans.factory.annotation.Autowired
2122
import org.springframework.stereotype.Service
@@ -34,22 +35,11 @@ class ForkWatchFactory(
3435
private val initialized = EnumMap<Chain, ForkWatch>(Chain::class.java)
3536
private val initializeLock = ReentrantLock()
3637

37-
private val posChains =
38-
listOf(
39-
// at this moment (Aug 2022) it's still a PoW, but upgrade is coming in weeks, so it's better to configure everything in advance
40-
Chain.ETHEREUM,
41-
// those are upgraded to Merge
42-
Chain.TESTNET_GOERLI,
43-
Chain.TESTNET_ROPSTEN,
44-
Chain.TESTNET_HOLESKY,
45-
Chain.TESTNET_SEPOLIA,
46-
)
47-
4838
fun create(chain: Chain): ForkWatch =
4939
initializeLock.withLock {
5040
initialized.getOrPut(chain) {
5141
val forkChoice =
52-
if (posChains.contains(chain)) {
42+
if (ChainOptions.isPos(chain)) {
5343
PriorityForkChoice().also {
5444
it.followUpstreams(
5545
currentMultistreamHolder

src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumMultistream.kt

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.emeraldpay.dshackle.upstream.ethereum
1818

1919
import io.emeraldpay.api.Chain
20+
import io.emeraldpay.dshackle.ChainOptions
2021
import io.emeraldpay.dshackle.cache.Caches
2122
import io.emeraldpay.dshackle.reader.CompoundReader
2223
import io.emeraldpay.dshackle.reader.MultistreamReader
@@ -68,32 +69,8 @@ open class EthereumMultistream(
6869

6970
private var subscribe = EthereumEgressSubscription(this, NoPendingTxes())
7071

71-
private val supportsEIP1559 =
72-
when (chain) {
73-
Chain.ETHEREUM,
74-
Chain.TESTNET_ROPSTEN,
75-
Chain.TESTNET_GOERLI,
76-
Chain.TESTNET_HOLESKY,
77-
Chain.TESTNET_SEPOLIA,
78-
Chain.TESTNET_HOODI,
79-
Chain.TESTNET_RINKEBY,
80-
-> true
81-
else -> false
82-
}
83-
84-
private val isPos =
85-
when (chain) {
86-
Chain.ETHEREUM,
87-
Chain.TESTNET_GOERLI,
88-
Chain.TESTNET_HOLESKY,
89-
Chain.TESTNET_HOODI,
90-
Chain.TESTNET_SEPOLIA,
91-
-> true
92-
else -> false
93-
}
94-
9572
private val feeEstimation =
96-
if (supportsEIP1559) {
73+
if (ChainOptions.supportsEIP1559(chain)) {
9774
EthereumPriorityFees(this, dataReaders, 256)
9875
} else {
9976
EthereumLegacyFees(this, dataReaders, 256)
@@ -153,7 +130,7 @@ open class EthereumMultistream(
153130
}
154131
} else {
155132
val newHead =
156-
if (isPos) {
133+
if (ChainOptions.isPos(chain)) {
157134
val heads = upstreams.map { Pair(it.getOptions().priority, it.getHead()) }
158135
MergedPosHead(heads)
159136
} else {

0 commit comments

Comments
 (0)