Skip to content

Commit

Permalink
lastSeen serialization fix, minor polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Oct 17, 2023
1 parent 7980b4a commit 4de322a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/main/resources/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2705,7 +2705,7 @@ paths:

/blocks/headerIds:
post:
summary: Get the list of full block info by given header ids
summary: Get full blocks by given header ids
operationId: getFullBlockByIds
tags:
- blocks
Expand All @@ -2727,7 +2727,7 @@ paths:
items:
$ref: '#/components/schemas/FullBlock'
'404':
description: Blocks with this ids doesn't exist
description: No block exist for every id provided
content:
application/json:
schema:
Expand Down Expand Up @@ -5126,7 +5126,7 @@ paths:

/utxo/withPool/byIds:
post:
summary: Get boxes JSONs for ids in array provided, from UTXO or the mempool.
summary: Get boxes for ids provided, from UTXO or the mempool.
operationId: getBoxWithPoolByIds
tags:
- utxo
Expand All @@ -5148,7 +5148,7 @@ paths:
items:
$ref: '#/components/schemas/ErgoTransactionOutput'
'404':
description: Any boxes from the list with this id doesn't exist
description: No any box exists for every id provided
content:
application/json:
schema:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ case class BlockchainApiRoute(readersHolder: ActorRef, ergoSettings: ErgoSetting
getHistoryWithMempool.map { case (history, mempool) =>
getAddress(address)(history) match {
case Some(addr) =>
(addr.balanceInfo.get.retreiveAdditionalTokenInfo(history), getUnconfirmedForAddress(address)(mempool).retreiveAdditionalTokenInfo(history))
(addr.balanceInfo.get.retrieveAdditionalTokenInfo(history), getUnconfirmedForAddress(address)(mempool).retrieveAdditionalTokenInfo(history))
case None =>
(BalanceInfo(), getUnconfirmedForAddress(address)(mempool).retreiveAdditionalTokenInfo(history))
(BalanceInfo(), getUnconfirmedForAddress(address)(mempool).retrieveAdditionalTokenInfo(history))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ case class BalanceInfo() extends ScorexLogging {
* @param history - database handle
* @return this object
*/
def retreiveAdditionalTokenInfo(history: ErgoHistoryReader): BalanceInfo = {
def retrieveAdditionalTokenInfo(history: ErgoHistoryReader): BalanceInfo = {
additionalTokenInfo ++= tokens.map(token => {
history.typedExtraIndexById[IndexedToken](uniqueId(token._1)) match {
case Some(iT) => (token._1,(iT.name,iT.decimals))
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/scorex/core/network/NetworkController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class NetworkController(ergoSettings: ErgoSettings,
val lastSeen = peerInfo.lastStoredActivityTime
val timeout = networkSettings.inactiveConnectionDeadline.toMillis
val delta = now - lastSeen
if (delta > timeout) {
if (delta > timeout && lastSeen > 0) {
log.info(s"Dropping connection with ${peerInfo}, last seen ${delta / 1000.0} seconds ago")
cp.handlerRef ! CloseConnection
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/scala/scorex/core/network/peer/PeerInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ object PeerInfoSerializer extends ErgoSerializer[PeerInfo] {
w.putLong(obj.lastHandshake)
w.putOption(obj.connectionType)((w,d) => w.putBoolean(d.isIncoming))
PeerSpecSerializer.serialize(obj.peerSpec, w)
w.putLong(obj.lastStoredActivityTime)
}

override def parse(r: Reader): PeerInfo = {
val lastHandshake = r.getLong()
val connectionType = r.getOption(if (r.getUByte() != 0) Incoming else Outgoing)
val peerSpec = PeerSpecSerializer.parse(r)
val lastStoredTime = r.getLong()
PeerInfo(peerSpec, lastHandshake, connectionType, lastStoredTime)
PeerInfo(peerSpec, lastHandshake, connectionType, lastStoredActivityTime = 0L)
}
}

0 comments on commit 4de322a

Please sign in to comment.