Skip to content

Commit

Permalink
configurable batch size for contract/scope spec txs (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
celloman authored Apr 27, 2022
1 parent 0e44d5a commit 54dc7cb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,13 @@ class ProvenanceGrpcService(
).scopeSpecification.specification
}

fun Collection<Message>.toTxBody(): TxBody = TxBody.newBuilder()
fun Collection<Message>.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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions p8e-api/src/main/resources/application-local.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 54dc7cb

Please sign in to comment.