Skip to content

Commit

Permalink
add a bit more debugging logging for retries
Browse files Browse the repository at this point in the history
  • Loading branch information
nullpointer0x00 committed Aug 20, 2024
1 parent 7e3e3ee commit fdfad30
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,7 @@ import io.provenance.explorer.domain.entities.ValidatorStateRecord
import io.provenance.explorer.domain.entities.ValidatorsCacheRecord
import io.provenance.explorer.domain.entities.updateHitCount
import io.provenance.explorer.domain.exceptions.requireNotNullToMessage
import io.provenance.explorer.domain.extensions.average
import io.provenance.explorer.domain.extensions.avg
import io.provenance.explorer.domain.extensions.get24HrBlockHeight
import io.provenance.explorer.domain.extensions.pageCountOfResults
import io.provenance.explorer.domain.extensions.sigToAddress
import io.provenance.explorer.domain.extensions.sigToBase64
import io.provenance.explorer.domain.extensions.toCoinStr
import io.provenance.explorer.domain.extensions.toDateTime
import io.provenance.explorer.domain.extensions.toDecimal
import io.provenance.explorer.domain.extensions.toDecimalStringOld
import io.provenance.explorer.domain.extensions.toOffset
import io.provenance.explorer.domain.extensions.toPercentage
import io.provenance.explorer.domain.extensions.toPercentageOld
import io.provenance.explorer.domain.extensions.translateAddress
import io.provenance.explorer.domain.extensions.translateByteArray
import io.provenance.explorer.domain.extensions.validatorMissedBlocks
import io.provenance.explorer.domain.extensions.validatorUptime
import io.provenance.explorer.domain.extensions.*

Check failure on line 26 in service/src/main/kotlin/io/provenance/explorer/service/ValidatorService.kt

View workflow job for this annotation

GitHub Actions / ktlint

Wildcard import (cannot be auto-corrected)
import io.provenance.explorer.domain.models.explorer.BlockProposer
import io.provenance.explorer.domain.models.explorer.CurrentValidatorState
import io.provenance.explorer.domain.models.explorer.hourlyBlockCount
Expand Down Expand Up @@ -492,20 +476,38 @@ class ValidatorService(
return BlockProposer(blockHeight, proposer, timestamp)
}

fun saveMissedBlocks(blockMeta: Query.GetBlockByHeightResponse) = transaction {
fun saveMissedBlocks(blockMeta: Query.GetBlockByHeightResponse, log: Boolean = false) = transaction {
val blockHeight = blockMeta.block.height()
if (log) {
logger.info("Processing missed blocks for height: $blockHeight")
}

val lastBlock = blockMeta.block.lastCommit
if (lastBlock.height.toInt() > 0) {
val signatures = lastBlock.signaturesList
.map { it.validatorAddress.translateByteArray().consensusAccountAddr }
val currentVals = ValidatorsCacheRecord.findById(lastBlock.height.toInt())?.validators
?: grpcClient.getValidatorsAtHeight(lastBlock.height.toInt())

currentVals.validatorsList.forEach { vali ->
if (!signatures.contains(vali.address)) {
logger.info("Inserting missed block record for height ${lastBlock.height.toInt()} and validator ${vali.address}")
MissedBlocksRecord.insert(lastBlock.height.toInt(), vali.address)
val lastBlockHeight = lastBlock.height.toInt()

if (lastBlockHeight > 0) {
val signatures = lastBlock.signaturesList.map { it.validatorAddress.translateByteArray().consensusAccountAddr }

var currentVals = ValidatorsCacheRecord.findById(lastBlockHeight)?.validators
if (currentVals == null) {
if (log) {
logger.info("Fetching validators from gRPC client for height: $lastBlockHeight")
}
currentVals = grpcClient.getValidatorsAtHeight(lastBlockHeight)
}

currentVals.validatorsList.forEach { validator ->
if (!signatures.contains(validator.address)) {
if (log) {
logger.info("Validator ${validator.address} missed block at height: $lastBlockHeight")
}
MissedBlocksRecord.insert(lastBlockHeight, validator.address)
}
}

if (log) {
logger.info("Finished processing missed blocks for height: $blockHeight")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class AsyncCachingV2(
if (rerunTxs.first) {
logger.info("attempting to calculate missing blocks for block ${blockRes.block.height()}")
}
validatorService.saveMissedBlocks(blockRes)
validatorService.saveMissedBlocks(blockRes, rerunTxs.first)
if (rerunTxs.first) {
logger.info("attempting to save txs ${blockRes.block.data.txsCount} for block ${blockRes.block.height()}")
}
Expand Down

0 comments on commit fdfad30

Please sign in to comment.