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

fix: Use INSUFFICIENT_RESOURCES_FOR_VALIDATE instead of INSUFFICIENT_MAX_FEE in v8 #2457

Merged
merged 5 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions clients/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ import (
)

var (
InvalidContractClass ErrorCode = "StarknetErrorCode.INVALID_CONTRACT_CLASS"
UndeclaredClass ErrorCode = "StarknetErrorCode.UNDECLARED_CLASS"
ClassAlreadyDeclared ErrorCode = "StarknetErrorCode.CLASS_ALREADY_DECLARED"
InsufficientMaxFee ErrorCode = "StarknetErrorCode.INSUFFICIENT_MAX_FEE"
InsufficientAccountBalance ErrorCode = "StarknetErrorCode.INSUFFICIENT_ACCOUNT_BALANCE"
ValidateFailure ErrorCode = "StarknetErrorCode.VALIDATE_FAILURE"
ContractBytecodeSizeTooLarge ErrorCode = "StarknetErrorCode.CONTRACT_BYTECODE_SIZE_TOO_LARGE"
DuplicatedTransaction ErrorCode = "StarknetErrorCode.DUPLICATED_TRANSACTION"
InvalidTransactionNonce ErrorCode = "StarknetErrorCode.INVALID_TRANSACTION_NONCE"
CompilationFailed ErrorCode = "StarknetErrorCode.COMPILATION_FAILED"
InvalidCompiledClassHash ErrorCode = "StarknetErrorCode.INVALID_COMPILED_CLASS_HASH"
ContractClassObjectSizeTooLarge ErrorCode = "StarknetErrorCode.CONTRACT_CLASS_OBJECT_SIZE_TOO_LARGE"
InvalidTransactionVersion ErrorCode = "StarknetErrorCode.INVALID_TRANSACTION_VERSION"
InvalidContractClassVersion ErrorCode = "StarknetErrorCode.INVALID_CONTRACT_CLASS_VERSION"
InvalidContractClass ErrorCode = "StarknetErrorCode.INVALID_CONTRACT_CLASS"
UndeclaredClass ErrorCode = "StarknetErrorCode.UNDECLARED_CLASS"
ClassAlreadyDeclared ErrorCode = "StarknetErrorCode.CLASS_ALREADY_DECLARED"
InsufficientMaxFee ErrorCode = "StarknetErrorCode.INSUFFICIENT_MAX_FEE"
InsufficientResourcesForValidate ErrorCode = "StarknetErrorCode.INSUFFICIENT_RESOURCES_FOR_VALIDATE"
InsufficientAccountBalance ErrorCode = "StarknetErrorCode.INSUFFICIENT_ACCOUNT_BALANCE"
ValidateFailure ErrorCode = "StarknetErrorCode.VALIDATE_FAILURE"
ContractBytecodeSizeTooLarge ErrorCode = "StarknetErrorCode.CONTRACT_BYTECODE_SIZE_TOO_LARGE"
DuplicatedTransaction ErrorCode = "StarknetErrorCode.DUPLICATED_TRANSACTION"
InvalidTransactionNonce ErrorCode = "StarknetErrorCode.INVALID_TRANSACTION_NONCE"
CompilationFailed ErrorCode = "StarknetErrorCode.COMPILATION_FAILED"
InvalidCompiledClassHash ErrorCode = "StarknetErrorCode.INVALID_COMPILED_CLASS_HASH"
ContractClassObjectSizeTooLarge ErrorCode = "StarknetErrorCode.CONTRACT_CLASS_OBJECT_SIZE_TOO_LARGE"
InvalidTransactionVersion ErrorCode = "StarknetErrorCode.INVALID_TRANSACTION_VERSION"
InvalidContractClassVersion ErrorCode = "StarknetErrorCode.INVALID_CONTRACT_CLASS_VERSION"
)

