Skip to content

Commit 87a4aa4

Browse files
committed
unify behavior between regular and fast sync
1 parent 8ccbcc3 commit 87a4aa4

10 files changed

+568
-647
lines changed

src/it/scala/io/iohk/ethereum/sync/FastSyncItSpec.scala

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package io.iohk.ethereum.sync
22

3-
import java.net.{InetSocketAddress, ServerSocket}
4-
53
import akka.util.ByteString
64
import io.iohk.ethereum.FlatSpecBase
75
import io.iohk.ethereum.domain._
86
import io.iohk.ethereum.ledger.InMemoryWorldStateProxy
97
import io.iohk.ethereum.sync.FastSyncItSpec._
10-
import io.iohk.ethereum.sync.FastSyncItSpecUtils.{FakePeer, FakePeerCustomConfig, HostConfig}
8+
import io.iohk.ethereum.sync.util.FastSyncItSpecUtils.FakePeer
9+
import io.iohk.ethereum.sync.util.SyncCommonItSpec._
10+
import io.iohk.ethereum.sync.util.SyncCommonItSpecUtils._
1111
import monix.execution.Scheduler
1212
import org.scalatest.BeforeAndAfter
1313
import org.scalatest.matchers.should.Matchers
1414

1515
import scala.concurrent.duration._
1616

17-
class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
17+
class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
1818
implicit val testScheduler = Scheduler.fixedPool("test", 16)
1919

2020
"FastSync" should "should sync blockchain without state nodes" in customTestCaseResourceM(
@@ -132,18 +132,6 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
132132
}
133133

134134
object FastSyncItSpec {
135-
def randomAddress(): InetSocketAddress = {
136-
val s = new ServerSocket(0)
137-
try {
138-
new InetSocketAddress("localhost", s.getLocalPort)
139-
} finally {
140-
s.close()
141-
}
142-
}
143-
144-
final case class BlockchainState(bestBlock: Block, currentWorldState: InMemoryWorldStateProxy, currentTd: BigInt)
145-
146-
val IdentityUpdate: (BigInt, InMemoryWorldStateProxy) => InMemoryWorldStateProxy = (_, world) => world
147135

148136
def updateWorldWithNAccounts(n: Int, world: InMemoryWorldStateProxy): InMemoryWorldStateProxy = {
149137
val resultWorld = (0 until n).foldLeft(world) { (world, num) =>

src/it/scala/io/iohk/ethereum/sync/RegularSyncItSpec.scala

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package io.iohk.ethereum.sync
22

33
import io.iohk.ethereum.FlatSpecBase
4-
import io.iohk.ethereum.sync.util.FakePeerRegularSync
5-
import io.iohk.ethereum.sync.util.SyncUtils.identityUpdate
4+
import io.iohk.ethereum.sync.util.RegularSyncItSpecUtils.FakePeer
5+
import io.iohk.ethereum.sync.util.SyncCommonItSpec._
66
import monix.execution.Scheduler
77
import org.scalatest.BeforeAndAfter
88
import org.scalatest.matchers.should.Matchers
@@ -12,48 +12,48 @@ import scala.concurrent.duration._
1212
class RegularSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
1313
implicit val testScheduler = Scheduler.fixedPool("test", 16)
1414

15-
it should "should sync blockchain with same best block" in customTestCaseResourceM(FakePeerRegularSync.start2FakePeersRes()) {
15+
it should "should sync blockchain with same best block" in customTestCaseResourceM(FakePeer.start2FakePeersRes()) {
1616
case (peer1, peer2) =>
1717
val blockNumer: Int = 2000
1818
for {
19-
_ <- peer2.importBlocksUntil(blockNumer)(identityUpdate)
19+
_ <- peer2.importBlocksUntil(blockNumer)(IdentityUpdate)
2020
_ <- peer1.connectToPeers(Set(peer2.node))
21-
_ <- peer1.start.delayExecution(50.milliseconds)
22-
_ <- peer2.broadcastBlock()(identityUpdate).delayExecution(500.milliseconds)
21+
_ <- peer1.startRegularSync().delayExecution(50.milliseconds)
22+
_ <- peer2.broadcastBlock()(IdentityUpdate).delayExecution(500.milliseconds)
2323
_ <- peer1.waitForRegularSyncLoadLastBlock(blockNumer)
2424
} yield {
2525
assert(peer1.bl.getBestBlockNumber() == peer2.bl.getBestBlockNumber())
2626
}
2727
}
2828

29-
it should "should sync blockchain progressing forward in the same time" in customTestCaseResourceM(FakePeerRegularSync.start2FakePeersRes()) {
29+
it should "should sync blockchain progressing forward in the same time" in customTestCaseResourceM(FakePeer.start2FakePeersRes()) {
3030
case (peer1, peer2) =>
3131
val blockNumer: Int = 2000
3232
for {
33-
_ <- peer2.start.delayExecution(50.milliseconds)
34-
_ <- peer2.importBlocksUntil(blockNumer)(identityUpdate)
33+
_ <- peer2.startRegularSync().delayExecution(50.milliseconds)
34+
_ <- peer2.importBlocksUntil(blockNumer)(IdentityUpdate)
3535
_ <- peer1.connectToPeers(Set(peer2.node))
36-
_ <- peer1.start.delayExecution(500.milliseconds)
37-
_ <- peer2.mineNewBlock()(identityUpdate).delayExecution(50.milliseconds)
36+
_ <- peer1.startRegularSync().delayExecution(500.milliseconds)
37+
_ <- peer2.mineNewBlock()(IdentityUpdate).delayExecution(50.milliseconds)
3838
_ <- peer1.waitForRegularSyncLoadLastBlock(blockNumer + 1)
3939
} yield {
4040
assert(peer1.bl.getBestBlockNumber() == peer2.bl.getBestBlockNumber())
4141
}
4242
}
4343

44-
it should "should sync peers with divergent chains will be forced to resolve branches"in customTestCaseResourceM(FakePeerRegularSync.start2FakePeersRes()) {
44+
it should "should sync peers with divergent chains will be forced to resolve branches"in customTestCaseResourceM(FakePeer.start2FakePeersRes()) {
4545
case (peer1, peer2) =>
4646
val blockNumer: Int = 2000
4747
for {
48-
_ <- peer2.importBlocksUntil(blockNumer)(identityUpdate)
49-
_ <- peer2.start.delayExecution(50.milliseconds)
50-
_ <- peer1.importBlocksUntil(blockNumer)(identityUpdate)
51-
_ <- peer1.start.delayExecution(50.milliseconds)
52-
_ <- peer2.mineNewBlock(10)(identityUpdate).delayExecution(500.milliseconds)
53-
_ <- peer2.mineNewBlock(10)(identityUpdate).delayExecution(500.milliseconds)
54-
_ <- peer2.mineNewBlock(10)(identityUpdate).delayExecution(500.milliseconds)
48+
_ <- peer2.importBlocksUntil(blockNumer)(IdentityUpdate)
49+
_ <- peer2.startRegularSync().delayExecution(50.milliseconds)
50+
_ <- peer1.importBlocksUntil(blockNumer)(IdentityUpdate)
51+
_ <- peer1.startRegularSync().delayExecution(50.milliseconds)
52+
_ <- peer2.mineNewBlock(10)(IdentityUpdate).delayExecution(500.milliseconds)
53+
_ <- peer2.mineNewBlock(10)(IdentityUpdate).delayExecution(500.milliseconds)
54+
_ <- peer2.mineNewBlock(10)(IdentityUpdate).delayExecution(500.milliseconds)
5555
_ <- peer2.waitForRegularSyncLoadLastBlock(blockNumer + 3)
56-
_ <- peer1.mineNewBlock()(identityUpdate).delayExecution(500.milliseconds)
56+
_ <- peer1.mineNewBlock()(IdentityUpdate).delayExecution(500.milliseconds)
5757
_ <- peer1.waitForRegularSyncLoadLastBlock(blockNumer + 1)
5858
_ <- peer1.connectToPeers(Set(peer2.node)).delayExecution(500.milliseconds)
5959
_ <- peer1.waitForRegularSyncLoadLastBlock(blockNumer + 3)

0 commit comments

Comments
 (0)