-
Notifications
You must be signed in to change notification settings - Fork 5
Offline evaluator to use in NewmChainService
#701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| .from(scalaSeq) | ||
| } | ||
|
|
||
| private fun hexToByteArray(hex: String): ByteArray = hex.chunked(2).map { it.toInt(16).toByte() }.toByteArray() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove helper function in favor of String.hexToByteArray() extension function in io.newm.chain.util.CardanoKtx
| * @param utxos All UTxOs needed for evaluation (source + reference inputs) | ||
| * @param config The configuration object containing network information | ||
| */ | ||
| fun evaluateTx( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do the plutus cost models come into play here? Are they hardcoded somewhere in CardanoInfo? If so, this seems brittle and we should get the plutus cost model from the blockchain instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, the CostModels are in ProtocolParameters, which are in CardanoInfo.
The evaluator itself needs only the slot config, the major protocol version and the cost models, so if the following signature is fine:
fun evaluateTx(
cborBytes: ByteArray,
utxos: Set<Utxo>,
slotConfig: SlotConfig,
costModels: CostModels
)Both of these types seem to be very straightforward to map to Scalus ledger types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this looks fine, I'd appreciate a hint of where these types are described in newm, and I'll ping you when I fix the function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sae3023 In TransactionBuilder.kt, it is constructed with a protocolParametersResult. Inside this structure is the plutusCostModels. All of this data currently comes from Ogmios through Kogmios which is our Ogmios gRPC wrapper in Kotlin. We're not trying to entirely eliminate Ogmios with this fix, just utilize Scalus where it makes sense for efficiency.
|
@AndrewWestberg PTAL I did the cost models, but I'm not entirely sure about the casts, doesn't look like it's the best way to do it, but I've sort of threw it together quickly. I'll take another look in the morning too. |
| RedeemerTag.valueOf("Cert") -> "certificate" | ||
| RedeemerTag.valueOf("Reward") -> "withdrawal" | ||
| RedeemerTag.valueOf("Voting") -> "vote" | ||
| RedeemerTag.valueOf("Proposing") -> "propose" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is RedeemerTag an enum and RedeemerTag.valueOf() returns the value? If so, we should use the enum values directly here in the left side. Example:
RedeemerTag.Spend -> "spend"
There's a FIXME in
NewmChainServiceabout using something that would allow you to omit Ogmois.Scalus contains an offline Plutus script evaluator, and this commit in my fork adds a tiny integration of the evaluator to newm-server.
Glad to ask any questions or to help with further integration.