Switch hardfork in getCommonConfiguration when EIP-1559 support is detected (#11385)

feature/default_network_editable
Brad Decker 3 years ago committed by GitHub
parent b9cf309404
commit 27c140355e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      app/scripts/controllers/transactions/index.js
  2. 1
      app/scripts/controllers/transactions/index.test.js
  3. 3
      app/scripts/metamask-controller.js
  4. 21
      shared/constants/network.js

@ -26,6 +26,7 @@ import {
import { METAMASK_CONTROLLER_EVENTS } from '../../metamask-controller';
import { GAS_LIMITS } from '../../../../shared/constants/gas';
import {
HARDFORKS,
MAINNET,
NETWORK_TYPE_RPC,
} from '../../../../shared/constants/network';
@ -35,8 +36,6 @@ import TxGasUtil from './tx-gas-utils';
import PendingTransactionTracker from './pending-tx-tracker';
import * as txUtils from './lib/util';
const HARDFORK = 'berlin';
const hstInterface = new ethers.utils.Interface(abi);
const MAX_MEMSTORE_TX_LIST_SIZE = 100; // Number of transactions (by unique nonces) to keep in memory
@ -82,6 +81,7 @@ export default class TransactionController extends EventEmitter {
this.networkStore = opts.networkStore || new ObservableStore({});
this._getCurrentChainId = opts.getCurrentChainId;
this.getProviderConfig = opts.getProviderConfig;
this.getEIP1559Compatibility = opts.getEIP1559Compatibility;
this.preferencesStore = opts.preferencesStore || new ObservableStore({});
this.provider = opts.provider;
this.getPermittedAccounts = opts.getPermittedAccounts;
@ -171,14 +171,23 @@ export default class TransactionController extends EventEmitter {
* transaction type to use.
* @returns {Common} common configuration object
*/
getCommonConfiguration() {
async getCommonConfiguration() {
const { type, nickname: name } = this.getProviderConfig();
const supportsEIP1559 = await this.getEIP1559Compatibility();
// This logic below will have to be updated each time a hardfork happens
// that carries with it a new Transaction type. It is inconsequential for
// hardforks that do not include new types.
const hardfork = supportsEIP1559 ? HARDFORKS.LONDON : HARDFORKS.BERLIN;
// type will be one of our default network names or 'rpc'. the default
// network names are sufficient configuration, simply pass the name as the
// chain argument in the constructor.
if (type !== NETWORK_TYPE_RPC) {
return new Common({ chain: type, hardfork: HARDFORK });
return new Common({
chain: type,
hardfork,
});
}
// For 'rpc' we need to use the same basic configuration as mainnet,
@ -203,7 +212,7 @@ export default class TransactionController extends EventEmitter {
networkId: networkId === 'loading' ? 0 : parseInt(networkId, 10),
};
return Common.forCustomChain(MAINNET, customChainParams, HARDFORK);
return Common.forCustomChain(MAINNET, customChainParams, hardfork);
}
/**
@ -637,7 +646,7 @@ export default class TransactionController extends EventEmitter {
};
// sign tx
const fromAddress = txParams.from;
const common = this.getCommonConfiguration();
const common = await this.getCommonConfiguration();
const unsignedEthTx = TransactionFactory.fromTxData(txParams, { common });
const signedEthTx = await this.signEthTx(unsignedEthTx, fromAddress);

@ -50,6 +50,7 @@ describe('Transaction Controller', function () {
return '0xee6b2800';
},
networkStore: new ObservableStore(currentNetworkId),
getEIP1559Compatibility: () => Promise.resolve(true),
txHistoryLimit: 10,
blockTracker: blockTrackerStub,
signTransaction: (ethTx) =>

@ -336,6 +336,9 @@ export default class MetamaskController extends EventEmitter {
getProviderConfig: this.networkController.getProviderConfig.bind(
this.networkController,
),
getEIP1559Compatibility: this.networkController.getEIP1559Compatibility.bind(
this.networkController,
),
networkStore: this.networkController.networkStore,
getCurrentChainId: this.networkController.getCurrentChainId.bind(
this.networkController,

@ -120,3 +120,24 @@ export const NATIVE_CURRENCY_TOKEN_IMAGE_MAP = {
};
export const INFURA_BLOCKED_KEY = 'countryBlocked';
/**
* Hardforks are points in the chain where logic is changed significantly
* enough where there is a fork and the new fork becomes the active chain.
* These constants are presented in chronological order starting with BERLIN
* because when we first needed to track the hardfork we had launched support
* for EIP-2718 (where transactions can have types and different shapes) and
* EIP-2930 (optional access lists), which were included in BERLIN.
*
* BERLIN - forked at block number 12,244,000, included typed transactions and
* optional access lists
* LONDON - future, upcoming fork that introduces the baseFeePerGas, an amount
* of the ETH transaction fees that will be burned instead of given to the
* miner. This change necessitated the third type of transaction envelope to
* specify maxFeePerGas and maxPriorityFeePerGas moving the fee bidding system
* to a second price auction model.
*/
export const HARDFORKS = {
BERLIN: 'berlin',
LONDON: 'london',
};

Loading…
Cancel
Save