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

formatting with new ktlint #312

Merged
merged 1 commit into from
Sep 29, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ continuation_indent_size = 4
ij_kotlin_name_count_to_use_star_import = 2147483647
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
ij_kotlin_packages_to_use_import_on_demand = dummy.**
ij_groovy_names_count_to_use_import_on_demand = 2147483647
ij_groovy_names_count_to_use_import_on_demand = 2147483647
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_allow_trailing_comma = true
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
repo_token: ${{ secrets.GITHUB_TOKEN }}
- name: Check
run: make test
env:
CI: true

- name: Upload Coverage Report
uses: codecov/codecov-action@v1
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jib: build-foundation

jib-docker: build-foundation
./gradlew jibDockerBuild -Pdocker=drpcorg

clean:
./gradlew clean;
cd foundation && ../gradlew clean
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,5 @@ jib = { id = "com.google.cloud.tools.jib", version = "2.7.1" }
spring = { id = "org.springframework.boot", version = "2.6.0" }
git = { id = "com.palantir.git-version", version = "0.12.3" }
protobuf = { id = "com.google.protobuf", version = "0.9.1" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "10.2.0" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "11.6.0" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
2 changes: 1 addition & 1 deletion src/main/kotlin/io/emeraldpay/dshackle/ChainValue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import kotlin.concurrent.withLock
* Keeps a lazily created value associated with a Chain
*/
class ChainValue<V>(
private val factory: (chain: Chain) -> V
private val factory: (chain: Chain) -> V,
) {

private val values = EnumMap<Chain, V>(Chain::class.java)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/io/emeraldpay/dshackle/FileResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package io.emeraldpay.dshackle
import java.io.File

open class FileResolver(
private val baseDir: File
private val baseDir: File,
) {

companion object {
Expand Down
11 changes: 6 additions & 5 deletions src/main/kotlin/io/emeraldpay/dshackle/GrpcServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ open class GrpcServer(
private val tlsSetup: TlsSetup,
private val accessHandler: AccessHandlerGrpc,
private val grpcServerBraveInterceptor: ServerInterceptor,
private val authInterceptor: AuthInterceptor
private val authInterceptor: AuthInterceptor,
) {
@Value("\${spring.application.max-metadata-size}")
private var maxMetadataSize: Int = Defaults.maxMetadataSize
Expand All @@ -58,7 +58,7 @@ open class GrpcServer(
override fun <ReqT : Any, RespT : Any> interceptCall(
call: ServerCall<ReqT, RespT>,
headers: io.grpc.Metadata,
next: ServerCallHandler<ReqT, RespT>
next: ServerCallHandler<ReqT, RespT>,
): ServerCall.Listener<ReqT> {
call.setCompression(Codec.Gzip().messageEncoding)
return next.startCall(call, headers)
Expand Down Expand Up @@ -102,15 +102,16 @@ open class GrpcServer(
val pool = Executors.newFixedThreadPool(20, CustomizableThreadFactory("fixed-grpc-"))

serverBuilder.executor(
if (mainConfig.monitoring.enableExtended)
if (mainConfig.monitoring.enableExtended) {
ExecutorServiceMetrics.monitor(
Metrics.globalRegistry,
pool,
"fixed-grpc-executor",
Tag.of("reactor_scheduler_id", "_")
Tag.of("reactor_scheduler_id", "_"),
)
else
} else {
pool
},
)

val server = serverBuilder.build()
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/io/emeraldpay/dshackle/HeapDumpCreator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class HeapDumpCreator {
val bean = ManagementFactory.newPlatformMXBeanProxy(
ManagementFactory.getPlatformMBeanServer(),
"com.sun.management:type=HotSpotDiagnostic",
HotSpotDiagnosticMXBean::class.java
HotSpotDiagnosticMXBean::class.java,
)
bean.setVMOption("HeapDumpOnOutOfMemoryError", "true")
bean.setVMOption("HeapDumpPath", fileName)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/io/emeraldpay/dshackle/ProxyStarter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ProxyStarter(
@Autowired private val tlsSetup: TlsSetup,
@Autowired private val accessHandlerHttp: AccessHandlerHttp,
// depend on Monitoring, declared here just to ensure it's properly initialized before the Proxy
@Autowired private val monitoringSetup: MonitoringSetup
@Autowired private val monitoringSetup: MonitoringSetup,
) {

companion object {
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/io/emeraldpay/dshackle/TlsSetup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import java.security.cert.CertificateFactory

@Service
open class TlsSetup(
@Autowired val fileResolver: FileResolver
@Autowired val fileResolver: FileResolver,
) {

companion object {
Expand Down Expand Up @@ -70,12 +70,12 @@ open class TlsSetup(
val sslContextBuilder = if (grpc) {
GrpcSslContexts.forServer(
fileResolver.resolve(config.certificate!!),
fileResolver.resolve(config.key!!)
fileResolver.resolve(config.key!!),
)
} else {
SslContextBuilder.forServer(
fileResolver.resolve(config.certificate!!),
fileResolver.resolve(config.key!!)
fileResolver.resolve(config.key!!),
)
}
if (config.clientCAs.isNotEmpty()) {
Expand All @@ -89,7 +89,7 @@ open class TlsSetup(
file.inputStream().use {
cf.generateCertificate(it) as java.security.cert.X509Certificate
}
}
},
)
if (config.clientRequire != null && config.clientRequire!!) {
sslContextBuilder.clientAuth(ClientAuth.REQUIRE)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/io/emeraldpay/dshackle/auth/AuthContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ class AuthContext {
data class TokenWrapper(
val token: String,
val issuedAt: Instant,
val sessionId: String
val sessionId: String,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ const val REFLECT_METHOD_NAME = "grpc.reflection.v1alpha.ServerReflection/Server

@Component
class AuthInterceptor(
private val authContext: AuthContext
private val authContext: AuthContext,
) : ServerInterceptor {
private val specialMethods = setOf(AUTH_METHOD_NAME, REFLECT_METHOD_NAME)

override fun <ReqT : Any, RespT : Any> interceptCall(
call: ServerCall<ReqT, RespT>,
headers: Metadata,
next: ServerCallHandler<ReqT, RespT>
next: ServerCallHandler<ReqT, RespT>,
): ServerCall.Listener<ReqT> {
val sessionId = headers.get(
Metadata.Key.of(SESSION_ID, ASCII_STRING_MARSHALLER)
Metadata.Key.of(SESSION_ID, ASCII_STRING_MARSHALLER),
)
val isOrdinaryMethod = !specialMethods.contains(call.methodDescriptor.fullMethodName)

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/io/emeraldpay/dshackle/auth/AuthRpc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import reactor.core.scheduler.Scheduler
@Service
class AuthRpc(
private val authService: AuthService,
private val authScheduler: Scheduler
private val authScheduler: Scheduler,
) : ReactorAuthGrpc.AuthImplBase() {

companion object {
Expand All @@ -39,7 +39,7 @@ class AuthRpc(
Mono.error(
Status.INTERNAL
.withDescription(message)
.asException()
.asException(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const val SESSION_ID = "sessionId"
const val VERSION = "version"

enum class AuthVersion {
V1;
V1,
;

companion object {
fun getVersion(version: String) = values().find { it.name == version }
Expand All @@ -32,7 +33,7 @@ enum class AuthVersion {
}

abstract class AuthProcessor(
private val authorizationConfig: AuthorizationConfig
private val authorizationConfig: AuthorizationConfig,
) {

open fun process(keys: KeyReader.Keys, token: String): AuthContext.TokenWrapper {
Expand Down Expand Up @@ -60,7 +61,7 @@ abstract class AuthProcessor(

@Component
open class AuthProcessorV1(
authorizationConfig: AuthorizationConfig
authorizationConfig: AuthorizationConfig,
) : AuthProcessor(authorizationConfig) {

override fun processInternal(privateKey: PrivateKey): AuthContext.TokenWrapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.springframework.stereotype.Component

@Component
class AuthProcessorResolver(
private val authProcessorV1: AuthProcessor
private val authProcessorV1: AuthProcessor,
) {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AuthService(
private val authorizationConfig: AuthorizationConfig,
private val rsaKeyReader: KeyReader,
private val authProcessorResolver: AuthProcessorResolver,
private val authContext: AuthContext
private val authContext: AuthContext,
) {

fun authenticate(token: String): String {
Expand All @@ -24,7 +24,7 @@ class AuthService(

val keys = rsaKeyReader.getKeyPair(
authorizationConfig.serverConfig.providerPrivateKeyPath,
authorizationConfig.serverConfig.externalPublicKeyPath
authorizationConfig.serverConfig.externalPublicKeyPath,
)
val decodedJwt = JWT.decode(token)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ interface KeyReader {

data class Keys(
val providerPrivateKey: PrivateKey,
val externalPublicKey: PublicKey
val externalPublicKey: PublicKey,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RsaKeyReader : KeyReader {

return KeyReader.Keys(
privateKey,
pubKey
pubKey,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import reactor.core.publisher.Mono
*/
open class BlockByHeight(
private val heights: Reader<Long, BlockId>,
private val blocks: Reader<BlockId, BlockContainer>
private val blocks: Reader<BlockId, BlockContainer>,
) : Reader<Long, BlockContainer> {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import io.emeraldpay.dshackle.reader.Reader
import reactor.core.publisher.Mono

open class BlocksMemCache(
maxSize: Int = 64
maxSize: Int = 64,
) : Reader<BlockId, BlockContainer> {

private val mapping = Caffeine.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import java.time.Instant
*/
class BlocksRedisCache(
redis: RedisReactiveCommands<String, ByteArray>,
chain: Chain
chain: Chain,
) : Reader<BlockId, BlockContainer>,
OnBlockRedisCache<BlockContainer>(redis, chain, CachesProto.ValueContainer.ValueType.BLOCK) {

Expand Down Expand Up @@ -69,7 +69,7 @@ class BlocksRedisCache(
BlockId.from(meta.parentHash.toByteArray()),
meta.txHashesList.map {
TxId(it.toByteArray())
}
},
)
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/io/emeraldpay/dshackle/cache/Caches.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ open class Caches(
private val redisTxsByHash: TxRedisCache?,
private val redisReceipts: ReceiptRedisCache?,
private val redisHeightByHashCache: HeightByHashRedisCache?,
private val cacheEnabled: Boolean
private val cacheEnabled: Boolean,
) {

companion object {
Expand Down Expand Up @@ -153,7 +153,7 @@ open class Caches(
Flux.fromIterable(transactions)
.doOnNext { memTxsByHash.add(it) }
.flatMap { redisTxsByHash.add(it, block) }
.then()
.then(),
)
}
}
Expand Down Expand Up @@ -224,7 +224,7 @@ open class Caches(
/**
* Data requested by client
*/
REQUESTED
REQUESTED,
}

class Builder {
Expand Down Expand Up @@ -298,7 +298,7 @@ open class Caches(
}
return Caches(
blocksByHash!!, blocksByHeight!!, txsByHash!!, receipts!!,
redisBlocksByHash, redisTxsByHash, redisReceiptCache, redisHeightByHashCache, cacheEnabled
redisBlocksByHash, redisTxsByHash, redisReceiptCache, redisHeightByHashCache, cacheEnabled,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import kotlin.system.exitProcess

@Repository
open class CachesFactory(
@Autowired private val cacheConfig: CacheConfig
@Autowired private val cacheConfig: CacheConfig,
) {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import reactor.core.publisher.Mono
class HeightByHashAdding(
private val mem: Reader<BlockId, Long>,
private val redis: HeightByHashCache?,
private val upstreamReader: Reader<BlockId, BlockContainer>
private val upstreamReader: Reader<BlockId, BlockContainer>,
) : Reader<BlockId, Long> {

companion object {
Expand All @@ -50,12 +50,12 @@ class HeightByHashAdding(
return mem.read(key)
.switchIfEmpty(
Mono.just(key)
.flatMap { redis.read(it) }
.flatMap { redis.read(it) },
)
.switchIfEmpty(
Mono.just(key)
.flatMap { upstreamReader.read(it) }
.flatMap { redis.add(it).then(Mono.just(it.height)) }
.flatMap { redis.add(it).then(Mono.just(it.height)) },
)
}
}
Expand All @@ -66,7 +66,7 @@ class HeightByHashAdding(
.switchIfEmpty(
Mono.just(key)
.flatMap { upstreamReader.read(it) }
.map { it.height }
.map { it.height },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory
import reactor.core.publisher.Mono

open class HeightByHashMemCache(
maxSize: Int = 256
maxSize: Int = 256,
) : Reader<BlockId, Long> {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import java.util.concurrent.TimeUnit
*/
class HeightByHashRedisCache(
private val redis: RedisReactiveCommands<String, ByteArray>,
private val chain: Chain
private val chain: Chain,
) : Reader<BlockId, Long>, HeightByHashCache {

companion object {
Expand Down
Loading
Loading