Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Scala 2.13.4 compiling #2294

Merged
merged 5 commits into from Nov 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 12 additions & 12 deletions .travis.yml
Expand Up @@ -9,7 +9,7 @@ jobs:
name: Compile Website
env:
- TEST_COMMAND="docs/mdoc"
scala: 2.13.3
scala: 2.13.4

- stage: trivial
os: linux
Expand All @@ -30,14 +30,14 @@ jobs:
name: Compile website
env:
- TEST_COMMAND="docs/mdoc"
scala: 2.13.3
scala: 2.13.4

- stage: test
name: Linux 2.13.3 bitcoind and eclair rpc tests
name: Linux 2.13.4 bitcoind and eclair rpc tests
os: linux
env:
- TEST_COMMAND="bitcoindRpcTest/test bitcoindRpc/coverageReport bitcoindRpc/coverageAggregate bitcoindRpc/coveralls eclairRpcTest/test eclairRpc/coverageReport eclairRpc/coverageAggregate eclairRpc/coveralls"
scala: 2.13.3
scala: 2.13.4

- stage: test
name: Linux 2.12.12 bitcoind and eclair rpc tests
Expand All @@ -47,11 +47,11 @@ jobs:
scala: 2.12.12

- stage: test
name: Linux 2.13.3 App, Chain, Node, and Core Tests
name: Linux 2.13.4 App, Chain, Node, and Core Tests
os: linux
env:
- TEST_COMMAND="chainTest/test chain/coverageReport chain/coverageAggregate chain/coveralls nodeTest/test node/coverageReport node/coverageAggregate node/coveralls cryptoTest/test crypto/coverageReport crypto/coverageAggregate crypto/coveralls coreTest/test core/coverageReport core/coverageAggregate core/coveralls secp256k1jni/test zmq/test zmq/coverageReport zmq/coverageAggregate zmq/coveralls appCommonsTest/test appServerTest/test"
scala: 2.13.3
scala: 2.13.4

- stage: test
name: Linux 2.12.12 App, Chain, Node, and Core Tests
Expand All @@ -60,11 +60,11 @@ jobs:
- TEST_COMMAND="chainTest/test chain/coverageReport chain/coverageAggregate chain/coveralls nodeTest/test node/coverageReport node/coverageAggregate node/coveralls cryptoTest/test crypto/coverageReport crypto/coverageAggregate crypto/coveralls coreTest/test core/coverageReport core/coverageAggregate core/coveralls secp256k1jni/test zmq/test zmq/coverageReport zmq/coverageAggregate zmq/coveralls appCommonsTest/test appServerTest/test"
scala: 2.12.12
- stage: test
name: Linux 2.13.3 KeyManager Wallet, dlc tests
name: Linux 2.13.4 KeyManager Wallet, dlc tests
os: linux
env:
- TEST_COMMAND="keyManagerTest/test keyManager/coverageReport keyManager/coverageAggregate keyManager/coveralls walletTest/test wallet/coverageReport wallet/coverageAggregate wallet/coveralls dlcOracleTest/test dlcOracle/coverageReport dlcOracle/coverageAggregate dlcOracle/coveralls"
scala: 2.13.3
scala: 2.13.4

- stage: test
name: Linux 2.12.12 KeyManager, Wallet, dlc tests
Expand All @@ -79,22 +79,22 @@ jobs:
env:
- DISABLE_SECP256K1="true"
- TEST_COMMAND="coreTest/test cryptoTest/test"
scala: 2.13.3
scala: 2.13.4

- stage: test
os: linux
name: "PostgreSQL tests"
env:
- PG_ENABLED="1"
- TEST_COMMAND="dbCommonsTest/test chainTest/test nodeTest/test walletTest/test"
scala: 2.13.3
scala: 2.13.4

- stage: test
os: osx
name: "macOS bitcoind and eclair tests"
env:
- TEST_COMMAND="cryptoTest/test coreTest/test appCommonsTest/test bitcoindRpcTest/test bitcoindRpc/coverageReport bitcoindRpc/coverageAggregate bitcoindRpc/coveralls eclairRpcTest/test eclairRpc/coverageReport eclairRpc/coverageAggregate eclairRpc/coveralls"
scala: 2.13.3
scala: 2.13.4

# skip all test tagged as UsesExperimentalBitcoind
# TODO remove this condition once we have a neutrino enabled bitcoind binary for OSX
Expand All @@ -103,7 +103,7 @@ jobs:
name: "macOS wallet, node, dlc tests"
env:
- TEST_COMMAND="walletTest/test wallet/coverageReport wallet/coverageAggregate wallet/coveralls nodeTest/test node/coverageReport node/coverageAggregate node/coveralls dlcOracleTest/test dlcOracle/coverageReport dlcOracle/coveralls"
scala: 2.13.3
scala: 2.13.4
# Release snapshots/versions of all libraries
# run ci-release only if previous stages passed
- stage: release
Expand Down
Expand Up @@ -284,17 +284,18 @@ private[blockchain] trait BaseBlockChainCompObject
val orderedHeaders =
connectWalkBackwards(current = childHeader, ancestors = ancestors)

