Skip to content

Commit

Permalink
removing outdated peer filters, BlockSectionsDownloadFilter / Headers…
Browse files Browse the repository at this point in the history
…DownloadFilter
  • Loading branch information
kushti committed Aug 14, 2023
1 parent 4443af5 commit b97a796
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import scorex.util.{ModifierId, ScorexLogging}
import scorex.core.network.DeliveryTracker
import scorex.core.network.peer.PenaltyType
import scorex.core.transaction.state.TransactionValidation.TooHighCostError
import scorex.core.app.Version
import scorex.crypto.hash.Digest32
import org.ergoplatform.nodeView.state.UtxoState.{ManifestId, SubtreeId}
import org.ergoplatform.ErgoLikeContext.Height
Expand Down Expand Up @@ -75,8 +74,6 @@ class ErgoNodeViewSynchronizer(networkControllerRef: ActorRef,
Restart
}

private val blockSectionsDownloadFilter = BlockSectionsDownloadFilter(settings.nodeSettings.stateType)

private var syncInfoV1CacheByHeadersHeight: Option[(Int, ErgoSyncInfoV1)] = Option.empty

private var syncInfoV2CacheByHeadersHeight: Option[(Int, ErgoSyncInfoV2)] = Option.empty
Expand Down Expand Up @@ -530,7 +527,8 @@ class ErgoNodeViewSynchronizer(networkControllerRef: ActorRef,
* @return available peers to download headers from together with the state/origin of the peer
*/
private def getPeersForDownloadingHeaders(callingPeer: ConnectedPeer): Iterable[ConnectedPeer] = {
syncTracker.peersByStatus.getOrElse(Older, Array(callingPeer))
val nonFiltered: Iterable[ConnectedPeer] = syncTracker.peersByStatus.getOrElse(Older, Array(callingPeer))
HeadersDownloadFilter.filter(nonFiltered)
}

/**
Expand All @@ -545,7 +543,7 @@ class ErgoNodeViewSynchronizer(networkControllerRef: ActorRef,
.orElse {
Option(peersByStatus.getOrElse(Unknown, mutable.WrappedArray.empty) ++ peersByStatus.getOrElse(Fork, mutable.WrappedArray.empty))
.filter(_.nonEmpty)
}.map(blockSectionsDownloadFilter.filter)
}.map(BlockSectionsDownloadFilter.filter)
}

/**
Expand Down Expand Up @@ -1129,14 +1127,8 @@ class ErgoNodeViewSynchronizer(networkControllerRef: ActorRef,
Seq.empty
}
case _ =>
if (peer.peerInfo.map(_.peerSpec.protocolVersion).getOrElse(Version.initial) == Version.v4043 &&
modifierTypeId == Header.modifierTypeId) {
log.debug("Header ids from 4.0.43")
Seq.empty
} else {
log.info(s"Processing ${invData.ids.length} non-tx invs (of type $modifierTypeId) from $peer")
invData.ids.filter(mid => deliveryTracker.status(mid, modifierTypeId, Seq(hr)) == ModifiersStatus.Unknown)
}
log.info(s"Processing ${invData.ids.length} non-tx invs (of type $modifierTypeId) from $peer")
invData.ids.filter(mid => deliveryTracker.status(mid, modifierTypeId, Seq(hr)) == ModifiersStatus.Unknown)
}

if (newModifierIds.nonEmpty) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/org/ergoplatform/network/ModePeerFeature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ case class ModePeerFeature(stateType: StateType,
override def serializer: ErgoSerializer[ModePeerFeature] = ModeFeatureSerializer

def allBlocksAvailable: Boolean = blocksToKeep == ModePeerFeature.AllBlocksKept

def allHeadersAvailable: Boolean = nipopowBootstrapped.isEmpty
}

object ModePeerFeature {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.ergoplatform.network

import org.ergoplatform.nodeView.state.StateType
import scorex.core.app.Version
import scorex.core.network.ConnectedPeer

Expand Down Expand Up @@ -48,44 +47,6 @@ trait VersionBasedPeerFilteringRule extends PeerFilteringRule {

}


/**
* 4.0.22+ allow for downloading ADProofs that are too big in block at 667614
* for prior versions, a peer will not deliver block # 667614 and some other blocks
*/
object DigestModeFilter extends VersionBasedPeerFilteringRule {

override def condition(version: Version): Boolean = {
version.compare(Version.v4022) >= 0
}

}

/**
* Filter out peers of 4.0.17 or 4.0.18 version as they are delivering broken block sections
*/
object BrokenModifiersFilter extends VersionBasedPeerFilteringRule {

override def condition(version: Version): Boolean = {
version != Version.v4017 && version != Version.v4018
}

}

/**
* Filter to download block sections, combining `DigestModeFilter` and `BrokenModifiersFilter`
* @param stateType - own (node's) state type
*/
final case class BlockSectionsDownloadFilter(stateType: StateType) extends VersionBasedPeerFilteringRule {
override def condition(version: Version): Boolean = {
if (stateType == StateType.Digest) {
DigestModeFilter.condition(version)
} else {
BrokenModifiersFilter.condition(version)
}
}
}

/**
* If peer's version is >= 4.0.16, the peer is supporting sync V2
*/
Expand Down Expand Up @@ -130,3 +91,21 @@ object NipopowSupportFilter extends PeerFilteringRule {
}

}

