diff --git a/p8e-api/src/main/kotlin/io/provenance/engine/config/Properties.kt b/p8e-api/src/main/kotlin/io/provenance/engine/config/Properties.kt index f3ca043..d9dbb6c 100644 --- a/p8e-api/src/main/kotlin/io/provenance/engine/config/Properties.kt +++ b/p8e-api/src/main/kotlin/io/provenance/engine/config/Properties.kt @@ -54,6 +54,7 @@ class ChaincodeProperties { @NotNull var mainNet: Boolean = false @NotNull var emptyIterationBackoffMS: Int = 1_000 @NotNull var txBatchSize: Int = 25 + @NotNull var specTxBatchSize: Int = 10 @NotNull var gasMultiplier: Double = 1.0 @NotNull var maxGasMultiplierPerDay: Int = 1000 @NotNull var blockHeightTimeoutInterval: Int = 20 diff --git a/p8e-api/src/main/kotlin/io/provenance/engine/service/ChaincodeInvokeService.kt b/p8e-api/src/main/kotlin/io/provenance/engine/service/ChaincodeInvokeService.kt index 4284416..c96acae 100644 --- a/p8e-api/src/main/kotlin/io/provenance/engine/service/ChaincodeInvokeService.kt +++ b/p8e-api/src/main/kotlin/io/provenance/engine/service/ChaincodeInvokeService.kt @@ -212,9 +212,7 @@ class ChaincodeInvokeService( val txBody = batch.map { it.attempts++ it.request - }.toTxBody().toBuilder() - .setTimeoutHeight(currentBlockHeight + chaincodeProperties.blockHeightTimeoutInterval) - .build() + }.toTxBody(currentBlockHeight + chaincodeProperties.blockHeightTimeoutInterval) // Send the transactions to the blockchain. val resp = synchronized(provenanceGrpc) { batchTx(txBody) } @@ -433,15 +431,18 @@ class ChaincodeInvokeService( .addAllSigners(owners) .build() } - val txBody = contractSpecTx.plus(scopeSpecTx).toTxBody() + contractSpecTx.plus(scopeSpecTx).chunked(chaincodeProperties.specTxBatchSize).forEach { messages -> + log.info("sending batch of ${messages.size} contract spec messages") + val txBody = messages.toTxBody(provenanceGrpc.getLatestBlock().block.header.height + chaincodeProperties.blockHeightTimeoutInterval) + + synchronized(provenanceGrpc) { + batchTx(txBody, applyMultiplier = false).also { + if (it.txResponse.code != 0) { + throw Exception("Error adding contract spec: ${it.txResponse.rawLog}") + } - synchronized(provenanceGrpc) { - batchTx(txBody, applyMultiplier = false).also { - if (it.txResponse.code != 0) { - throw Exception("Error adding contract spec: ${it.txResponse.rawLog}") + log.info("contract spec batch made it to mempool with txhash = ${it.txResponse.txhash}") } - - log.info("batch made it to mempool with txhash = ${it.txResponse.txhash}") } } } catch(e: Throwable) { diff --git a/p8e-api/src/main/kotlin/io/provenance/engine/service/ProvenanceGrpcService.kt b/p8e-api/src/main/kotlin/io/provenance/engine/service/ProvenanceGrpcService.kt index bd011aa..f19a017 100644 --- a/p8e-api/src/main/kotlin/io/provenance/engine/service/ProvenanceGrpcService.kt +++ b/p8e-api/src/main/kotlin/io/provenance/engine/service/ProvenanceGrpcService.kt @@ -207,8 +207,13 @@ class ProvenanceGrpcService( ).scopeSpecification.specification } -fun Collection.toTxBody(): TxBody = TxBody.newBuilder() +fun Collection.toTxBody(timeoutHeight: Long? = null): TxBody = TxBody.newBuilder() .addAllMessages(map { it.toAny() }) + .also { + if (timeoutHeight != null) { + it.setTimeoutHeight(timeoutHeight) + } + } .build() fun Message.toTxBody(): TxBody = listOf(this).toTxBody() diff --git a/p8e-api/src/main/resources/application-container.properties b/p8e-api/src/main/resources/application-container.properties index 32aa8f8..c80b483 100644 --- a/p8e-api/src/main/resources/application-container.properties +++ b/p8e-api/src/main/resources/application-container.properties @@ -44,6 +44,7 @@ chaincode.chainId=${CHAINCODE_CHAIN_ID} chaincode.mnemonic=${CHAINCODE_MNEMONIC} chaincode.emptyIterationBackoffMS=${CHAINCODE_EMPTY_ITERATION_BACKOFF:750} chaincode.txBatchSize=${CHAINCODE_TX_BATCH_SIZE:25} +chaincode.specTxBatchSize=${CHAINCODE_SPEC_TX_BATCH_SIZE:10} chaincode.gasMultiplier=${CHAINCODE_GAS_MULTIPLIER:1.0} chaincode.maxGasMultiplierPerDay=${CHAINCODE_MAX_GAS_MULTIPLIER_PER_DAY:1000} chaincode.blockHeightTimeoutInterval=${CHAINCODE_BLOCK_HEIGHT_TIMEOUT_INTERVAL:20} diff --git a/p8e-api/src/main/resources/application-local.properties b/p8e-api/src/main/resources/application-local.properties index 34818ed..ea3c348 100644 --- a/p8e-api/src/main/resources/application-local.properties +++ b/p8e-api/src/main/resources/application-local.properties @@ -39,6 +39,7 @@ chaincode.chainId=chain-local chaincode.mnemonic=${CHAINCODE_MNEMONIC} chaincode.emptyIterationBackoffMS=750 chaincode.txBatchSize=25 +chaincode.specTxBatchSize=25 # Elasticsearch elasticsearch.host=localhost