Skip to content

Commit

Permalink
Merge pull request #6276 from onflow/bastian/fix-contract-cleanup-mig…
Browse files Browse the repository at this point in the history
…ration-non-determinism

Fix non-determinism in contract code and contract names cleanup migration
  • Loading branch information
turbolent authored Jul 29, 2024
2 parents 18c8533 + 8dac0d9 commit 25ec90b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion cmd/util/ledger/migrations/contract_cleanup_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,17 @@ func (d *ContractCleanupMigration) MigrateAccount(
contractNameSet[contractName] = struct{}{}
}

contractNamesSorted := make([]string, 0, len(contractNameSet))
for contractName := range contractNameSet {
contractNamesSorted = append(contractNamesSorted, contractName)
}
sort.Strings(contractNamesSorted)

// Cleanup the code for each contract in the account.
// If the contract code is empty, the contract code register will be removed,
// and the contract name will be removed from the account's contract names.

for contractName := range contractNameSet {
for _, contractName := range contractNamesSorted {
removed, err := d.cleanupContractCode(
address,
accountRegisters,
Expand Down
5 changes: 3 additions & 2 deletions cmd/util/ledger/migrations/contract_cleanup_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,16 @@ func TestContractCleanupMigration2(t *testing.T) {
reporter := rwf.reportWriters[contractCleanupReporterName]
require.NotNil(t, reporter)

// Order is alphabetical
assert.Equal(t,
[]any{
emptyContractRemoved{
AccountAddress: address,
ContractName: contractNameEmpty1,
ContractName: contractNameEmpty2,
},
emptyContractRemoved{
AccountAddress: address,
ContractName: contractNameEmpty2,
ContractName: contractNameEmpty1,
},
contractNamesChanged{
AccountAddress: address,
Expand Down

0 comments on commit 25ec90b

Please sign in to comment.