/**
* Filter to download block sections (except of headers)
*/
object BlockSectionsDownloadFilter extends PeerFilteringRule {
override def condition(peer: ConnectedPeer): Boolean = {
peer.mode.exists(_.allBlocksAvailable)
}
}

/**
* Filter to download headers
*/
object HeadersDownloadFilter extends PeerFilteringRule {
override def condition(peer: ConnectedPeer): Boolean = {
peer.mode.exists(_.allHeadersAvailable)
}
}
8 changes: 0 additions & 8 deletions src/main/scala/scorex/core/app/Version.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ object Version {

val initial: Version = Version(0, 0, 1)

val v4017: Version = Version(4, 0, 17)

val v4018: Version = Version(4, 0, 18)

val v4022: Version = Version(4, 0, 22)

val v4043: Version = Version(4, 0, 43)

val Eip37ForkVersion: Version = Version(4, 0, 100)
val JitSoftForkVersion: Version = Version(5, 0, 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,6 @@ class PeerFilteringRuleSpecification extends ErgoPropertyTest {
SyncV2Filter.filter(Seq(v1Peer, v2Peer0, v2Peer1, v2Peer2)) shouldBe Seq(v2Peer0, v2Peer1, v2Peer2)
}

property("digest mode filter") {
val beforePeer = peerWithVersion(Version(4, 0, 21))
val afterPeer0 = peerWithVersion(Version(4, 0, 22))
val afterPeer1 = peerWithVersion(Version(5, 0, 0))

DigestModeFilter.filter(Seq(beforePeer, afterPeer0, afterPeer1)) shouldBe Seq(afterPeer0, afterPeer1)
}

property("broken modifiers filter") {
val inPeer0 = peerWithVersion(Version(4, 0, 17))
val inPeer1 = peerWithVersion(Version(4, 0, 18))
val outPeer0 = peerWithVersion(Version(4, 0, 16))
val outPeer1 = peerWithVersion(Version(4, 0, 19))
val outPeer2 = peerWithVersion(Version(5, 0, 0))

BrokenModifiersFilter.filter(Seq(inPeer0, inPeer1, outPeer0, outPeer1, outPeer2)) shouldBe
Seq(outPeer0, outPeer1, outPeer2)
}

property("utxo set snapshot filter") {
val peer0 = peerWithVersion(Version(4, 0, 17))
val peer1 = peerWithVersion(Version(4, 0, 18))
Expand Down

0 comments on commit b97a796

Please sign in to comment.