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

Add logs to merge #5484

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions cmd/util/ledger/migrations/cadence_values_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func (m *CadenceBaseMigrator) MigrateAccount(
return MergeRegisterChanges(
migrationRuntime.Snapshot.Payloads,
result.WriteSet,
flow.ConvertAddress(address),
m.log,
)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/util/ledger/migrations/deploy_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func NewTransactionBasedMigration(
return MergeRegisterChanges(
snapshot.Payloads,
executionSnapshot.WriteSet,
// we expect more than one address to change here
flow.EmptyAddress,
Comment on lines +56 to +57
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably be a parameter. In NewDeploymentMigration, the value can be authorizer, i.e. where the contract is deployed to

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transactions will change more than just the authoriser account.
They might also change the global uuid counter.

logger,
)
}
Expand Down
33 changes: 29 additions & 4 deletions cmd/util/ledger/migrations/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,33 @@ import (
func MergeRegisterChanges(
originalPayloads map[flow.RegisterID]*ledger.Payload,
changes map[flow.RegisterID]flow.RegisterValue,
expectedAddress flow.Address,
logger zerolog.Logger,
) ([]*ledger.Payload, error) {

newPayloads := make([]*ledger.Payload, 0, len(originalPayloads))

// Add all new payloads.
for id, value := range changes {
delete(originalPayloads, id)
if len(value) == 0 {
continue
}

if expectedAddress != flow.EmptyAddress {
ownerAddress := flow.BytesToAddress([]byte(id.Owner))

if ownerAddress != expectedAddress {
// something was changed that does not belong to this account. Log it.
logger.Error().
Str("key", id.String()).
Str("owner_address", ownerAddress.Hex()).
Str("account", expectedAddress.Hex()).
Hex("value", value).
Msg("key is part of the change set, but is for a different account")
}
}

key := convert.RegisterIDToLedgerKey(id)
newPayloads = append(newPayloads, ledger.NewPayload(key, value))
}
Expand All @@ -33,10 +50,18 @@ func MergeRegisterChanges(
continue
}

// If the payload had changed, then it has been added earlier.
// So skip old payload.
if _, contains := changes[id]; contains {
continue
if expectedAddress != flow.EmptyAddress {
ownerAddress := flow.BytesToAddress([]byte(id.Owner))

if ownerAddress != expectedAddress {
// something was changed that does not belong to this account. Log it.
logger.Error().
Str("key", id.String()).
Str("owner_address", ownerAddress.Hex()).
Str("account", expectedAddress.Hex()).
Hex("value", value.Value()).
Msg("key is part of the original set, but is for a different account")
}
}

newPayloads = append(newPayloads, value)
Expand Down