Skip to content
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

Support RPC 0.6.0 #358

Merged
merged 103 commits into from
Dec 13, 2023
Merged

Support RPC 0.6.0 #358

merged 103 commits into from
Dec 13, 2023

Conversation

DelevoXDG
Copy link
Contributor

@DelevoXDG DelevoXDG commented Nov 22, 2023

Describe your changes

  • Bump devnet to version w/ rpc 0.6.0 support
    • sncast doesn't have support for RPC 0.6.0, temporarily use don't create new account and fetch it from a file instead
    • temporarily transfer STRK from predeployed account; should instead mint when it's possible on devnet
      instead of deploying one
  • Add v3 Transaction and TransactionPayload dataclasses
    • Rename versionless Transaction and TransactionPayload dataclasses (add V1):
      • InvokeTransactionPayload -> InvokeTransactionV1Payload
      • DeployAccountTransactionPayload -> DeployAccountTransactionV1Payload
  • Account and StandardAccount: add methods to support v3 transactions
    • Add new Params.kt
      • move (v1) ExecutionParams to it
      • Add v3 Params:
        • Base: ParamsV3
        • Invoke: ExecutionParamsV3
        • Declare: DeclareParamsV3
        • DeployAccount: DeployAccountParamsV3
    • sign variations for signing v3 invoke transactions
    • signDeployAccount variations for signing v3 deploy account transactions
    • signDeclare variations for signing v3 declare transactions
    • executeV3 for singing and sending v3 invoke transactions
    • estimateFeeV3 for estimating fee of v3 transactions
    • Note: it's planned to refactor the Account interface to make methods more coherent
  • Provider and StandardProvider:
    • Support passing simulation flags when estimating fee; Add SimulationFlagForEstimateFee
      • Use SKIP_VALIDATE by default
    • Support v3 payloads
  • Push members down from interfaces to implementation (Account, Provider)
  • TransactionHashCalculator
    • support v3 hash calculations
    • Change function names to include v1 in versionless funcitons
  • Add several workarounds to support 0.6.0 nodes that deviate from the spec (Remove node-specific workarounds #344)
  • Add new NumAsHexBase types: Uint64, Uint128
    • Refactor NumAsHexSerializer, FeltSerializer, add Uint128Serializer and Uint64Serializer
  • Make Uint256 conform to NumAsHex base
  • Simplify TransactionPayloadSerilalizer
  • Move fee utils to EstimateFeeResponse
  • ResourcePrice: priceInStark -> princeInFri
  • Add PriceUnit
  • Add ResourceBounds and ResourceBoundsMapping
  • ExecutionResources: all fields changed from NumAsHex to int; add segmentArenaApplications
  • FunctionInvocation (trace API): add execution_resources
  • Add DAMode
  • Update tests
  • Bump version to 0.9.0

Linked issues

Closes #356

Breaking changes

  • This issue contains breaking changes

@DelevoXDG DelevoXDG added this to the 0.9.0 milestone Nov 22, 2023
@DelevoXDG DelevoXDG self-assigned this Nov 22, 2023
@@ -33,6 +33,15 @@ enum class TransactionType(val txPrefix: Felt) {
L1_HANDLER(Felt.fromHex("0x6c315f68616e646c6572")), // encodeShortString('l1_handler')
}

@Serializable
enum class DAMode {
Copy link
Contributor Author

@DelevoXDG DelevoXDG Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's DA_MODE in the spec, but naming this DAMode seems very non-java, so maybe we should deviate from the spec a bit and rename it to DataAvailabilityMode?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave it as is

@DelevoXDG
Copy link
Contributor Author

Blocked by #326

@DelevoXDG DelevoXDG changed the title [WIP] Support RPC 0.6.0 Support RPC 0.6.0 Dec 13, 2023
@DelevoXDG DelevoXDG marked this pull request as ready for review December 13, 2023 13:47
Comment on lines +62 to +83
fun toMaxFee(overhead: Double = 0.5): Felt {
return addOverhead(overallFee.value, overhead).toFelt
}

fun toResourceBounds(
amountOverhead: Double = 0.1,
unitPriceOverhead: Double = 0.5,
): ResourceBoundsMapping {
val maxAmount = addOverhead(gasConsumed.value, amountOverhead).toUint64
val maxPricePerUnit = addOverhead(gasPrice.value, unitPriceOverhead).toUint128

// As of Starknet 0.13.0, the L2 gas is not supported
// Because of this, the L2 gas values are hardcoded to 0
return ResourceBoundsMapping(
l1Gas = ResourceBounds(maxAmount = maxAmount, maxPricePerUnit = maxPricePerUnit),
l2Gas = ResourceBounds(maxAmount = Uint64.ZERO, maxPricePerUnit = Uint128.ZERO),
)
}
private fun addOverhead(value: BigInteger, overhead: Double): BigInteger {
val multiplier = ((1 + overhead) * 100).roundToInt().toBigInteger()
return value.multiply(multiplier).divide(BigInteger.valueOf(100))
}
Copy link
Contributor Author

@DelevoXDG DelevoXDG Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically don't define several methods inside files with just dataclasses.
However, I think the way it was done (just plain function), is sub-optimal, since we shouldn't really get max fee or resource bounds without having estimate response.

We could:

  • move this particular response to separate file
  • define those methods as extensions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make an issue and think about it at later date

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, #375

@DelevoXDG DelevoXDG requested a review from THenry14 December 13, 2023 14:22
Comment on lines +449 to +456
companion object {
@field:JvmField
val ZERO = ResourceBounds(Uint64.ZERO, Uint128.ZERO)
}

fun toMaxFee(): Felt {
return maxAmount.value.multiply(maxPricePerUnit.value).toFelt
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar as above, convenience methods that could be changed to extensions, moved to another file or left as is.

DelevoXDG and others added 2 commits December 13, 2023 15:41
Co-authored-by: Wojciech Szymczyk <[email protected]>
Co-authored-by: Wojciech Szymczyk <[email protected]>
@DelevoXDG DelevoXDG requested a review from THenry14 December 13, 2023 15:48
Copy link
Member

@THenry14 THenry14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll fix some of design issues etc in consecutive PRs

@DelevoXDG DelevoXDG merged commit ec4ccb2 into main Dec 13, 2023
2 checks passed
@DelevoXDG DelevoXDG deleted the feat/356-support-rpc-0.6.0 branch February 5, 2024 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Starknet 0.13.0
2 participants