filecoin-project / specs-actors

DEPRECATED Specification of builtin actors, in the form of executable code.
Other
86 stars 102 forks source link

Change Label to be a Union of strings and bytes #1580

Closed arajasek closed 2 years ago

arajasek commented 2 years ago

Implements FIP-0027. Will need a migration.

codecov-commenter commented 2 years ago

Codecov Report

Merging #1580 (f65d10f) into master (5f5089f) will increase coverage by 0.0%. The diff coverage is 69.2%.

@@          Coverage Diff           @@
##           master   #1580   +/-   ##
======================================
  Coverage    69.0%   69.0%           
======================================
  Files          73      74    +1     
  Lines        8798    8887   +89     
======================================
+ Hits         6077    6140   +63     
- Misses       1859    1873   +14     
- Partials      862     874   +12     
ZenGround0 commented 2 years ago

Can't tag you for review since you opened this @arajasek but please review this too

ZenGround0 commented 2 years ago

Yes bullets 1 and 2 were inherited from your draft of the PR.

For the first point, this is just the current state of the chain, after unmarshalling proposals we then further check we're not exceeding max label length. Seems like the right breakdown. Let cbor worry about cbor limits let application code worry about application limits.

Am I misunderstanding, or would NewLabelFromString("").IsEmpty() return false? Is that intentional? We could mitigate by making IsEmpty() return len(label.s) == 0 && len(label.bs) == 0?

Yeah its intentional. Its a type thing not a value thing. Empty means contains no string or bytes and the empty string is a string. EmptyLabel serializes to a string but its not a string. This is all just shorthand to be a bit clearer than comparing both fields to nil in a few places. I'll add a comment but don't think this needs to change. Your suggestion is outdated with the pointer representation I changed to on steb's suggestion. b and s are pointers so never have length.

For the final point you added these when you made this PR and they turned out useful for testing. I made ToBytes convert a string on steb's suggestion. But I think your right that converting here doesn't make sense so I'll change that back to erroring if its not bytes.

Stebalien commented 2 years ago

Yeah its intentional. Its a type thing not a value thing. Empty means contains no string or bytes and the empty string is a string. EmptyLabel serializes to a string but its not a string. This is all just shorthand to be a bit clearer than comparing both fields to nil in a few places. I'll add a comment but don't think this needs to change. Your suggestion is outdated with the pointer representation I changed to on steb's suggestion. b and s are pointers so never have length.

We shouldn't distinguish between the two kinds of empty. That is, DealLabel{} and DealLabel{s: ""} should be indistinguishable.

arajasek commented 2 years ago

Sorry, I'm still confused about the emptiness thing. Some qs:

I might be wrong about some of these claims.