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: RPC v0.8 now doesn't support broadcasted transaction less than v3 #2544

Merged
merged 4 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ func New(cfg *Config, version string, logLevel *utils.LogLevel) (*Node, error) {
if err = jsonrpcServerV08.RegisterMethods(methodsV08...); err != nil {
return nil, err
}
jsonrpcServerV07 := jsonrpc.NewServer(maxGoroutines, log).WithValidator(validator.Validator())
jsonrpcServerV07 := jsonrpc.NewServer(maxGoroutines, log)
methodsV07, pathV07 := rpcHandler.MethodsV0_7()
if err = jsonrpcServerV07.RegisterMethods(methodsV07...); err != nil {
return nil, err
}
jsonrpcServerV06 := jsonrpc.NewServer(maxGoroutines, log).WithValidator(validator.Validator())
jsonrpcServerV06 := jsonrpc.NewServer(maxGoroutines, log)
methodsV06, pathV06 := rpcHandler.MethodsV0_6()
if err = jsonrpcServerV06.RegisterMethods(methodsV06...); err != nil {
return nil, err
Expand Down
22 changes: 11 additions & 11 deletions rpc/v8/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,24 +212,24 @@ type ResourceBounds struct {
type Transaction struct {
Hash *felt.Felt `json:"transaction_hash,omitempty"`
Type TransactionType `json:"type" validate:"required"`
Version *felt.Felt `json:"version,omitempty" validate:"required"`
Nonce *felt.Felt `json:"nonce,omitempty" validate:"required_unless=Version 0x0"`
MaxFee *felt.Felt `json:"max_fee,omitempty" validate:"required_if=Version 0x0,required_if=Version 0x1,required_if=Version 0x2"`
Version *felt.Felt `json:"version,omitempty" validate:"required,version_0x3"`
Nonce *felt.Felt `json:"nonce,omitempty" validate:"required"`
MaxFee *felt.Felt `json:"max_fee,omitempty"`
ContractAddress *felt.Felt `json:"contract_address,omitempty"`
ContractAddressSalt *felt.Felt `json:"contract_address_salt,omitempty" validate:"required_if=Type DEPLOY,required_if=Type DEPLOY_ACCOUNT"`
ClassHash *felt.Felt `json:"class_hash,omitempty" validate:"required_if=Type DEPLOY,required_if=Type DEPLOY_ACCOUNT"`
ConstructorCallData *[]*felt.Felt `json:"constructor_calldata,omitempty" validate:"required_if=Type DEPLOY,required_if=Type DEPLOY_ACCOUNT"`
SenderAddress *felt.Felt `json:"sender_address,omitempty" validate:"required_if=Type DECLARE,required_if=Type INVOKE Version 0x1,required_if=Type INVOKE Version 0x3"`
SenderAddress *felt.Felt `json:"sender_address,omitempty" validate:"required_if=Type DECLARE,required_if=Type INVOKE"`
Signature *[]*felt.Felt `json:"signature,omitempty" validate:"required"`
CallData *[]*felt.Felt `json:"calldata,omitempty" validate:"required_if=Type INVOKE"`
EntryPointSelector *felt.Felt `json:"entry_point_selector,omitempty" validate:"required_if=Type INVOKE Version 0x0"`
CompiledClassHash *felt.Felt `json:"compiled_class_hash,omitempty" validate:"required_if=Type DECLARE Version 0x2"`
EntryPointSelector *felt.Felt `json:"entry_point_selector,omitempty"`
CompiledClassHash *felt.Felt `json:"compiled_class_hash,omitempty"`
ResourceBounds *map[Resource]ResourceBounds `json:"resource_bounds,omitempty" validate:"resource_bounds_required"`
Tip *felt.Felt `json:"tip,omitempty" validate:"required_if=Version 0x3"`
PaymasterData *[]*felt.Felt `json:"paymaster_data,omitempty" validate:"required_if=Version 0x3"`
AccountDeploymentData *[]*felt.Felt `json:"account_deployment_data,omitempty" validate:"required_if=Type INVOKE Version 0x3,required_if=Type DECLARE Version 0x3"`
NonceDAMode *DataAvailabilityMode `json:"nonce_data_availability_mode,omitempty" validate:"required_if=Version 0x3"`
FeeDAMode *DataAvailabilityMode `json:"fee_data_availability_mode,omitempty" validate:"required_if=Version 0x3"`
Tip *felt.Felt `json:"tip,omitempty" validate:"required"`
PaymasterData *[]*felt.Felt `json:"paymaster_data,omitempty" validate:"required"`
AccountDeploymentData *[]*felt.Felt `json:"account_deployment_data,omitempty" validate:"required_if=Type INVOKE,required_if=Type DECLARE"`
NonceDAMode *DataAvailabilityMode `json:"nonce_data_availability_mode,omitempty" validate:"required"`
FeeDAMode *DataAvailabilityMode `json:"fee_data_availability_mode,omitempty" validate:"required"`
}

type TransactionStatus struct {
Expand Down
19 changes: 19 additions & 0 deletions rpc/v8/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,20 @@ func TestResourceBoundsValidation(t *testing.T) {
"fee_data_availability_mode": "L1",
"account_deployment_data": []
}`
invokeV1 := `{
"type": "INVOKE",
"sender_address": "0x4a7876e03402cf253efdb3b17c760ee7349c7ec2876059b83ec2c92ca451e16",
"calldata": [
"0x1",
"0x3745ab04a431fc02871a139be6b93d9260b0ff3e779ad9c8b377183b23109f1",
"0x6a26462a114fa5e0c0e6b9cd8442c79e1ad560232e65427e16de301eb99b89",
"0x0"
],
"max_fee": "0x0",
"version": "0x100000000000000000000000000000001",
"signature": [],
"nonce": "0x34f6"
}`

tests := []struct {
name string
Expand All @@ -1507,6 +1521,11 @@ func TestResourceBoundsValidation(t *testing.T) {
txnJSON: validInvokeV3,
wantErr: false,
},
{
name: "valid v1",
txnJSON: invokeV1,
wantErr: true,
},
}

validate := validator.Validator()
Expand Down
19 changes: 10 additions & 9 deletions validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@

func validateResourceBounds(fl validator.FieldLevel) bool {
req, ok := fl.Parent().Interface().(rpcv8.Transaction)
if !ok {
return false
}
return ok && req.ResourceBounds != nil && len(*req.ResourceBounds) == 3
}

version := req.Version.String()
if (version == "0x3" || version == "0x100000000000000000000000000000003") &&
(req.ResourceBounds == nil || len(*req.ResourceBounds) != 3) {
return false
}
return true
// Custom validation function for version
func validateVersion03(fl validator.FieldLevel) bool {
version, ok := fl.Field().Interface().(string)
return ok && (version == "0x3" || version == "0x100000000000000000000000000000003")
}

// Validator returns a singleton that can be used to validate various objects
Expand All @@ -39,6 +36,10 @@
panic("failed to register validation: " + err.Error())
}

if err := v.RegisterValidation("version_0x3", validateVersion03); err != nil {
panic("failed to register validation: " + err.Error())

Check warning on line 40 in validator/validator.go

View check run for this annotation

Codecov / codecov/patch

validator/validator.go#L40

Added line #L40 was not covered by tests
}

// Register these types to use their string representation for validation
// purposes
v.RegisterCustomTypeFunc(func(field reflect.Value) any {
Expand Down
Loading