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

Sync feature/atree-register-inlining-v1.0 with master #3351

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
2bbe2f6
Cadence 1.0 got merged into master, Emulator has been on Cadence 1.0 …
turbolent May 7, 2024
8bd7911
v1.0.0-preview.26
turbolent May 7, 2024
ee20f86
Merge pull request #3321 from onflow/release/v1.0.0-preview.26
turbolent May 7, 2024
e8315d5
Make migration error stack trace configurable
SupunS May 8, 2024
4bfebda
add reproducer
turbolent May 8, 2024
a9d1105
remove panic
turbolent May 8, 2024
beb77f2
report error if capability is issued with id 0
dsainati1 May 8, 2024
34ef697
Merge pull request #3322 from onflow/supun/disable-error-stacktraces
SupunS May 8, 2024
e52d5a5
Merge pull request #3325 from onflow/bastian/3323-fix-invalid-capabil…
turbolent May 8, 2024
dc924bd
fix borrowing of contract interface
turbolent May 8, 2024
b69571a
Merge pull request #3327 from onflow/bastian/3241-fix-contract-interf…
turbolent May 8, 2024
a90f1ac
cache the results of the static type migration
turbolent May 8, 2024
6bfcfb4
clean up
turbolent May 8, 2024
a0c136d
refactor static type tests to run test cases independently
turbolent May 8, 2024
f3f92ab
always cache result of entitlements migration, even when result is th…
turbolent May 8, 2024
0e6ae52
improve explanation why only parent is cached
turbolent May 8, 2024
81c7de9
cache migration errors
turbolent May 8, 2024
21f06f7
only cache at root type
turbolent May 8, 2024
64d069c
Merge pull request #3329 from onflow/bastian/3326-cache-static-type-m…
turbolent May 8, 2024
716e0c5
adding staged contracts migration report from TN state taken on May 8
j1010001 May 9, 2024
a4a2434
Merge pull request #3330 from onflow/jan/add-migrations-data
turbolent May 9, 2024
41f0300
Fix resource loss check in dictionary set-key
SupunS Apr 18, 2024
bb10009
port fixes to v0.42
dsainati1 Apr 30, 2024
63abc0f
apply suggested fixes
dsainati1 Apr 30, 2024
e0d5536
Fix merge
SupunS May 9, 2024
f73163c
Merge pull request #3319 from onflow/bastian/update-flow-go-related-c…
turbolent May 9, 2024
850c2db
Merge pull request #3331 from onflow/supun/port-fixes
SupunS May 9, 2024
b1700d5
handle missing interfaces in Cadence 1.0 contract update validator
turbolent May 13, 2024
f02a00f
Merge pull request #3337 from onflow/bastian/3336-fix-missing-interfa…
turbolent May 13, 2024
4297256
allow construction of paths with syntactically invalid identifiers
turbolent May 13, 2024
be70c5b
Merge pull request #3338 from onflow/bastian/improve-path-constructor
turbolent May 13, 2024
db70473
Check dictionary keys when checking the ability for dereferencing
SupunS Apr 30, 2024
a7082d9
Use parent to determine whether an expression is target of an invocation
SupunS Apr 19, 2024
97d55e5
Improve static validation of contract/transaction moves
SupunS Apr 22, 2024
28ecf17
Wrap host-functions with a bound-function for function-typed members …
SupunS Apr 23, 2024
814f29d
Add more tests
SupunS Apr 23, 2024
4fdc362
Rename host function constructor
SupunS May 1, 2024
6902a10
Always create BoundHostFunction values for value-methods
SupunS May 1, 2024
13bf1e2
Refactor and improve comments
SupunS May 2, 2024
f6ff979
Create bound functions for standard library functions
SupunS May 2, 2024
7fce2d9
Lint
SupunS May 14, 2024
6ca283e
Add invalidation for storage references
SupunS Apr 23, 2024
f072d74
Add more tests
SupunS Apr 23, 2024
09a03e7
add test for invalid transfer in execute
dsainati1 Apr 23, 2024
e608200
add test for recursive transfer
dsainati1 Apr 23, 2024
2b11bb1
prevent resource capture on the left
dsainati1 Apr 24, 2024
d0faf53
prevent capturing nested resources on the left of an assignment
dsainati1 Apr 24, 2024
3ee6a30
only report nested resource capture errors for transaction resources
dsainati1 Apr 24, 2024
d8240b4
update transfer test
dsainati1 Apr 25, 2024
9d2d882
add more tests
dsainati1 Apr 25, 2024
35b787c
fix tests
dsainati1 Apr 25, 2024
ac93894
apply suggested fixes
dsainati1 Apr 30, 2024
6701229
Undo exporting variables
SupunS May 14, 2024
781aadc
Bump atree version to v0.7.0-rc.2
fxamacker May 14, 2024
58d55aa
Merge pull request #3347 from onflow/fxamacker/bump-atree-version
fxamacker May 14, 2024
cb7627b
Add Storage.NondeterministicCommit for migrations
fxamacker May 14, 2024
25c2174
Merge pull request #3348 from onflow/fxamacker/add-nondeterministic-c…
fxamacker May 14, 2024
a0e71bd
Refactor
SupunS May 14, 2024
282c93c
Merge pull request #3339 from onflow/supun/port-229
SupunS May 14, 2024
49c7f8f
Merge pull request #3340 from onflow/supun/port-220
SupunS May 14, 2024
dc63152
Merge branch 'master' of https://github.com/onflow/cadence into supun…
SupunS May 14, 2024
321a305
Refactor
SupunS May 14, 2024
b2a8d8e
Remove invalid runtime test
SupunS May 14, 2024
fb35240
Merge pull request #3345 from onflow/supun/port-225
SupunS May 14, 2024
07a2143
Make linter happy
SupunS May 15, 2024
8b6e4b6
Merge pull request #3341 from onflow/supun/port-221
SupunS May 15, 2024
b2462eb
Improve comment
SupunS May 15, 2024
ba7c74c
Merge branch 'master' of https://github.com/onflow/cadence into supun…
SupunS May 15, 2024
6e3c6ee
Merge branch 'supun/port-222' of https://github.com/onflow/cadence in…
SupunS May 15, 2024
b7cafe9
Fix merge
SupunS May 15, 2024
b36c399
Merge pull request #3342 from onflow/supun/port-222
SupunS May 15, 2024
7584510
Merge branch 'master' of https://github.com/onflow/cadence into supun…
SupunS May 15, 2024
f420d12
Fix lint issues
SupunS May 15, 2024
e7fbb09
Merge pull request #3343 from onflow/supun/port-223
SupunS May 15, 2024
a7942a2
v1.0.0-preview.27
turbolent May 15, 2024
bb4542c
Merge pull request #3349 from onflow/release/v1.0.0-preview.27
turbolent May 15, 2024
986cb08
Merge branch 'master' into fxamacker/sync-atree-register-inlining-v1.0
fxamacker May 15, 2024
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
2 changes: 0 additions & 2 deletions .github/workflows/downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
uses: actions/checkout@v3
with:
repository: 'onflow/flow-go'
ref: ${{ github.base_ref == 'master' && 'feature/stable-cadence' || 'master' }}

