Skip to content

Commit

Permalink
Merge pull request #617 from wavesplatform/node-296-block-in-logs
Browse files Browse the repository at this point in the history
Node 296 block in logs
  • Loading branch information
alexeykiselev authored Oct 20, 2017
2 parents 99e1c4f + bad5a25 commit 31db78d
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/main/scala/com/wavesplatform/Coordinator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ object Coordinator extends ScorexLogging with Instrumented {
firstDeclined
.foldLeft[Either[ValidationError, BigInt]](Right(history.score())) {
case (_, (i, b, e)) if i == 0 =>
log.warn(s"Can't process fork starting with $lastCommonBlockId, error appending block ${b.uniqueId}: $e")
log.warn(s"Can't process fork starting with $lastCommonBlockId, error appending block $b: $e")
Left(e)

case (r, (i, b, e)) =>
log.debug(s"Processed $i of ${newBlocks.size} blocks from extension")
log.warn(s"Can't process fork starting with $lastCommonBlockId, error appending block ${b.uniqueId}: $e")
log.warn(s"Can't process fork starting with $lastCommonBlockId, error appending block $b: $e")
r
}
}
Expand Down Expand Up @@ -150,7 +150,7 @@ object Coordinator extends ScorexLogging with Instrumented {
featureProvider: FeatureProvider)
(block: Block, local: Boolean): Either[ValidationError, Int] = for {
_ <- Either.cond(checkpoint.isBlockValid(block.signerData.signature, history.height() + 1), (),
GenericError(s"Block ${block.uniqueId} at height ${history.height() + 1} is not valid w.r.t. checkpoint"))
GenericError(s"Block $block at height ${history.height() + 1} is not valid w.r.t. checkpoint"))
_ <- blockConsensusValidation(history, featureProvider, settings, time.correctedTime(), block) { height =>
PoSCalc.generatingBalance(stateReader, settings.functionalitySettings, block.signerData.generator, height).toEither.left.map(_.toString)
.flatMap(validateEffectiveBalance(featureProvider, settings.functionalitySettings, block, height))
Expand Down Expand Up @@ -188,7 +188,7 @@ object Coordinator extends ScorexLogging with Instrumented {
val hh = existingItems.map(_.height) :+ genesisBlockHeight
history.blockAt(hh(fork.size)).foreach {
lastValidBlock =>
log.warn(s"Fork detected (length = ${fork.size}), rollback to last valid block id [${lastValidBlock.uniqueId}]")
log.warn(s"Fork detected (length = ${fork.size}), rollback to last valid block $lastValidBlock]")
blockBlockForkStats.increment()
blockForkHeightStats.record(fork.size)
blockchainUpdater.removeAfter(lastValidBlock.uniqueId)
Expand Down Expand Up @@ -229,7 +229,7 @@ object Coordinator extends ScorexLogging with Instrumented {
hit = calcHit(prevBlockData, generator)
target = calcTarget(parent.consensusData.baseTarget, parent.timestamp, blockTime, effectiveBalance)
_ <- Either.cond(hit < target, (), s"calculated hit $hit >= calculated target $target")
} yield ()).left.map(e => GenericError(s"Block ${block.uniqueId} is invalid: $e"))
} yield ()).left.map(e => GenericError(s"Block $block is invalid: $e"))
}

private val blockBlockForkStats = Kamon.metrics.counter("block-fork")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class HistoryWriterImpl private(file: Option[File], val synchronizationToken: Re

if (h % 100 == 0) db.compact(CompactFillRate, CompactMemorySize)

log.trace(s"Full Block(id=${block.uniqueId},txs_count=${block.transactionData.size}) persisted")
log.trace(s"Full Block $block(id=${block.uniqueId} persisted")
blockDiff
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,18 @@ class CoordinatorHandler(checkpointService: CheckpointService,
Signed.validateSignatures(b).flatMap(b => processBlock(b, false))
} map {
case Right(None) =>
log.trace(s"Block ${b.uniqueId} already appended")
log.trace(s"Block $b already appended")
case Right(Some(newScore)) =>
log.debug(s"Appended block ${b.uniqueId}")
log.debug(s"Appended block $b")
if (b.transactionData.isEmpty)
allChannels.broadcast(BlockForged(b), Some(ctx.channel()))
miner.scheduleMining()
allChannels.broadcast(LocalScoreChanged(newScore))
case Left(is: InvalidSignature) =>
peerDatabase.blacklistAndClose(ctx.channel(), s"Could not append block ${b.uniqueId}: $is")
peerDatabase.blacklistAndClose(ctx.channel(), s"Could not append block $b: $is")
case Left(ve) =>
BlockStats.declined(b, BlockStats.Source.Broadcast)
log.debug(s"Could not append block ${b.uniqueId}: $ve")
log.debug(s"Could not append block $b: $ve")
}).onErrorHandle[Unit](ctx.fireExceptionCaught).runAsync

