Skip to content

Commit

Permalink
add MsgP8eMemorializeContractRequest message-based fee to calc (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
celloman authored Feb 15, 2022
1 parent d27b71e commit 163a5f4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ChaincodeProperties {
@NotNull var gasMultiplier: Double = 1.0
@NotNull var maxGasMultiplierPerDay: Int = 1000
@NotNull var blockHeightTimeoutInterval: Int = 20
@NotNull var memorializeMsgFeeNanoHash: Long = 10
}

@ConfigurationProperties(prefix = "elasticsearch")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class ChaincodeInvokeService(
scopeLockHeights.remove(it.key) // we only want to log this error once per scope
}
}

private val MEMORIALIZE_MESSAGE_TYPEURL = MsgP8eMemorializeContractRequest.getDefaultInstance().toAny().typeUrl
}

private val objectMapper = ObjectMapper().configureProvenance()
Expand Down Expand Up @@ -464,6 +466,9 @@ class ChaincodeInvokeService(
log.info("skipping gasMultiplier due to daily limit")
}

estimate.messageFeesNanoHash = body.messagesList.count { it.typeUrl == MEMORIALIZE_MESSAGE_TYPEURL } * chaincodeProperties.memorializeMsgFeeNanoHash
log.info("Adding additional message fee of ${estimate.messageFeesNanoHash}nhash (${estimate.messageFeesNanoHash / 1000000000L}hash) for ${body.messagesList.size} messages")

return provenanceGrpc.batchTx(body, accountNumber, sequenceNumber, estimate)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,12 @@ data class GasEstimate(val estimate: Long, val feeAdjustment: Double? = DEFAULT_

private val adjustment = feeAdjustment ?: DEFAULT_FEE_ADJUSTMENT
private var gasMultiplier = 1.0
var messageFeesNanoHash = 0L

fun setGasMultiplier(multiplier: Double) { gasMultiplier = multiplier }

val limit
get() = (estimate * adjustment * gasMultiplier).roundUp()
val fees
get() = (limit * DEFAULT_GAS_PRICE).roundUp()
get() = (limit * DEFAULT_GAS_PRICE + messageFeesNanoHash).roundUp()
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ chaincode.txBatchSize=${CHAINCODE_TX_BATCH_SIZE:25}
chaincode.gasMultiplier=${CHAINCODE_GAS_MULTIPLIER:1.0}
chaincode.maxGasMultiplierPerDay=${CHAINCODE_MAX_GAS_MULTIPLIER_PER_DAY:1000}
chaincode.blockHeightTimeoutInterval=${CHAINCODE_BLOCK_HEIGHT_TIMEOUT_INTERVAL:20}
chaincode.memorializeMsgFeeNanoHash=${CHAINCODE_MEMORIALIZE_MSG_FEE_NANO_HASH:10000000000}

# Elasticsearch
elasticsearch.host=${ELASTICSEARCH_HOST}
Expand Down

0 comments on commit 163a5f4

Please sign in to comment.