Skip to content

Commit

Permalink
make provenance query timeout configurable (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
celloman authored Dec 5, 2023
1 parent da7ad65 commit 5fb9a6c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/io/provenance/p8e/plugin/Dsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ open class P8eLocationExtension {
var signingPrivateKey: String? = ""
var osUrl: String? = ""
var provenanceUrl: String? = ""
var provenanceQueryTimeoutSeconds: String = "10"
var audience: Map<String, P8ePartyExtension> = emptyMap()
var chainId: String? = ""
var mainNet: Boolean = chainId == "pio-mainnet-1"
Expand Down
35 changes: 3 additions & 32 deletions src/main/kotlin/io/provenance/p8e/plugin/ProvenanceClient.kt
Original file line number Diff line number Diff line change
@@ -1,54 +1,24 @@
package io.provenance.p8e.plugin

import com.fasterxml.jackson.annotation.JsonAlias
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.JsonDeserializer
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.google.protobuf.Any
import com.google.protobuf.ByteString
import com.google.protobuf.Message
import cosmos.base.v1beta1.CoinOuterClass
import cosmos.crypto.secp256k1.Keys
import cosmos.tx.signing.v1beta1.Signing
import cosmos.tx.v1beta1.ServiceOuterClass.BroadcastMode
import cosmos.tx.v1beta1.TxOuterClass.AuthInfo
import cosmos.tx.v1beta1.TxOuterClass.Fee
import cosmos.tx.v1beta1.TxOuterClass.ModeInfo
import cosmos.tx.v1beta1.TxOuterClass.SignDoc
import cosmos.tx.v1beta1.TxOuterClass.SignerInfo
import cosmos.tx.v1beta1.TxOuterClass.Tx
import cosmos.tx.v1beta1.TxOuterClass.TxBody
import io.grpc.ManagedChannel
import io.provenance.client.common.extensions.toCoin
import io.provenance.client.common.gas.prices.cachedGasPrice
import io.provenance.client.common.gas.prices.constGasPrice
import io.provenance.client.grpc.BaseReq
import io.provenance.client.grpc.BaseReqSigner
import io.provenance.client.grpc.GasEstimationMethod
import io.provenance.client.grpc.PbClient
import io.provenance.client.grpc.floatingGasPrices
import io.provenance.client.grpc.nodeFloorGasPrice
import io.provenance.metadata.v1.ContractSpecificationRequest
import io.provenance.metadata.v1.ContractSpecificationResponse
import io.provenance.metadata.v1.ScopeSpecificationRequest
import io.provenance.metadata.v1.ScopeSpecificationResponse
import io.provenance.scope.objectstore.util.sha256
import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey
import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey
import org.kethereum.crypto.CURVE
import org.kethereum.crypto.api.ec.ECDSASignature
import org.kethereum.crypto.impl.ec.EllipticCurveSigner
import org.slf4j.Logger
import java.io.IOException
import java.math.BigInteger
import java.net.URI
import java.security.KeyPair
import java.util.concurrent.TimeUnit
import kotlin.math.ceil
import kotlin.time.Duration.Companion.hours

fun Collection<Message>.toTxBody(): TxBody = TxBody.newBuilder()
.addAllMessages(this.map { it.toAny() })
Expand All @@ -68,12 +38,13 @@ class ProvenanceClient(channel: ManagedChannel, val logger: Logger, val location
),
channel = channel
)
private val queryTimeoutSeconds = location.provenanceQueryTimeoutSeconds.toLong()

fun scopeSpecification(request: ScopeSpecificationRequest): ScopeSpecificationResponse =
inner.metadataClient.withDeadlineAfter(10, TimeUnit.SECONDS).scopeSpecification(request)
inner.metadataClient.withDeadlineAfter(queryTimeoutSeconds, TimeUnit.SECONDS).scopeSpecification(request)

fun contractSpecification(request: ContractSpecificationRequest): ContractSpecificationResponse =
inner.metadataClient.withDeadlineAfter(10, TimeUnit.SECONDS).contractSpecification(request)
inner.metadataClient.withDeadlineAfter(queryTimeoutSeconds, TimeUnit.SECONDS).contractSpecification(request)

private class SequenceMismatch(message: String): Exception(message)
fun writeTx(signer: BaseReqSigner, txBody: TxBody) {
Expand Down

0 comments on commit 5fb9a6c

Please sign in to comment.