case md: MicroblockData =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ExtensionBlocksLoader(
} else {
newBlocks.par.find(!_.signatureValid) match {
case Some(invalidBlock) =>
peerDatabase.blacklistAndClose(ctx.channel(),s"Got block ${invalidBlock.uniqueId} with invalid signature")
peerDatabase.blacklistAndClose(ctx.channel(),s"Got block $invalidBlock with invalid signature")
case None =>
log.trace(s"${id(ctx)} Chain is valid, pre-check passed")
ctx.fireChannelRead(ExtensionBlocks(newBlocks))
Expand Down
6 changes: 2 additions & 4 deletions src/main/scala/com/wavesplatform/network/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ case class LocalScoreChanged(newLocalScore: History.BlockchainScore) extends Mes
case class RawBytes(code: Byte, data: Array[Byte]) extends Message
case class BlockForged(block: Block) extends Message
case class MicroBlockRequest(totalBlockSig: ByteStr) extends Message
case class MicroBlockResponse(microblock: MicroBlock) extends Message {
override def toString: String = s"MicroBlockResponse(MicroBlock(${microblock.totalResBlockSig.trim}~>${microblock.prevResBlockSig.trim}))"
}
case class MicroBlockResponse(microblock: MicroBlock) extends Message
case class LoadBlockchainExtension(lastBlockIds: Seq[ByteStr])
case class ExtensionIds(lastCommonId: ByteStr, extensionIds: Seq[ByteStr])
case class ExtensionBlocks(extension: Seq[Block])

case class MicroBlockInv(sender: PublicKeyAccount, totalBlockSig: ByteStr, prevBlockSig: ByteStr, signature: ByteStr) extends Message with Signed {
override protected def signatureValid: Boolean = EllipticCurveImpl.verify(signature.arr, sender.toAddress.bytes.arr ++ totalBlockSig.arr ++ prevBlockSig.arr, sender.publicKey)
override def toString: String = s"MicroBlockInv(totalBlockSig=$totalBlockSig, prevBlockSig=${prevBlockSig.trim})"
override def toString: String = s"MicroBlockInv(totalBlockSig=${totalBlockSig.trim}, prevBlockSig=${prevBlockSig.trim})"
}
object MicroBlockInv{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ class BlockchainUpdaterImpl private(persisted: StateWriter with StateReader,
}
} else if (areVersionsOfSameBlock(block, ng.base)) {
if (block.transactionData.size <= ng.transactions.size) {
log.trace(s"Existing liquid block is better than new one, discarding ${block.uniqueId}")
log.trace(s"Existing liquid block is better than new one, discarding $block")
Right(None)
} else {
log.trace(s"New liquid block is better version of exsting, swapping")
BlockDiffer.fromBlock(settings.blockchainSettings.functionalitySettings, featureProvider, currentPersistedBlocksState, historyWriter.lastBlock, block).map(d => Some((d, Seq.empty[Transaction])))
}
} else {
Left(BlockAppendError(s"Competitor's liquid block(id=${block.uniqueId.trim} score=${block.blockScore}) is not better than existing(ng.base.id=${ng.base.uniqueId.trim} score=${ng.base.blockScore})", block))
Left(BlockAppendError(s"Competitor's liquid block $block(score=${block.blockScore}) is not better than existing (ng.base ${ng.base}(score=${ng.base.blockScore}))", block))
}
case Some(ng) if !ng.contains(block.reference) =>
Left(BlockAppendError(s"References incorrect or non-existing block", block))
Expand Down Expand Up @@ -180,7 +180,7 @@ class BlockchainUpdaterImpl private(persisted: StateWriter with StateReader,
val height = historyWriter.height() + 1
ngState.set(Some(NgState(block, newBlockDiff, 0L, featuresApprovedWithBlock(block))))
historyReader.lastBlockId().foreach(lastBlockId.onNext)
log.info(s"Block ${block.uniqueId} -> ${block.reference.trim} appended. New height: $height, transactions: ${block.transactionData.size})")
log.info(s"Block $block appended. New height: $height, transactions: ${block.transactionData.size})")
discacrded
case None => Seq.empty
})
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/scorex/block/Block.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ case class Block(timestamp: Long,
override lazy val signedDescendants: Seq[Signed] = transactionData

override def toString: String =
s"Block(timestamp=$timestamp, version=$version, reference=$reference, signerData=$signerData, consensusData=$consensusData, transactions.size=${transactionData.size}, supportedFeaturesIds=$featureVotes) "
s"Block(${signerData.signature} -> ${reference.trim}, txs=${transactionData.size}, feratures=$featureVotes) "

}

Expand Down
4 changes: 1 addition & 3 deletions src/main/scala/scorex/transaction/ValidationError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ object ValidationError {
case class AliasNotExists(a: Alias) extends ValidationError
case class OrderValidationError(order: Order, err: String) extends ValidationError
case class Mistiming(err: String) extends ValidationError
case class BlockAppendError(err: String,b: Block) extends ValidationError {
override def toString: String = s"BlockAppendError($err, BlockId=${b.uniqueId}])"
}
case class BlockAppendError(err: String,b: Block) extends ValidationError
case class MicroBlockAppendError(err: String, microBlock: MicroBlock) extends ValidationError {
override def toString: String = s"MicroBlockAppendError($err, ${microBlock.totalResBlockSig} ~> ${microBlock.prevResBlockSig.trim}])"
}
Expand Down

0 comments on commit 31db78d

Please sign in to comment.