Skip to content

Commit d09db3d

Browse files
sstonedpad85
andauthored
Upgrade to kotlin 1.5 (#297)
* Upgrade to kotlin 1.5 * Use kodein-log 0.11.1 (official version, not our fork) * Use kotlin 1.5.31, secp256k1-kmp 0.6.0 and bitcoin-kmp 0.8.0 Co-authored-by: dpad85 <[email protected]>
1 parent da7b603 commit d09db3d

File tree

26 files changed

+93
-102
lines changed

26 files changed

+93
-102
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ jobs:
3333
uses: actions/checkout@v2
3434
with:
3535
submodules: 'true'
36-
- name: Checkout kodein-log with UTC fork
37-
uses: actions/checkout@v2
38-
with:
39-
repository: dpad85/Kodein-Log
40-
ref: utc-timezone
41-
path: kodein-log
4236

4337
# 2 - setup cache and tools
4438
- name: Cached Konan
@@ -63,12 +57,6 @@ jobs:
6357
with:
6458
java-version: 11
6559

66-
# 3 - build dependencies
67-
- name: Build kodein-log and publish it to local maven
68-
run: |
69-
cd kodein-log
70-
./gradlew publishToMavenLocal
71-
7260
# 4 - tests
7361
- name: Check with integration
7462
if: matrix.os == 'ubuntu-latest'

BUILD.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,6 @@ brew install libtool
1616
brew install gmp
1717
```
1818

19-
## Required dependency
20-
21-
This project currently depends on a fork of the `kodein-logs` library. This lib must be built manually and deployed to the local maven repository before being able to build `lightning-kmp`. To do so:
22-
1. clone [the GitHub repo](https://github.com/dpad85/Kodein-Log)
23-
```
24-
git clone [email protected]:dpad85/Kodein-Log.git
25-
cd Kodein-Log
26-
```
27-
2. checkout the `0.10.1-utc` tag
28-
```
29-
git checkout 0.10.1-utc
30-
```
31-
4. build and deploy the library:
32-
```
33-
./gradlew build
34-
./gradlew publishToMavenLocal
35-
```
36-
37-
Note: this dependency is a temporary workaround and will be removed as soon as possible.
38-
3919
## Build
4020

4121
You should start by cloning the repository locally:

build.gradle.kts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
22
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
33

44
plugins {
5-
kotlin("multiplatform") version "1.4.31"
6-
kotlin("plugin.serialization") version "1.4.30"
5+
kotlin("multiplatform") version "1.5.31"
6+
kotlin("plugin.serialization") version "1.5.31"
77
`maven-publish`
88
}
99

1010
allprojects {
1111
group = "fr.acinq.lightning"
12-
version = "1.0-beta17"
12+
version = "1.1-SNAPSHOT"
1313

1414
repositories {
1515
mavenLocal()
@@ -23,17 +23,17 @@ allprojects {
2323
val currentOs = org.gradle.internal.os.OperatingSystem.current()
2424

2525
kotlin {
26-
val ktorVersion: String by extra { "1.5.3" }
26+
val ktorVersion: String by extra { "1.6.3" }
2727
fun ktor(module: String) = "io.ktor:ktor-$module:$ktorVersion"
28-
val secp256k1Version = "0.5.1"
29-
val serializationVersion = "1.1.0"
30-
val coroutineVersion = "1.4.3-native-mt"
28+
val secp256k1Version = "0.6.0"
29+
val serializationVersion = "1.2.2"
30+
val coroutineVersion = "1.5.2-native-mt"
3131

3232
val commonMain by sourceSets.getting {
3333
dependencies {
34-
api("fr.acinq.bitcoin:bitcoin-kmp:0.7.0")
34+
api("fr.acinq.bitcoin:bitcoin-kmp:0.8.0")
3535
api("fr.acinq.secp256k1:secp256k1-kmp:$secp256k1Version")
36-
api("org.kodein.log:kodein-log:0.10.1-utc")
36+
api("org.kodein.log:kodein-log:0.11.1")
3737
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion")
3838
api("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion")
3939
api("org.jetbrains.kotlinx:kotlinx-serialization-cbor:$serializationVersion")

lightning-kmp-test-fixtures/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ val currentOs = org.gradle.internal.os.OperatingSystem.current()
88
kotlin {
99
val ktorVersion: String by rootProject.extra
1010
fun ktor(module: String) = "io.ktor:ktor-$module:$ktorVersion"
11-
val serializationVersion = "1.0.0-RC"
1211

1312
val commonMain by sourceSets.getting {
1413
dependencies {

lightning-kmp-test-fixtures/src/commonMain/kotlin/fr/acinq/lightning/tests/io/peer/builders.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,13 @@ import fr.acinq.lightning.wire.ChannelReestablish
2424
import fr.acinq.lightning.wire.FundingLocked
2525
import fr.acinq.lightning.wire.Init
2626
import fr.acinq.lightning.wire.LightningMessage
27-
import kotlinx.coroutines.CoroutineScope
28-
import kotlinx.coroutines.ExperimentalCoroutinesApi
27+
import kotlinx.coroutines.*
2928
import kotlinx.coroutines.flow.Flow
3029
import kotlinx.coroutines.flow.collect
3130
import kotlinx.coroutines.flow.first
3231
import kotlinx.coroutines.flow.flow
33-
import kotlinx.coroutines.isActive
34-
import kotlinx.coroutines.launch
3532

36-
@OptIn(ExperimentalCoroutinesApi::class)
33+
@OptIn(ExperimentalCoroutinesApi::class, kotlinx.coroutines.ObsoleteCoroutinesApi::class)
3734
public suspend fun newPeers(
3835
scope: CoroutineScope,
3936
nodeParams: Pair<NodeParams, NodeParams>,
@@ -114,6 +111,7 @@ public suspend fun newPeers(
114111
return PeerTuple(alice, bob, alice2bob, bob2alice)
115112
}
116113

114+
@OptIn(ObsoleteCoroutinesApi::class)
117115
public suspend fun CoroutineScope.newPeer(
118116
nodeParams: NodeParams,
119117
walletParams: WalletParams,
@@ -161,7 +159,7 @@ public suspend fun CoroutineScope.newPeer(
161159
return peer
162160
}
163161

164-
@OptIn(ExperimentalCoroutinesApi::class)
162+
@OptIn(ExperimentalCoroutinesApi::class, kotlinx.coroutines.ObsoleteCoroutinesApi::class)
165163
public fun buildPeer(
166164
scope: CoroutineScope,
167165
nodeParams: NodeParams,

lightning-kmp-test-fixtures/src/commonMain/kotlin/fr/acinq/lightning/tests/utils/runTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import kotlin.time.seconds
1111
expect fun runSuspendBlocking(block: suspend CoroutineScope.() -> Unit)
1212

1313
@OptIn(ExperimentalTime::class)
14-
fun runSuspendTest(timeout: Duration = 30.seconds, test: suspend CoroutineScope.() -> Unit) {
14+
fun runSuspendTest(timeout: Duration = Duration.seconds(30), test: suspend CoroutineScope.() -> Unit) {
1515
runSuspendBlocking {
1616
withTimeout(timeout) {
1717
launch {

src/commonMain/kotlin/fr/acinq/lightning/blockchain/electrum/ElectrumClient.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import kotlinx.coroutines.flow.collect
2020
import kotlinx.coroutines.flow.filter
2121
import kotlinx.serialization.json.Json
2222
import kotlin.native.concurrent.ThreadLocal
23+
import kotlin.time.Duration
2324
import kotlin.time.ExperimentalTime
2425
import kotlin.time.seconds
2526

@@ -58,6 +59,7 @@ internal sealed class ClientState {
5859
abstract fun process(event: ClientEvent): Pair<ClientState, List<ElectrumClientAction>>
5960
}
6061

62+
@ObsoleteCoroutinesApi
6163
internal object WaitingForVersion : ClientState() {
6264
override fun process(event: ClientEvent): Pair<ClientState, List<ElectrumClientAction>> = when {
6365
event is ReceivedResponse && event.response is Either.Right -> {
@@ -77,6 +79,7 @@ internal object WaitingForVersion : ClientState() {
7779
}
7880
}
7981

82+
@ObsoleteCoroutinesApi
8083
internal object WaitingForTip : ClientState() {
8184
override fun process(event: ClientEvent): Pair<ClientState, List<ElectrumClientAction>> =
8285
when (event) {
@@ -97,6 +100,7 @@ internal object WaitingForTip : ClientState() {
97100
}
98101
}
99102

103+
@ObsoleteCoroutinesApi
100104
internal data class ClientRunning(
101105
val height: Int,
102106
val tip: BlockHeader,
@@ -138,6 +142,7 @@ internal data class ClientRunning(
138142
}
139143
}
140144

145+
@ObsoleteCoroutinesApi
141146
internal object ClientClosed : ClientState() {
142147
override fun process(event: ClientEvent): Pair<ClientState, List<ElectrumClientAction>> =
143148
when (event) {
@@ -149,6 +154,7 @@ internal object ClientClosed : ClientState() {
149154
}
150155
}
151156

157+
@ObsoleteCoroutinesApi
152158
private fun ClientState.unhandled(event: ClientEvent): Pair<ClientState, List<ElectrumClientAction>> =
153159
when (event) {
154160
Disconnected -> ClientClosed to emptyList()
@@ -159,12 +165,14 @@ private fun ClientState.unhandled(event: ClientEvent): Pair<ClientState, List<El
159165
}
160166
}
161167

168+
@ObsoleteCoroutinesApi
162169
private class ClientStateBuilder {
163170
var state: ClientState = ClientClosed
164171
var actions = emptyList<ElectrumClientAction>()
165172
fun build() = state to actions
166173
}
167174

175+
@ObsoleteCoroutinesApi
168176
private fun newState(init: ClientStateBuilder.() -> Unit) = ClientStateBuilder().apply(init).build()
169177

170178
private fun ClientState.returnState(actions: List<ElectrumClientAction> = emptyList()): Pair<ClientState, List<ElectrumClientAction>> = this to actions
@@ -176,7 +184,7 @@ data class RequestResponseTimestamp(
176184
val lastResponseTimestamp: Long?
177185
)
178186

179-
@OptIn(ExperimentalCoroutinesApi::class, ExperimentalTime::class)
187+
@OptIn(ExperimentalCoroutinesApi::class, ExperimentalTime::class, ObsoleteCoroutinesApi::class)
180188
class ElectrumClient(
181189
socketBuilder: TcpSocket.Builder?,
182190
scope: CoroutineScope
@@ -284,7 +292,7 @@ class ElectrumClient(
284292

285293
suspend fun ping() {
286294
while (isActive) {
287-
delay(30.seconds)
295+
delay(Duration.seconds(30))
288296
send(Ping.asJsonRPCRequest(-1).encodeToByteArray())
289297
}
290298
}

src/commonMain/kotlin/fr/acinq/lightning/blockchain/electrum/ElectrumDataTypes.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ internal fun parseJsonResponse(request: ElectrumRequest, rpcResponse: JsonRPCRes
315315
var progress = 0
316316
val inputSize = input.availableBytes
317317
while (progress < inputSize) {
318-
val header = input.readNBytes(headerSize)
318+
val header = input.readNBytes(headerSize)!!
319319
add(BlockHeader.read(header))
320320
progress += headerSize
321321
}

src/commonMain/kotlin/fr/acinq/lightning/blockchain/electrum/ElectrumWatcher.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ private data class WatcherDisconnected(
7272
val block2tx: Map<Long, List<Transaction>> = mapOf(),
7373
val getTxQueue: List<GetTxWithMeta> = listOf()
7474
) : WatcherState() {
75+
@OptIn(ObsoleteCoroutinesApi::class)
7576
override fun process(event: WatcherEvent): Pair<WatcherState, List<WatcherAction>> =
7677
when (event) {
7778
is ClientStateUpdate -> {
@@ -353,6 +354,7 @@ private data class WatcherRunning(
353354
}
354355
}
355356

357+
@OptIn(ObsoleteCoroutinesApi::class)
356358
private fun setupWatch(watch: Watch) = when (watch) {
357359
is WatchLost -> returnState() // ignore WatchLost for now
358360
in watches -> returnState()
@@ -509,7 +511,7 @@ class ElectrumWatcher(
509511
private fun startTimer() {
510512
if (timerJob != null) return
511513

512-
val timeMillis: Long = 2 * 1_000 // fire timer every 2 seconds
514+
val timeMillis: Long = 2L * 1_000 // fire timer every 2 seconds
513515
timerJob = launch {
514516
delay(timeMillis)
515517
while(isActive) {
@@ -605,6 +607,7 @@ class ElectrumWatcher(
605607
companion object {
606608
val logger by lightningLogger<ElectrumWatcher>()
607609

610+
@ObsoleteCoroutinesApi
608611
internal fun registerToScriptHash(watch: Watch): RegisterToScriptHashNotification? = when (watch) {
609612
is WatchSpent -> {
610613
val (_, txid, outputIndex, publicKeyScript, _) = watch

src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import kotlinx.coroutines.channels.Channel.Factory.BUFFERED
3030
import kotlinx.coroutines.channels.ReceiveChannel
3131
import kotlinx.coroutines.channels.consumeEach
3232
import kotlinx.coroutines.flow.*
33+
import kotlin.time.Duration
3334
import kotlin.time.ExperimentalTime
3435
import kotlin.time.seconds
3536

@@ -60,6 +61,7 @@ data class SwapInResponseEvent(val swapInResponse: SwapInResponse) : PeerListene
6061
data class SwapInPendingEvent(val swapInPending: SwapInPending) : PeerListenerEvent()
6162
data class SwapInConfirmedEvent(val swapInConfirmed: SwapInConfirmed) : PeerListenerEvent()
6263

64+
@ObsoleteCoroutinesApi
6365
@OptIn(ExperimentalStdlibApi::class, ExperimentalCoroutinesApi::class, ExperimentalTime::class)
6466
class Peer(
6567
val nodeParams: NodeParams,
@@ -275,14 +277,14 @@ class Peer(
275277
suspend fun doPing() {
276278
val ping = Ping(10, ByteVector("deadbeef"))
277279
while (isActive) {
278-
delay(30.seconds)
280+
delay(Duration.seconds(30))
279281
sendToPeer(ping)
280282
}
281283
}
282284

283285
suspend fun checkPaymentsTimeout() {
284286
while (isActive) {
285-
delay(30.seconds)
287+
delay(Duration.seconds(30))
286288
input.send(CheckPaymentsTimeout)
287289
}
288290
}

0 commit comments

Comments
 (0)