val initBlockchainOpt = orderedHeaders match {
case Vector() | _ +: Vector() =>
val initBlockchainOpt = {
if (orderedHeaders.isEmpty || orderedHeaders.length == 1) {
//for the case of _ +: Vector() this means only our
//child header is in the chain, which means we
//weren't able to form a blockchain
None
case h +: _ =>
} else {
//find our first header as we need it's Db representation
//rather than just the raw header
val dbOpt = ancestors.find(_.hashBE == h.hashBE)
val dbOpt = ancestors.find(_.hashBE == orderedHeaders.head.hashBE)
Some(Blockchain.fromHeaders(Vector(dbOpt.get)))
}
}

//now let's connect headers
Expand Down
Expand Up @@ -63,23 +63,25 @@ class ChainHandler(
val maxWork = groupedChains.keys.max
val chainsByWork = groupedChains(maxWork)

val bestHeader: BlockHeaderDb = chainsByWork match {
case Vector() =>
val bestHeader: BlockHeaderDb = {
if (chainsByWork.isEmpty) {
// This should never happen
val errMsg = s"Did not find blockchain with work $maxWork"
logger.error(errMsg)
throw new RuntimeException(errMsg)
case chain +: Vector() =>
chain.tip
case chain +: rest =>
} else if (chainsByWork.length == 1) {
chainsByWork.head.tip
} else {
val tips = chainsByWork
.map(_.tip.hashBE.hex)
.mkString(", ")
logger.warn(
s"We have multiple competing blockchains with same work, selecting by time: ${(chain +: rest)
.map(_.tip.hashBE.hex)
.mkString(", ")}")
s"We have multiple competing blockchains with same work, selecting by time: $tips")
//since we have same chainwork, just take the oldest tip
//as that's "more likely" to have been propagated first
//and had more miners building on top of it
chainsByWork.sortBy(_.tip.time).head.tip
}
}
bestHeader
}
Expand Down
Expand Up @@ -11,6 +11,13 @@ class CurrencyUnitTest extends BitcoinSUnitTest {

behavior of "Satoshis"

it must "have 1BTC == 100,000,000 satoshis" in {
assert(Bitcoins.one == Satoshis(100000000))
assert(Satoshis(100000000) == Bitcoins.one)
assert(Satoshis.zero == Bitcoins.zero)
assert(Bitcoins.zero == Satoshis.zero)
}

it must "have symmetry serialization" in {
forAll(CurrencyUnitGenerator.satoshis) { satoshis =>
assert(Satoshis(satoshis.hex) == satoshis)
Expand Down
Expand Up @@ -38,6 +38,8 @@ object Base58ValidTestCaseProtocol extends DefaultJsonProtocol {
Left(Sha256Hash160Digest(elements(1).convertTo[String]))
case b if b.isRight =>
Right(ECPrivateKey(elements(1).convertTo[String]))
case _ =>
sys.error(s"Should be left or right")
}
Base58ValidTestCaseImpl(addressOrPrivateKey(elements),
isHashOrPrivKey(elements),
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/scala/org/bitcoins/core/currency/CurrencyUnits.scala
Expand Up @@ -74,6 +74,19 @@ sealed abstract class CurrencyUnit
def toBigDecimal: BigDecimal

protected def underlying: A

override def equals(obj: Any): Boolean = {
//needed for cases like
//1BTC == 100,000,000 satoshis should be true
//weirdly enough, this worked in scala version < 2.13.4
//but seems to be broken in 2.13.4 :/
//try removing this and running code, you should see
//failures in the 'walletTest' module
obj match {
case cu: CurrencyUnit => cu.satoshis == satoshis
case _ => false
}
}
}

sealed abstract class Satoshis extends CurrencyUnit {
Expand Down
Expand Up @@ -157,11 +157,11 @@ object LnTaggedFields {
val newRemaining = t.slice(payload.size, t.size)

loop(newRemaining, fields :+ tag)
case IndexedSeq() =>
fields
case _ +: _ | _ +: _ +: _ =>
throw new IllegalArgumentException(
"Failed to parse LnTaggedFields, needs 15bits of meta data to be able to parse")
case _: Vector[_] =>
fields
}
}

Expand Down
Expand Up @@ -119,7 +119,8 @@ sealed abstract class ScriptParser
.decodeHex(
BytesUtil.flipEndianness(
h)) ++ bytesToPushOntoStack.bytes ++ accum)
case Vector() => accum
case _: Vector[_] =>
accum
}
}
if (tryParsingLong(str) && str.size > 1 && str.substring(0, 2) != "0x") {
Expand Down
2 changes: 1 addition & 1 deletion inThisBuild.sbt
Expand Up @@ -3,7 +3,7 @@ import sbt.Keys.excludeLintKeys
import scala.util.Properties

val scala2_12 = "2.12.12"
val scala2_13 = "2.13.3"
val scala2_13 = "2.13.4"

scalafmtOnCompile in ThisBuild := !Properties.envOrNone("CI").contains("true")

Expand Down
4 changes: 3 additions & 1 deletion project/CommonSettings.scala
Expand Up @@ -99,7 +99,9 @@ object CommonSettings {
"-Ywarn-unused",
"-unchecked",
"-deprecation",
"-feature"
"-feature",
"-Ypatmat-exhaust-depth",
"off"
) ++ commonCompilerOpts ++ {
if (scalaVersion.startsWith("2.13")) scala2_13CompilerOpts
else nonScala2_13CompilerOpts
Expand Down