allow debugging various fork

pull/5370/head
yann300 4 years ago committed by joseph izang
parent bae7da7284
commit 6182dfe7bd
  1. 3
      apps/debugger/src/app/debugger-api.ts
  2. 22
      apps/remix-ide/src/blockchain/execution-context.js
  3. 4
      libs/remix-debug/src/Ethdebugger.ts
  4. 3
      libs/remix-debug/src/debugger/debugger.ts
  5. 12
      libs/remix-debug/src/trace/traceManager.ts
  6. 121
      libs/remix-lib/src/execution/forkAt.ts
  7. 4
      libs/remix-lib/src/index.ts
  8. 3
      libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx

@ -111,8 +111,7 @@ export const DebuggerApiMixin = (Base) => class extends Base {
}
return null
},
debugWithGeneratedSources: false,
fork: 'berlin'
debugWithGeneratedSources: false
})
return await debug.debugger.traceManager.getTrace(hash)
}

@ -1,6 +1,7 @@
/* global ethereum */
'use strict'
import Web3 from 'web3'
import { execution } from '@remix-project/remix-lib'
import EventManager from '../lib/events'
let web3
@ -21,7 +22,7 @@ export class ExecutionContext {
this.executionContext = null
this.blockGasLimitDefault = 4300000
this.blockGasLimit = this.blockGasLimitDefault
this.currentFork = ' - '
this.currentFork = 'berlin'
this.mainNetGenesisHash = '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3'
this.customNetWorks = {}
this.blocks = {}
@ -134,8 +135,6 @@ export class ExecutionContext {
return cb()
}
this.currentFork = ' - '
if (context === 'injected') {
if (injectedProvider === undefined) {
infoCb('No injected Web3 provider found. Make sure your provider (e.g. MetaMask) is active and running (when recently activated you may have to reload the page).')
@ -144,7 +143,7 @@ export class ExecutionContext {
this.askPermission()
this.executionContext = context
web3.setProvider(injectedProvider)
this._updateBlockGasLimit()
this._updateChainContext()
this.event.trigger('contextChanged', ['injected'])
return cb()
}
@ -171,12 +170,19 @@ export class ExecutionContext {
this.listenOnLastBlockId = null
}
_updateBlockGasLimit () {
_updateChainContext () {
if (this.getProvider() !== 'vm') {
web3.eth.getBlock('latest', (err, block) => {
web3.eth.getBlock('latest', async (err, block) => {
if (!err) {
// we can't use the blockGasLimit cause the next blocks could have a lower limit : https://github.com/ethereum/remix/issues/506
this.blockGasLimit = (block && block.gasLimit) ? Math.floor(block.gasLimit - (5 * block.gasLimit) / 1024) : this.blockGasLimitDefault
try {
this.currentFork = execution.forkAt(await web3.eth.net.getId(), block.number)
} catch (e) {
this.currentFork = 'berlin'
console.log(`unable to detect fork, defaulting to ${this.currentFork}..`)
console.error(e)
}
} else {
this.blockGasLimit = this.blockGasLimitDefault
}
@ -186,7 +192,7 @@ export class ExecutionContext {
listenOnLastBlock () {
this.listenOnLastBlockId = setInterval(() => {
this._updateBlockGasLimit()
this._updateChainContext()
}, 15000)
}
@ -200,7 +206,7 @@ export class ExecutionContext {
web3.eth.net.isListening((err, isConnected) => {
if (!err && isConnected === true) {
this.executionContext = context
this._updateBlockGasLimit()
this._updateChainContext()
this.event.trigger('contextChanged', [context])
this.event.trigger('web3EndpointChanged')
cb()

@ -41,7 +41,7 @@ export class Ethdebugger {
this.opts = opts
this.event = new EventManager()
this.traceManager = new TraceManager({ web3: this.web3, fork: this.opts.fork })
this.traceManager = new TraceManager({ web3: this.web3 })
this.codeManager = new CodeManager(this.traceManager)
this.solidityProxy = new SolidityProxy({ getCurrentCalledAddressAt: this.traceManager.getCurrentCalledAddressAt.bind(this.traceManager), getCode: this.codeManager.getCode.bind(this.codeManager) })
this.storageResolver = null
@ -55,7 +55,7 @@ export class Ethdebugger {
}
setManagers () {
this.traceManager = new TraceManager({ web3: this.web3, fork: this.opts.fork })
this.traceManager = new TraceManager({ web3: this.web3 })
this.codeManager = new CodeManager(this.traceManager)
this.solidityProxy = new SolidityProxy({ getCurrentCalledAddressAt: this.traceManager.getCurrentCalledAddressAt.bind(this.traceManager), getCode: this.codeManager.getCode.bind(this.codeManager) })
this.storageResolver = null

@ -26,8 +26,7 @@ export class Debugger {
this.debugger = new Ethdebugger({
web3: options.web3,
debugWithGeneratedSources: options.debugWithGeneratedSources,
compilationResult: this.compilationResult,
fork: options.fork
compilationResult: this.compilationResult
})
const { traceManager, callTree, solidityProxy } = this.debugger

@ -1,9 +1,9 @@
'use strict'
import { util, execution } from '@remix-project/remix-lib'
import { TraceAnalyser } from './traceAnalyser'
import { TraceCache } from './traceCache'
import { TraceStepManager } from './traceStepManager'
import { isCreateInstruction } from './traceHelper'
import { util } from '@remix-project/remix-lib'
export class TraceManager {
web3
@ -17,7 +17,6 @@ export class TraceManager {
constructor (options) {
this.web3 = options.web3
this.fork = options.fork
this.isLoading = false
this.trace = null
this.traceCache = new TraceCache()
@ -37,6 +36,15 @@ export class TraceManager {
if (result['structLogs'].length > 0) {
this.trace = result['structLogs']
try {
const networkId = await this.web3.eth.net.getId()
this.fork = execution.forkAt(networkId, tx.blockNumber)
} catch (e) {
this.fork = 'berlin'
console.log(`unable to detect fork, defaulting to ${this.fork}..`)
console.error(e)
}
this.traceAnalyser.analyse(result['structLogs'], tx)
this.isLoading = false
return true

@ -0,0 +1,121 @@
'use strict'
/**
* returns the fork name for the @argument networkId and @argument blockNumber
*
* @param {Object} networkId - network Id (1 for VM, 3 for Ropsten, 4 for Rinkeby, 5 for Goerli)
* @param {Object} blockNumber - block number
* @return {String} - fork name (Berlin, Istanbul, ...)
*/
export function forkAt (networkId, blockNumber) {
if (forks[networkId]) {
let currentForkName = forks[networkId][0].name
for (const fork of forks[networkId]) {
if (blockNumber >= fork.number) {
currentForkName = fork.name
}
}
return currentForkName
}
return 'berlin'
}
// see https://github.com/ethereum/go-ethereum/blob/master/params/config.go
const forks = {
1: [
{
number: 4370000,
name: 'byzantium'
},
{
number: 7280000,
name: 'constantinople'
},
{
number: 7280000,
name: 'petersburg'
},
{
number: 9069000,
name: 'istanbul'
},
{
number: 9200000,
name: 'muirglacier'
},
{
number: 12244000,
name: 'berlin'
}
],
3: [
{
number: 1700000,
name: 'byzantium'
},
{
number: 4230000,
name: 'constantinople'
},
{
number: 4939394,
name: 'petersburg'
},
{
number: 6485846,
name: 'istanbul'
},
{
number: 7117117,
name: 'muirglacier'
},
{
number: 9812189,
name: 'berlin'
},
{
number: 10499401,
name: 'london'
}
],
4: [
{
number: 1035301,
name: 'byzantium'
},
{
number: 3660663,
name: 'constantinople'
},
{
number: 4321234,
name: 'petersburg'
},
{
number: 5435345,
name: 'istanbul'
},
{
number: 8290928,
name: 'berlin'
},
{
number: 8897988,
name: 'london'
}
],
5: [
{
number: 1561651,
name: 'istanbul'
},
{
number: 4460644,
name: 'berlin'
},
{
number: 5062605,
name: 'london'
}
]
}

@ -13,6 +13,7 @@ import * as txFormat from './execution/txFormat'
import { TxListener } from './execution/txListener'
import { TxRunner } from './execution/txRunner'
import { LogsManager } from './execution/logsManager'
import { forkAt } from './execution/forkAt'
import * as typeConversion from './execution/typeConversion'
import { TxRunnerVM } from './execution/txRunnerVM'
import { TxRunnerWeb3 } from './execution/txRunnerWeb3'
@ -45,7 +46,8 @@ function modules () {
TxRunnerWeb3: TxRunnerWeb3,
TxRunnerVM: TxRunnerVM,
typeConversion: typeConversion,
LogsManager
LogsManager,
forkAt
}
}
}

@ -208,8 +208,7 @@ export const DebuggerUI = (props: DebuggerUIProps) => {
}
return null
},
debugWithGeneratedSources: state.opt.debugWithGeneratedSources,
fork: 'berlin'
debugWithGeneratedSources: state.opt.debugWithGeneratedSources
})
debuggerInstance.debug(blockNumber, txNumber, tx, () => {

Loading…
Cancel
Save