Skip to content

Commit 6c44067

Browse files
committed
Merge remote-tracking branch 'origin/develop' into etcm-302/add-more-logging-to-best-block-handling
2 parents 77242d8 + 20d055d commit 6c44067

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

repo.nix

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,31 @@
1111
"artifacts" = {
1212
"nix-Sonatype OSS Snapshots/io/iohk/scalanet-discovery_2.12/0.4-SNAPSHOT/scalanet-discovery_2.12-0.4-SNAPSHOT-javadoc.jar" = {
1313
url = "https://oss.sonatype.org/content/repositories/snapshots/io/iohk/scalanet-discovery_2.12/0.4-SNAPSHOT/scalanet-discovery_2.12-0.4-SNAPSHOT-javadoc.jar";
14-
sha256 = "DE0EEBB8211154F3C84A9021AFCEDA2A4D2C2BF435D05BE52E8C28DDC9E4A032";
14+
sha256 = "E1BFC529ACE03B29B2D7AB72F8587C55EDEEEE211EC795E328E2F738D67ECE57";
1515
};
1616
"nix-Sonatype OSS Snapshots/io/iohk/scalanet-discovery_2.12/0.4-SNAPSHOT/scalanet-discovery_2.12-0.4-SNAPSHOT-sources.jar" = {
1717
url = "https://oss.sonatype.org/content/repositories/snapshots/io/iohk/scalanet-discovery_2.12/0.4-SNAPSHOT/scalanet-discovery_2.12-0.4-SNAPSHOT-sources.jar";
18-
sha256 = "6B7039C8D68F3DEB3DC7C856B74D3232D58175DDCAA43BCA54FA95E9FDD273BE";
18+
sha256 = "A86A69FB1E4973AFE1FC83FA6F49C6E71221083F437CB75333461024EBC39962";
1919
};
2020
"nix-Sonatype OSS Snapshots/io/iohk/scalanet-discovery_2.12/0.4-SNAPSHOT/scalanet-discovery_2.12-0.4-SNAPSHOT.jar" = {
2121
url = "https://oss.sonatype.org/content/repositories/snapshots/io/iohk/scalanet-discovery_2.12/0.4-SNAPSHOT/scalanet-discovery_2.12-0.4-SNAPSHOT.jar";
22-
sha256 = "180A1C65E0D848C15D5C4E6D5179D9BE355EE024FFB3908D0E768774A1D83E77";
22+
sha256 = "72DB578799E07B3D10612C8A61BFA3D21EAC31312E0BAFECCD203D0D637D7498";
2323
};
2424
"nix-Sonatype OSS Snapshots/io/iohk/scalanet-discovery_2.12/0.4-SNAPSHOT/scalanet-discovery_2.12-0.4-SNAPSHOT.pom" = {
2525
url = "https://oss.sonatype.org/content/repositories/snapshots/io/iohk/scalanet-discovery_2.12/0.4-SNAPSHOT/scalanet-discovery_2.12-0.4-SNAPSHOT.pom";
2626
sha256 = "30830E277F9651F63FA521F111BFF95E00DD3B96FEF481E8B334F6539521B738";
2727
};
2828
"nix-Sonatype OSS Snapshots/io/iohk/scalanet_2.12/0.4-SNAPSHOT/scalanet_2.12-0.4-SNAPSHOT-javadoc.jar" = {
2929
url = "https://oss.sonatype.org/content/repositories/snapshots/io/iohk/scalanet_2.12/0.4-SNAPSHOT/scalanet_2.12-0.4-SNAPSHOT-javadoc.jar";
30-
sha256 = "84CED4F8BABB8C6EDBAECBAFF12EF3E01DA0F8999C7228F841F3CCB57C2C0062";
30+
sha256 = "B38F674EEA0E4660D2A39245D9BC129FD9171312C5CCCCE9DB5D1BC140865A86";
3131
};
3232
"nix-Sonatype OSS Snapshots/io/iohk/scalanet_2.12/0.4-SNAPSHOT/scalanet_2.12-0.4-SNAPSHOT-sources.jar" = {
3333
url = "https://oss.sonatype.org/content/repositories/snapshots/io/iohk/scalanet_2.12/0.4-SNAPSHOT/scalanet_2.12-0.4-SNAPSHOT-sources.jar";
34-
sha256 = "995E546CF8AACB892B3A303975ABD37C55D3D522BCBD92E9ACBA9F5176953614";
34+
sha256 = "DBF79681BAC9A923B0EAB597BE5B849C6F444BB11662BB07DC755BBBD97590EB";
3535
};
3636
"nix-Sonatype OSS Snapshots/io/iohk/scalanet_2.12/0.4-SNAPSHOT/scalanet_2.12-0.4-SNAPSHOT.jar" = {
3737
url = "https://oss.sonatype.org/content/repositories/snapshots/io/iohk/scalanet_2.12/0.4-SNAPSHOT/scalanet_2.12-0.4-SNAPSHOT.jar";
38-
sha256 = "23876478C378D4485CA0159C75CA111E28218740816F7F8A4EA681215E66478F";
38+
sha256 = "98D7F789C0A80FE7F810B0BD75A0F623E787C0212CEBDB71B2501EA7588C999C";
3939
};
4040
"nix-Sonatype OSS Snapshots/io/iohk/scalanet_2.12/0.4-SNAPSHOT/scalanet_2.12-0.4-SNAPSHOT.pom" = {
4141
url = "https://oss.sonatype.org/content/repositories/snapshots/io/iohk/scalanet_2.12/0.4-SNAPSHOT/scalanet_2.12-0.4-SNAPSHOT.pom";

src/main/scala/io/iohk/ethereum/jsonrpc/EthService.scala

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import io.iohk.ethereum.jsonrpc.{FilterManager => FM}
3434
import monix.eval.Task
3535
import org.bouncycastle.util.encoders.Hex
3636

37+
import scala.collection.concurrent.{Map => ConcurrentMap, TrieMap}
3738
import scala.concurrent.duration.FiniteDuration
3839
import scala.language.existentials
3940
import scala.reflect.ClassTag
@@ -226,8 +227,7 @@ class EthService(
226227

227228
import EthService._
228229

229-
val hashRate: AtomicReference[Map[ByteString, (BigInt, Date)]] =
230-
new AtomicReference[Map[ByteString, (BigInt, Date)]](Map())
230+
val hashRate: ConcurrentMap[ByteString, (BigInt, Date)] = new TrieMap[ByteString, (BigInt, Date)]()
231231
val lastActive = new AtomicReference[Option[Date]](None)
232232

233233
private[this] def consensus = ledger.consensus
@@ -481,11 +481,9 @@ class EthService(
481481
def submitHashRate(req: SubmitHashRateRequest): ServiceResponse[SubmitHashRateResponse] =
482482
ifEthash(req) { req =>
483483
reportActive()
484-
hashRate.updateAndGet((t: Map[ByteString, (BigInt, Date)]) => {
485-
val now = new Date
486-
removeObsoleteHashrates(now, t + (req.id -> (req.hashRate, now)))
487-
})
488-
484+
val now = new Date
485+
removeObsoleteHashrates(now)
486+
hashRate.put(req.id, (req.hashRate -> now))
489487
SubmitHashRateResponse(true)
490488
}
491489

@@ -527,20 +525,14 @@ class EthService(
527525

528526
def getHashRate(req: GetHashRateRequest): ServiceResponse[GetHashRateResponse] =
529527
ifEthash(req) { _ =>
530-
val hashRates: Map[ByteString, (BigInt, Date)] = hashRate.updateAndGet((t: Map[ByteString, (BigInt, Date)]) => {
531-
removeObsoleteHashrates(new Date, t)
532-
})
533-
528+
removeObsoleteHashrates(new Date)
534529
//sum all reported hashRates
535-
GetHashRateResponse(hashRates.mapValues { case (hr, _) => hr }.values.sum)
530+
GetHashRateResponse(hashRate.map { case (_, (hr, _)) => hr }.sum)
536531
}
537532

538533
// NOTE This is called from places that guarantee we are running Ethash consensus.
539-
private def removeObsoleteHashrates(
540-
now: Date,
541-
rates: Map[ByteString, (BigInt, Date)]
542-
): Map[ByteString, (BigInt, Date)] = {
543-
rates.filter { case (_, (_, reported)) =>
534+
private def removeObsoleteHashrates(now: Date): Unit = {
535+
hashRate.retain { case (_, (_, reported)) =>
544536
Duration.between(reported.toInstant, now.toInstant).toMillis < jsonRpcConfig.minerActiveTimeout.toMillis
545537
}
546538
}

0 commit comments

Comments
 (0)