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

Optimise merge registers for migrations - Revert of Revert #5613

Merged
merged 19 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
6 changes: 3 additions & 3 deletions cmd/util/ledger/migrations/account_storage_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/onflow/cadence/runtime/interpreter"
"github.com/rs/zerolog"

"github.com/onflow/flow-go/cmd/util/ledger/util/snapshot"
"github.com/onflow/flow-go/ledger"
"github.com/onflow/flow-go/model/flow"
)
Expand All @@ -24,6 +25,7 @@ func NewAccountStorageMigration(
payloads,
chainID,
MigratorRuntimeConfig{},
snapshot.SmallChangeSetSnapshot,
)
if err != nil {
return nil, fmt.Errorf("failed to create migrator runtime: %w", err)
Expand Down Expand Up @@ -58,11 +60,9 @@ func NewAccountStorageMigration(
flow.Address(address): {},
}

newPayloads, err := MergeRegisterChanges(
migrationRuntime.Snapshot.Payloads,
newPayloads, err := migrationRuntime.Snapshot.ApplyChangesAndGetNewPayloads(
result.WriteSet,
expectedAddresses,
nil,
log,
)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions cmd/util/ledger/migrations/atree_register_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (m *AtreeRegisterMigrator) MigrateAccount(
m.rw.Write(migrationProblem{
Address: address.Hex(),
Key: "",
Size: len(mr.Snapshot.Payloads),
Size: mr.Snapshot.Len(),
Kind: "more_registers_after_migration",
Msg: fmt.Sprintf("original: %d, new: %d", originalLen, newLen),
})
Expand Down Expand Up @@ -270,7 +270,7 @@ func (m *AtreeRegisterMigrator) convertStorageDomain(

m.rw.Write(migrationProblem{
Address: mr.Address.Hex(),
Size: len(mr.Snapshot.Payloads),
Size: mr.Snapshot.Len(),
Key: fmt.Sprintf("%v (%T)", key, key),
Kind: "migration_failure",
Msg: err.Error(),
Expand All @@ -288,7 +288,7 @@ func (m *AtreeRegisterMigrator) validateChangesAndCreateNewRegisters(
storageMapIds map[string]struct{},
) ([]*ledger.Payload, error) {
originalPayloadsSnapshot := mr.Snapshot
originalPayloads := originalPayloadsSnapshot.Payloads
originalPayloads := originalPayloadsSnapshot.PayloadMap()
newPayloads := make([]*ledger.Payload, 0, len(originalPayloads))

// store state payload so that it can be updated
Expand Down Expand Up @@ -374,7 +374,7 @@ func (m *AtreeRegisterMigrator) validateChangesAndCreateNewRegisters(
m.rw.Write(migrationProblem{
Address: mr.Address.Hex(),
Key: id.String(),
Size: len(mr.Snapshot.Payloads),
Size: mr.Snapshot.Len(),
Kind: "not_migrated",
Msg: fmt.Sprintf("%x", value.Value()),
})
Expand Down
5 changes: 3 additions & 2 deletions cmd/util/ledger/migrations/atree_register_migrator_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/onflow/cadence/runtime/interpreter"

"github.com/onflow/flow-go/cmd/util/ledger/util"
migrationSnapshot "github.com/onflow/flow-go/cmd/util/ledger/util/snapshot"
"github.com/onflow/flow-go/fvm/environment"
"github.com/onflow/flow-go/fvm/storage/state"
"github.com/onflow/flow-go/ledger"
Expand All @@ -21,7 +22,7 @@ func NewAtreeRegisterMigratorRuntime(
*AtreeRegisterMigratorRuntime,
error,
) {
snapshot, err := util.NewPayloadSnapshot(payloads)
snapshot, err := migrationSnapshot.NewPayloadSnapshot(payloads, migrationSnapshot.LargeChangeSetOrReadonlySnapshot)
if err != nil {
return nil, fmt.Errorf("failed to create payload snapshot: %w", err)
}
Expand Down Expand Up @@ -54,7 +55,7 @@ func NewAtreeRegisterMigratorRuntime(
}

type AtreeRegisterMigratorRuntime struct {
Snapshot *util.PayloadSnapshot
Snapshot migrationSnapshot.MigrationSnapshot
TransactionState state.NestedTransactionPreparer
Interpreter *interpreter.Interpreter
Storage *runtime.Storage
Expand Down
6 changes: 6 additions & 0 deletions cmd/util/ledger/migrations/cadence_value_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/interpreter"

"github.com/onflow/flow-go/cmd/util/ledger/util/snapshot"
"github.com/onflow/flow-go/fvm/environment"
"github.com/onflow/flow-go/ledger"
"github.com/onflow/flow-go/ledger/common/convert"
Expand Down Expand Up @@ -175,6 +176,7 @@ func TestDiffCadenceValues(t *testing.T) {
},
flow.Emulator,
MigratorRuntimeConfig{},
snapshot.LargeChangeSetOrReadonlySnapshot,
)
require.NoError(t, err)

Expand Down Expand Up @@ -277,6 +279,7 @@ func TestDiffCadenceValues(t *testing.T) {
},
flow.Emulator,
MigratorRuntimeConfig{},
snapshot.LargeChangeSetOrReadonlySnapshot,
)
require.NoError(t, err)

Expand Down Expand Up @@ -386,6 +389,7 @@ func TestDiffCadenceValues(t *testing.T) {
},
flow.Emulator,
MigratorRuntimeConfig{},
snapshot.LargeChangeSetOrReadonlySnapshot,
)
require.NoError(t, err)

Expand Down Expand Up @@ -506,6 +510,7 @@ func TestDiffCadenceValues(t *testing.T) {
},
flow.Emulator,
MigratorRuntimeConfig{},
snapshot.LargeChangeSetOrReadonlySnapshot,
)
require.NoError(t, err)

Expand Down Expand Up @@ -633,6 +638,7 @@ func createStorageMapPayloads(t *testing.T, address common.Address, domain strin
},
flow.Emulator,
MigratorRuntimeConfig{},
snapshot.LargeChangeSetOrReadonlySnapshot,
)
require.NoError(t, err)

Expand Down
3 changes: 2 additions & 1 deletion cmd/util/ledger/migrations/cadence_value_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/rs/zerolog"

"github.com/onflow/flow-go/cmd/util/ledger/util"
migrationSnapshot "github.com/onflow/flow-go/cmd/util/ledger/util/snapshot"
"github.com/onflow/flow-go/ledger"
)

Expand Down Expand Up @@ -395,7 +396,7 @@ func newReadonlyStorageRuntime(payloads []*ledger.Payload) (
*readonlyStorageRuntime,
error,
) {
snapshot, err := util.NewPayloadSnapshot(payloads)
snapshot, err := migrationSnapshot.NewPayloadSnapshot(payloads, migrationSnapshot.LargeChangeSetOrReadonlySnapshot)
if err != nil {
return nil, fmt.Errorf("failed to create payload snapshot: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/util/ledger/migrations/cadence_values_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/onflow/flow-go/cmd/util/ledger/reporters"
"github.com/onflow/flow-go/cmd/util/ledger/util"
"github.com/onflow/flow-go/cmd/util/ledger/util/snapshot"
"github.com/onflow/flow-go/fvm/environment"
"github.com/onflow/flow-go/fvm/tracing"
"github.com/onflow/flow-go/ledger"
Expand Down Expand Up @@ -109,6 +110,7 @@ func (m *CadenceBaseMigrator) MigrateAccount(
oldPayloads,
m.chainID,
m.migratorRuntimeConfig,
snapshot.SmallChangeSetSnapshot,
)
if err != nil {
return nil, fmt.Errorf("failed to create migrator runtime: %w", err)
Expand Down Expand Up @@ -214,11 +216,9 @@ func (m *CadenceBaseMigrator) MigrateAccount(
flow.Address(address): {},
}

newPayloads, err := MergeRegisterChanges(
migrationRuntime.Snapshot.Payloads,
newPayloads, err := migrationRuntime.Snapshot.ApplyChangesAndGetNewPayloads(
result.WriteSet,
expectedAddresses,
expectedAddresses,
m.log,
)
if err != nil {
Expand Down
13 changes: 7 additions & 6 deletions cmd/util/ledger/migrations/cadence_values_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/onflow/flow-go/cmd/util/ledger/reporters"
"github.com/onflow/flow-go/cmd/util/ledger/util"
"github.com/onflow/flow-go/cmd/util/ledger/util/snapshot"
"github.com/onflow/flow-go/fvm/environment"
"github.com/onflow/flow-go/fvm/systemcontracts"
"github.com/onflow/flow-go/ledger"
Expand Down Expand Up @@ -125,6 +126,7 @@ func checkMigratedPayloads(
newPayloads,
chainID,
MigratorRuntimeConfig{},
snapshot.SmallChangeSetSnapshot,
)
require.NoError(t, err)

Expand Down Expand Up @@ -743,6 +745,7 @@ func TestProgramParsingError(t *testing.T) {
payloads,
chainID,
MigratorRuntimeConfig{},
snapshot.SmallChangeSetSnapshot,
)
require.NoError(t, err)

Expand Down Expand Up @@ -793,11 +796,9 @@ func TestProgramParsingError(t *testing.T) {
flow.Address(testAddress): {},
}

payloads, err = MergeRegisterChanges(
runtime.Snapshot.Payloads,
payloads, err = runtime.Snapshot.ApplyChangesAndGetNewPayloads(
result.WriteSet,
expectedAddresses,
nil,
logger,
)
require.NoError(t, err)
Expand Down Expand Up @@ -888,6 +889,7 @@ func TestCoreContractUsage(t *testing.T) {
payloads,
chainID,
MigratorRuntimeConfig{},
snapshot.SmallChangeSetSnapshot,
)
require.NoError(t, err)

Expand Down Expand Up @@ -930,11 +932,9 @@ func TestCoreContractUsage(t *testing.T) {
flow.Address(testAddress): {},
}

payloads, err = MergeRegisterChanges(
runtime.Snapshot.Payloads,
payloads, err = runtime.Snapshot.ApplyChangesAndGetNewPayloads(
result.WriteSet,
expectedAddresses,
nil,
logger,
)
require.NoError(t, err)
Expand Down Expand Up @@ -978,6 +978,7 @@ func TestCoreContractUsage(t *testing.T) {
payloads,
chainID,
MigratorRuntimeConfig{},
snapshot.SmallChangeSetSnapshot,
)
require.NoError(t, err)

Expand Down
2 changes: 2 additions & 0 deletions cmd/util/ledger/migrations/contract_checking_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/rs/zerolog"

"github.com/onflow/flow-go/cmd/util/ledger/reporters"
"github.com/onflow/flow-go/cmd/util/ledger/util/snapshot"
"github.com/onflow/flow-go/ledger"
"github.com/onflow/flow-go/ledger/common/convert"
"github.com/onflow/flow-go/model/flow"
Expand Down Expand Up @@ -43,6 +44,7 @@ func NewContractCheckingMigration(
contractPayloads,
chainID,
MigratorRuntimeConfig{},
snapshot.LargeChangeSetOrReadonlySnapshot,
)
if err != nil {
return nil, fmt.Errorf("failed to create migrator runtime: %w", err)
Expand Down
72 changes: 0 additions & 72 deletions cmd/util/ledger/migrations/merge.go

This file was deleted.

6 changes: 4 additions & 2 deletions cmd/util/ledger/migrations/migrator_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/onflow/cadence/runtime/stdlib"

"github.com/onflow/flow-go/cmd/util/ledger/util"
"github.com/onflow/flow-go/cmd/util/ledger/util/snapshot"
"github.com/onflow/flow-go/fvm/environment"
"github.com/onflow/flow-go/fvm/evm"
evmStdlib "github.com/onflow/flow-go/fvm/evm/stdlib"
Expand All @@ -18,7 +19,7 @@ import (
)

type MigratorRuntime struct {
Snapshot *util.PayloadSnapshot
Snapshot snapshot.MigrationSnapshot
TransactionState state.NestedTransactionPreparer
Interpreter *interpreter.Interpreter
Storage *runtime.Storage
Expand Down Expand Up @@ -99,11 +100,12 @@ func NewMigratorRuntime(
payloads []*ledger.Payload,
chainID flow.ChainID,
config MigratorRuntimeConfig,
snapshotType snapshot.MigrationSnapshotType,
) (
*MigratorRuntime,
error,
) {
snapshot, err := util.NewPayloadSnapshot(payloads)
snapshot, err := snapshot.NewPayloadSnapshot(payloads, snapshotType)
if err != nil {
return nil, fmt.Errorf("failed to create payload snapshot: %w", err)
}
Expand Down
Loading
Loading