- name: Setup Go
uses: actions/setup-go@v3
Expand All @@ -53,7 +52,6 @@ jobs:
uses: actions/checkout@v3
with:
repository: 'onflow/flow-emulator'
ref: ${{ github.base_ref == 'master' && 'master' || 'release/v0' }}

- name: Setup Go
uses: actions/setup-go@v3
Expand Down
30 changes: 23 additions & 7 deletions migrations/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ import (
"github.com/onflow/cadence/runtime/interpreter"
)

type CachedStaticType struct {
StaticType interpreter.StaticType
Error error
}

type StaticTypeCache interface {
Get(typeID interpreter.TypeID) (interpreter.StaticType, bool)
Set(typeID interpreter.TypeID, ty interpreter.StaticType)
Get(typeID interpreter.TypeID) (CachedStaticType, bool)
Set(
typeID interpreter.TypeID,
staticType interpreter.StaticType,
err error,
)
}

type DefaultStaticTypeCache struct {
Expand All @@ -37,14 +46,21 @@ func NewDefaultStaticTypeCache() *DefaultStaticTypeCache {
return &DefaultStaticTypeCache{}
}

func (c *DefaultStaticTypeCache) Get(typeID interpreter.TypeID) (interpreter.StaticType, bool) {
func (c *DefaultStaticTypeCache) Get(typeID interpreter.TypeID) (CachedStaticType, bool) {
v, ok := c.entries.Load(typeID)
if !ok {
return nil, false
return CachedStaticType{}, false
}
return v.(interpreter.StaticType), true
return v.(CachedStaticType), true
}

func (c *DefaultStaticTypeCache) Set(typeID interpreter.TypeID, ty interpreter.StaticType) {
c.entries.Store(typeID, ty)
func (c *DefaultStaticTypeCache) Set(
typeID interpreter.TypeID,
staticType interpreter.StaticType,
err error,
) {
c.entries.Store(typeID, CachedStaticType{
StaticType: staticType,
Error: err,
})
}
67 changes: 31 additions & 36 deletions migrations/entitlements/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (m EntitlementsMigration) ConvertToEntitledType(
staticType interpreter.StaticType,
) (
resultType interpreter.StaticType,
conversionErr error,
err error,
) {
if staticType == nil {
return nil, nil
Expand All @@ -89,13 +89,11 @@ func (m EntitlementsMigration) ConvertToEntitledType(
staticTypeID := staticType.ID()

if migratedType, exists := migratedTypeCache.Get(staticTypeID); exists {
return migratedType, nil
return migratedType.StaticType, migratedType.Error
}

defer func() {
if resultType != nil && conversionErr == nil {
migratedTypeCache.Set(staticTypeID, resultType)
}
migratedTypeCache.Set(staticTypeID, resultType, err)
}()

switch t := staticType.(type) {
Expand All @@ -105,8 +103,7 @@ func (m EntitlementsMigration) ConvertToEntitledType(

convertedReferencedType, err := m.ConvertToEntitledType(referencedType)
if err != nil {
conversionErr = err
return
return nil, err
}

var returnNew bool
Expand Down Expand Up @@ -164,96 +161,94 @@ func (m EntitlementsMigration) ConvertToEntitledType(
}

if returnNew {
resultType = interpreter.NewReferenceStaticType(nil, auth, referencedType)
return
return interpreter.NewReferenceStaticType(nil, auth, referencedType), nil
}

case *interpreter.CapabilityStaticType:
convertedBorrowType, err := m.ConvertToEntitledType(t.BorrowType)
if err != nil {
conversionErr = err
return
return nil, err
}

if convertedBorrowType != nil {
resultType = interpreter.NewCapabilityStaticType(nil, convertedBorrowType)
return
return interpreter.NewCapabilityStaticType(nil, convertedBorrowType), nil
}

case *interpreter.VariableSizedStaticType:
elementType := t.Type

convertedElementType, err := m.ConvertToEntitledType(elementType)
if err != nil {
conversionErr = err
return
return nil, err
}

if convertedElementType != nil {
resultType = interpreter.NewVariableSizedStaticType(nil, convertedElementType)
return
return interpreter.NewVariableSizedStaticType(nil, convertedElementType), nil
}

case *interpreter.ConstantSizedStaticType:
elementType := t.Type

convertedElementType, err := m.ConvertToEntitledType(elementType)
if err != nil {
conversionErr = err
return
return nil, err
}

if convertedElementType != nil {
resultType = interpreter.NewConstantSizedStaticType(nil, convertedElementType, t.Size)
return
return interpreter.NewConstantSizedStaticType(nil, convertedElementType, t.Size), nil
}

case *interpreter.DictionaryStaticType:
keyType := t.KeyType

convertedKeyType, err := m.ConvertToEntitledType(keyType)
if err != nil {
conversionErr = err
return
return nil, err
}

valueType := t.ValueType

convertedValueType, err := m.ConvertToEntitledType(valueType)
if err != nil {
conversionErr = err
return
return nil, err
}

if convertedKeyType != nil {
if convertedValueType != nil {
resultType = interpreter.NewDictionaryStaticType(nil, convertedKeyType, convertedValueType)
return
return interpreter.NewDictionaryStaticType(
nil,
convertedKeyType,
convertedValueType,
), nil
} else {
resultType = interpreter.NewDictionaryStaticType(nil, convertedKeyType, valueType)
return
return interpreter.NewDictionaryStaticType(
nil,
convertedKeyType,
valueType,
), nil
}
} else if convertedValueType != nil {
resultType = interpreter.NewDictionaryStaticType(nil, keyType, convertedValueType)
return
return interpreter.NewDictionaryStaticType(
nil,
keyType,
convertedValueType,
), nil
}

case *interpreter.OptionalStaticType:
innerType := t.Type

convertedInnerType, err := m.ConvertToEntitledType(innerType)
if err != nil {
conversionErr = err
return
return nil, err
}

if convertedInnerType != nil {
resultType = interpreter.NewOptionalStaticType(nil, convertedInnerType)
return
return interpreter.NewOptionalStaticType(nil, convertedInnerType), nil
}
}

return
return nil, nil
}

// ConvertValueToEntitlements converts the input value into a version compatible with the new entitlements feature,
Expand Down
22 changes: 19 additions & 3 deletions migrations/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type StorageMigration struct {
name string
address common.Address
dictionaryKeyConflicts int
stacktraceEnabled bool
}

func NewStorageMigration(
Expand All @@ -79,8 +80,13 @@ func NewStorageMigration(
}, nil
}

func (m *StorageMigration) WithErrorStacktrace(stacktraceEnabled bool) *StorageMigration {
m.stacktraceEnabled = stacktraceEnabled
return m
}

func (m *StorageMigration) Commit() error {
return m.storage.Commit(m.interpreter, false)
return m.storage.NondeterministicCommit(m.interpreter, false)
}

func (m *StorageMigration) Migrate(migrator StorageMapKeyMigrator) {
Expand Down Expand Up @@ -185,12 +191,17 @@ func (m *StorageMigration) MigrateNestedValue(
err = fmt.Errorf("%v", r)
}

var stack []byte
if m.stacktraceEnabled {
stack = debug.Stack()
}

err = StorageMigrationError{
StorageKey: storageKey,
StorageMapKey: storageMapKey,
Migration: m.name,
Err: err,
Stack: debug.Stack(),
Stack: stack,
}

if reporter != nil {
Expand Down Expand Up @@ -777,12 +788,17 @@ func (m *StorageMigration) migrate(
err = fmt.Errorf("%v", r)
}

var stack []byte
if m.stacktraceEnabled {
stack = debug.Stack()
}

err = StorageMigrationError{
StorageKey: storageKey,
StorageMapKey: storageMapKey,
Migration: migration.Name(),
Err: err,
Stack: debug.Stack(),
Stack: stack,
}
}
}()
Expand Down
2 changes: 2 additions & 0 deletions migrations/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,8 @@ func TestMigrationPanic(t *testing.T) {

reporter := newTestReporter()

migration = migration.WithErrorStacktrace(true)

migration.Migrate(
migration.NewValueMigrationsPathMigrator(
reporter,
Expand Down
5 changes: 3 additions & 2 deletions migrations/statictypes/account_type_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,14 +506,15 @@ func TestAccountTypeInTypeValueMigration(t *testing.T) {
StorageMapKey: storageMapKey,
}: {},
},
reporter.migrated)
reporter.migrated,
)
}

// Assert the migrated values.

storageMap := storage.GetStorageMap(account, pathDomain.Identifier(), false)
require.NotNil(t, storageMap)
require.Equal(t, storageMap.Count(), uint64(1))
require.Equal(t, uint64(1), storageMap.Count())

value := storageMap.ReadValue(nil, storageMapKey)

Expand Down
Loading
Loading