-
Notifications
You must be signed in to change notification settings - Fork 698
feat: use clarity-serialization
in clarity
#6310
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
base: develop
Are you sure you want to change the base?
feat: use clarity-serialization
in clarity
#6310
Conversation
…end-on-clarity-serialization
…end-on-clarity-serialization
…end-on-clarity-serialization
…end-on-clarity-serialization
…end-on-clarity-serialization
…ity-depend-on-clarity-serialization
…ity-depend-on-clarity-serialization
clarity/src/vm/types/signatures.rs
Outdated
) -> Result<TupleTypeSignature> { | ||
if let SymbolicExpressionType::List(ref name_type_pairs) = type_def.expr { | ||
let mapped_key_types = parse_name_type_pairs(epoch, name_type_pairs, accounting)?; | ||
TupleTypeSignature::try_from(mapped_key_types).map_err(CheckErrors::from) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this error conversion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in b0957e3
} | ||
} | ||
} | ||
|
||
/// Parsing functions. | ||
impl TypeSignature { | ||
pub trait TypeSignatureExt { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a docstring explaining this trait.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, seeing this massive trait and the traits above it, all of which only seem to exist because SymbolicExpression
isn't in clarity-serialization
, I'm inclined to take back what I said earlier about keeping SymbolicExpression
in clarity
. Please instead move SymbolicExpression
and its ilk to clarity-serialization
so these traits can be removed. We'll just port the feature flags from clarity
to clarity-serialization
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment for now, but I am open to revisit this if you think otherwise! The main reasons I initially avoided moving this in clarity-serialization was because most of these functions require both for SymbolicExpression
and CostTracker
which I saw more as a runtime construct and more appropriate for clarity
. CostTracker also depends on ClarityCostFunction, ExecutionCost, and CostErrors.
But with the latest changes I already needed to move ExecutionCost and CostErrors into clarity-serialization, so I’m open to also moving ClarityCostFunction
and CostTracker
if you think that would be cleaner. Let me know what you prefer!
stackslib/src/blockstack_cli.rs
Outdated
@@ -236,6 +238,22 @@ impl From<ClarityError> for CliError { | |||
} | |||
} | |||
|
|||
impl From<ClarityCodecError> for CliError { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please drop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in 40a95ee
stackslib/src/net/mod.rs
Outdated
@@ -537,6 +537,12 @@ impl From<InterpreterError> for Error { | |||
} | |||
} | |||
|
|||
impl From<CodecError> for Error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please drop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in 40a95ee
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your continued work on separating out Clarity serialization code from clarity
. There are a few show-stopping issues that must be addressed, which are detailed in my comments, but I'll summarize below.
-
Error types in Clarity are generally consensus-critical. In particular,
InterpreterError
andCheckErrors
are handled differently in transaction-processing -- the former marks a block as invalid, while the latter can be mined. The replacement of both of these variants and others withCodecErrors
is a consensus-critical bug that must be reverted throughout. -
There is a lot of code churn here that has arisen from the fact that
SymbolicExpression
is inclarity
, notclarity-serialization
. This has lead to the need for several traits whose only purpose is to allow types defined inclarity-serialization
to continue to have their existing methods which either tookSymbolicExpression
-based types as arguments or returned aSymbolicExpression
-based type. This code churn can and should be avoided, since all of this is consensus-critical. I think it would be better to moveSymbolicExpression
toclarity-serialization
, even though it would mean that feature flags inclarity
would need to be duplicated inclarity-serialization
.
#[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize, Deserialize)] | ||
pub struct FunctionIdentifier { | ||
identifier: String, | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed for the StackTrace
type used in Error
IOError(IncomparableError<std::io::Error>), | ||
BadTypeError(CheckErrors), | ||
DeserializationError(String), | ||
DeserializeExpected(Box<TypeSignature>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
originally, this was DeserializeExpected(TypeSignature)
does this change cause any problems?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine, because AFAIK we never match on whether or not a substructure is a Box<T>
anywhere in the codebase (that would be very weird).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain the reason for the change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same reason as for #6310 (comment). But if you prefer I could move even this change to the separate PR
@@ -12,11 +12,12 @@ readme = "README.md" | |||
[dependencies] | |||
lazy_static = { workspace = true } | |||
regex = { version = "1", default-features = false } | |||
rusqlite = { workspace = true, optional = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed for implementing ToSql
and FromSql
for ExecutionCost
, and defining InterpreterError::SqliteError(IncomparableError<SqliteError>)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this might need some thought. I thought clarity-serialization
was supposed to be able to run in WASM? If so, then rusqlite
can't be a required dependency IIRC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't be a problem in this case, rustqlite will only be included if built with the rusqlite
feature. If building this with
cargo build -p clarity-serialization --features "wasm-web"
(for js support)
cargo build -p clarity-serialization --features "wasm-deterministic"
(for deterministic environment like CosmWasm)
it will still work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the structs remaining in this file (e.g. FunctionSignature
, FixedFunction
, etc.) and their implementations, were not originally needed in clarity-serialization
, but since we are going to rename this into clarity-types
I was thinking of moving them all. Any opinions?
} | ||
} | ||
} | ||
|
||
/// Parsing functions. | ||
impl TypeSignature { | ||
pub trait TypeSignatureExt { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment for now, but I am open to revisit this if you think otherwise! The main reasons I initially avoided moving this in clarity-serialization was because most of these functions require both for SymbolicExpression
and CostTracker
which I saw more as a runtime construct and more appropriate for clarity
. CostTracker also depends on ClarityCostFunction, ExecutionCost, and CostErrors.
But with the latest changes I already needed to move ExecutionCost and CostErrors into clarity-serialization, so I’m open to also moving ClarityCostFunction
and CostTracker
if you think that would be cleaner. Let me know what you prefer!
pub type CheckResult<T> = Result<T, CheckError>; | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub enum CheckErrors { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be consensus breaking if we modify CheckErrors
to Box
all TypeSignature
and Value
in order to remove #![allow(clippy::result_large_err)]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that should be fine, because we don't ever check a type's substructure to see if it contains a Box<T>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given it will be require a big amount of line changes, I'll just do it in a separate PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for completeness, here is the PR that boxes the data in some errors and fixes all the clippy::result_large_err
warnings. No need to review it now of course :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've opened a PR as a follow-up to expand input coverage further, in line with #6355.
Description
Points for Discussion from #6297:
clarity-serialization
, I consolidated all error types into a single CodecError enum with a 1:1 match with the original errors inclarity
. However, when converting back to the older error types usingFrom<CodecError>
, some variants don’t have a clear or meaningful equivalent. I’ve routed them through generic catch-all cases. Even if the current code doesn't reach those conversions, I am not happy with this mapping strategy and am open to suggestions!Applicable issues
Additional info (benefits, drawbacks, caveats)
Checklist
docs/rpc/openapi.yaml
andrpc-endpoints.md
for v2 endpoints,event-dispatcher.md
for new events)clarity-benchmarking
repobitcoin-tests.yml