Skip to content

Commit 6eacaf0

Browse files
Merge branch 'master' into sre/jp/703/add-folder-config-to-transit
2 parents 73b65ae + 74c199e commit 6eacaf0

20 files changed

+588
-595
lines changed

cmd/util/ledger/migrations/add_key_migration.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@ func (m *AddKeyMigration) MigrateAccount(
149149

150150
flowAddress := flow.ConvertAddress(address)
151151

152-
keyIndex, err := migrationRuntime.Accounts.GetPublicKeyCount(flowAddress)
152+
keyIndex, err := migrationRuntime.Accounts.GetAccountPublicKeyCount(flowAddress)
153153
if err != nil {
154154
return fmt.Errorf("failed to get public key count: %w", err)
155155
}
156156

157-
err = migrationRuntime.Accounts.AppendPublicKey(flowAddress, key)
157+
err = migrationRuntime.Accounts.AppendAccountPublicKey(flowAddress, key)
158158
if err != nil {
159159
return fmt.Errorf("failed to append public key: %w", err)
160160
}

cmd/util/ledger/migrations/storage_used_migration_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func TestAccountStatusMigration(t *testing.T) {
9595

9696
require.Equal(t, sizeOfTheStatusPayload, accountStatus.StorageUsed())
9797
require.Equal(t, atree.SlabIndex{0, 0, 0, 0, 0, 0, 0, 6}, accountStatus.SlabIndex())
98-
require.Equal(t, uint32(5), accountStatus.PublicKeyCount())
98+
require.Equal(t, uint32(5), accountStatus.AccountPublicKeyCount())
9999
require.Equal(t, uint64(0), accountStatus.AccountIdCounter())
100100
})
101101
t.Run("status register v2", func(t *testing.T) {
@@ -123,7 +123,7 @@ func TestAccountStatusMigration(t *testing.T) {
123123

124124
require.Equal(t, sizeOfTheStatusPayload, accountStatus.StorageUsed())
125125
require.Equal(t, atree.SlabIndex{0, 0, 0, 0, 0, 0, 0, 6}, accountStatus.SlabIndex())
126-
require.Equal(t, uint32(5), accountStatus.PublicKeyCount())
126+
require.Equal(t, uint32(5), accountStatus.AccountPublicKeyCount())
127127
require.Equal(t, uint64(3), accountStatus.AccountIdCounter())
128128
})
129129

@@ -152,7 +152,7 @@ func TestAccountStatusMigration(t *testing.T) {
152152

153153
require.Equal(t, sizeOfTheStatusPayload, accountStatus.StorageUsed())
154154
require.Equal(t, atree.SlabIndex{0, 0, 0, 0, 0, 0, 0, 6}, accountStatus.SlabIndex())
155-
require.Equal(t, uint32(5), accountStatus.PublicKeyCount())
155+
require.Equal(t, uint32(5), accountStatus.AccountPublicKeyCount())
156156
require.Equal(t, uint64(3), accountStatus.AccountIdCounter())
157157
})
158158

@@ -202,7 +202,7 @@ func TestAccountStatusMigration(t *testing.T) {
202202

203203
require.Equal(t, sizeOfTheStatusPayload+dataRegisterSize, accountStatus.StorageUsed())
204204
require.Equal(t, atree.SlabIndex{0, 0, 0, 0, 0, 0, 0, 6}, accountStatus.SlabIndex())
205-
require.Equal(t, uint32(5), accountStatus.PublicKeyCount())
205+
require.Equal(t, uint32(5), accountStatus.AccountPublicKeyCount())
206206
require.Equal(t, uint64(3), accountStatus.AccountIdCounter())
207207
})
208208
}

