Skip to content
This repository has been archived by the owner on Jan 29, 2019. It is now read-only.

Commit

Permalink
#132 Wrong ETH Contract Balance
Browse files Browse the repository at this point in the history
-- add bundle download trace metrics
  • Loading branch information
hleb-albau committed May 25, 2018
1 parent a16307d commit 12a851d
Showing 1 changed file with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package fund.cyber.pump.ethereum.client

import fund.cyber.common.await
import fund.cyber.pump.common.node.BlockBundle
import fund.cyber.pump.common.node.BlockchainInterface
import fund.cyber.pump.ethereum.client.genesis.EthereumGenesisDataProvider
import fund.cyber.common.await
import fund.cyber.pump.common.pool.PoolInterface
import fund.cyber.pump.ethereum.client.genesis.EthereumGenesisDataProvider
import fund.cyber.search.model.chains.ChainEntity
import fund.cyber.search.model.chains.ChainEntityType
import fund.cyber.search.model.ethereum.EthereumBlock
Expand All @@ -22,16 +22,16 @@ import org.web3j.protocol.parity.methods.response.Trace
import java.math.BigInteger

class EthereumBlockBundle(
override val hash: String,
override val parentHash: String,
override val number: Long,
override val blockSize: Int,
val block: EthereumBlock,
val uncles: List<EthereumUncle>,
val txes: List<EthereumTx>
override val hash: String,
override val parentHash: String,
override val number: Long,
override val blockSize: Int,
val block: EthereumBlock,
val uncles: List<EthereumUncle>,
val txes: List<EthereumTx>
) : BlockBundle {
override fun entitiesByType(chainEntityType: ChainEntityType): List<ChainEntity> {
return when(chainEntityType) {
return when (chainEntityType) {
ChainEntityType.BLOCK -> listOf(block)
ChainEntityType.TX -> txes
ChainEntityType.UNCLE -> uncles
Expand All @@ -42,20 +42,22 @@ class EthereumBlockBundle(

@Component
class EthereumBlockchainInterface(
private val parityClient: Parity,
private val parityToBundleConverter: ParityToEthereumBundleConverter,
private val genesisDataProvider: EthereumGenesisDataProvider,
monitoring: MeterRegistry
private val parityClient: Parity,
private val parityToBundleConverter: ParityToEthereumBundleConverter,
private val genesisDataProvider: EthereumGenesisDataProvider,
monitoring: MeterRegistry
) : BlockchainInterface<EthereumBlockBundle>, PoolInterface<EthereumTx> {

private val downloadSpeedMonitor = monitoring.timer("pump_bundle_download")
private val downloadBundleMonitor = monitoring.timer("pump_bundle_download")
private val downloadReceiptesMonitor = monitoring.timer("pump_tx_receipt_download")
private val downloadTracesMonitor = monitoring.timer("pump_traces_download")

override fun lastNetworkBlock() = parityClient.ethBlockNumber().send().blockNumber.longValueExact()

override fun blockBundleByNumber(number: Long): EthereumBlockBundle {


val bundleRawData = downloadSpeedMonitor.recordCallable { downloadBundleData(number) }
val bundleRawData = downloadBundleMonitor.recordCallable { downloadBundleData(number) }

val bundle = parityToBundleConverter.convert(bundleRawData)
return if (number == 0L) genesisDataProvider.provide(bundle) else bundle
Expand All @@ -79,18 +81,17 @@ class EthereumBlockchainInterface(

val uncles = downloadUnclesData(ethBlock)

val txsReceipts = downloadTransactionReceiptData(ethBlock)

val calls = parityClient.traceBlock(blockParameter).send().traces
val txsReceipts = downloadReceiptesMonitor.recordCallable { downloadTransactionReceiptData(ethBlock) }
val calls = downloadTracesMonitor.recordCallable { parityClient.traceBlock(blockParameter).send().traces }

return BundleRawData(ethBlock.block, uncles, txsReceipts, calls)
}

private fun downloadUnclesData(ethBlock: EthBlock): List<EthBlock.Block> {
val unclesFutures = ethBlock.block.uncles.mapIndexed { index, _ ->
parityClient
.ethGetUncleByBlockHashAndIndex(ethBlock.block.hash, BigInteger.valueOf(index.toLong()))
.sendAsync()
.ethGetUncleByBlockHashAndIndex(ethBlock.block.hash, BigInteger.valueOf(index.toLong()))
.sendAsync()
}
return unclesFutures.await().map { uncleEthBlock -> uncleEthBlock.block }
}
Expand Down

0 comments on commit 12a851d

Please sign in to comment.