type Client struct {
Expand Down
67 changes: 34 additions & 33 deletions rpc/rpccore/rpccore.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,40 @@ type TraceCacheKey struct {
}

var (
ErrContractNotFound = &jsonrpc.Error{Code: 20, Message: "Contract not found"}
ErrBlockNotFound = &jsonrpc.Error{Code: 24, Message: "Block not found"}
ErrInvalidTxHash = &jsonrpc.Error{Code: 25, Message: "Invalid transaction hash"}
ErrInvalidBlockHash = &jsonrpc.Error{Code: 26, Message: "Invalid block hash"}
ErrInvalidTxIndex = &jsonrpc.Error{Code: 27, Message: "Invalid transaction index in a block"}
ErrClassHashNotFound = &jsonrpc.Error{Code: 28, Message: "Class hash not found"}
ErrTxnHashNotFound = &jsonrpc.Error{Code: 29, Message: "Transaction hash not found"}
ErrPageSizeTooBig = &jsonrpc.Error{Code: 31, Message: "Requested page size is too big"}
ErrNoBlock = &jsonrpc.Error{Code: 32, Message: "There are no blocks"}
ErrInvalidContinuationToken = &jsonrpc.Error{Code: 33, Message: "Invalid continuation token"}
ErrTooManyKeysInFilter = &jsonrpc.Error{Code: 34, Message: "Too many keys provided in a filter"}
ErrContractError = &jsonrpc.Error{Code: 40, Message: "Contract error"}
ErrTransactionExecutionError = &jsonrpc.Error{Code: 41, Message: "Transaction execution error"}
ErrStorageProofNotSupported = &jsonrpc.Error{Code: 42, Message: "The node doesn't support storage proofs for blocks that are too far in the past"} //nolint:lll
ErrInvalidContractClass = &jsonrpc.Error{Code: 50, Message: "Invalid contract class"}
ErrClassAlreadyDeclared = &jsonrpc.Error{Code: 51, Message: "Class already declared"}
ErrInternal = &jsonrpc.Error{Code: jsonrpc.InternalError, Message: "Internal error"}
ErrInvalidTransactionNonce = &jsonrpc.Error{Code: 52, Message: "Invalid transaction nonce"}
ErrInsufficientMaxFee = &jsonrpc.Error{Code: 53, Message: "Max fee is smaller than the minimal transaction cost (validation plus fee transfer)"} //nolint:lll
ErrInsufficientAccountBalance = &jsonrpc.Error{Code: 54, Message: "Account balance is smaller than the transaction's max_fee"}
ErrValidationFailure = &jsonrpc.Error{Code: 55, Message: "Account validation failed"}
ErrCompilationFailed = &jsonrpc.Error{Code: 56, Message: "Compilation failed"}
ErrContractClassSizeTooLarge = &jsonrpc.Error{Code: 57, Message: "Contract class size is too large"}
ErrNonAccount = &jsonrpc.Error{Code: 58, Message: "Sender address is not an account contract"}
ErrDuplicateTx = &jsonrpc.Error{Code: 59, Message: "A transaction with the same hash already exists in the mempool"}
ErrCompiledClassHashMismatch = &jsonrpc.Error{Code: 60, Message: "the compiled class hash did not match the one supplied in the transaction"} //nolint:lll
ErrUnsupportedTxVersion = &jsonrpc.Error{Code: 61, Message: "the transaction version is not supported"}
ErrUnsupportedContractClassVersion = &jsonrpc.Error{Code: 62, Message: "the contract class version is not supported"}
ErrUnexpectedError = &jsonrpc.Error{Code: 63, Message: "An unexpected error occurred"}
ErrInvalidSubscriptionID = &jsonrpc.Error{Code: 66, Message: "Invalid subscription id"}
ErrTooManyAddressesInFilter = &jsonrpc.Error{Code: 67, Message: "Too many addresses in filter sender_address filter"}
ErrTooManyBlocksBack = &jsonrpc.Error{Code: 68, Message: fmt.Sprintf("Cannot go back more than %v blocks", MaxBlocksBack)}
ErrCallOnPending = &jsonrpc.Error{Code: 69, Message: "This method does not support being called on the pending block"}
ErrContractNotFound = &jsonrpc.Error{Code: 20, Message: "Contract not found"}
ErrBlockNotFound = &jsonrpc.Error{Code: 24, Message: "Block not found"}
ErrInvalidTxHash = &jsonrpc.Error{Code: 25, Message: "Invalid transaction hash"}
ErrInvalidBlockHash = &jsonrpc.Error{Code: 26, Message: "Invalid block hash"}
ErrInvalidTxIndex = &jsonrpc.Error{Code: 27, Message: "Invalid transaction index in a block"}
ErrClassHashNotFound = &jsonrpc.Error{Code: 28, Message: "Class hash not found"}
ErrTxnHashNotFound = &jsonrpc.Error{Code: 29, Message: "Transaction hash not found"}
ErrPageSizeTooBig = &jsonrpc.Error{Code: 31, Message: "Requested page size is too big"}
ErrNoBlock = &jsonrpc.Error{Code: 32, Message: "There are no blocks"}
ErrInvalidContinuationToken = &jsonrpc.Error{Code: 33, Message: "Invalid continuation token"}
ErrTooManyKeysInFilter = &jsonrpc.Error{Code: 34, Message: "Too many keys provided in a filter"}
ErrContractError = &jsonrpc.Error{Code: 40, Message: "Contract error"}
ErrTransactionExecutionError = &jsonrpc.Error{Code: 41, Message: "Transaction execution error"}
ErrStorageProofNotSupported = &jsonrpc.Error{Code: 42, Message: "The node doesn't support storage proofs for blocks that are too far in the past"} //nolint:lll
ErrInvalidContractClass = &jsonrpc.Error{Code: 50, Message: "Invalid contract class"}
ErrClassAlreadyDeclared = &jsonrpc.Error{Code: 51, Message: "Class already declared"}
ErrInternal = &jsonrpc.Error{Code: jsonrpc.InternalError, Message: "Internal error"}
ErrInvalidTransactionNonce = &jsonrpc.Error{Code: 52, Message: "Invalid transaction nonce"}
ErrInsufficientMaxFee = &jsonrpc.Error{Code: 53, Message: "Max fee is smaller than the minimal transaction cost (validation plus fee transfer)"} //nolint:lll
ErrInsufficientResourcesForValidate = &jsonrpc.Error{Code: 53, Message: "The transaction’s resources don’t cover validation or the minimal transaction fee"} //nolint:lll
ErrInsufficientAccountBalance = &jsonrpc.Error{Code: 54, Message: "Account balance is smaller than the transaction's max_fee"}
ErrValidationFailure = &jsonrpc.Error{Code: 55, Message: "Account validation failed"}
ErrCompilationFailed = &jsonrpc.Error{Code: 56, Message: "Compilation failed"}
ErrContractClassSizeTooLarge = &jsonrpc.Error{Code: 57, Message: "Contract class size is too large"}
ErrNonAccount = &jsonrpc.Error{Code: 58, Message: "Sender address is not an account contract"}
ErrDuplicateTx = &jsonrpc.Error{Code: 59, Message: "A transaction with the same hash already exists in the mempool"}
ErrCompiledClassHashMismatch = &jsonrpc.Error{Code: 60, Message: "the compiled class hash did not match the one supplied in the transaction"} //nolint:lll
ErrUnsupportedTxVersion = &jsonrpc.Error{Code: 61, Message: "the transaction version is not supported"}
ErrUnsupportedContractClassVersion = &jsonrpc.Error{Code: 62, Message: "the contract class version is not supported"}
ErrUnexpectedError = &jsonrpc.Error{Code: 63, Message: "An unexpected error occurred"}
ErrInvalidSubscriptionID = &jsonrpc.Error{Code: 66, Message: "Invalid subscription id"}
ErrTooManyAddressesInFilter = &jsonrpc.Error{Code: 67, Message: "Too many addresses in filter sender_address filter"}
ErrTooManyBlocksBack = &jsonrpc.Error{Code: 68, Message: fmt.Sprintf("Cannot go back more than %v blocks", MaxBlocksBack)}
ErrCallOnPending = &jsonrpc.Error{Code: 69, Message: "This method does not support being called on the pending block"}

// These errors can be only be returned by Juno-specific methods.
ErrSubscriptionNotFound = &jsonrpc.Error{Code: 100, Message: "Subscription not found"}
Expand Down
4 changes: 2 additions & 2 deletions rpc/v8/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@
return rpccore.ErrClassHashNotFound
case gateway.ClassAlreadyDeclared:
return rpccore.ErrClassAlreadyDeclared
case gateway.InsufficientMaxFee:
return rpccore.ErrInsufficientMaxFee
case gateway.InsufficientResourcesForValidate:
return rpccore.ErrInsufficientResourcesForValidate

Check warning on line 683 in rpc/v8/transaction.go

View check run for this annotation

Codecov / codecov/patch

rpc/v8/transaction.go#L682-L683

Added lines #L682 - L683 were not covered by tests
case gateway.InsufficientAccountBalance:
return rpccore.ErrInsufficientAccountBalance
case gateway.ValidateFailure:
Expand Down