fvm/environment/account_info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func (info *accountInfo) GetAccountKeys(
312312
) {
313313
defer info.tracer.StartChildSpan(trace.FVMEnvGetAccountKeys).End()
314314

315-
accountKeys, err := info.accounts.GetPublicKeys(address)
315+
accountKeys, err := info.accounts.GetAccountPublicKeys(address)
316316

317317
if err != nil {
318318
return nil, err
@@ -330,7 +330,7 @@ func (info *accountInfo) GetAccountKeyByIndex(
330330
) {
331331
defer info.tracer.StartChildSpan(trace.FVMEnvGetAccountKey).End()
332332

333-
accountKey, err := info.accounts.GetPublicKey(address, index)
333+
accountKey, err := info.accounts.GetAccountPublicKey(address, index)
334334

335335
if err != nil {
336336
return nil, err

fvm/environment/account_key_reader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (reader *accountKeyReader) GetAccountKey(
120120
address := flow.ConvertAddress(runtimeAddress)
121121

122122
// address verification is also done in this step
123-
accountPublicKey, err := reader.accounts.GetPublicKey(
123+
accountPublicKey, err := reader.accounts.GetAccountPublicKey(
124124
address,
125125
keyIndex)
126126
if err != nil {
@@ -167,7 +167,7 @@ func (reader *accountKeyReader) AccountKeysCount(
167167
}
168168

169169
// address verification is also done in this step
170-
keyCount, err := reader.accounts.GetPublicKeyCount(
170+
keyCount, err := reader.accounts.GetAccountPublicKeyCount(
171171
flow.ConvertAddress(runtimeAddress))
172172

173173
return keyCount, err

fvm/environment/account_key_updater.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func (updater *accountKeyUpdater) addAccountKey(
237237
errors.NewAccountNotFoundError(address))
238238
}
239239

240-
keyIndex, err := updater.accounts.GetPublicKeyCount(address)
240+
keyIndex, err := updater.accounts.GetAccountPublicKeyCount(address)
241241
if err != nil {
242242
return nil, fmt.Errorf("adding account key failed: %w", err)
243243
}
@@ -251,7 +251,7 @@ func (updater *accountKeyUpdater) addAccountKey(
251251
return nil, fmt.Errorf("adding account key failed: %w", err)
252252
}
253253

254-
err = updater.accounts.AppendPublicKey(address, *accountPublicKey)
254+
err = updater.accounts.AppendAccountPublicKey(address, *accountPublicKey)
255255
if err != nil {
256256
return nil, fmt.Errorf("adding account key failed: %w", err)
257257
}
@@ -293,7 +293,7 @@ func (updater *accountKeyUpdater) revokeAccountKey(
293293
}
294294

295295
var publicKey flow.AccountPublicKey
296-
publicKey, err = updater.accounts.GetPublicKey(
296+
publicKey, err = updater.accounts.GetAccountPublicKey(
297297
address,
298298
keyIndex)
299299
if err != nil {
@@ -310,7 +310,7 @@ func (updater *accountKeyUpdater) revokeAccountKey(
310310
// mark this key as revoked
311311
publicKey.Revoked = true
312312

313-
_, err = updater.accounts.SetPublicKey(
313+
_, err = updater.accounts.SetAccountPublicKey(
314314
address,
315315
keyIndex,
316316
publicKey)

fvm/environment/account_key_updater_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,23 @@ var _ environment.Accounts = &FakeAccounts{}
151151

152152
func (f FakeAccounts) Exists(address flow.Address) (bool, error) { return true, nil }
153153
func (f FakeAccounts) Get(address flow.Address) (*flow.Account, error) { return &flow.Account{}, nil }
154-
func (f FakeAccounts) GetPublicKeyCount(_ flow.Address) (uint32, error) {
154+
func (f FakeAccounts) GetAccountPublicKeyCount(_ flow.Address) (uint32, error) {
155155
return f.keyCount, nil
156156
}
157-
func (f FakeAccounts) AppendPublicKey(_ flow.Address, _ flow.AccountPublicKey) error { return nil }
158-
func (f FakeAccounts) GetPublicKey(address flow.Address, keyIndex uint32) (flow.AccountPublicKey, error) {
157+
func (f FakeAccounts) AppendAccountPublicKey(_ flow.Address, _ flow.AccountPublicKey) error {
158+
return nil
159+
}
160+
func (f FakeAccounts) GetAccountPublicKey(address flow.Address, keyIndex uint32) (flow.AccountPublicKey, error) {
159161
if keyIndex >= f.keyCount {
160162
return flow.AccountPublicKey{}, errors.NewAccountPublicKeyNotFoundError(address, keyIndex)
161163
}
162164
return FakePublicKey{}.toAccountPublicKey(), nil
163165
}
164166

165-
func (f FakeAccounts) SetPublicKey(_ flow.Address, _ uint32, _ flow.AccountPublicKey) ([]byte, error) {
167+
func (f FakeAccounts) SetAccountPublicKey(_ flow.Address, _ uint32, _ flow.AccountPublicKey) ([]byte, error) {
166168
return nil, nil
167169
}
168-
func (f FakeAccounts) GetPublicKeys(address flow.Address) ([]flow.AccountPublicKey, error) {
170+
func (f FakeAccounts) GetAccountPublicKeys(address flow.Address) ([]flow.AccountPublicKey, error) {
169171
return make([]flow.AccountPublicKey, f.keyCount), nil
170172
}
171173
func (f FakeAccounts) GetContractNames(_ flow.Address) ([]string, error) { return nil, nil }

fvm/environment/accounts.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ const (
2323
type Accounts interface {
2424
Exists(address flow.Address) (bool, error)
2525
Get(address flow.Address) (*flow.Account, error)
26-
GetPublicKeyCount(address flow.Address) (uint32, error)
27-
AppendPublicKey(address flow.Address, key flow.AccountPublicKey) error
28-
GetPublicKey(address flow.Address, keyIndex uint32) (flow.AccountPublicKey, error)
29-
SetPublicKey(address flow.Address, keyIndex uint32, publicKey flow.AccountPublicKey) ([]byte, error)
30-
GetPublicKeys(address flow.Address) ([]flow.AccountPublicKey, error)
26+
GetAccountPublicKeyCount(address flow.Address) (uint32, error)
27+
AppendAccountPublicKey(address flow.Address, key flow.AccountPublicKey) error
28+
GetAccountPublicKey(address flow.Address, keyIndex uint32) (flow.AccountPublicKey, error)
29+
SetAccountPublicKey(address flow.Address, keyIndex uint32, publicKey flow.AccountPublicKey) ([]byte, error)
30+
GetAccountPublicKeys(address flow.Address) ([]flow.AccountPublicKey, error)
3131
GetContractNames(address flow.Address) ([]string, error)
3232
GetContract(contractName string, address flow.Address) ([]byte, error)
3333
ContractExists(contractName string, address flow.Address) (bool, error)
@@ -124,7 +124,7 @@ func (a *StatefulAccounts) Get(address flow.Address) (*flow.Account, error) {
124124
}
125125

126126
var publicKeys []flow.AccountPublicKey
127-
publicKeys, err = a.GetPublicKeys(address)
127+
publicKeys, err = a.GetAccountPublicKeys(address)
128128
if err != nil {
129129
return nil, err
130130
}
@@ -181,10 +181,10 @@ func (a *StatefulAccounts) Create(
181181
return fmt.Errorf("failed to create a new account: %w", err)
182182
}
183183

184-
return a.SetAllPublicKeys(newAddress, publicKeys)
184+
return a.SetAllAccountPublicKeys(newAddress, publicKeys)
185185
}
186186

187-
func (a *StatefulAccounts) GetPublicKey(
187+
func (a *StatefulAccounts) GetAccountPublicKey(
188188
address flow.Address,
189189
keyIndex uint32,
190190
) (
@@ -212,7 +212,7 @@ func (a *StatefulAccounts) GetPublicKey(
212212
return decodedPublicKey, nil
213213
}
214214

215-
func (a *StatefulAccounts) GetPublicKeyCount(
215+
func (a *StatefulAccounts) GetAccountPublicKeyCount(
216216
address flow.Address,
217217
) (
218218
uint32,
@@ -222,7 +222,7 @@ func (a *StatefulAccounts) GetPublicKeyCount(
222222
if err != nil {
223223
return 0, fmt.Errorf("failed to get public key count: %w", err)
224224
}
225-
return status.PublicKeyCount(), nil
225+
return status.AccountPublicKeyCount(), nil
226226
}
227227

228228
func (a *StatefulAccounts) setPublicKeyCount(
@@ -237,7 +237,7 @@ func (a *StatefulAccounts) setPublicKeyCount(
237237
err)
238238
}
239239

240-
status.SetPublicKeyCount(count)
240+
status.SetAccountPublicKeyCount(count)
241241

242242
err = a.setAccountStatus(address, status)
243243
if err != nil {
@@ -249,20 +249,20 @@ func (a *StatefulAccounts) setPublicKeyCount(
249249
return nil
250250
}
251251

252-
func (a *StatefulAccounts) GetPublicKeys(
252+
func (a *StatefulAccounts) GetAccountPublicKeys(
253253
address flow.Address,
254254
) (
255255
publicKeys []flow.AccountPublicKey,
256256
err error,
257257
) {
258-
count, err := a.GetPublicKeyCount(address)
258+
count, err := a.GetAccountPublicKeyCount(address)
259259
if err != nil {
260260
return nil, err
261261
}
262262
publicKeys = make([]flow.AccountPublicKey, count)
263263

264264
for i := uint32(0); i < count; i++ {
265-
publicKey, err := a.GetPublicKey(address, i)
265+
publicKey, err := a.GetAccountPublicKey(address, i)
266266
if err != nil {
267267
return nil, err
268268
}
@@ -273,7 +273,7 @@ func (a *StatefulAccounts) GetPublicKeys(
273273
return publicKeys, nil
274274
}
275275

276-
func (a *StatefulAccounts) SetPublicKey(
276+
func (a *StatefulAccounts) SetAccountPublicKey(
277277
address flow.Address,
278278
keyIndex uint32,
279279
publicKey flow.AccountPublicKey,
@@ -303,7 +303,7 @@ func (a *StatefulAccounts) SetPublicKey(
303303
return encodedPublicKey, err
304304
}
305305

306-
func (a *StatefulAccounts) SetAllPublicKeys(
306+
func (a *StatefulAccounts) SetAllAccountPublicKeys(
307307
address flow.Address,
308308
publicKeys []flow.AccountPublicKey,
309309
) error {
@@ -318,7 +318,7 @@ func (a *StatefulAccounts) SetAllPublicKeys(
318318
}
319319

320320
for i, publicKey := range publicKeys {
321-
_, err := a.SetPublicKey(address, uint32(i), publicKey)
321+
_, err := a.SetAccountPublicKey(address, uint32(i), publicKey)
322322
if err != nil {
323323
return err
324324
}
@@ -327,7 +327,7 @@ func (a *StatefulAccounts) SetAllPublicKeys(
327327
return a.setPublicKeyCount(address, count)
328328
}
329329

330-
func (a *StatefulAccounts) AppendPublicKey(
330+
func (a *StatefulAccounts) AppendAccountPublicKey(
331331
address flow.Address,
332332
publicKey flow.AccountPublicKey,
333333
) error {
@@ -344,7 +344,7 @@ func (a *StatefulAccounts) AppendPublicKey(
344344
"signature algorithm type not found")
345345
}
346346

347-
count, err := a.GetPublicKeyCount(address)
347+
count, err := a.GetAccountPublicKeyCount(address)
348348
if err != nil {
349349
return err
350350
}
@@ -356,7 +356,7 @@ func (a *StatefulAccounts) AppendPublicKey(
356356
MaxPublicKeyCount)
357357
}
358358

359-
_, err = a.SetPublicKey(address, count, publicKey)
359+
_, err = a.SetAccountPublicKey(address, count, publicKey)
360360
if err != nil {
361361
return err
362362
}

fvm/environment/accounts_status.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ import (
1111
)
1212

1313
const (
14-
flagSize = 1
15-
storageUsedSize = 8
16-
storageIndexSize = 8
17-
oldPublicKeyCountsSize = 8
18-
publicKeyCountsSize = 4
19-
addressIdCounterSize = 8
14+
flagSize = 1
15+
storageUsedSize = 8
16+
storageIndexSize = 8
17+
oldAccountPublicKeyCountsSize = 8
18+
accountPublicKeyCountsSize = 4
19+
addressIdCounterSize = 8
2020

2121
// accountStatusSizeV1 is the size of the account status before the address
2222
// id counter was added. After Crescendo check if it can be removed as all accounts
2323
// should then have the new status sile len.
2424
accountStatusSizeV1 = flagSize +
2525
storageUsedSize +
2626
storageIndexSize +
27-
oldPublicKeyCountsSize
27+
oldAccountPublicKeyCountsSize
2828

2929
// accountStatusSizeV2 is the size of the account status before
3030
// the public key count was changed from 8 to 4 bytes long.
@@ -33,20 +33,20 @@ const (
3333
accountStatusSizeV2 = flagSize +
3434
storageUsedSize +
3535
storageIndexSize +
36-
oldPublicKeyCountsSize +
36+
oldAccountPublicKeyCountsSize +
3737
addressIdCounterSize
3838

3939
accountStatusSizeV3 = flagSize +
4040
storageUsedSize +
4141
storageIndexSize +
42-
publicKeyCountsSize +
42+
accountPublicKeyCountsSize +
4343
addressIdCounterSize
4444

45-
flagIndex = 0
46-
storageUsedStartIndex = flagIndex + flagSize
47-
storageIndexStartIndex = storageUsedStartIndex + storageUsedSize
48-
publicKeyCountsStartIndex = storageIndexStartIndex + storageIndexSize
49-
addressIdCounterStartIndex = publicKeyCountsStartIndex + publicKeyCountsSize
45+
flagIndex = 0
46+
storageUsedStartIndex = flagIndex + flagSize
47+
storageIndexStartIndex = storageUsedStartIndex + storageUsedSize
48+
accountPublicKeyCountsStartIndex = storageIndexStartIndex + storageIndexSize
49+
addressIdCounterStartIndex = accountPublicKeyCountsStartIndex + accountPublicKeyCountsSize
5050
)
5151

5252
// AccountStatus holds meta information about an account
@@ -118,7 +118,7 @@ func AccountStatusFromBytes(inp []byte) (*AccountStatus, error) {
118118
cutEnd := flagSize +
119119
storageUsedSize +
120120
storageIndexSize +
121-
(oldPublicKeyCountsSize - publicKeyCountsSize)
121+
(oldAccountPublicKeyCountsSize - accountPublicKeyCountsSize)
122122

123123
// check if the public key count is larger than 4 bytes
124124
for i := cutStart; i < cutEnd; i++ {
@@ -128,7 +128,7 @@ func AccountStatusFromBytes(inp []byte) (*AccountStatus, error) {
128128
storageIndexSize:flagSize+
129129
storageUsedSize+
130130
storageIndexSize+
131-
oldPublicKeyCountsSize]), inp2[i])
131+
oldAccountPublicKeyCountsSize]), inp2[i])
132132
}
133133
}
134134

@@ -192,14 +192,14 @@ func (a *AccountStatus) SlabIndex() atree.SlabIndex {
192192
return index
193193
}
194194

195-
// SetPublicKeyCount updates the public key count of the account
196-
func (a *AccountStatus) SetPublicKeyCount(count uint32) {
197-
binary.BigEndian.PutUint32(a[publicKeyCountsStartIndex:publicKeyCountsStartIndex+publicKeyCountsSize], count)
195+
// SetAccountPublicKeyCount updates the account public key count of the account
196+
func (a *AccountStatus) SetAccountPublicKeyCount(count uint32) {
197+
binary.BigEndian.PutUint32(a[accountPublicKeyCountsStartIndex:accountPublicKeyCountsStartIndex+accountPublicKeyCountsSize], count)
198198
}
199199

200-
// PublicKeyCount returns the public key count of the account
201-
func (a *AccountStatus) PublicKeyCount() uint32 {
202-
return binary.BigEndian.Uint32(a[publicKeyCountsStartIndex : publicKeyCountsStartIndex+publicKeyCountsSize])
200+
// AccountPublicKeyCount returns the account public key count of the account
201+
func (a *AccountStatus) AccountPublicKeyCount() uint32 {
202+
return binary.BigEndian.Uint32(a[accountPublicKeyCountsStartIndex : accountPublicKeyCountsStartIndex+accountPublicKeyCountsSize])
203203
}
204204

205205
// SetAccountIdCounter updates id counter of the account

0 commit comments

Comments
 (0)