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

Allows adding new interface conformances during a contract update #1395

Merged
merged 4 commits into from
Feb 3, 2022

Conversation

SupunS
Copy link
Member

@SupunS SupunS commented Feb 2, 2022

Work towards #1394

Description

This PR allows adding interface conformances during a contract update.

Removing existing conformances are continue to be not allowed.


  • 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

@codecov-commenter
Copy link

codecov-commenter commented Feb 2, 2022

Codecov Report

Merging #1395 (41d78ec) into master (d3124c5) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1395      +/-   ##
==========================================
+ Coverage   75.81%   75.84%   +0.02%     
==========================================
  Files         279      279              
  Lines       38780    38774       -6     
==========================================
+ Hits        29402    29407       +5     
+ Misses       8016     8007       -9     
+ Partials     1362     1360       -2     
Flag Coverage Δ
unittests 75.84% <100.00%> (+0.02%) ⬆️

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

Impacted Files Coverage Δ
runtime/errors.go 52.21% <ø> (+0.90%) ⬆️
runtime/contract_update_validation.go 79.21% <100.00%> (+3.15%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d3124c5...41d78ec. Read the comment docs.

@SupunS SupunS force-pushed the supun/conformance-restrictions branch from 494d614 to 41d78ec Compare February 2, 2022 23:24
@github-actions
Copy link

github-actions bot commented Feb 2, 2022

Cadence Benchstat comparison

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

Results

old.txtnew.txt
time/opdelta
QualifiedIdentifierCreation/One_level-22.79ns ± 2%2.86ns ± 4%+2.48%(p=0.048 n=7+7)
ParseDeploy/decode_hex-21.40ms ± 2%1.43ms ± 2%+2.04%(p=0.022 n=6+7)
RuntimeFungibleTokenTransfer-21.53ms ±26%1.57ms ±26%~(p=0.710 n=7+7)
RuntimeResourceDictionaryValues-216.9ms ± 1%17.2ms ± 3%~(p=0.180 n=6+6)
ParseDeploy/byte_array-229.8ms ± 6%30.5ms ± 3%~(p=0.445 n=7+6)
ParseArray-218.8ms ±19%18.3ms ± 5%~(p=0.902 n=7+7)
ParseFungibleToken-2218µs ± 3%226µs ± 7%~(p=0.051 n=6+7)
ParseInfix-211.6µs ± 4%11.7µs ± 2%~(p=0.731 n=7+6)
QualifiedIdentifierCreation/Three_levels-2170ns ± 4%169ns ± 3%~(p=0.874 n=7+7)
ContractInterfaceFungibleToken-250.2µs ± 9%47.5µs ± 3%~(p=0.097 n=7+7)
CheckContractInterfaceFungibleTokenConformance-2162µs ± 5%158µs ± 3%~(p=0.128 n=7+7)
InterpretRecursionFib-22.88ms ± 6%2.80ms ± 3%~(p=0.318 n=7+7)
NewInterpreter/new_interpreter-21.31µs ± 3%1.33µs ± 5%~(p=0.456 n=7+7)
NewInterpreter/new_sub-interpreter-22.58µs ± 4%2.64µs ± 7%~(p=0.737 n=7+7)
 
alloc/opdelta
RuntimeFungibleTokenTransfer-2277kB ± 0%277kB ± 0%~(p=0.383 n=7+7)
RuntimeResourceDictionaryValues-24.05MB ± 0%4.05MB ± 0%~(p=0.259 n=7+7)
QualifiedIdentifierCreation/One_level-20.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-264.0B ± 0%64.0B ± 0%~(all equal)
ContractInterfaceFungibleToken-226.5kB ± 0%26.5kB ± 0%~(p=0.592 n=7+7)
CheckContractInterfaceFungibleTokenConformance-265.7kB ± 0%65.7kB ± 0%~(p=0.462 n=7+7)
InterpretRecursionFib-21.24MB ± 0%1.24MB ± 0%~(p=0.254 n=7+7)
NewInterpreter/new_interpreter-2768B ± 0%768B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-21.24kB ± 0%1.24kB ± 0%~(all equal)
 
allocs/opdelta
RuntimeFungibleTokenTransfer-24.61k ± 0%4.61k ± 0%~(p=0.901 n=7+7)
RuntimeResourceDictionaryValues-2102k ± 0%102k ± 0%~(p=0.169 n=7+7)
QualifiedIdentifierCreation/One_level-20.00 0.00 ~(all equal)
QualifiedIdentifierCreation/Three_levels-22.00 ± 0%2.00 ± 0%~(all equal)
ContractInterfaceFungibleToken-2457 ± 0%457 ± 0%~(all equal)
CheckContractInterfaceFungibleTokenConformance-21.07k ± 0%1.07k ± 0%~(all equal)
InterpretRecursionFib-225.0k ± 0%25.0k ± 0%~(all equal)
NewInterpreter/new_interpreter-212.0 ± 0%12.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-238.0 ± 0%38.0 ± 0%~(all equal)
 

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.

Great work!

Comment on lines 507 to 509
for _, oldConformance := range oldConformances {
found := false
for _, newConformance := range newConformances {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can optimize the quadratic search here to avoid blow-up (in a follow-up PR). I guess because the outer loop break on first missing, it is actually OK?

Copy link
Member Author

Choose a reason for hiding this comment

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

Optimized it here: 3c22c34


err := deployAndUpdate(t, "Test1", oldCode, newCode)
require.NoError(t, err)
})
}

func TestConformanceChanges(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Good idea to add full runtime tests 👍

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!

Comment on lines +514 to +516
// Remove the matched conformance, so we don't have to check it again.
// i.e: optimization
newConformances = append(newConformances[:index], newConformances[index+1:]...)
Copy link
Member

Choose a reason for hiding this comment

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

Great idea! Double checked with https://go.dev/play/p/N233f-oGIDh, as I was not quite sure how modifying newConformances here affects the range over it / the inner loop

Copy link
Member Author

Choose a reason for hiding this comment

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

It always breaks from the inner-loop after modification, so should be safe. Thanks for double-checking!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants