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

Publish and Claim: Inbox API for Capability Bootstrapping #1983

Merged
merged 43 commits into from
Oct 6, 2022

Conversation

dsainati1
Copy link
Contributor

@dsainati1 dsainati1 commented Sep 19, 2022

Closes #1951

This is an implementation of the Publish/Claim API described in this FLIP: onflow/flow#1122


  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@github-actions
Copy link

github-actions bot commented Sep 19, 2022

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit 66b8591
The command for i in {1..N}; do go test ./... -run=XXX -bench=. -benchmem -shuffle=on; done was used.
Bench tests were run a total of 7 times on each branch.

Collapsed results for better readability

old.txtnew.txt
time/opdelta
CheckContractInterfaceFungibleTokenConformance-2113µs ± 1%112µs ± 0%~(p=0.530 n=7+5)
ContractInterfaceFungibleToken-241.1µs ± 1%40.8µs ± 1%−0.75%(p=0.009 n=6+6)
InterpretRecursionFib-22.54ms ± 1%2.52ms ± 1%−0.76%(p=0.022 n=7+6)
NewInterpreter/new_interpreter-21.20µs ± 1%1.21µs ± 2%+1.09%(p=0.003 n=7+6)
NewInterpreter/new_sub-interpreter-2653ns ± 1%653ns ± 0%~(p=0.667 n=6+6)
ParseArray-27.96ms ± 7%7.68ms ± 1%−3.51%(p=0.001 n=7+7)
ParseDeploy/byte_array-211.6ms ± 3%11.5ms ± 1%~(p=0.383 n=7+7)
ParseDeploy/decode_hex-21.22ms ± 5%1.18ms ± 1%−2.80%(p=0.026 n=7+7)
ParseFungibleToken/With_memory_metering-2182µs ± 1%184µs ± 2%~(p=0.209 n=7+7)
ParseFungibleToken/Without_memory_metering-2144µs ± 1%147µs ± 4%+1.67%(p=0.035 n=6+7)
ParseInfix-27.10µs ± 0%7.17µs ± 1%~(p=0.101 n=6+7)
QualifiedIdentifierCreation/One_level-22.64ns ±22%2.42ns ± 0%~(p=0.068 n=7+6)
QualifiedIdentifierCreation/Three_levels-2122ns ± 1%118ns ± 3%−2.96%(p=0.007 n=6+7)
RuntimeFungibleTokenTransfer-2520µs ±23%539µs ±21%~(p=0.620 n=7+7)
RuntimeResourceDictionaryValues-25.07ms ± 0%5.09ms ± 0%~(p=0.051 n=6+7)
RuntimeScriptNoop-222.0µs ±30%18.6µs ±33%~(p=0.053 n=7+7)
ValueIsSubtypeOfSemaType-285.9ns ± 3%90.4ns ± 1%+5.28%(p=0.001 n=7+7)
 
alloc/opdelta
CheckContractInterfaceFungibleTokenConformance-251.0kB ± 0%51.0kB ± 0%~(all equal)
ContractInterfaceFungibleToken-224.2kB ± 0%24.2kB ± 0%~(all equal)
InterpretRecursionFib-21.00MB ± 0%1.00MB ± 0%~(p=0.385 n=7+6)
NewInterpreter/new_interpreter-2848B ± 0%848B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-2264B ± 0%264B ± 0%~(all equal)
ParseArray-22.71MB ± 3%2.71MB ± 3%~(p=0.805 n=7+7)
ParseDeploy/byte_array-24.10MB ± 0%4.10MB ± 0%~(p=0.974 n=6+6)
ParseDeploy/decode_hex-2214kB ± 0%214kB ± 0%~(p=0.242 n=7+7)
ParseFungibleToken/With_memory_metering-229.4kB ± 0%29.4kB ± 0%~(p=0.172 n=6+7)
ParseFungibleToken/Without_memory_metering-229.4kB ± 0%29.4kB ± 0%~(p=0.927 n=7+7)
ParseInfix-21.93kB ± 0%1.93kB ± 0%~(p=0.278 n=7+7)
QualifiedIdentifierCreation/One_level-20.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-264.0B ± 0%64.0B ± 0%~(all equal)
RuntimeFungibleTokenTransfer-2102kB ± 0%103kB ± 1%~(p=0.073 n=7+7)
RuntimeResourceDictionaryValues-22.27MB ± 0%2.27MB ± 0%~(p=0.219 n=7+7)
RuntimeScriptNoop-28.82kB ± 0%8.84kB ± 0%~(p=0.177 n=5+6)
ValueIsSubtypeOfSemaType-248.0B ± 0%48.0B ± 0%~(all equal)
 
allocs/opdelta
CheckContractInterfaceFungibleTokenConformance-2915 ± 0%915 ± 0%~(all equal)
ContractInterfaceFungibleToken-2436 ± 0%436 ± 0%~(all equal)
InterpretRecursionFib-218.9k ± 0%18.9k ± 0%~(all equal)
NewInterpreter/new_interpreter-214.0 ± 0%14.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-25.00 ± 0%5.00 ± 0%~(all equal)
ParseArray-269.6k ± 0%69.6k ± 0%~(p=1.000 n=7+7)
ParseDeploy/byte_array-2104k ± 0%104k ± 0%~(p=1.000 n=7+7)
ParseDeploy/decode_hex-275.0 ± 0%75.0 ± 0%~(all equal)
ParseFungibleToken/With_memory_metering-21.00k ± 0%1.00k ± 0%~(all equal)
ParseFungibleToken/Without_memory_metering-21.00k ± 0%1.00k ± 0%~(all equal)
ParseInfix-260.0 ± 0%60.0 ± 0%~(all equal)
QualifiedIdentifierCreation/One_level-20.00 0.00 ~(all equal)
QualifiedIdentifierCreation/Three_levels-22.00 ± 0%2.00 ± 0%~(all equal)
RuntimeFungibleTokenTransfer-22.06k ± 0%2.06k ± 0%+0.10%(p=0.001 n=7+7)
RuntimeResourceDictionaryValues-236.9k ± 0%36.9k ± 0%+0.01%(p=0.002 n=7+7)
RuntimeScriptNoop-2145 ± 0%145 ± 0%~(all equal)
ValueIsSubtypeOfSemaType-21.00 ± 0%1.00 ± 0%~(all equal)
 

@codecov
Copy link

codecov bot commented Sep 19, 2022

Codecov Report

Merging #1983 (23a228d) into master (66b8591) will decrease coverage by 0.02%.
The diff coverage is 71.24%.

@@            Coverage Diff             @@
##           master    #1983      +/-   ##
==========================================
- Coverage   77.44%   77.42%   -0.03%     
==========================================
  Files         302      303       +1     
  Lines       62683    63128     +445     
==========================================
+ Hits        48543    48874     +331     
- Misses      12416    12510      +94     
- Partials     1724     1744      +20     
Flag Coverage Δ
unittests 77.42% <71.24%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
runtime/common/memorykind_string.go 40.00% <ø> (ø)
runtime/common/metering.go 92.23% <ø> (ø)
runtime/interpreter/accountcontracts.go 76.81% <0.00%> (ø)
runtime/interpreter/accountkeys.go 72.00% <0.00%> (ø)
runtime/interpreter/primitivestatictype.go 86.92% <ø> (ø)
runtime/interpreter/primitivestatictype_string.go 80.00% <ø> (ø)
runtime/interpreter/visitor.go 9.75% <0.00%> (-0.25%) ⬇️
runtime/stdlib/flow.go 86.53% <ø> (ø)
runtime/interpreter/decode.go 46.14% <26.08%> (-0.74%) ⬇️
runtime/interpreter/value.go 70.76% <40.22%> (-0.26%) ⬇️
... and 10 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@@ -16486,6 +16486,8 @@ func (v *DictionaryValue) IsResourceKinded(interpreter *Interpreter) bool {
type OptionalValue interface {
Value
isOptionalValue()
iter(f func(Value))
fmap(inter *Interpreter, f func(Value) Value) OptionalValue
Copy link
Contributor

Choose a reason for hiding this comment

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

now we gotta extend optionals all the way with <*>, >>=, <|>, and <>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would love to make OptionalValue generic in its Value (i.e. something like type OptionalValue[T any] interface { ... so that less downcasting is necessary in cases like these, but it seems like a lot of restructuring of code in order to make Go not complain about circular references in the visitor.

Copy link
Contributor

@dreamsmasher dreamsmasher left a comment

Choose a reason for hiding this comment

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

LGTM, what's currently missing compared to a full PR?

@dsainati1
Copy link
Contributor Author

LGTM, what's currently missing compared to a full PR?

Consensus on the FLIP. This is explicitly a draft implementation of the FLIP as it stands currently. If the FLIP were accepted with no changes today, then this PR would be good-to-go as-is, but if the API changes in the FLIP then the PR will need to be updated to reflect that.

dsainati1 and others added 4 commits October 3, 2022 14:57
Co-authored-by: Bastian Müller <bastian@axiomzen.co>
Co-authored-by: Bastian Müller <bastian@axiomzen.co>
Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Looks good, just a couple storage-related issues left.

Also, the documentation checkbox in the description can be marked as done, the PR contains documentation for the new feature 👍

runtime/interpreter/primitivestatictype.go Outdated Show resolved Hide resolved
runtime/interpreter/value.go Outdated Show resolved Hide resolved
runtime/stdlib/account.go Outdated Show resolved Hide resolved
runtime/stdlib/account.go Outdated Show resolved Hide resolved
Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Looks good! Only thing left is fixing the primitive static type constants

runtime/interpreter/primitivestatictype.go Outdated Show resolved Hide resolved
runtime/interpreter/encoding_test.go Outdated Show resolved Hide resolved
Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Nice work!

runtime/interpreter/statictype_test.go Show resolved Hide resolved
@turbolent
Copy link
Member

This is a rather large new feature, maybe hold off with merging this until we released the final version for the spork.
It would be good to test this more extensively, especially in terms of how this change handles existing data.

Copy link
Member

@SupunS SupunS left a comment

Choose a reason for hiding this comment

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

LGTM!

docs/language/accounts.mdx Outdated Show resolved Hide resolved
docs/language/accounts.mdx Outdated Show resolved Hide resolved
docs/language/core-events.md Outdated Show resolved Hide resolved
runtime/interpreter/accountinbox.go Outdated Show resolved Hide resolved
nil,
).(interpreter.AddressValue)

publishedValue := interpreter.NewPublishedValue(inter, recipient, value)
Copy link
Member

@SupunS SupunS Oct 5, 2022

Choose a reason for hiding this comment

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

Instead of transferring value and recipient separately, can we transfer the publishedValue at once?
Although, I'm not sure what the Transfer of PublishedValue is supposed to do/be-like, maybe @turbolent knows better.

Copy link
Member

@turbolent turbolent Oct 6, 2022

Choose a reason for hiding this comment

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

Yes, like noted above, Transfer would have to handle its children, like e.g. SomeValue.Transfer (or e.g. containers like Array)

Copy link
Member

Choose a reason for hiding this comment

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

just double-checking: was this added? couldn't find it in the newest commits

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh; I was interpreted @turbolent's comment to mean that this would be handled in the case where we generalized PublishedValue to be a container for arbitrary Value types in the future. I can submit another PR with this fix if that wasn't the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dsainati1 dsainati1 merged commit 1db2320 into master Oct 6, 2022
@dsainati1 dsainati1 deleted the sainati/1951-publish-claim branch October 6, 2022 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API for bootstrapping Capabilities
4 participants