From 68065c62ac3b6447cd569b2e797793191273259c Mon Sep 17 00:00:00 2001 From: Faye Amacker <33205765+fxamacker@users.noreply.github.com> Date: Mon, 29 Jan 2024 09:58:15 -0600 Subject: [PATCH 1/3] Integrate Atree inlining & Cadence v0.42 to flow-go --- cmd/util/ledger/migrations/utils.go | 8 +- .../ledger/reporters/atree_decode_test.go | 2 +- .../util/migration_runtime_interface.go | 2 +- cmd/util/ledger/util/util.go | 20 ++-- .../state/bootstrap/bootstrap_test.go | 2 +- fvm/accounts_test.go | 2 +- fvm/environment/account_key_updater_test.go | 4 +- fvm/environment/accounts.go | 12 +-- fvm/environment/accounts_status.go | 6 +- fvm/environment/accounts_status_test.go | 4 +- fvm/environment/accounts_test.go | 14 +-- fvm/environment/mock/accounts.go | 12 +-- fvm/environment/mock/environment.go | 12 +-- fvm/environment/mock/value_store.go | 12 +-- fvm/environment/value_store.go | 20 ++-- fvm/evm/emulator/state/collection.go | 97 +++++++++++-------- fvm/evm/emulator/state/stateDB_test.go | 8 +- fvm/evm/testutils/backend.go | 28 +++--- fvm/evm/testutils/cadence.go | 20 ++-- go.mod | 4 +- go.sum | 8 +- insecure/go.mod | 4 +- insecure/go.sum | 8 +- integration/go.mod | 2 +- integration/go.sum | 4 +- model/flow/ledger_test.go | 2 +- utils/unittest/execution_state.go | 6 +- 27 files changed, 168 insertions(+), 155 deletions(-) diff --git a/cmd/util/ledger/migrations/utils.go b/cmd/util/ledger/migrations/utils.go index e747b3dc508..4ef30eb315c 100644 --- a/cmd/util/ledger/migrations/utils.go +++ b/cmd/util/ledger/migrations/utils.go @@ -51,11 +51,11 @@ func (a *AccountsAtreeLedger) ValueExists(owner, key []byte) (exists bool, err e return len(v) > 0, nil } -// AllocateStorageIndex allocates new storage index under the owner accounts to store a new register -func (a *AccountsAtreeLedger) AllocateStorageIndex(owner []byte) (atree.StorageIndex, error) { - v, err := a.Accounts.AllocateStorageIndex(flow.BytesToAddress(owner)) +// AllocateSlabIndex allocates new storage index under the owner accounts to store a new register +func (a *AccountsAtreeLedger) AllocateSlabIndex(owner []byte) (atree.SlabIndex, error) { + v, err := a.Accounts.AllocateSlabIndex(flow.BytesToAddress(owner)) if err != nil { - return atree.StorageIndex{}, fmt.Errorf("storage address allocation failed: %w", err) + return atree.SlabIndex{}, fmt.Errorf("storage address allocation failed: %w", err) } return v, nil } diff --git a/cmd/util/ledger/reporters/atree_decode_test.go b/cmd/util/ledger/reporters/atree_decode_test.go index 73b69a7e54b..8d06f1e28fa 100644 --- a/cmd/util/ledger/reporters/atree_decode_test.go +++ b/cmd/util/ledger/reporters/atree_decode_test.go @@ -145,7 +145,7 @@ func TestMapDataSlabCollisionCount(t *testing.T) { 0x82, 0x76, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x76, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, - // element: [hhhhhhhhhhhhhhhhhhhhhh:StorageID(1,2,3,4,5,6,7,8,0,0,0,0,0,0,0,4)] + // element: [hhhhhhhhhhhhhhhhhhhhhh:SlabID(1,2,3,4,5,6,7,8,0,0,0,0,0,0,0,4)] 0x82, 0x76, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0xd8, 0xff, 0x50, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, diff --git a/cmd/util/ledger/util/migration_runtime_interface.go b/cmd/util/ledger/util/migration_runtime_interface.go index c72d8493095..dbda3c5e964 100644 --- a/cmd/util/ledger/util/migration_runtime_interface.go +++ b/cmd/util/ledger/util/migration_runtime_interface.go @@ -242,7 +242,7 @@ func (m MigrationRuntimeInterface) GetAccountContractNames(_ runtime.Address) ([ panic("unexpected GetAccountContractNames call") } -func (m MigrationRuntimeInterface) AllocateStorageIndex(_ []byte) (atree.StorageIndex, error) { +func (m MigrationRuntimeInterface) AllocateStorageIndex(_ []byte) (atree.SlabIndex, error) { panic("unexpected AllocateStorageIndex call") } diff --git a/cmd/util/ledger/util/util.go b/cmd/util/ledger/util/util.go index 46cc54e6850..d05faf45cc3 100644 --- a/cmd/util/ledger/util/util.go +++ b/cmd/util/ledger/util/util.go @@ -55,11 +55,11 @@ func (a *AccountsAtreeLedger) ValueExists(owner, key []byte) (exists bool, err e return len(v) > 0, nil } -// AllocateStorageIndex allocates new storage index under the owner accounts to store a new register -func (a *AccountsAtreeLedger) AllocateStorageIndex(owner []byte) (atree.StorageIndex, error) { - v, err := a.Accounts.AllocateStorageIndex(flow.BytesToAddress(owner)) +// AllocateSlabIndex allocates new storage index under the owner accounts to store a new register +func (a *AccountsAtreeLedger) AllocateSlabIndex(owner []byte) (atree.SlabIndex, error) { + v, err := a.Accounts.AllocateSlabIndex(flow.BytesToAddress(owner)) if err != nil { - return atree.StorageIndex{}, fmt.Errorf("storage index allocation failed: %w", err) + return atree.SlabIndex{}, fmt.Errorf("storage index allocation failed: %w", err) } return v, nil } @@ -108,8 +108,8 @@ var _ common.MemoryGauge = (*NopMemoryGauge)(nil) type PayloadsReadonlyLedger struct { Snapshot *PayloadSnapshot - AllocateStorageIndexFunc func(owner []byte) (atree.StorageIndex, error) - SetValueFunc func(owner, key, value []byte) (err error) + AllocateSlabIndexFunc func(owner []byte) (atree.SlabIndex, error) + SetValueFunc func(owner, key, value []byte) (err error) } func (p *PayloadsReadonlyLedger) GetValue(owner, key []byte) (value []byte, err error) { @@ -133,12 +133,12 @@ func (p *PayloadsReadonlyLedger) ValueExists(owner, key []byte) (exists bool, er return ok, nil } -func (p *PayloadsReadonlyLedger) AllocateStorageIndex(owner []byte) (atree.StorageIndex, error) { - if p.AllocateStorageIndexFunc != nil { - return p.AllocateStorageIndexFunc(owner) +func (p *PayloadsReadonlyLedger) AllocateSlabIndex(owner []byte) (atree.SlabIndex, error) { + if p.AllocateSlabIndexFunc != nil { + return p.AllocateSlabIndexFunc(owner) } - panic("AllocateStorageIndex not expected to be called") + panic("AllocateSlabIndex not expected to be called") } func NewPayloadsReadonlyLedger(snapshot *PayloadSnapshot) *PayloadsReadonlyLedger { diff --git a/engine/execution/state/bootstrap/bootstrap_test.go b/engine/execution/state/bootstrap/bootstrap_test.go index 7ef8bc35d84..1f88475bdba 100644 --- a/engine/execution/state/bootstrap/bootstrap_test.go +++ b/engine/execution/state/bootstrap/bootstrap_test.go @@ -53,7 +53,7 @@ func TestBootstrapLedger(t *testing.T) { } func TestBootstrapLedger_ZeroTokenSupply(t *testing.T) { - expectedStateCommitmentBytes, _ := hex.DecodeString("8d9d52a66a832898f6f2416b703759b7ecd1eb390db6d5e727c2daeec001ffc6") + expectedStateCommitmentBytes, _ := hex.DecodeString("392f542db3a5e08acbbd96a84d40e79b3883f9ede2e8a04de9b9ae49d5446997") expectedStateCommitment, err := flow.ToStateCommitment(expectedStateCommitmentBytes) require.NoError(t, err) diff --git a/fvm/accounts_test.go b/fvm/accounts_test.go index 02613379e73..69cc7130927 100644 --- a/fvm/accounts_test.go +++ b/fvm/accounts_test.go @@ -1606,7 +1606,7 @@ func TestAccountBalanceFields(t *testing.T) { _, output, err = vm.Run(ctx, script, snapshotTree) assert.NoError(t, err) assert.NoError(t, output.Err) - assert.Equal(t, cadence.UFix64(99_993_040), output.Value) + assert.Equal(t, cadence.UFix64(99_993_750), output.Value) }), ) diff --git a/fvm/environment/account_key_updater_test.go b/fvm/environment/account_key_updater_test.go index 61bb4c00d7d..79b3385972e 100644 --- a/fvm/environment/account_key_updater_test.go +++ b/fvm/environment/account_key_updater_test.go @@ -217,8 +217,8 @@ func (f FakeAccounts) Create(_ []flow.AccountPublicKey, _ flow.Address) error { func (f FakeAccounts) GetValue(_ flow.RegisterID) (flow.RegisterValue, error) { return nil, nil } func (f FakeAccounts) GetStorageUsed(_ flow.Address) (uint64, error) { return 0, nil } func (f FakeAccounts) SetValue(_ flow.RegisterID, _ []byte) error { return nil } -func (f FakeAccounts) AllocateStorageIndex(_ flow.Address) (atree.StorageIndex, error) { - return atree.StorageIndex{}, nil +func (f FakeAccounts) AllocateSlabIndex(_ flow.Address) (atree.SlabIndex, error) { + return atree.SlabIndex{}, nil } func (f FakeAccounts) GenerateAccountLocalID(address flow.Address) (uint64, error) { return 0, nil diff --git a/fvm/environment/accounts.go b/fvm/environment/accounts.go index b6ca1bd2d0a..50abfb174d8 100644 --- a/fvm/environment/accounts.go +++ b/fvm/environment/accounts.go @@ -36,7 +36,7 @@ type Accounts interface { GetValue(id flow.RegisterID) (flow.RegisterValue, error) GetStorageUsed(address flow.Address) (uint64, error) SetValue(id flow.RegisterID, value flow.RegisterValue) error - AllocateStorageIndex(address flow.Address) (atree.StorageIndex, error) + AllocateSlabIndex(address flow.Address) (atree.SlabIndex, error) GenerateAccountLocalID(address flow.Address) (uint64, error) } @@ -52,16 +52,16 @@ func NewAccounts(txnState state.NestedTransactionPreparer) *StatefulAccounts { } } -func (a *StatefulAccounts) AllocateStorageIndex( +func (a *StatefulAccounts) AllocateSlabIndex( address flow.Address, ) ( - atree.StorageIndex, + atree.SlabIndex, error, ) { // get status status, err := a.getAccountStatus(address) if err != nil { - return atree.StorageIndex{}, err + return atree.SlabIndex{}, err } // get and increment the index @@ -79,7 +79,7 @@ func (a *StatefulAccounts) AllocateStorageIndex( []byte{}) }) if err != nil { - return atree.StorageIndex{}, fmt.Errorf( + return atree.SlabIndex{}, fmt.Errorf( "failed to allocate an storage index: %w", err) } @@ -88,7 +88,7 @@ func (a *StatefulAccounts) AllocateStorageIndex( status.SetStorageIndex(newIndexBytes) err = a.setAccountStatus(address, status) if err != nil { - return atree.StorageIndex{}, fmt.Errorf( + return atree.SlabIndex{}, fmt.Errorf( "failed to allocate an storage index: %w", err) } diff --git a/fvm/environment/accounts_status.go b/fvm/environment/accounts_status.go index a420051550f..93c9a81db6e 100644 --- a/fvm/environment/accounts_status.go +++ b/fvm/environment/accounts_status.go @@ -105,13 +105,13 @@ func (a *AccountStatus) StorageUsed() uint64 { } // SetStorageIndex updates the storage index of the account -func (a *AccountStatus) SetStorageIndex(index atree.StorageIndex) { +func (a *AccountStatus) SetStorageIndex(index atree.SlabIndex) { copy(a[storageIndexStartIndex:storageIndexStartIndex+storageIndexSize], index[:storageIndexSize]) } // StorageIndex returns the storage index of the account -func (a *AccountStatus) StorageIndex() atree.StorageIndex { - var index atree.StorageIndex +func (a *AccountStatus) StorageIndex() atree.SlabIndex { + var index atree.SlabIndex copy(index[:], a[storageIndexStartIndex:storageIndexStartIndex+storageIndexSize]) return index } diff --git a/fvm/environment/accounts_status_test.go b/fvm/environment/accounts_status_test.go index 543ee2b05f1..4ab3c9c1ee5 100644 --- a/fvm/environment/accounts_status_test.go +++ b/fvm/environment/accounts_status_test.go @@ -15,7 +15,7 @@ func TestAccountStatus(t *testing.T) { s := environment.NewAccountStatus() t.Run("test setting values", func(t *testing.T) { - index := atree.StorageIndex{1, 2, 3, 4, 5, 6, 7, 8} + index := atree.SlabIndex{1, 2, 3, 4, 5, 6, 7, 8} s.SetStorageIndex(index) s.SetPublicKeyCount(34) s.SetStorageUsed(56) @@ -58,7 +58,7 @@ func TestAccountStatus(t *testing.T) { migrated, err := environment.AccountStatusFromBytes(oldBytes) require.NoError(t, err) - require.Equal(t, atree.StorageIndex{0, 0, 0, 0, 0, 0, 0, 6}, migrated.StorageIndex()) + require.Equal(t, atree.SlabIndex{0, 0, 0, 0, 0, 0, 0, 6}, migrated.StorageIndex()) require.Equal(t, uint64(5), migrated.PublicKeyCount()) require.Equal(t, uint64(7)+increaseInSize, migrated.StorageUsed()) require.Equal(t, uint64(0), migrated.AccountIdCounter()) diff --git a/fvm/environment/accounts_test.go b/fvm/environment/accounts_test.go index c6ef3cce467..aea1c564eca 100644 --- a/fvm/environment/accounts_test.go +++ b/fvm/environment/accounts_test.go @@ -413,7 +413,7 @@ func createByteArray(size int) []byte { return bytes } -func TestAccounts_AllocateStorageIndex(t *testing.T) { +func TestAccounts_AllocateSlabIndex(t *testing.T) { txnState := testutils.NewSimpleTransaction(nil) accounts := environment.NewAccounts(txnState) address := flow.HexToAddress("01") @@ -422,17 +422,17 @@ func TestAccounts_AllocateStorageIndex(t *testing.T) { require.NoError(t, err) // no register set case - i, err := accounts.AllocateStorageIndex(address) + i, err := accounts.AllocateSlabIndex(address) require.NoError(t, err) - require.Equal(t, i, atree.StorageIndex([8]byte{0, 0, 0, 0, 0, 0, 0, 1})) + require.Equal(t, i, atree.SlabIndex([8]byte{0, 0, 0, 0, 0, 0, 0, 1})) // register already set case - i, err = accounts.AllocateStorageIndex(address) + i, err = accounts.AllocateSlabIndex(address) require.NoError(t, err) - require.Equal(t, i, atree.StorageIndex([8]byte{0, 0, 0, 0, 0, 0, 0, 2})) + require.Equal(t, i, atree.SlabIndex([8]byte{0, 0, 0, 0, 0, 0, 0, 2})) // register update successful - i, err = accounts.AllocateStorageIndex(address) + i, err = accounts.AllocateSlabIndex(address) require.NoError(t, err) - require.Equal(t, i, atree.StorageIndex([8]byte{0, 0, 0, 0, 0, 0, 0, 3})) + require.Equal(t, i, atree.SlabIndex([8]byte{0, 0, 0, 0, 0, 0, 0, 3})) } diff --git a/fvm/environment/mock/accounts.go b/fvm/environment/mock/accounts.go index ee4656a4be8..413a25b9b4e 100644 --- a/fvm/environment/mock/accounts.go +++ b/fvm/environment/mock/accounts.go @@ -15,20 +15,20 @@ type Accounts struct { mock.Mock } -// AllocateStorageIndex provides a mock function with given fields: address -func (_m *Accounts) AllocateStorageIndex(address flow.Address) (atree.StorageIndex, error) { +// AllocateSlabIndex provides a mock function with given fields: address +func (_m *Accounts) AllocateSlabIndex(address flow.Address) (atree.SlabIndex, error) { ret := _m.Called(address) - var r0 atree.StorageIndex + var r0 atree.SlabIndex var r1 error - if rf, ok := ret.Get(0).(func(flow.Address) (atree.StorageIndex, error)); ok { + if rf, ok := ret.Get(0).(func(flow.Address) (atree.SlabIndex, error)); ok { return rf(address) } - if rf, ok := ret.Get(0).(func(flow.Address) atree.StorageIndex); ok { + if rf, ok := ret.Get(0).(func(flow.Address) atree.SlabIndex); ok { r0 = rf(address) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(atree.StorageIndex) + r0 = ret.Get(0).(atree.SlabIndex) } } diff --git a/fvm/environment/mock/environment.go b/fvm/environment/mock/environment.go index da65b863989..6c54806f3fa 100644 --- a/fvm/environment/mock/environment.go +++ b/fvm/environment/mock/environment.go @@ -136,20 +136,20 @@ func (_m *Environment) AddEncodedAccountKey(address common.Address, publicKey [] return r0 } -// AllocateStorageIndex provides a mock function with given fields: owner -func (_m *Environment) AllocateStorageIndex(owner []byte) (atree.StorageIndex, error) { +// AllocateSlabIndex provides a mock function with given fields: owner +func (_m *Environment) AllocateSlabIndex(owner []byte) (atree.SlabIndex, error) { ret := _m.Called(owner) - var r0 atree.StorageIndex + var r0 atree.SlabIndex var r1 error - if rf, ok := ret.Get(0).(func([]byte) (atree.StorageIndex, error)); ok { + if rf, ok := ret.Get(0).(func([]byte) (atree.SlabIndex, error)); ok { return rf(owner) } - if rf, ok := ret.Get(0).(func([]byte) atree.StorageIndex); ok { + if rf, ok := ret.Get(0).(func([]byte) atree.SlabIndex); ok { r0 = rf(owner) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(atree.StorageIndex) + r0 = ret.Get(0).(atree.SlabIndex) } } diff --git a/fvm/environment/mock/value_store.go b/fvm/environment/mock/value_store.go index acfc3918545..59c54d7dac2 100644 --- a/fvm/environment/mock/value_store.go +++ b/fvm/environment/mock/value_store.go @@ -13,20 +13,20 @@ type ValueStore struct { mock.Mock } -// AllocateStorageIndex provides a mock function with given fields: owner -func (_m *ValueStore) AllocateStorageIndex(owner []byte) (atree.StorageIndex, error) { +// AllocateSlabIndex provides a mock function with given fields: owner +func (_m *ValueStore) AllocateSlabIndex(owner []byte) (atree.SlabIndex, error) { ret := _m.Called(owner) - var r0 atree.StorageIndex + var r0 atree.SlabIndex var r1 error - if rf, ok := ret.Get(0).(func([]byte) (atree.StorageIndex, error)); ok { + if rf, ok := ret.Get(0).(func([]byte) (atree.SlabIndex, error)); ok { return rf(owner) } - if rf, ok := ret.Get(0).(func([]byte) atree.StorageIndex); ok { + if rf, ok := ret.Get(0).(func([]byte) atree.SlabIndex); ok { r0 = rf(owner) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(atree.StorageIndex) + r0 = ret.Get(0).(atree.SlabIndex) } } diff --git a/fvm/environment/value_store.go b/fvm/environment/value_store.go index 8113de6762c..4f768378500 100644 --- a/fvm/environment/value_store.go +++ b/fvm/environment/value_store.go @@ -20,7 +20,7 @@ type ValueStore interface { ValueExists(owner []byte, key []byte) (bool, error) - AllocateStorageIndex(owner []byte) (atree.StorageIndex, error) + AllocateSlabIndex(owner []byte) (atree.SlabIndex, error) } type ParseRestrictedValueStore struct { @@ -82,16 +82,16 @@ func (store ParseRestrictedValueStore) ValueExists( key) } -func (store ParseRestrictedValueStore) AllocateStorageIndex( +func (store ParseRestrictedValueStore) AllocateSlabIndex( owner []byte, ) ( - atree.StorageIndex, + atree.SlabIndex, error, ) { return parseRestrict1Arg1Ret( store.txnState, trace.FVMEnvAllocateStorageIndex, - store.impl.AllocateStorageIndex, + store.impl.AllocateSlabIndex, owner) } @@ -189,26 +189,26 @@ func (store *valueStore) ValueExists( return len(v) > 0, nil } -// AllocateStorageIndex allocates new storage index under the owner accounts +// AllocateSlabIndex allocates new storage index under the owner accounts // to store a new register. -func (store *valueStore) AllocateStorageIndex( +func (store *valueStore) AllocateSlabIndex( owner []byte, ) ( - atree.StorageIndex, + atree.SlabIndex, error, ) { defer store.tracer.StartChildSpan(trace.FVMEnvAllocateStorageIndex).End() err := store.meter.MeterComputation(ComputationKindAllocateStorageIndex, 1) if err != nil { - return atree.StorageIndex{}, fmt.Errorf( + return atree.SlabIndex{}, fmt.Errorf( "allocate storage index failed: %w", err) } - v, err := store.accounts.AllocateStorageIndex(flow.BytesToAddress(owner)) + v, err := store.accounts.AllocateSlabIndex(flow.BytesToAddress(owner)) if err != nil { - return atree.StorageIndex{}, fmt.Errorf( + return atree.SlabIndex{}, fmt.Errorf( "storage address allocation failed: %w", err) } diff --git a/fvm/evm/emulator/state/collection.go b/fvm/evm/emulator/state/collection.go index b2bb605c903..58d8f7fd862 100644 --- a/fvm/evm/emulator/state/collection.go +++ b/fvm/evm/emulator/state/collection.go @@ -47,16 +47,16 @@ func NewCollectionProvider( // calling twice for the same collection might result in odd-behaviours // currently collection provider doesn't do any internal caching to protect aginast these cases func (cp *CollectionProvider) CollectionByID(collectionID []byte) (*Collection, error) { - storageID, err := atree.NewStorageIDFromRawBytes(collectionID) + slabID, err := atree.NewSlabIDFromRawBytes(collectionID) if err != nil { return nil, err } - // sanity check the storage ID address - if storageID.Address != cp.rootAddr { - return nil, fmt.Errorf("root address mismatch %x != %x", storageID.Address, cp.rootAddr) - } + // TODO: sanity check the slab ID address + // if slabID.Address != cp.rootAddr { + // return nil, fmt.Errorf("root address mismatch %x != %x", storageID.Address, cp.rootAddr) + // } - omap, err := atree.NewMapWithRootID(cp.storage, storageID, atree.NewDefaultDigesterBuilder()) + omap, err := atree.NewMapWithRootID(cp.storage, slabID, atree.NewDefaultDigesterBuilder()) if err != nil { return nil, err } @@ -74,7 +74,7 @@ func (cp *CollectionProvider) NewCollection() (*Collection, error) { return nil, err } storageIDBytes := make([]byte, storageIDSize) - _, err = omap.StorageID().ToRawBytes(storageIDBytes) + _, err = omap.SlabID().ToRawBytes(storageIDBytes) if err != nil { return nil, err } @@ -110,7 +110,7 @@ func (c *Collection) CollectionID() []byte { // // if key doesn't exist it returns nil (no error) func (c *Collection) Get(key []byte) ([]byte, error) { - data, err := c.omap.Get(compare, hashInputProvider, NewByteStringValue(key)) + value, err := c.omap.Get(compare, hashInputProvider, NewByteStringValue(key)) if err != nil { var keyNotFoundError *atree.KeyNotFoundError if errors.As(err, &keyNotFoundError) { @@ -119,11 +119,6 @@ func (c *Collection) Get(key []byte) ([]byte, error) { return nil, err } - value, err := data.StoredValue(c.omap.Storage) - if err != nil { - return nil, err - } - return value.(ByteStringValue).Bytes(), nil } @@ -136,9 +131,9 @@ func (c *Collection) Set(key, value []byte) error { return err } - if id, ok := existingValueStorable.(atree.StorageIDStorable); ok { + if id, ok := existingValueStorable.(atree.SlabIDStorable); ok { // NOTE: deep remove isn't necessary because value is ByteStringValue (not container) - err := c.storage.Remove(atree.StorageID(id)) + err := c.storage.Remove(atree.SlabID(id)) if err != nil { return err } @@ -159,9 +154,9 @@ func (c *Collection) Remove(key []byte) error { return err } - if id, ok := existingValueStorable.(atree.StorageIDStorable); ok { + if id, ok := existingValueStorable.(atree.SlabIDStorable); ok { // NOTE: deep remove isn't necessary because value is ByteStringValue (not container) - err := c.storage.Remove(atree.StorageID(id)) + err := c.storage.Remove(atree.SlabID(id)) if err != nil { return err } @@ -175,8 +170,8 @@ func (c *Collection) Destroy() ([][]byte, error) { keys := make([][]byte, c.omap.Count()) i := 0 err := c.omap.PopIterate(func(keyStorable atree.Storable, valueStorable atree.Storable) { - if id, ok := valueStorable.(atree.StorageIDStorable); ok { - err := c.storage.Remove(atree.StorageID(id)) + if id, ok := valueStorable.(atree.SlabIDStorable); ok { + err := c.storage.Remove(atree.SlabID(id)) if err != nil && cachedErr == nil { cachedErr = err } @@ -194,7 +189,7 @@ func (c *Collection) Destroy() ([][]byte, error) { if err != nil { return keys, err } - return keys, c.storage.Remove(c.omap.StorageID()) + return keys, c.storage.Remove(c.omap.SlabID()) } type ByteStringValue struct { @@ -224,24 +219,7 @@ func (v ByteStringValue) Storable(storage atree.SlabStorage, address atree.Addre } // Create StorableSlab - id, err := storage.GenerateStorageID(address) - if err != nil { - return nil, err - } - - slab := &atree.StorableSlab{ - StorageID: id, - Storable: v, - } - - // Store StorableSlab in storage - err = storage.Store(id, slab) - if err != nil { - return nil, err - } - - // Return storage id as storable - return atree.StorageIDStorable(id), nil + return atree.NewStorableSlab(storage, address, v) } func (v ByteStringValue) Encode(enc *atree.Encoder) error { @@ -306,7 +284,7 @@ func (v ByteStringValue) Bytes() []byte { return v.data } -func decodeStorable(dec *cbor.StreamDecoder, _ atree.StorageID) (atree.Storable, error) { +func decodeStorable(dec *cbor.StreamDecoder, slabID atree.SlabID, inlinedExtraData []atree.ExtraData) (atree.Storable, error) { t, err := dec.NextType() if err != nil { return nil, err @@ -328,8 +306,31 @@ func decodeStorable(dec *cbor.StreamDecoder, _ atree.StorageID) (atree.Storable, switch tagNumber { - case atree.CBORTagStorageID: - return atree.DecodeStorageIDStorable(dec) + case atree.CBORTagSlabID: + return atree.DecodeSlabIDStorable(dec) + + case atree.CBORTagInlinedArray: + return atree.DecodeInlinedArrayStorable( + dec, + decodeStorable, + slabID, + inlinedExtraData) + + case atree.CBORTagInlinedMap: + return atree.DecodeInlinedMapStorable( + dec, + decodeStorable, + slabID, + inlinedExtraData, + ) + + case atree.CBORTagInlinedCompactMap: + return atree.DecodeInlinedCompactMapStorable( + dec, + decodeStorable, + slabID, + inlinedExtraData, + ) default: return nil, fmt.Errorf("invalid tag number %d", tagNumber) @@ -398,11 +399,23 @@ type emptyTypeInfo struct{} var _ atree.TypeInfo = emptyTypeInfo{} +func (emptyTypeInfo) IsComposite() bool { + return false +} + +func (emptyTypeInfo) Identifier() string { + return "" +} + +func (e emptyTypeInfo) Copy() atree.TypeInfo { + return e +} + func (emptyTypeInfo) Encode(e *cbor.StreamEncoder) error { return e.EncodeNil() } -func (i emptyTypeInfo) Equal(other atree.TypeInfo) bool { +func (emptyTypeInfo) Equal(other atree.TypeInfo) bool { _, ok := other.(emptyTypeInfo) return ok } diff --git a/fvm/evm/emulator/state/stateDB_test.go b/fvm/evm/emulator/state/stateDB_test.go index 2d45395a72e..866aabba9e5 100644 --- a/fvm/evm/emulator/state/stateDB_test.go +++ b/fvm/evm/emulator/state/stateDB_test.go @@ -247,8 +247,8 @@ func TestStateDB(t *testing.T) { SetValueFunc: func(owner, key, value []byte) error { return atree.NewUserError(fmt.Errorf("key not found")) }, - AllocateStorageIndexFunc: func(owner []byte) (atree.StorageIndex, error) { - return atree.StorageIndex{}, nil + AllocateSlabIndexFunc: func(owner []byte) (atree.SlabIndex, error) { + return atree.SlabIndex{}, nil }, } db, err := state.NewStateDB(ledger, rootAddr) @@ -271,8 +271,8 @@ func TestStateDB(t *testing.T) { SetValueFunc: func(owner, key, value []byte) error { return atree.NewFatalError(fmt.Errorf("key not found")) }, - AllocateStorageIndexFunc: func(owner []byte) (atree.StorageIndex, error) { - return atree.StorageIndex{}, nil + AllocateSlabIndexFunc: func(owner []byte) (atree.SlabIndex, error) { + return atree.SlabIndex{}, nil }, } db, err := state.NewStateDB(ledger, rootAddr) diff --git a/fvm/evm/testutils/backend.go b/fvm/evm/testutils/backend.go index fc08d84aad8..c8948872f39 100644 --- a/fvm/evm/testutils/backend.go +++ b/fvm/evm/testutils/backend.go @@ -73,14 +73,14 @@ func GetSimpleValueStore() *TestValueStore { bytesRead += len(fk) + len(value) return len(value) > 0, nil }, - AllocateStorageIndexFunc: func(owner []byte) (atree.StorageIndex, error) { + AllocateSlabIndexFunc: func(owner []byte) (atree.SlabIndex, error) { index := allocator[string(owner)] var data [8]byte allocator[string(owner)] = index + 1 binary.BigEndian.PutUint64(data[:], index) bytesRead += len(owner) + 8 bytesWritten += len(owner) + 8 - return atree.StorageIndex(data), nil + return atree.SlabIndex(data), nil }, TotalStorageSizeFunc: func() int { size := 0 @@ -170,15 +170,15 @@ func (tb *TestBackend) DropEvents() { } type TestValueStore struct { - GetValueFunc func(owner, key []byte) ([]byte, error) - SetValueFunc func(owner, key, value []byte) error - ValueExistsFunc func(owner, key []byte) (bool, error) - AllocateStorageIndexFunc func(owner []byte) (atree.StorageIndex, error) - TotalStorageSizeFunc func() int - TotalBytesReadFunc func() int - TotalBytesWrittenFunc func() int - TotalStorageItemsFunc func() int - ResetStatsFunc func() + GetValueFunc func(owner, key []byte) ([]byte, error) + SetValueFunc func(owner, key, value []byte) error + ValueExistsFunc func(owner, key []byte) (bool, error) + AllocateSlabIndexFunc func(owner []byte) (atree.SlabIndex, error) + TotalStorageSizeFunc func() int + TotalBytesReadFunc func() int + TotalBytesWrittenFunc func() int + TotalStorageItemsFunc func() int + ResetStatsFunc func() } var _ environment.ValueStore = &TestValueStore{} @@ -204,11 +204,11 @@ func (vs *TestValueStore) ValueExists(owner, key []byte) (bool, error) { return vs.ValueExistsFunc(owner, key) } -func (vs *TestValueStore) AllocateStorageIndex(owner []byte) (atree.StorageIndex, error) { - if vs.AllocateStorageIndexFunc == nil { +func (vs *TestValueStore) AllocateSlabIndex(owner []byte) (atree.SlabIndex, error) { + if vs.AllocateSlabIndexFunc == nil { panic("method not set") } - return vs.AllocateStorageIndexFunc(owner) + return vs.AllocateSlabIndexFunc(owner) } func (vs *TestValueStore) TotalBytesRead() int { diff --git a/fvm/evm/testutils/cadence.go b/fvm/evm/testutils/cadence.go index a35070c3f69..cfcfeeadb41 100644 --- a/fvm/evm/testutils/cadence.go +++ b/fvm/evm/testutils/cadence.go @@ -80,11 +80,11 @@ func EncodeArgs(argValues []cadence.Value) [][]byte { } type TestLedger struct { - StoredValues map[string][]byte - OnValueExists func(owner, key []byte) (exists bool, err error) - OnGetValue func(owner, key []byte) (value []byte, err error) - OnSetValue func(owner, key, value []byte) (err error) - OnAllocateStorageIndex func(owner []byte) (atree.StorageIndex, error) + StoredValues map[string][]byte + OnValueExists func(owner, key []byte) (exists bool, err error) + OnGetValue func(owner, key []byte) (value []byte, err error) + OnSetValue func(owner, key, value []byte) (err error) + OnAllocateSlabIndex func(owner []byte) (atree.SlabIndex, error) } var _ atree.Ledger = TestLedger{} @@ -101,8 +101,8 @@ func (s TestLedger) ValueExists(owner, key []byte) (exists bool, err error) { return s.OnValueExists(owner, key) } -func (s TestLedger) AllocateStorageIndex(owner []byte) (atree.StorageIndex, error) { - return s.OnAllocateStorageIndex(owner) +func (s TestLedger) AllocateSlabIndex(owner []byte) (atree.SlabIndex, error) { + return s.OnAllocateSlabIndex(owner) } func (s TestLedger) Dump() { @@ -147,7 +147,7 @@ func NewTestLedger( } return nil }, - OnAllocateStorageIndex: func(owner []byte) (result atree.StorageIndex, err error) { + OnAllocateSlabIndex: func(owner []byte) (result atree.SlabIndex, err error) { index := storageIndices[string(owner)] + 1 storageIndices[string(owner)] = index binary.BigEndian.PutUint64(result[:], index) @@ -330,8 +330,8 @@ func (i *TestRuntimeInterface) SetValue(owner, key, value []byte) (err error) { return i.Storage.SetValue(owner, key, value) } -func (i *TestRuntimeInterface) AllocateStorageIndex(owner []byte) (atree.StorageIndex, error) { - return i.Storage.AllocateStorageIndex(owner) +func (i *TestRuntimeInterface) AllocateSlabIndex(owner []byte) (atree.SlabIndex, error) { + return i.Storage.AllocateSlabIndex(owner) } func (i *TestRuntimeInterface) CreateAccount(payer runtime.Address) (address runtime.Address, err error) { diff --git a/go.mod b/go.mod index 7a66c8ec8a5..a4b38ce459b 100644 --- a/go.mod +++ b/go.mod @@ -47,8 +47,8 @@ require ( github.com/multiformats/go-multiaddr v0.12.2 github.com/multiformats/go-multiaddr-dns v0.3.1 github.com/multiformats/go-multihash v0.2.3 - github.com/onflow/atree v0.6.0 - github.com/onflow/cadence v0.42.11 + github.com/onflow/atree v0.8.0-rc.3 + github.com/onflow/cadence v0.42.11-atree-register-inlining.2.0.20240521221904-9615ee937719 github.com/onflow/flow v0.3.4 github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.1-0.20231219201108-fbdb10b0a2da github.com/onflow/flow-core-contracts/lib/go/templates v0.15.1-0.20231219201108-fbdb10b0a2da diff --git a/go.sum b/go.sum index 6664d0fba74..b6cb0752dd0 100644 --- a/go.sum +++ b/go.sum @@ -993,13 +993,13 @@ github.com/olekukonko/tablewriter v0.0.2-0.20190409134802-7e037d187b0c/go.mod h1 github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onflow/atree v0.1.0-beta1.0.20211027184039-559ee654ece9/go.mod h1:+6x071HgCF/0v5hQcaE5qqjc2UqN5gCU8h5Mk6uqpOg= -github.com/onflow/atree v0.6.0 h1:j7nQ2r8npznx4NX39zPpBYHmdy45f4xwoi+dm37Jk7c= -github.com/onflow/atree v0.6.0/go.mod h1:gBHU0M05qCbv9NN0kijLWMgC47gHVNBIp4KmsVFi0tc= +github.com/onflow/atree v0.8.0-rc.3 h1:BHVkJLrBHhHo7ET8gkuS1+lyQGNekYYOyoICGK3RFNM= +github.com/onflow/atree v0.8.0-rc.3/go.mod h1:7YNAyCd5JENq+NzH+fR1ABUZVzbSq9dkt0+5fZH3L2A= github.com/onflow/boxo v0.0.0-20240201202436-f2477b92f483 h1:LpiQhTAfM9CAmNVEs0n//cBBgCg+vJSiIxTHYUklZ84= github.com/onflow/boxo v0.0.0-20240201202436-f2477b92f483/go.mod h1:pIZgTWdm3k3pLF9Uq6MB8JEcW07UDwNJjlXW1HELW80= github.com/onflow/cadence v0.20.1/go.mod h1:7mzUvPZUIJztIbr9eTvs+fQjWWHTF8veC+yk4ihcNIA= -github.com/onflow/cadence v0.42.11 h1:ybyO3oCNEiFqLimwJyC6e2USxA84qP8mu3OhhPOA0D0= -github.com/onflow/cadence v0.42.11/go.mod h1:1wFd+LiNiN6qoZXof3MBdpM6d8BsxbVIxOA77LbIYmE= +github.com/onflow/cadence v0.42.11-atree-register-inlining.2.0.20240521221904-9615ee937719 h1:A2Z8OK5NtJ4n6NRK2Oz65z8y0gRTcTslKG1vQy+wwck= +github.com/onflow/cadence v0.42.11-atree-register-inlining.2.0.20240521221904-9615ee937719/go.mod h1:/qhvKrT4aNmq/cy5ngna493EljQvonQBYjyrbOELHUk= github.com/onflow/flow v0.3.4 h1:FXUWVdYB90f/rjNcY0Owo30gL790tiYff9Pb/sycXYE= github.com/onflow/flow v0.3.4/go.mod h1:lzyAYmbu1HfkZ9cfnL5/sjrrsnJiUU8fRL26CqLP7+c= github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.1-0.20231219201108-fbdb10b0a2da h1:8CEioYNnP0rwjnRbKDgs8SmiQTsdaroeX4d/Q3pQuh4= diff --git a/insecure/go.mod b/insecure/go.mod index 00a0c961944..bf46edc18d2 100644 --- a/insecure/go.mod +++ b/insecure/go.mod @@ -196,8 +196,8 @@ require ( github.com/multiformats/go-varint v0.0.7 // indirect github.com/nxadm/tail v1.4.8 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect - github.com/onflow/atree v0.6.0 // indirect - github.com/onflow/cadence v0.42.11 // indirect + github.com/onflow/atree v0.8.0-rc.3 // indirect + github.com/onflow/cadence v0.42.11-atree-register-inlining.2.0.20240521221904-9615ee937719 // indirect github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.1-0.20231219201108-fbdb10b0a2da // indirect github.com/onflow/flow-core-contracts/lib/go/templates v0.15.1-0.20231219201108-fbdb10b0a2da // indirect github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20230711213910-baad011d2b13 // indirect diff --git a/insecure/go.sum b/insecure/go.sum index af824e1c60c..6d807f89c4b 100644 --- a/insecure/go.sum +++ b/insecure/go.sum @@ -970,11 +970,11 @@ github.com/olekukonko/tablewriter v0.0.2-0.20190409134802-7e037d187b0c/go.mod h1 github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onflow/atree v0.1.0-beta1.0.20211027184039-559ee654ece9/go.mod h1:+6x071HgCF/0v5hQcaE5qqjc2UqN5gCU8h5Mk6uqpOg= -github.com/onflow/atree v0.6.0 h1:j7nQ2r8npznx4NX39zPpBYHmdy45f4xwoi+dm37Jk7c= -github.com/onflow/atree v0.6.0/go.mod h1:gBHU0M05qCbv9NN0kijLWMgC47gHVNBIp4KmsVFi0tc= +github.com/onflow/atree v0.8.0-rc.3 h1:BHVkJLrBHhHo7ET8gkuS1+lyQGNekYYOyoICGK3RFNM= +github.com/onflow/atree v0.8.0-rc.3/go.mod h1:7YNAyCd5JENq+NzH+fR1ABUZVzbSq9dkt0+5fZH3L2A= github.com/onflow/cadence v0.20.1/go.mod h1:7mzUvPZUIJztIbr9eTvs+fQjWWHTF8veC+yk4ihcNIA= -github.com/onflow/cadence v0.42.11 h1:ybyO3oCNEiFqLimwJyC6e2USxA84qP8mu3OhhPOA0D0= -github.com/onflow/cadence v0.42.11/go.mod h1:1wFd+LiNiN6qoZXof3MBdpM6d8BsxbVIxOA77LbIYmE= +github.com/onflow/cadence v0.42.11-atree-register-inlining.2.0.20240521221904-9615ee937719 h1:A2Z8OK5NtJ4n6NRK2Oz65z8y0gRTcTslKG1vQy+wwck= +github.com/onflow/cadence v0.42.11-atree-register-inlining.2.0.20240521221904-9615ee937719/go.mod h1:/qhvKrT4aNmq/cy5ngna493EljQvonQBYjyrbOELHUk= github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.1-0.20231219201108-fbdb10b0a2da h1:8CEioYNnP0rwjnRbKDgs8SmiQTsdaroeX4d/Q3pQuh4= github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.1-0.20231219201108-fbdb10b0a2da/go.mod h1:WHp24VkUQfcfZi0XjI1uRVRt5alM5SHVkwOil1U2Tpc= github.com/onflow/flow-core-contracts/lib/go/templates v0.15.1-0.20231219201108-fbdb10b0a2da h1:V2zI6AfDtPykMGhgw69ZEGcvyMudRUFOVHYCMN4BbQo= diff --git a/integration/go.mod b/integration/go.mod index 4fd7d00cfe7..0963a3ebdad 100644 --- a/integration/go.mod +++ b/integration/go.mod @@ -242,7 +242,7 @@ require ( github.com/multiformats/go-multistream v0.5.0 // indirect github.com/multiformats/go-varint v0.0.7 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect - github.com/onflow/atree v0.6.0 // indirect + github.com/onflow/atree v0.8.0-rc.3 // indirect github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20230711213910-baad011d2b13 // indirect github.com/onflow/flow-nft/lib/go/contracts v1.1.0 // indirect github.com/onflow/nft-storefront/lib/go/contracts v0.0.0-20221222181731-14b90207cead // indirect diff --git a/integration/go.sum b/integration/go.sum index 16f4e98b4c6..892fe70e47c 100644 --- a/integration/go.sum +++ b/integration/go.sum @@ -965,8 +965,8 @@ github.com/olekukonko/tablewriter v0.0.2-0.20190409134802-7e037d187b0c/go.mod h1 github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onflow/atree v0.1.0-beta1.0.20211027184039-559ee654ece9/go.mod h1:+6x071HgCF/0v5hQcaE5qqjc2UqN5gCU8h5Mk6uqpOg= -github.com/onflow/atree v0.6.0 h1:j7nQ2r8npznx4NX39zPpBYHmdy45f4xwoi+dm37Jk7c= -github.com/onflow/atree v0.6.0/go.mod h1:gBHU0M05qCbv9NN0kijLWMgC47gHVNBIp4KmsVFi0tc= +github.com/onflow/atree v0.8.0-rc.3 h1:BHVkJLrBHhHo7ET8gkuS1+lyQGNekYYOyoICGK3RFNM= +github.com/onflow/atree v0.8.0-rc.3/go.mod h1:7YNAyCd5JENq+NzH+fR1ABUZVzbSq9dkt0+5fZH3L2A= github.com/onflow/cadence v0.20.1/go.mod h1:7mzUvPZUIJztIbr9eTvs+fQjWWHTF8veC+yk4ihcNIA= github.com/onflow/cadence v0.42.11 h1:ybyO3oCNEiFqLimwJyC6e2USxA84qP8mu3OhhPOA0D0= github.com/onflow/cadence v0.42.11/go.mod h1:1wFd+LiNiN6qoZXof3MBdpM6d8BsxbVIxOA77LbIYmE= diff --git a/model/flow/ledger_test.go b/model/flow/ledger_test.go index b287c3d3bb0..f188e1625cf 100644 --- a/model/flow/ledger_test.go +++ b/model/flow/ledger_test.go @@ -87,7 +87,7 @@ func TestRegisterID_IsInternalState(t *testing.T) { func TestRegisterID_String(t *testing.T) { t.Run("atree slab", func(t *testing.T) { // slab with 189 should result in \\xbd - slabIndex := atree.StorageIndex([8]byte{0, 0, 0, 0, 0, 0, 0, 189}) + slabIndex := atree.SlabIndex([8]byte{0, 0, 0, 0, 0, 0, 0, 189}) id := flow.NewRegisterID( flow.BytesToAddress([]byte{1, 2, 3, 10}), diff --git a/utils/unittest/execution_state.go b/utils/unittest/execution_state.go index f8e227f32ad..ba55225fc48 100644 --- a/utils/unittest/execution_state.go +++ b/utils/unittest/execution_state.go @@ -24,7 +24,7 @@ const ServiceAccountPrivateKeySignAlgo = crypto.ECDSAP256 const ServiceAccountPrivateKeyHashAlgo = hash.SHA2_256 // Pre-calculated state commitment with root account with the above private key -const GenesisStateCommitmentHex = "e4674bba14f59af783bbf70b2a43c1696a7d9888eeaca86cf74b033580fe1c23" +const GenesisStateCommitmentHex = "8fc77d82c5d75a0245d895eab22483f398cf7220e594bbc9a132a79885e5ae90" var GenesisStateCommitment flow.StateCommitment @@ -88,10 +88,10 @@ func genesisCommitHexByChainID(chainID flow.ChainID) string { return GenesisStateCommitmentHex } if chainID == flow.Testnet { - return "bfe964655cf13711b93dbaf156aaebbc24a607beed69dd36d71b593832b5129c" + return "b0576092e923680d0ffe501e3a2ab322829847f783685ce155b59831f4201303" } if chainID == flow.Sandboxnet { return "e1c08b17f9e5896f03fe28dd37ca396c19b26628161506924fbf785834646ea1" } - return "a56a2750708bc981eb949a3b02a41061dc6b7e6bfa9f31a19a48f560f616bed3" + return "007505a38a93e5e1c2267bcf1b7811b7553340458ea6d0f46efe0bfd3127a183" } From 9efe85dc03a86658912d12f6db1dbc01c8c89c2b Mon Sep 17 00:00:00 2001 From: Faye Amacker <33205765+fxamacker@users.noreply.github.com> Date: Thu, 18 Apr 2024 22:46:51 -0500 Subject: [PATCH 2/3] Check slab ID address --- fvm/evm/emulator/state/collection.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/fvm/evm/emulator/state/collection.go b/fvm/evm/emulator/state/collection.go index 58d8f7fd862..057e126666e 100644 --- a/fvm/evm/emulator/state/collection.go +++ b/fvm/evm/emulator/state/collection.go @@ -51,10 +51,14 @@ func (cp *CollectionProvider) CollectionByID(collectionID []byte) (*Collection, if err != nil { return nil, err } - // TODO: sanity check the slab ID address - // if slabID.Address != cp.rootAddr { - // return nil, fmt.Errorf("root address mismatch %x != %x", storageID.Address, cp.rootAddr) - // } + + // sanity check the slab ID address + var address atree.Address + binary.BigEndian.PutUint64(address[:], slabID.AddressAsUint64()) + + if address != cp.rootAddr { + return nil, fmt.Errorf("root address mismatch %x != %x", address, cp.rootAddr) + } omap, err := atree.NewMapWithRootID(cp.storage, slabID, atree.NewDefaultDigesterBuilder()) if err != nil { From b57feb5436f3bfbd46cbf810a1b6ae54b774a12b Mon Sep 17 00:00:00 2001 From: Faye Amacker <33205765+fxamacker@users.noreply.github.com> Date: Wed, 22 May 2024 18:54:43 -0500 Subject: [PATCH 3/3] Bump Cadence version in integration --- integration/go.mod | 2 +- integration/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integration/go.mod b/integration/go.mod index 0963a3ebdad..14ba645250e 100644 --- a/integration/go.mod +++ b/integration/go.mod @@ -19,7 +19,7 @@ require ( github.com/ipfs/go-datastore v0.6.0 github.com/ipfs/go-ds-badger2 v0.1.3 github.com/libp2p/go-libp2p v0.32.2 - github.com/onflow/cadence v0.42.11 + github.com/onflow/cadence v0.42.11-atree-register-inlining.2.0.20240521221904-9615ee937719 github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.1-0.20231219201108-fbdb10b0a2da github.com/onflow/flow-core-contracts/lib/go/templates v0.15.1-0.20231219201108-fbdb10b0a2da github.com/onflow/flow-emulator v0.59.0 diff --git a/integration/go.sum b/integration/go.sum index 892fe70e47c..98da69e7042 100644 --- a/integration/go.sum +++ b/integration/go.sum @@ -968,8 +968,8 @@ github.com/onflow/atree v0.1.0-beta1.0.20211027184039-559ee654ece9/go.mod h1:+6x github.com/onflow/atree v0.8.0-rc.3 h1:BHVkJLrBHhHo7ET8gkuS1+lyQGNekYYOyoICGK3RFNM= github.com/onflow/atree v0.8.0-rc.3/go.mod h1:7YNAyCd5JENq+NzH+fR1ABUZVzbSq9dkt0+5fZH3L2A= github.com/onflow/cadence v0.20.1/go.mod h1:7mzUvPZUIJztIbr9eTvs+fQjWWHTF8veC+yk4ihcNIA= -github.com/onflow/cadence v0.42.11 h1:ybyO3oCNEiFqLimwJyC6e2USxA84qP8mu3OhhPOA0D0= -github.com/onflow/cadence v0.42.11/go.mod h1:1wFd+LiNiN6qoZXof3MBdpM6d8BsxbVIxOA77LbIYmE= +github.com/onflow/cadence v0.42.11-atree-register-inlining.2.0.20240521221904-9615ee937719 h1:A2Z8OK5NtJ4n6NRK2Oz65z8y0gRTcTslKG1vQy+wwck= +github.com/onflow/cadence v0.42.11-atree-register-inlining.2.0.20240521221904-9615ee937719/go.mod h1:/qhvKrT4aNmq/cy5ngna493EljQvonQBYjyrbOELHUk= github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.1-0.20231219201108-fbdb10b0a2da h1:8CEioYNnP0rwjnRbKDgs8SmiQTsdaroeX4d/Q3pQuh4= github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.1-0.20231219201108-fbdb10b0a2da/go.mod h1:WHp24VkUQfcfZi0XjI1uRVRt5alM5SHVkwOil1U2Tpc= github.com/onflow/flow-core-contracts/lib/go/templates v0.15.1-0.20231219201108-fbdb10b0a2da h1:V2zI6AfDtPykMGhgw69ZEGcvyMudRUFOVHYCMN4BbQo=