Skip to content

Commit

Permalink
Merge branch 'phase/4/jsonrpc' of github.com:input-output-hk/etc-clie…
Browse files Browse the repository at this point in the history
…nt into fix/miningAfterPeerResponseTimeout
  • Loading branch information
Nicolas Tallar committed Jun 29, 2017
2 parents 1e27ce3 + 6a09b0d commit 5f0cdde
Show file tree
Hide file tree
Showing 18 changed files with 134 additions and 109 deletions.
2 changes: 2 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
dependencies:
pre:
- sudo add-apt-repository -y ppa:ethereum/ethereum; sudo apt-get update; sudo apt-get install -y solc
override:
- echo "OK, let's go!"
2 changes: 1 addition & 1 deletion src/main/scala/io/iohk/ethereum/jsonrpc/EthService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class EthService(

lazy val blockchain = BlockchainImpl(blockchainStorages)

val minerTimeOut: Long = 5.seconds.toMillis
val minerTimeOut: Long = 5.seconds.toMillis // TODO: configure timeout
val hashRate: AtomicReference[Map[ByteString, (BigInt, Date)]] = new AtomicReference[Map[ByteString, (BigInt, Date)]](Map())
val lastActive = new AtomicReference[Option[Date]](None)

Expand Down
14 changes: 0 additions & 14 deletions src/test/scala/io/iohk/ethereum/DefaultPatience.scala

This file was deleted.

11 changes: 11 additions & 0 deletions src/test/scala/io/iohk/ethereum/Timeouts.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.iohk.ethereum

import scala.concurrent.duration._

object Timeouts {

val shortTimeout: FiniteDuration = 500.millis
val normalTimeout: FiniteDuration = 3.seconds
val longTimeout: FiniteDuration = 10.seconds
val veryLongTimeout: FiniteDuration = 30.seconds
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,24 @@ package io.iohk.ethereum.blockchain.sync
import akka.actor.ActorSystem
import akka.pattern._
import akka.testkit.TestActorRef
import akka.util.{ByteString, Timeout}
import akka.util.ByteString
import io.iohk.ethereum.NormalPatience
import io.iohk.ethereum.blockchain.sync.FastSync.SyncState
import io.iohk.ethereum.blockchain.sync.FastSyncStateActor.GetStorage
import io.iohk.ethereum.db.dataSource.EphemDataSource
import io.iohk.ethereum.db.storage.FastSyncStateStorage
import io.iohk.ethereum.domain.BlockHeader
import org.scalatest.concurrent.Eventually
import org.scalatest.time._
import org.scalatest.{AsyncFlatSpec, Matchers}

import scala.concurrent.duration._

class FastSyncStateActorSpec extends AsyncFlatSpec with Matchers with Eventually {
class FastSyncStateActorSpec extends AsyncFlatSpec with Matchers with Eventually with NormalPatience {

"FastSyncStateActor" should "eventually persist a newest state of a fast sync" in {

val dataSource = EphemDataSource()
implicit val system = ActorSystem("FastSyncStateActorSpec_System")
implicit val timeout: Timeout = 20.seconds
val syncStateActor = TestActorRef(new FastSyncStateActor)
val maxN = 10
implicit val patienceConfig = PatienceConfig(timeout = Span(3, Seconds))

val targetBlockHeader = BlockHeader(ByteString(""), ByteString(""), ByteString(""), ByteString(""), ByteString(""),
ByteString(""), ByteString(""), 0, 0, 0, 0, 0, ByteString(""), ByteString(""), ByteString(""))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import akka.actor.{ActorSystem, Props}
import akka.testkit.{TestActorRef, TestProbe}
import akka.util.ByteString
import com.miguno.akka.testing.VirtualTime
import io.iohk.ethereum.Mocks
import io.iohk.ethereum.{Mocks, Timeouts}
import io.iohk.ethereum.blockchain.sync.FastSync.{StateMptNodeHash, SyncState}
import io.iohk.ethereum.blockchain.sync.SyncController.MinedBlock
import io.iohk.ethereum.domain.{Account, Block, BlockHeader}
Expand Down Expand Up @@ -233,7 +233,7 @@ class SyncControllerSpec extends FlatSpec with Matchers {
Subscribe(MessageClassifier(Set(BlockHeaders.code), PeerSelector.WithId(peer.id)))
)

etcPeerManager.expectMsgAllOf(10.seconds,
etcPeerManager.expectMsgAllOf(Timeouts.normalTimeout,
EtcPeerManagerActor.SendMessage(
GetBlockHeaders(Left(expectedMaxBlock + 2), Config.FastSync.blockHeadersPerRequest, 0, reverse = false),
peer.id),
Expand Down Expand Up @@ -344,7 +344,7 @@ class SyncControllerSpec extends FlatSpec with Matchers {
etcPeerManager.expectMsg(EtcPeerManagerActor.SendMessage(GetBlockBodies(Seq(nextNewBlockHeader.hash)), peer.id))

//wait for actor to insert data
Thread.sleep(3.seconds.toMillis)
Thread.sleep(Timeouts.normalTimeout.toMillis)

blockchain.getBlockByNumber(expectedMaxBlock) shouldBe Some(Block(newBlockHeaderParent, BlockBody(Nil, Nil)))
blockchain.getTotalDifficultyByHash(newBlockHeaderParent.hash) shouldBe Some(commonRootTotalDifficulty + newBlockHeaderParent.difficulty)
Expand Down Expand Up @@ -491,7 +491,7 @@ class SyncControllerSpec extends FlatSpec with Matchers {
syncController.children.last ! MessageFromPeer(BlockBodies(Seq(BlockBody(Nil, Nil), BlockBody(Nil, Nil))), peer1.id)

//TODO: investigate why such a long timeout is required
etcPeerManager.expectMsgAllOf(20.seconds,
etcPeerManager.expectMsgAllOf(Timeouts.veryLongTimeout,
EtcPeerManagerActor.SendMessage(
GetBlockHeaders(Left(expectedMaxBlock + 3), Config.FastSync.blockHeadersPerRequest, 0, reverse = false), peer1.id),
EtcPeerManagerActor.SendMessage(
Expand Down Expand Up @@ -577,7 +577,7 @@ class SyncControllerSpec extends FlatSpec with Matchers {
syncController.children.last ! MessageFromPeer(BlockBodies(Seq(BlockBody(Nil, Nil), BlockBody(Nil, Nil))), peer1.id)

//TODO: investigate why such a long timeout is required
etcPeerManager.expectMsgAllOf(20.seconds,
etcPeerManager.expectMsgAllOf(Timeouts.veryLongTimeout,
EtcPeerManagerActor.SendMessage(
NewBlock(Block(newBlockHeader, BlockBody(Nil, Nil)), maxBlocTotalDifficulty + newBlockDifficulty), peer1.id),
EtcPeerManagerActor.SendMessage(
Expand Down Expand Up @@ -636,15 +636,15 @@ class SyncControllerSpec extends FlatSpec with Matchers {
etcPeerManager.expectMsg(EtcPeerManagerActor.SendMessage(GetBlockBodies(Seq(newBlockHeader.hash)), peer1.id))
syncController.children.last ! MessageFromPeer(BlockBodies(Seq(BlockBody(Nil, Nil))), peer1.id)

peerMessageBus.expectMsgAllOf(5.seconds,
peerMessageBus.expectMsgAllOf(Timeouts.normalTimeout,
Subscribe(MessageClassifier(Set(BlockHeaders.code), PeerSelector.WithId(peer1.id))),
Subscribe(MessageClassifier(Set(BlockBodies.code), PeerSelector.WithId(peer1.id))),
Unsubscribe(MessageClassifier(Set(BlockHeaders.code), PeerSelector.WithId(peer1.id))),
Subscribe(MessageClassifier(Set(BlockHeaders.code), PeerSelector.WithId(peer2.id))),
Unsubscribe(MessageClassifier(Set(BlockBodies.code), PeerSelector.WithId(peer1.id))))

//As block execution failed for a block received from peer1, the same block is asked to peer2
etcPeerManager.expectMsg(10.seconds, EtcPeerManagerActor.SendMessage(
etcPeerManager.expectMsg(Timeouts.longTimeout, EtcPeerManagerActor.SendMessage(
GetBlockHeaders(Left(expectedMaxBlock + 1), Config.FastSync.blockHeadersPerRequest, 0, reverse = false),
peer2.id))

Expand All @@ -663,8 +663,6 @@ class SyncControllerSpec extends FlatSpec with Matchers {

val peer = Peer(new InetSocketAddress("127.0.0.1", 0), peerTestProbe.ref)

time.advance(1.seconds)

val peer1Status= Status(1, 1, 1, ByteString("peer1_bestHash"), ByteString("unused"))

etcPeerManager.send(syncController, HandshakedPeers(Map(
Expand Down Expand Up @@ -693,11 +691,11 @@ class SyncControllerSpec extends FlatSpec with Matchers {
syncController.children.last ! MessageFromPeer(BlockHeaders(Seq()), peer.id)

//wait for empty headers processing
Thread.sleep(1.seconds.toMillis)
Thread.sleep(Timeouts.shortTimeout.toMillis)
syncController ! MinedBlock(Block(minedBlockHeader,BlockBody(Nil,Nil)))

//wait for actor to insert data
Thread.sleep(3.seconds.toMillis)
Thread.sleep(Timeouts.normalTimeout.toMillis)
blockchain.getBlockByNumber(expectedMaxBlock + 1) shouldBe Some(Block(minedBlockHeader, BlockBody(Nil, Nil)))
blockchain.getTotalDifficultyByHash(minedBlockHeader.hash) shouldBe Some(maxBlocTotalDifficulty + minedBlockHeader.difficulty)

Expand Down
31 changes: 13 additions & 18 deletions src/test/scala/io/iohk/ethereum/jsonrpc/EthServiceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package io.iohk.ethereum.jsonrpc
import akka.actor.ActorSystem
import akka.testkit.TestProbe
import akka.util.ByteString
import io.iohk.ethereum.{DefaultPatience, Fixtures, crypto}
import com.miguno.akka.testing.VirtualTime
import io.iohk.ethereum.{Fixtures, NormalPatience, Timeouts, crypto}
import io.iohk.ethereum.db.components.{SharedEphemDataSources, Storages}
import io.iohk.ethereum.domain.{Address, Block, BlockHeader, BlockchainImpl}
import io.iohk.ethereum.db.storage.AppStateStorage
Expand Down Expand Up @@ -31,10 +32,8 @@ import io.iohk.ethereum.vm.UInt256
import org.scalamock.scalatest.MockFactory
import org.spongycastle.util.encoders.Hex

import scala.concurrent.duration._

// scalastyle:off file.size.limit
class EthServiceSpec extends FlatSpec with Matchers with ScalaFutures with MockFactory with DefaultPatience {
class EthServiceSpec extends FlatSpec with Matchers with ScalaFutures with MockFactory with NormalPatience {

behavior of "EthService"

Expand Down Expand Up @@ -509,13 +508,13 @@ class EthServiceSpec extends FlatSpec with Matchers with ScalaFutures with MockF
val id2 = ByteString("id2")

ethService.submitHashRate(SubmitHashRateRequest(rate, id1)).futureValue shouldEqual Right(SubmitHashRateResponse(true))
Thread.sleep(2.seconds.toMillis)
Thread.sleep(ethService.minerTimeOut / 2)
ethService.submitHashRate(SubmitHashRateRequest(rate, id2)).futureValue shouldEqual Right(SubmitHashRateResponse(true))

val response1 = ethService.getHashRate(GetHashRateRequest())
response1.futureValue shouldEqual Right(GetHashRateResponse(rate * 2))

Thread.sleep(4.seconds.toMillis)
Thread.sleep(ethService.minerTimeOut / 2)
val response2 = ethService.getHashRate(GetHashRateRequest())
response2.futureValue shouldEqual Right(GetHashRateResponse(rate))
}
Expand All @@ -527,8 +526,6 @@ class EthServiceSpec extends FlatSpec with Matchers with ScalaFutures with MockF
(appStateStorage.getBestBlockNumber _).expects().returning(0)
ethService.getWork(GetWorkRequest())

Thread.sleep(1.seconds.toMillis)

val response = ethService.getMining(GetMiningRequest())

response.futureValue shouldEqual Right(GetMiningResponse(true))
Expand All @@ -541,8 +538,6 @@ class EthServiceSpec extends FlatSpec with Matchers with ScalaFutures with MockF
(appStateStorage.getBestBlockNumber _).expects().returning(0)
ethService.submitWork(SubmitWorkRequest(ByteString("nonce"), ByteString(Hex.decode("01" * 32)), ByteString(Hex.decode("01" * 32))))

Thread.sleep(1.seconds.toMillis)

val response = ethService.getMining(GetMiningRequest())

response.futureValue shouldEqual Right(GetMiningResponse(true))
Expand All @@ -553,8 +548,6 @@ class EthServiceSpec extends FlatSpec with Matchers with ScalaFutures with MockF

ethService.submitHashRate(SubmitHashRateRequest(42, ByteString("id")))

Thread.sleep(1.seconds.toMillis)

val response = ethService.getMining(GetMiningRequest())

response.futureValue shouldEqual Right(GetMiningResponse(true))
Expand All @@ -565,7 +558,7 @@ class EthServiceSpec extends FlatSpec with Matchers with ScalaFutures with MockF
(appStateStorage.getBestBlockNumber _).expects().returning(0)
ethService.getWork(GetWorkRequest())

Thread.sleep(6.seconds.toMillis)
Thread.sleep(ethService.minerTimeOut)

val response = ethService.getMining(GetMiningRequest())

Expand Down Expand Up @@ -785,17 +778,19 @@ class EthServiceSpec extends FlatSpec with Matchers with ScalaFutures with MockF
override val blockCacheSize: Int = 30
override val ommersPoolSize: Int = 30
override val txPoolSize: Int = 30
override val poolingServicesTimeout: FiniteDuration = 3.seconds
override val poolingServicesTimeout: FiniteDuration = Timeouts.normalTimeout
}

val filterConfig = new FilterConfig {
override val filterTimeout: FiniteDuration = 3.seconds
override val filterManagerQueryTimeout: FiniteDuration = 3.seconds
override val pendingTransactionsManagerQueryTimeout: FiniteDuration = 3.seconds
override val filterTimeout: FiniteDuration = Timeouts.normalTimeout
override val filterManagerQueryTimeout: FiniteDuration = Timeouts.normalTimeout
override val pendingTransactionsManagerQueryTimeout: FiniteDuration = Timeouts.normalTimeout
}

val ethService = new EthService(storagesInstance.storages, blockGenerator, appStateStorage, miningConfig, ledger,
keyStore, pendingTransactionsManager.ref, syncingController.ref, ommersPool.ref, filterManager.ref, filterConfig)
keyStore, pendingTransactionsManager.ref, syncingController.ref, ommersPool.ref, filterManager.ref, filterConfig) {
override val minerTimeOut: Long = Timeouts.shortTimeout.toMillis
}

val blockToRequest = Block(Fixtures.Blocks.Block3125369.header, Fixtures.Blocks.Block3125369.body)
val blockToRequestNumber = blockToRequest.header.number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.scalatest.{FlatSpec, Matchers}
import org.spongycastle.util.encoders.Hex
import akka.pattern.ask
import com.miguno.akka.testing.VirtualTime
import io.iohk.ethereum.DefaultPatience
import io.iohk.ethereum.NormalPatience
import io.iohk.ethereum.crypto.ECDSASignature
import io.iohk.ethereum.jsonrpc.FilterManager.LogFilterLogs
import io.iohk.ethereum.ledger.BloomFilter
Expand All @@ -25,9 +25,7 @@ import org.scalatest.concurrent.ScalaFutures

import scala.concurrent.duration._

class FilterManagerSpec extends FlatSpec with Matchers with ScalaFutures with DefaultPatience {

implicit val timeout = Timeout(5.seconds)
class FilterManagerSpec extends FlatSpec with Matchers with ScalaFutures with NormalPatience {

"FilterManager" should "handle log filter logs and changes" in new TestSetup {

Expand Down

0 comments on commit 5f0cdde

Please sign in to comment.