Skip to content

Charge for compiling a contract's regular expressions at registration #5894

Open

Description

@QuantumExplorer

Basic explanation

Registering or updating a data contract compiles its regular expressions: every string property's pattern, and every regexPattern of a contested index's fieldMatches. Nothing charges for that work. This issue tracks adding a price for it to the fee schedule.

Where patterns are compiled today

From protocol version 15 a contract's patterns are compiled in three passes, none of them charged:

  1. The pattern bound of fix(platform)!: a data contract holds a bounded number of patterns of bounded compiled size (PV15) #5879 (DataContract::validate_schema_patterns) compiles each distinct pattern to check that it compiles within max_schema_pattern_compiled_size.
  2. The index parser compiles every regexPattern of a contested index.
  3. The schema builders compile every pattern for the validator documents are checked with.

The registration fee is computed from the number of document types, indexes and tokens, plus the keywords, while validation operations are charged by schema size and property count. A contract refused because a pattern does not compile pays only the base costs of its transition, not for the patterns compiled before the refusal.

Why it is bounded already

From protocol version 15 a contract holds at most 32 patterns (max_contract_schema_patterns), each compiling within 128 KiB, so one pass costs at most about 11 ms and 4 MiB. check_tx holds a contract to the same bound at every protocol version. So this is about charging for bounded work, not about bounding it.

Proposal

  • Add a compile operation to a new FEE_VERSION schedule, recorded as a ProtocolValidationOperation by each pass that compiles a pattern, including a compile that fails, so that a contract refused for a pattern pays for the compiles before the refusal.
  • Select it only from the protocol version that adopts it, so blocks of earlier versions keep their fees.

Open questions

  • A flat rate per pattern, or one in proportion to the compiled size the regex crate accounts?
  • Charge each pass, or once for each distinct pattern?

Raised in review of #5879.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions