-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There are several kinds of errors in Sentry which indicate that there are properties in controller state we are attempting to persist that do not have corresponding metadata. This indicates that these properties were removed at some point from the controller's state but no migration was added that removed them from the persisted wallet state. In many cases, at the time of removal, such a migration was not needed because the controller in question inherited from BaseController v1. However, we have made a targeted effort over the past few years to migrate all controllers to BaseController v2, and so it matters now that every property have corresponding metadata or else are removed from state. We don't want these errors to show up in Sentry because they create noise, so this commit removes these properties from state.
- Loading branch information
Showing
3 changed files
with
351 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,271 @@ | ||
import { omit } from 'lodash'; | ||
import { migrate, version } from './139'; | ||
|
||
const oldVersion = 138; | ||
|
||
const dataWithAllControllerProperties = { | ||
AppStateController: {}, | ||
NetworkController: {}, | ||
PreferencesController: {}, | ||
}; | ||
|
||
describe(`migration #${version}`, () => { | ||
it('updates the version metadata', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: {}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.meta).toStrictEqual({ version }); | ||
}); | ||
|
||
it('does nothing if state has no AppStateController property, even if it has other relevant properties', async () => { | ||
const data = omit(dataWithAllControllerProperties, 'AppStateController'); | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual(data); | ||
}); | ||
|
||
it('deletes AppStateController.serviceWorkerLastActiveTime from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
AppStateController: { | ||
serviceWorkerLastActiveTime: 5, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
AppStateController: {}, | ||
}); | ||
}); | ||
|
||
it('does nothing if state has no NetworkController property, even if it has other relevant properties', async () => { | ||
const data = omit(dataWithAllControllerProperties, 'NetworkController'); | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual(data); | ||
}); | ||
|
||
it('deletes NetworkController.networkConfigurations from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
NetworkController: { | ||
networkConfigurations: { | ||
'AAAA-AAAA-AAAA-AAAA': { | ||
doesnt: 'matter', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
NetworkController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes NetworkController.providerConfig from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
NetworkController: { | ||
providerConfig: { | ||
doesnt: 'matter', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
NetworkController: {}, | ||
}); | ||
}); | ||
|
||
it('does nothing if state has no PreferencesController property, even if it has other relevant properties', async () => { | ||
const data = omit(dataWithAllControllerProperties, 'PreferencesController'); | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual(data); | ||
}); | ||
|
||
it('deletes PreferencesController.customNetworkListEnabled from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
customNetworkListEnabled: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
PreferencesController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes PreferencesController.disabledRpcMethodPreferences from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
disabledRpcMethodPreferences: { | ||
doesnt: 'matter', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
PreferencesController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes PreferencesController.eip1559V2Enabled from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
eip1559V2Enabled: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
PreferencesController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes PreferencesController.hasDismissedOpenSeaToBlockaidBanner from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
hasDismissedOpenSeaToBlockaidBanner: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
PreferencesController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes PreferencesController.hasMigratedFromOpenSeaToBlockaid from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
hasMigratedFromOpenSeaToBlockaid: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
PreferencesController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes PreferencesController.improvedTokenAllowanceEnabled from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
improvedTokenAllowanceEnabled: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
PreferencesController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes PreferencesController.infuraBlocked from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
infuraBlocked: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
PreferencesController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes PreferencesController.useCollectibleDetection from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
useCollectibleDetection: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
PreferencesController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes PreferencesController.useStaticTokenList from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
useStaticTokenList: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
PreferencesController: {}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { hasProperty, isObject } from '@metamask/utils'; | ||
import { cloneDeep } from 'lodash'; | ||
|
||
type VersionedData = { | ||
meta: { version: number }; | ||
data: Record<string, unknown>; | ||
}; | ||
|
||
export const version = 138; | ||
|
||
/** | ||
* This migration deletes properties from state which have been removed in | ||
* previous commits. | ||
* | ||
* @param originalVersionedData - Versioned MetaMask extension state, exactly | ||
* what we persist to dist. | ||
* @param originalVersionedData.meta - State metadata. | ||
* @param originalVersionedData.meta.version - The current state version. | ||
* @param originalVersionedData.data - The persisted MetaMask state, keyed by | ||
* controller. | ||
* @returns Updated versioned MetaMask extension state. | ||
*/ | ||
export async function migrate( | ||
originalVersionedData: VersionedData, | ||
): Promise<VersionedData> { | ||
const versionedData = cloneDeep(originalVersionedData); | ||
versionedData.meta.version = version; | ||
transformState(versionedData.data); | ||
return versionedData; | ||
} | ||
|
||
function transformState(state: Record<string, unknown>) { | ||
if ( | ||
hasProperty(state, 'AppStateController') && | ||
isObject(state.AppStateController) | ||
) { | ||
// Removed in 4ea52511eb7934bf0ce6b9b7d570a525120229ce | ||
delete state.AppStateController.serviceWorkerLastActiveTime; | ||
} | ||
|
||
if ( | ||
hasProperty(state, 'NetworkController') && | ||
isObject(state.NetworkController) | ||
) { | ||
// Removed in 555d42b9ead0f4919356ff16e11c663c5e38639e | ||
delete state.NetworkController.networkConfigurations; | ||
// Removed in 800a9d3a177446ff2d05e3e95ec06b3658474207 with a migration, but | ||
// still persists for some people for some reason | ||
delete state.NetworkController.providerConfig; | ||
} | ||
|
||
if ( | ||
hasProperty(state, 'PreferencesController') && | ||
isObject(state.PreferencesController) | ||
) { | ||
// Removed in 6c84e9604c7160dd91c685f301f3c8bd128ad3e3 | ||
delete state.PreferencesController.customNetworkListEnabled; | ||
// Removed in e6ecd956b054a29481071e4eded2f8cd17d137d2 | ||
delete state.PreferencesController.disabledRpcMethodPreferences; | ||
// Removed in 8125473dc53476b6685c5e85918f89bce87e3006 | ||
delete state.PreferencesController.eip1559V2Enabled; | ||
// Removed in 699ddccc76302df6130835dc6655077806bf6335 | ||
delete state.PreferencesController.hasDismissedOpenSeaToBlockaidBanner; | ||
// I could find references to this in the commit history, but don't know | ||
// where it was removed | ||
delete state.PreferencesController.hasMigratedFromOpenSeaToBlockaid; | ||
// Removed in f988dc1c5ef98ec72212d1f58e736556273b68f7 | ||
delete state.PreferencesController.improvedTokenAllowanceEnabled; | ||
// Removed in 315c043785cd5d7a4b0f7e974097ccac18a6b241 | ||
delete state.PreferencesController.infuraBlocked; | ||
// Removed in 4f66dc948fee54b8491227414342ab0d373475f1 with a migration, but | ||
// still persists for some people for some reason | ||
delete state.PreferencesController.useCollectibleDetection; | ||
// Removed in eb987a47b51ce410de0047ec883bb4549ce80c85 | ||
delete state.PreferencesController.useStaticTokenList; | ||
} | ||
|
||
return state; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters