diff --git a/.github/workflows/Linux_2.12_App_Chain_Node_Core_Tests.yml b/.github/workflows/Linux_2.12_App_Chain_Core_Tests.yml similarity index 62% rename from .github/workflows/Linux_2.12_App_Chain_Node_Core_Tests.yml rename to .github/workflows/Linux_2.12_App_Chain_Core_Tests.yml index a31b427cd3..739f99bee8 100644 --- a/.github/workflows/Linux_2.12_App_Chain_Node_Core_Tests.yml +++ b/.github/workflows/Linux_2.12_App_Chain_Core_Tests.yml @@ -1,4 +1,4 @@ -name: Linux 2.12 App, Chain, Node, and Core Tests +name: Linux 2.12 App, Chain, and Core Tests env: COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} @@ -28,4 +28,4 @@ jobs: ~/.bitcoin-s/binaries key: ${{ runner.os }}-cache - name: run tests - run: sbt ++2.12.14 downloadBitcoind coverage chainTest/test chain/coverageReport chain/coverageAggregate chain/coveralls nodeTest/test node/coverageReport node/coverageAggregate node/coveralls cryptoJVM/test cryptoTestJVM/test cryptoJVM/coverageReport cryptoJVM/coverageAggregate cryptoJVM/coveralls coreTestJVM/test dlcTest/test coreJVM/coverageReport coreJVM/coverageAggregate coreJVM/coveralls secp256k1jni/test zmq/test zmq/coverageReport zmq/coverageAggregate zmq/coveralls appCommonsTest/test appServerTest/test oracleServerTest/test dlcNodeTest/test + run: sbt ++2.12.14 downloadBitcoind coverage chainTest/test chain/coverageReport chain/coverageAggregate chain/coveralls cryptoJVM/test cryptoTestJVM/test cryptoJVM/coverageReport cryptoJVM/coverageAggregate cryptoJVM/coveralls coreTestJVM/test dlcTest/test coreJVM/coverageReport coreJVM/coverageAggregate coreJVM/coveralls secp256k1jni/test zmq/test zmq/coverageReport zmq/coverageAggregate zmq/coveralls appCommonsTest/test appServerTest/test oracleServerTest/test diff --git a/.github/workflows/Linux_2.12_Node_Tests.yml b/.github/workflows/Linux_2.12_Node_Tests.yml new file mode 100644 index 0000000000..57c900b11a --- /dev/null +++ b/.github/workflows/Linux_2.12_Node_Tests.yml @@ -0,0 +1,31 @@ +name: Linux 2.12 Node Tests +env: + COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} + +on: + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + timeout-minutes: 60 + if: "! contains(github.event.pull_request.labels.*.name, 'documentation')" + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Setup Scala + uses: olafurpg/setup-scala@v10 + with: + java-version: zulu@1.11 + - name: Cache + uses: actions/cache@v2 + with: + path: | + ~/.ivy2/cache + ~/.sbt + ~/.bitcoin-s/binaries + key: ${{ runner.os }}-cache + - name: run tests + run: sbt ++2.12.14 downloadBitcoind coverage nodeTest/test node/coverageReport node/coverageAggregate node/coveralls dlcNodeTest/test diff --git a/.github/workflows/Linux_2.13_App_Chain_Node_Core_Tests.yml b/.github/workflows/Linux_2.13_App_Chain_Core_Tests.yml similarity index 62% rename from .github/workflows/Linux_2.13_App_Chain_Node_Core_Tests.yml rename to .github/workflows/Linux_2.13_App_Chain_Core_Tests.yml index e1ae0310ed..a983350014 100644 --- a/.github/workflows/Linux_2.13_App_Chain_Node_Core_Tests.yml +++ b/.github/workflows/Linux_2.13_App_Chain_Core_Tests.yml @@ -1,4 +1,4 @@ -name: Linux 2.13 App, Chain, Node, and Core Tests +name: Linux 2.13 App, Chain, and Core Tests env: COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} @@ -28,4 +28,4 @@ jobs: ~/.bitcoin-s/binaries key: ${{ runner.os }}-cache - name: run tests - run: sbt ++2.13.6 downloadBitcoind coverage chainTest/test chain/coverageReport chain/coverageAggregate chain/coveralls nodeTest/test node/coverageReport node/coverageAggregate node/coveralls cryptoTestJVM/test cryptoJVM/test cryptoJVM/coverageReport cryptoJVM/coverageAggregate cryptoJVM/coveralls coreTestJVM/test dlcTest/test coreJVM/coverageReport coreJVM/coverageAggregate coreJVM/coveralls secp256k1jni/test zmq/test zmq/coverageReport zmq/coverageAggregate zmq/coveralls appCommonsTest/test appServerTest/test oracleServerTest/test dlcNodeTest/test + run: sbt ++2.13.6 downloadBitcoind coverage chainTest/test chain/coverageReport chain/coverageAggregate chain/coveralls cryptoTestJVM/test cryptoJVM/test cryptoJVM/coverageReport cryptoJVM/coverageAggregate cryptoJVM/coveralls coreTestJVM/test dlcTest/test coreJVM/coverageReport coreJVM/coverageAggregate coreJVM/coveralls secp256k1jni/test zmq/test zmq/coverageReport zmq/coverageAggregate zmq/coveralls appCommonsTest/test appServerTest/test oracleServerTest/test diff --git a/.github/workflows/Linux_2.13_Node_Tests.yml b/.github/workflows/Linux_2.13_Node_Tests.yml new file mode 100644 index 0000000000..5f74d3ad81 --- /dev/null +++ b/.github/workflows/Linux_2.13_Node_Tests.yml @@ -0,0 +1,31 @@ +name: Linux 2.13 Node Tests +env: + COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} + +on: + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + timeout-minutes: 60 + if: "! contains(github.event.pull_request.labels.*.name, 'documentation')" + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Setup Scala + uses: olafurpg/setup-scala@v10 + with: + java-version: zulu@1.11 + - name: Cache + uses: actions/cache@v2 + with: + path: | + ~/.ivy2/cache + ~/.sbt + ~/.bitcoin-s/binaries + key: ${{ runner.os }}-cache + - name: run tests + run: sbt ++2.13.6 downloadBitcoind coverage nodeTest/test node/coverageReport node/coverageAggregate node/coveralls dlcNodeTest/test diff --git a/node-test/src/test/scala/org/bitcoins/node/networking/P2PClientTest.scala b/node-test/src/test/scala/org/bitcoins/node/networking/P2PClientTest.scala index af358ecb6b..21f7c9b193 100644 --- a/node-test/src/test/scala/org/bitcoins/node/networking/P2PClientTest.scala +++ b/node-test/src/test/scala/org/bitcoins/node/networking/P2PClientTest.scala @@ -1,6 +1,5 @@ package org.bitcoins.node.networking -import akka.io.Tcp import akka.testkit.{TestActorRef, TestProbe} import org.bitcoins.core.config.TestNet3 import org.bitcoins.core.number.{Int32, UInt32, UInt64} @@ -201,7 +200,7 @@ class P2PClientTest isConnectedF.flatMap { _ => val isDisconnectedF = for { p2pClient <- p2pClientF - _ = p2pClient.actor ! Tcp.Abort + _ = p2pClient.actor ! P2PClient.CloseCommand isDisconnected <- TestAsyncUtil.retryUntilSatisfiedF(p2pClient.isDisconnected, interval = 1.second, diff --git a/node/src/main/scala/org/bitcoins/node/Node.scala b/node/src/main/scala/org/bitcoins/node/Node.scala index d6a4ef9aae..4e80df1dfd 100644 --- a/node/src/main/scala/org/bitcoins/node/Node.scala +++ b/node/src/main/scala/org/bitcoins/node/Node.scala @@ -170,7 +170,6 @@ trait Node extends NodeApi with ChainQueryApi with P2PLogger { isInitializedF.failed.foreach { err => logger.error( s"Failed to connect with peer=${peers(idx)} with err=$err") - sys.exit(-1) } isInitializedF.map { _ => nodeAppConfig.nodeType match { diff --git a/node/src/main/scala/org/bitcoins/node/networking/P2PClient.scala b/node/src/main/scala/org/bitcoins/node/networking/P2PClient.scala index 2628a534d7..4e335bad7e 100644 --- a/node/src/main/scala/org/bitcoins/node/networking/P2PClient.scala +++ b/node/src/main/scala/org/bitcoins/node/networking/P2PClient.scala @@ -70,6 +70,8 @@ case class P2PClientActor( extends Actor with P2PLogger { + private case object ReconnectCommand extends NodeCommand + private var currentPeerMsgHandlerRecv = initPeerMsgHandlerReceiver private var reconnectHandlerOpt: Option[() => Future[Unit]] = None @@ -105,12 +107,15 @@ case class P2PClientActor( case payload: NetworkPayload => val networkMsg = NetworkMessage(network, payload) self.forward(networkMsg) - case message: Tcp.Message => + case message: Tcp.Event => val newUnalignedBytes = - handleTcpMessage(message, peerConnection, unalignedBytes) + handleEvent(message, peerConnection, unalignedBytes) context.become(awaitNetworkRequest(peerConnection, newUnalignedBytes)) - case nodeCommand: NodeCommand => - handleNodeCommand(nodeCommand, Some(peerConnection)) + case P2PClient.CloseCommand => + logger.info(s"disconnecting from peer $peer") + currentPeerMsgHandlerRecv = + currentPeerMsgHandlerRecv.initializeDisconnect() + peerConnection ! Tcp.Close case metaMsg: P2PClient.MetaMsg => sender() ! handleMetaMsg(metaMsg) case Terminated(actor) if actor == peerConnection => @@ -119,13 +124,13 @@ case class P2PClientActor( override def receive: Receive = LoggingReceive { case P2PClient.ConnectCommand => - handleNodeCommand(P2PClient.ConnectCommand, None) + connect() case metaMsg: P2PClient.MetaMsg => sender() ! handleMetaMsgDisconnected(metaMsg) } def reconnecting: Receive = LoggingReceive { - case P2PClient.ReconnectCommand => + case ReconnectCommand => logger.info(s"reconnecting to ${peer.socket}") reconnectHandlerOpt = Some(onReconnect) connect() @@ -242,32 +247,13 @@ case class P2PClientActor( reconnectionTry = reconnectionTry + 1 import context.dispatcher - context.system.scheduler.scheduleOnce(delay)( - self ! P2PClient.ReconnectCommand) + context.system.scheduler.scheduleOnce(delay)(self ! ReconnectCommand) context.become(reconnecting) } } } - /** Handles boiler plate [[Tcp.Message]] types. - * - * @return the unaligned bytes if we haven't received a full Bitcoin P2P message yet - */ - private def handleTcpMessage( - message: Tcp.Message, - peerConnection: ActorRef, - unalignedBytes: ByteVector): ByteVector = { - message match { - case event: Tcp.Event => - handleEvent(event, peerConnection, unalignedBytes = unalignedBytes) - case command: Tcp.Command => - handleCommand(command, peerConnection) - - unalignedBytes - } - } - /** This function is responsible for handling a [[Tcp.Event]] algebraic data type */ private def handleEvent( @@ -369,20 +355,6 @@ case class P2PClientActor( } } - /** This function is responsible for handling a [[Tcp.Command]] algebraic data type - */ - private def handleCommand( - command: Tcp.Command, - peerConnection: ActorRef): Unit = - command match { - case closeCmd @ (Tcp.ConfirmedClose | Tcp.Close | Tcp.Abort) => - peerConnection ! closeCmd - case connectCmd: Tcp.Connect => - manager ! connectCmd - case bind: Tcp.Bind => - manager ! bind - } - /** Returns the current state of our peer given the [[P2PClient.MetaMsg meta message]] */ private def handleMetaMsg(metaMsg: P2PClient.MetaMsg): Boolean = { @@ -412,20 +384,6 @@ case class P2PClientActor( peerConnection ! Tcp.ResumeReading } - private def handleNodeCommand( - command: NodeCommand, - peerConnectionOpt: Option[ActorRef]): Unit = command match { - case P2PClient.ConnectCommand => - connect() - case P2PClient.ReconnectCommand => - reconnect() - case P2PClient.CloseCommand => - currentPeerMsgHandlerRecv = - currentPeerMsgHandlerRecv.initializeDisconnect() - peerConnectionOpt.map(actor => actor.tell(Tcp.Close, self)) - () - } - } case class P2PClient(actor: ActorRef, peer: Peer) extends P2PLogger { @@ -467,9 +425,6 @@ object P2PClient extends P2PLogger { sealed trait NodeCommand case object ConnectCommand extends NodeCommand - - case object ReconnectCommand extends NodeCommand - case object CloseCommand extends NodeCommand /** A message hierarchy that canbe sent to [[P2PClientActor P2P Client Actor]] diff --git a/zmq/src/test/scala/org/bitcoins/zmq/ZMQSubscriberTest.scala b/zmq/src/test/scala/org/bitcoins/zmq/ZMQSubscriberTest.scala index 8346c0d65f..cb88d7fcd7 100644 --- a/zmq/src/test/scala/org/bitcoins/zmq/ZMQSubscriberTest.scala +++ b/zmq/src/test/scala/org/bitcoins/zmq/ZMQSubscriberTest.scala @@ -39,7 +39,7 @@ class ZMQSubscriberTest extends AsyncFlatSpec with Logging { //and set the bitcoin.conf file to allow for //zmq connections //see: https://github.com/bitcoin/bitcoin/blob/master/doc/zmq.md - val socket = new InetSocketAddress("tcp://127.0.0.1", 29000) + val socket = new InetSocketAddress("127.0.0.1", 29000) val zmqSub = new ZMQSubscriber(socket, None, None, rawTxListener, rawBlockListener)