diff --git a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/BitcoinCore.kt b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/BitcoinCore.kt index eb999ec08..449c9f356 100644 --- a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/BitcoinCore.kt +++ b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/BitcoinCore.kt @@ -474,6 +474,7 @@ class BitcoinCore( val statusInfo = LinkedHashMap() statusInfo["Synced Until"] = lastBlockInfo?.timestamp?.let { Date(it) } ?: "N/A" + statusInfo["Syncing Peer"] = initialBlockDownload.syncPeer?.host ?: "N/A" statusInfo["Errors"] = errorStorage.errors statusInfo["Last Block Height"] = lastBlockInfo?.height ?: "N/A" @@ -485,6 +486,18 @@ class BitcoinCore( peerStatus["Host"] = peer.host peerStatus["Best Block"] = peer.announcedLastBlockHeight + peer.tasks.let { peerTasks -> + if (peerTasks.isEmpty()) { + peerStatus["tasks"] = "no tasks" + } else { + val tasks = LinkedHashMap() + peerTasks.forEach { task -> + tasks[task.javaClass.simpleName] = "[${task.state}]" + } + peerStatus["tasks"] = tasks + } + } + peers["Peer ${index + 1}"] = peerStatus } diff --git a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/blocks/InitialBlockDownload.kt b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/blocks/InitialBlockDownload.kt index 77448f6b3..5caee0f67 100644 --- a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/blocks/InitialBlockDownload.kt +++ b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/blocks/InitialBlockDownload.kt @@ -23,7 +23,7 @@ class InitialBlockDownload( private val peerSwitchMinimumRatio = 1.5 @Volatile - private var syncPeer: Peer? = null + var syncPeer: Peer? = null private var selectNewPeer = false private val peersQueue = Executors.newSingleThreadExecutor() private val logger = Logger.getLogger("IBD") diff --git a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/Peer.kt b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/Peer.kt index a70e84e82..8af944e4e 100644 --- a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/Peer.kt +++ b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/Peer.kt @@ -30,10 +30,10 @@ class Peer( var synced = false var connected = false var connectionTime: Long = 1000 - private var connectStartTime: Long? = null + var tasks = mutableListOf() + private var connectStartTime: Long? = null private val peerConnection = PeerConnection(host, network, this, executorService, networkMessageParser, networkMessageSerializer) - private var tasks = mutableListOf() private val timer = PeerTimer() val ready: Boolean diff --git a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/GetBlockHashesTask.kt b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/GetBlockHashesTask.kt index 9037f1d35..4194fe2b0 100644 --- a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/GetBlockHashesTask.kt +++ b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/GetBlockHashesTask.kt @@ -24,6 +24,9 @@ class GetBlockHashesTask(private val blockLocatorHashes: List, expect allowedIdleTime = Math.max(minAllowedIdleTime, resolvedAllowedIdleTime.toLong()) } + override val state: String + get() = "expectedHashesMinCount: $expectedHashesMinCount; allowedIdleTime: $allowedIdleTime" + override fun start() { requester?.let { it.send(GetBlocksMessage(blockLocatorHashes, it.protocolVersion, ByteArray(32))) } resetTimer() diff --git a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/GetMerkleBlocksTask.kt b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/GetMerkleBlocksTask.kt index 1f92fb3cb..81117d089 100644 --- a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/GetMerkleBlocksTask.kt +++ b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/GetMerkleBlocksTask.kt @@ -37,6 +37,9 @@ class GetMerkleBlocksTask( private var maxWarningCount = 10 private var firstResponseReceived = false + override val state: String + get() = "minMerkleBlocksCount: ${minMerkleBlocks.roundToInt()}; minTransactionsCount: ${minTransactions.roundToInt()}; minTransactionsSize: ${minTransactions.roundToInt()}" + override fun start() { val items = blockHashes.map { hash -> InventoryItem(InventoryItem.MSG_FILTERED_BLOCK, hash.headerHash) diff --git a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/PeerTask.kt b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/PeerTask.kt index d43f4ea76..195a79e81 100644 --- a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/PeerTask.kt +++ b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/PeerTask.kt @@ -16,6 +16,7 @@ open class PeerTask { var requester: Requester? = null var listener: Listener? = null + open val state: String = "" protected var lastActiveTime: Long? = null protected var allowedIdleTime: Long? = null diff --git a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/RequestTransactionsTask.kt b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/RequestTransactionsTask.kt index 35165a11b..3162cb71b 100644 --- a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/RequestTransactionsTask.kt +++ b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/RequestTransactionsTask.kt @@ -10,6 +10,10 @@ class RequestTransactionsTask(hashes: List) : PeerTask() { val hashes = hashes.toMutableList() var transactions = mutableListOf() + override val state: String + get() = + "hashesCount: ${hashes.size}; receivedTransactionsCount: ${transactions.size}" + override fun start() { val items = hashes.map { hash -> InventoryItem(InventoryItem.MSG_TX, hash) diff --git a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/SendTransactionTask.kt b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/SendTransactionTask.kt index 5e15571e6..c1cbfae4d 100644 --- a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/SendTransactionTask.kt +++ b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/network/peer/task/SendTransactionTask.kt @@ -1,5 +1,6 @@ package io.horizontalsystems.bitcoincore.network.peer.task +import io.horizontalsystems.bitcoincore.extensions.toReversedHex import io.horizontalsystems.bitcoincore.models.InventoryItem import io.horizontalsystems.bitcoincore.network.messages.GetDataMessage import io.horizontalsystems.bitcoincore.network.messages.IMessage @@ -8,6 +9,10 @@ import io.horizontalsystems.bitcoincore.network.messages.TransactionMessage import io.horizontalsystems.bitcoincore.storage.FullTransaction class SendTransactionTask(val transaction: FullTransaction) : PeerTask() { + + override val state: String + get() = "transaction: ${transaction.header.hash.toReversedHex()}" + override fun start() { requester?.send(InvMessage(InventoryItem.MSG_TX, transaction.header.hash)) }