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

[6.0.0] activation details and revised checkSoftForkCondition #1029

Open
wants to merge 3 commits into
base: v6.0.0
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import sigma.VersionContext
import sigma.ast.SCollectionType.{CollectionTypeCode, NestedCollectionTypeCode}
import sigma.ast._
import sigma.util.safeNewArray
import sigma.validation.ValidationRules.{CheckPrimitiveTypeCode, CheckTypeCode}
import sigma.validation.ValidationRules.{CheckPrimitiveTypeCode, CheckTypeCode, CheckTypeCodeV6}

import java.nio.charset.StandardCharsets

Expand All @@ -14,6 +14,8 @@ class TypeSerializer {
import TypeSerializer._

def getEmbeddableType(code: Int): SType = {
// todo : add versioning to the check like done for other rules
// todo : add unsigned bit int to embeddable id to type
CheckPrimitiveTypeCode(code.toByte)
embeddableIdToType(code)
}
Expand Down Expand Up @@ -215,9 +217,13 @@ class TypeSerializer {
}
SFunc(tDom, tRange, tpeParams)
case _ =>
// todo: 6.0: replace 1008 check with identical behavior but other opcode, to activate
// ReplacedRule(1008 -> new opcode) during 6.0 activation
CheckTypeCode(c.toByte)
// the #1008 check replaced with one with identical behavior but different opcode (1018), to activate
// ReplacedRule(1008 -> 1018) during 6.0 activation
if (VersionContext.current.isV6SoftForkActivated) {
CheckTypeCodeV6(c.toByte)
} else {
CheckTypeCode(c.toByte)
}
NoType
}
}
Expand Down
12 changes: 10 additions & 2 deletions core/shared/src/main/scala/sigma/validation/ValidationRules.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ object ValidationRules {
/** The id of the first validation rule. Can be used as the beginning of the rules id range. */
val FirstRuleId = 1000.toShort

object CheckPrimitiveTypeCode extends ValidationRule(1007,
class CheckPrimitiveTypeCodeTemplate(ruleId: Short) extends ValidationRule(ruleId,
"Check the primitive type code is supported or is added via soft-fork")
with SoftForkWhenCodeAdded {
override protected lazy val settings: SigmaValidationSettings = coreSettings
Expand All @@ -93,7 +93,11 @@ object ValidationRules {
}
}

object CheckTypeCode extends ValidationRule(1008,
object CheckPrimitiveTypeCode extends CheckPrimitiveTypeCodeTemplate(1007)

object CheckPrimitiveTypeCodeV6 extends CheckPrimitiveTypeCodeTemplate(1017)

class CheckTypeCodeTemplate(ruleId: Short) extends ValidationRule(ruleId,
"Check the non-primitive type code is supported or is added via soft-fork")
with SoftForkWhenCodeAdded {
override protected lazy val settings: SigmaValidationSettings = coreSettings
Expand All @@ -109,6 +113,10 @@ object ValidationRules {
}
}

object CheckTypeCode extends CheckTypeCodeTemplate(1008)

object CheckTypeCodeV6 extends CheckTypeCodeTemplate(1018)

object CheckSerializableTypeCode extends ValidationRule(1009,
"Check the data values of the type (given by type code) can be serialized")
with SoftForkWhenReplaced {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ object ValidationRules {
// }
}

object CheckAndGetMethod extends ValidationRule(1011,
class CheckAndGetMethodTemplate(ruleId: Short) extends ValidationRule(ruleId,
"Check the type has the declared method.") {
override protected lazy val settings: SigmaValidationSettings = currentSettings

Expand All @@ -128,6 +128,9 @@ object ValidationRules {
}
}

object CheckAndGetMethod extends CheckAndGetMethodTemplate(1011)
object CheckAndGetMethodV6 extends CheckAndGetMethodTemplate(1016)

object CheckHeaderSizeBit extends ValidationRule(1012,
"For version greater then 0, size bit should be set.") with SoftForkWhenReplaced {
override protected lazy val settings: SigmaValidationSettings = currentSettings
Expand Down Expand Up @@ -171,7 +174,9 @@ object ValidationRules {
CheckHeaderSizeBit,
CheckCostFuncOperation,
CheckPositionLimit,
CheckLoopLevelInCostFunction
CheckLoopLevelInCostFunction,
// v6 validation rules below
CheckAndGetMethodV6
)

/** Validation settings that correspond to the current version of the ErgoScript implementation.
Expand Down
8 changes: 6 additions & 2 deletions data/shared/src/main/scala/sigma/ast/methods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ sealed trait MethodsContainer {

/** Lookup method in this type by method's id or throw ValidationException.
* This method can be used in trySoftForkable section to either obtain valid method
* or catch ValidatioinException which can be checked for soft-fork condition.
* or catch ValidationException which can be checked for soft-fork condition.
* It delegate to getMethodById to lookup method.
*
* @see getMethodById
*/
def methodById(methodId: Byte): SMethod = {
ValidationRules.CheckAndGetMethod(this, methodId)
if (VersionContext.current.isV6SoftForkActivated) {
ValidationRules.CheckAndGetMethodV6(this, methodId)
} else {
ValidationRules.CheckAndGetMethod(this, methodId)
}
}

/** Finds a method descriptor [[SMethod]] for the given name. */
Expand Down
Loading