Skip to content

Commit

Permalink
Logs and some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vsuharnikov committed Dec 23, 2024
1 parent 7b3bb0e commit 120a54f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
15 changes: 10 additions & 5 deletions node/src/main/scala/com/wavesplatform/mining/Miner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,19 @@ class MinerImpl(

def forgeBlock(account: KeyPair): Either[String, (Block, MiningConstraint)] = {
// should take last block right at the time of mining since microblocks might have been added
val height = blockchainUpdater.height
val version = blockchainUpdater.nextBlockVersion
val lastBlockHeader = blockchainUpdater.lastBlockHeader.get.header
val reference = blockchainUpdater.bestLastBlockInfo(System.currentTimeMillis() - minMicroBlockDurationMills).get.blockId
val height = blockchainUpdater.height
val version = blockchainUpdater.nextBlockVersion

metrics.blockBuildTimeStats.measureSuccessful(for {
_ <- checkQuorumAvailable()
balance = blockchainUpdater.generatingBalance(account.toAddress, Some(reference))
reference = {
val ts = System.currentTimeMillis() - minMicroBlockDurationMills
val blockId = blockchainUpdater.bestLastBlockInfo(ts).get.blockId
log.debug(s"Getting a reference block at $ts: $blockId")
blockId
}
balance = blockchainUpdater.generatingBalance(account.toAddress, Some(reference))
lastBlockHeader = blockchainUpdater.lastBlockHeader.get.header // We'll need only baseTarget, timestamp and reference
validBlockDelay <- pos
.getValidBlockDelay(height, account, lastBlockHeader.baseTarget, balance)
.leftMap(_.toString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,10 @@ class BlockchainUpdaterImpl(
val transactionsRoot = ng.createTransactionsRoot(microBlock)
blockchainUpdateTriggers.onProcessMicroBlock(microBlock, keyBlockSnapshot, this, blockId, transactionsRoot)

this.ngState = Some(ng.append(microBlock, snapshot, carry, totalFee, System.currentTimeMillis, computedStateHash, Some(blockId)))
val ts = System.currentTimeMillis
this.ngState = Some(ng.append(microBlock, snapshot, carry, totalFee, ts, computedStateHash, Some(blockId)))

log.info(s"${microBlock.stringRepr(blockId)} appended, diff=${snapshot.hashString}")
log.info(s"${microBlock.stringRepr(blockId)} appended at $ts, diff=${snapshot.hashString}")
internalLastBlockInfo.onNext(LastBlockInfo(blockId, height, score, ready = true))

blockId
Expand Down Expand Up @@ -798,15 +799,17 @@ class BlockchainUpdaterImpl(
snapshotBlockchain.resolveERC20Address(address)
}

override def lastStateHash(refId: Option[ByteStr]): ByteStr =
override def lastStateHash(refId: Option[ByteStr]): ByteStr = readLock {
ngState
.map { ng =>
refId.filter(ng.contains).fold(ng.bestLiquidComputedStateHash)(id => ng.snapshotFor(id)._4)
}
.getOrElse(rocksdb.lastStateHash(None))
}

def snapshotBlockchain: SnapshotBlockchain =
def snapshotBlockchain: SnapshotBlockchain = readLock {
ngState.fold[SnapshotBlockchain](SnapshotBlockchain(rocksdb, StateSnapshot.empty))(SnapshotBlockchain(rocksdb, _))
}

// noinspection ScalaStyle,TypeAnnotation
private[this] object metrics {
Expand Down

0 comments on commit 120a54f

Please sign in to comment.