diff --git a/src/main/kotlin/io/emeraldpay/dshackle/Global.kt b/src/main/kotlin/io/emeraldpay/dshackle/Global.kt index 1ec1c3df..b1ebd933 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/Global.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/Global.kt @@ -44,8 +44,15 @@ class Global { "ethereum" to Chain.ETHEREUM, "ethereum-classic" to Chain.ETHEREUM_CLASSIC, "eth" to Chain.ETHEREUM, - "polygon" to Chain.MATIC, - "matic" to Chain.MATIC, + "polygon" to Chain.POLYGON, + "matic" to Chain.POLYGON, + "arbitrum" to Chain.ARBITRUM, + "arb" to Chain.ARBITRUM, + "optimism" to Chain.OPTIMISM, + "binance" to Chain.BSC, + "bsc" to Chain.BSC, + "bnb-smart-chan" to Chain.BSC, + "etc" to Chain.ETHEREUM_CLASSIC, "etc" to Chain.ETHEREUM_CLASSIC, "morden" to Chain.TESTNET_MORDEN, "kovan" to Chain.TESTNET_KOVAN, diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/TokensConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/TokensConfig.kt index 55560767..d0944965 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/TokensConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/TokensConfig.kt @@ -41,7 +41,7 @@ class TokensConfig( type == null -> type address.isNullOrBlank() -> "address" blockchain != null && - (BlockchainType.from(blockchain!!) == BlockchainType.ETHEREUM_POS || BlockchainType.from(blockchain!!) == BlockchainType.ETHEREUM) && + (BlockchainType.from(blockchain!!) == BlockchainType.EVM_POS || BlockchainType.from(blockchain!!) == BlockchainType.EVM_POW) && !Address.isValidAddress(address) -> "address" else -> null } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt index 024030a8..292bdbbb 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt @@ -31,6 +31,7 @@ import io.emeraldpay.dshackle.upstream.Multistream import io.emeraldpay.dshackle.upstream.MultistreamHolder import io.emeraldpay.dshackle.upstream.Selector import io.emeraldpay.dshackle.upstream.calls.EthereumCallSelector +import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcError import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcException @@ -66,14 +67,16 @@ open class NativeCall( private val ethereumCallSelectors = EnumMap(Chain::class.java) init { + val casting = mapOf( + BlockchainType.EVM_POS to EthereumPosMultiStream::class.java, + BlockchainType.EVM_POW to EthereumMultistream::class.java, + ) + multistreamHolder.observeChains().subscribe { chain -> - if ((BlockchainType.from(chain) == BlockchainType.ETHEREUM_POS || BlockchainType.from(chain) == BlockchainType.ETHEREUM) && !ethereumCallSelectors.containsKey( - chain - ) - ) { + casting[BlockchainType.from(chain)]?.let { cast -> multistreamHolder.getUpstream(chain)?.let { up -> - val reader = up.cast(EthereumPosMultiStream::class.java).getReader() - ethereumCallSelectors[chain] = EthereumCallSelector(reader.heightByHash()) + val reader = up.cast(cast).getReader() + ethereumCallSelectors.putIfAbsent(chain, EthereumCallSelector(reader.heightByHash())) } } } @@ -212,7 +215,7 @@ open class NativeCall( } // for ethereum the actual block needed for the call may be specified in the call parameters val callSpecificMatcher: Mono = - if (BlockchainType.from(upstream.chain) == BlockchainType.ETHEREUM_POS || BlockchainType.from(upstream.chain) == BlockchainType.ETHEREUM) { + if (BlockchainType.from(upstream.chain) == BlockchainType.EVM_POS || BlockchainType.from(upstream.chain) == BlockchainType.EVM_POW) { ethereumCallSelectors[chain]?.getMatcher(method, params, upstream.getHead()) } else { null diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeSubscribe.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeSubscribe.kt index f57b0fd7..6edd8027 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeSubscribe.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeSubscribe.kt @@ -57,7 +57,7 @@ open class NativeSubscribe( fun start(request: BlockchainOuterClass.NativeSubscribeRequest): Publisher { val chain = Chain.byId(request.chainValue) - if (BlockchainType.from(chain) != BlockchainType.ETHEREUM_POS && BlockchainType.from(chain) != BlockchainType.ETHEREUM) { + if (BlockchainType.from(chain) != BlockchainType.EVM_POS && BlockchainType.from(chain) != BlockchainType.EVM_POW) { return Mono.error(UnsupportedOperationException("Native subscribe is not supported for ${chain.chainCode}")) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackERC20Address.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackERC20Address.kt index 0f47b6e2..6de9b522 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackERC20Address.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackERC20Address.kt @@ -70,7 +70,7 @@ class TrackERC20Address( override fun isSupported(chain: Chain, asset: String): Boolean { return tokens.containsKey(TokenId(chain, asset.lowercase(Locale.getDefault()))) && - (BlockchainType.from(chain) == BlockchainType.ETHEREUM_POS || BlockchainType.from(chain) == BlockchainType.ETHEREUM) && multistreamHolder.isAvailable(chain) + (BlockchainType.from(chain) == BlockchainType.EVM_POS || BlockchainType.from(chain) == BlockchainType.EVM_POW) && multistreamHolder.isAvailable(chain) } override fun getBalance(request: BlockchainOuterClass.BalanceRequest): Flux { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumAddress.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumAddress.kt index 7a03d93e..4bef295d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumAddress.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumAddress.kt @@ -43,7 +43,7 @@ class TrackEthereumAddress( override fun isSupported(chain: Chain, asset: String): Boolean { return asset == "ether" && - (BlockchainType.from(chain) == BlockchainType.ETHEREUM_POS || BlockchainType.from(chain) == BlockchainType.ETHEREUM) && multistreamHolder.isAvailable(chain) + (BlockchainType.from(chain) == BlockchainType.EVM_POS || BlockchainType.from(chain) == BlockchainType.EVM_POW) && multistreamHolder.isAvailable(chain) } override fun getBalance(request: BlockchainOuterClass.BalanceRequest): Flux { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumTx.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumTx.kt index b3cea3cd..75401d78 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumTx.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumTx.kt @@ -62,7 +62,7 @@ class TrackEthereumTx( private val log = LoggerFactory.getLogger(TrackEthereumTx::class.java) override fun isSupported(chain: Chain): Boolean { - return (BlockchainType.from(chain) == BlockchainType.ETHEREUM_POS || BlockchainType.from(chain) == BlockchainType.ETHEREUM) && multistreamHolder.isAvailable(chain) + return (BlockchainType.from(chain) == BlockchainType.EVM_POS || BlockchainType.from(chain) == BlockchainType.EVM_POW) && multistreamHolder.isAvailable(chain) } override fun subscribe(request: BlockchainOuterClass.TxStatusRequest): Flux { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt b/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt index e984e91b..bda626e2 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt @@ -87,13 +87,13 @@ open class ConfiguredUpstreams( val options = (up.options ?: UpstreamsConfig.Options()) .merge(defaultOptions[chain] ?: UpstreamsConfig.Options.getDefaults()) val upstream = when (BlockchainType.from(chain)) { - BlockchainType.ETHEREUM -> { + BlockchainType.EVM_POW -> { buildEthereumUpstream(up.cast(UpstreamsConfig.EthereumConnection::class.java), chain, options) } BlockchainType.BITCOIN -> { buildBitcoinUpstream(up.cast(UpstreamsConfig.BitcoinConnection::class.java), chain, options) } - BlockchainType.ETHEREUM_POS -> { + BlockchainType.EVM_POS -> { buildEthereumPosUpstream(up.cast(UpstreamsConfig.EthereumPosConnection::class.java), chain, options) } else -> { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt index fbf75e53..7587d6c2 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt @@ -62,7 +62,7 @@ open class CurrentMultistreamHolder( val chain = change.chain try { when (BlockchainType.from(chain)) { - BlockchainType.ETHEREUM -> { + BlockchainType.EVM_POW -> { val up = change.upstream.cast(EthereumUpstream::class.java) val current = chainMapping[chain] val factory = Callable { @@ -70,7 +70,7 @@ open class CurrentMultistreamHolder( } processUpdate(change, up, current, factory) } - BlockchainType.ETHEREUM_POS -> { + BlockchainType.EVM_POS -> { val up = change.upstream.cast(EthereumPosUpstream::class.java) val current = chainMapping[chain] val factory = Callable { @@ -145,9 +145,9 @@ open class CurrentMultistreamHolder( fun setupDefaultMethods(chain: Chain): CallMethods { val created = when (BlockchainType.from(chain)) { - BlockchainType.ETHEREUM -> DefaultEthereumMethods(chain) + BlockchainType.EVM_POW -> DefaultEthereumMethods(chain) BlockchainType.BITCOIN -> DefaultBitcoinMethods() - BlockchainType.ETHEREUM_POS -> DefaultEthereumMethods(chain) + BlockchainType.EVM_POS -> DefaultEthereumMethods(chain) else -> throw IllegalStateException("Unsupported chain: $chain") } callTargets[chain] = created diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt index 66bce62a..f3a65f90 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt @@ -125,7 +125,7 @@ class DefaultEthereumMethods( Chain.ETHEREUM_CLASSIC == chain -> { "\"1\"" } - Chain.MATIC == chain -> { + Chain.POLYGON == chain -> { "\"137\"" } Chain.TESTNET_MORDEN == chain -> { @@ -151,7 +151,7 @@ class DefaultEthereumMethods( Chain.ETHEREUM == chain -> { "\"0x1\"" } - Chain.MATIC == chain -> { + Chain.POLYGON == chain -> { "\"0x89\"" } Chain.TESTNET_ROPSTEN == chain -> { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumBlockValidator.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumBlockValidator.kt index eb5113b7..81d41144 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumBlockValidator.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumBlockValidator.kt @@ -111,7 +111,7 @@ class EthereumBlockValidator : BlockValidator { ) } - val timestampValid = it.timestamp > cur.timestamp + val timestampValid = it.timestamp >= cur.timestamp if (!timestampValid) { log.warn( "Block timestamp {} not valid for {}. Must be greater than {}", diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt index b2b6bec2..44eec5d0 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt @@ -240,6 +240,7 @@ open class WsConnection( .aggregateFrames(msgSizeLimit) .receiveFrames() .map { ByteBufInputStream(it.content()).readAllBytes() } + .filter{ it.isNotEmpty() } .flatMap { try { val msg = parser.parse(it) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcUpstreams.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcUpstreams.kt index 446dd487..db8774ad 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcUpstreams.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcUpstreams.kt @@ -190,11 +190,11 @@ class GrpcUpstreams( ) val blockchainType = BlockchainType.from(chain) - if (blockchainType == BlockchainType.ETHEREUM) { + if (blockchainType == BlockchainType.EVM_POW) { return getOrCreateEthereum(chain, metrics) } else if (blockchainType == BlockchainType.BITCOIN) { return getOrCreateBitcoin(chain, metrics) - } else if (blockchainType == BlockchainType.ETHEREUM_POS) { + } else if (blockchainType == BlockchainType.EVM_POS) { return getOrCreateEthereumPos(chain, metrics) } else { throw IllegalArgumentException("Unsupported blockchain: $chain") diff --git a/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy b/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy index 59414f04..660b7611 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy @@ -27,11 +27,9 @@ import io.emeraldpay.dshackle.upstream.calls.CallMethods import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods import io.emeraldpay.dshackle.upstream.Upstream import io.emeraldpay.dshackle.upstream.MultistreamHolder -import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosRpcUpstream import io.emeraldpay.dshackle.upstream.ethereum.EthereumReader -import io.emeraldpay.dshackle.upstream.ethereum.EthereumRpcUpstream import io.emeraldpay.grpc.BlockchainType import io.emeraldpay.grpc.Chain import org.jetbrains.annotations.NotNull @@ -48,7 +46,7 @@ class MultistreamHolderMock implements MultistreamHolder { Multistream addUpstream(@NotNull Chain chain, @NotNull Upstream up) { if (!upstreams.containsKey(chain)) { - if (BlockchainType.from(chain) == BlockchainType.ETHEREUM_POS) { + if (BlockchainType.from(chain) == BlockchainType.EVM_POS) { if (up instanceof EthereumPosMultiStream) { upstreams[chain] = up } else if (up instanceof EthereumPosRpcUpstream) {