From f21d0c896dc59804a25ca9a7f9c1d7d2bb70e0e4 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 2 Dec 2024 10:06:05 -0800 Subject: [PATCH] push up all the logging --- .../java/org/xmtp/android/library/Client.kt | 22 ++++++++++++++++++- .../android/library/messages/PrivateKey.kt | 9 +++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/org/xmtp/android/library/Client.kt b/library/src/main/java/org/xmtp/android/library/Client.kt index d9e3d94b5..0b4069b26 100644 --- a/library/src/main/java/org/xmtp/android/library/Client.kt +++ b/library/src/main/java/org/xmtp/android/library/Client.kt @@ -63,12 +63,15 @@ class Client() { } suspend fun getOrCreateInboxId(environment: ClientOptions.Api, address: String): String { + val start = Date() var inboxId = getInboxIdForAddress( logger = XMTPLogger(), host = environment.env.getUrl(), isSecure = environment.isSecure, accountAddress = address.lowercase() ) + val end = Date() + Log.d("PERF", "Get inboxId in ${(end.time - start.time) / 1000.0}s") if (inboxId.isNullOrBlank()) { inboxId = generateInboxId(address.lowercase(), 0.toULong()) } @@ -166,6 +169,7 @@ class Client() { ): Pair { val alias = "xmtp-${options.api.env}-$inboxId" + val start1 = Date() val mlsDbDirectory = options.dbDirectory val directoryFile = if (mlsDbDirectory != null) { File(mlsDbDirectory) @@ -174,7 +178,10 @@ class Client() { } directoryFile.mkdir() dbPath = directoryFile.absolutePath + "/$alias.db3" + val end1 = Date() + Log.d("PERF", "Create database ${(end1.time - start1.time) / 1000.0}s") + val start = Date() val ffiClient = createClient( logger = logger, host = options.api.env.getUrl(), @@ -187,18 +194,25 @@ class Client() { legacySignedPrivateKeyProto = null, historySyncUrl = options.historySyncUrl ) + val end = Date() + Log.d("PERF", "Create ffi client in ${(end.time - start.time) / 1000.0}s") options.preAuthenticateToInboxCallback?.let { runBlocking { it.invoke() } } + val start2 = Date() ffiClient.signatureRequest()?.let { signatureRequest -> signingKey?.let { handleSignature(signatureRequest, it) } ?: throw XMTPException("No signer passed but signer was required.") + val start3 = Date() ffiClient.registerIdentity(signatureRequest) + val end3 = Date() + Log.d("PERF", "Register identity ${(end3.time - start3.time) / 1000.0}s") } - + val end2 = Date() + Log.d("PERF", "Handle signatures ${(end2.time - start2.time) / 1000.0}s") return Pair(ffiClient, dbPath) } @@ -235,9 +249,15 @@ class Client() { signingKey.blockNumber?.toULong() ) } else { + val start1 = Date() signingKey.sign(signatureRequest.signatureText())?.let { + val start3 = Date() signatureRequest.addEcdsaSignature(it.rawData) + val end3 = Date() + Log.d("PERF", "Add signature ${(end3.time - start3.time) / 1000.0}s") } + val end1 = Date() + Log.d("PERF", "Do signing ${(end1.time - start1.time) / 1000.0}s") } } diff --git a/library/src/main/java/org/xmtp/android/library/messages/PrivateKey.kt b/library/src/main/java/org/xmtp/android/library/messages/PrivateKey.kt index 7f251d33b..39d3f9ac5 100644 --- a/library/src/main/java/org/xmtp/android/library/messages/PrivateKey.kt +++ b/library/src/main/java/org/xmtp/android/library/messages/PrivateKey.kt @@ -1,5 +1,6 @@ package org.xmtp.android.library.messages +import android.util.Log import com.google.protobuf.kotlin.toByteString import org.web3j.crypto.ECKeyPair import org.web3j.crypto.Sign @@ -63,6 +64,7 @@ class PrivateKeyBuilder : SigningKey { } override suspend fun sign(data: ByteArray): SignatureOuterClass.Signature { + val start = Date() val signatureData = Sign.signMessage( data, @@ -71,12 +73,17 @@ class PrivateKeyBuilder : SigningKey { ) val signatureKey = KeyUtil.getSignatureBytes(signatureData) - return SignatureOuterClass.Signature.newBuilder().also { + val sign = SignatureOuterClass.Signature.newBuilder().also { it.ecdsaCompact = it.ecdsaCompact.toBuilder().also { builder -> builder.bytes = signatureKey.take(64).toByteArray().toByteString() builder.recovery = signatureKey[64].toInt() }.build() }.build() + val end = Date() + val time1 = end.time - start.time + Log.d("PERF", "Did the signature ${time1 / 1000.0}s") + + return sign } override suspend fun sign(message: String): SignatureOuterClass.Signature {