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

Unknown conditions with cost #170

Merged
merged 1 commit into from
Jun 1, 2023
Merged

Unknown conditions with cost #170

merged 1 commit into from
Jun 1, 2023

Conversation

arvidn
Copy link
Contributor

@arvidn arvidn commented May 26, 2023

overview

This patch assign cost to some (currently unknown) condition codes, when the ENABLE_SOFTFORK_CONDITION flag is set. Setting this flag is a hard fork, and so is changing the costs of unknown conditions. This flag is intended to be set when the 2.0 hard fork activates.

The rationale for this change is to enable adding new conditions with cost as soft forks in the future. It is already possible to soft-fork in new conditions, but they must all have cost 0, since all unknown conditions currently have 0 cost.

the details

Currently, all defined condition codes fit in 1 byte, so ConditionOpcode is an alias for u8. This patch changes this to be an alias for u16. This allows the conditions parser to handle 2-byte conditions.

When the flag ENABLE_SOFTFORK_CONDITION is enabled, any 2-byte condition opcode whose first byte is 0x01 is assigned a cost equal to the second bytes value AND 0x07 multiplied by 200000, plus 1'000'000.

examples

bye 0 byte 1 cost
1 0 1'000'000
1 1 1'200'000
1 2 1'400'000
1 3 1'600'000
1 4 1'800'000
1 5 2'000'000
1 6 2'200'000
1 7 2'400'000
1 8 1'000'000
1 2 1'200'000
1 ... ...
1 253 2'000'000
1 254 2'200'000
1 255 2'400'000

@coveralls-official
Copy link

Pull Request Test Coverage Report for Build 5091164883

  • 35 of 38 (92.11%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.5%) to 61.156%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/gen/opcodes.rs 22 23 95.65%
src/gen/validation_error.rs 0 2 0.0%
Totals Coverage Status
Change from base Build 5083277513: 0.5%
Covered Lines: 825
Relevant Lines: 1349

💛 - Coveralls

… to soft-fork in new conditions with cost in the future. 256 condition opcodes are reserved assigned cost ranging from 1000000 to 2400000
@arvidn arvidn force-pushed the unknown-conditions-with-cost branch from 0c4079a to 575ce60 Compare May 30, 2023 19:47
@arvidn arvidn marked this pull request as ready for review May 30, 2023 20:14
Copy link
Contributor

@richardkiss richardkiss left a comment

Choose a reason for hiding this comment

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

Seems reasonable.

@arvidn arvidn merged commit d61066e into main Jun 1, 2023
@arvidn arvidn deleted the unknown-conditions-with-cost branch June 1, 2023 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants