fix caching contract storage

pull/1122/head
yann300 4 years ago
parent 5d4df4fdbc
commit 5442d69616
  1. 35
      libs/remix-lib/src/web3Provider/web3VmProvider.ts

@ -74,14 +74,17 @@ export class Web3VmProvider {
setVM (vm) { setVM (vm) {
if (this.vm === vm) return if (this.vm === vm) return
this.vm = vm this.vm = vm
this.vm.on('step', (data) => { this.vm.on('step', async (data, next) => {
this.pushTrace(data) await this.pushTrace(data)
next()
}) })
this.vm.on('afterTx', (data) => { this.vm.on('afterTx', async (data, next) => {
this.txProcessed(data) await this.txProcessed(data)
next()
}) })
this.vm.on('beforeTx', (data) => { this.vm.on('beforeTx', async (data, next) => {
this.txWillProcess(data) await this.txWillProcess(data)
next()
}) })
} }
@ -91,7 +94,7 @@ export class Web3VmProvider {
return ret return ret
} }
txWillProcess (data) { async txWillProcess (data) {
this.incr++ this.incr++
this.processingHash = hexConvert(data.hash()) this.processingHash = hexConvert(data.hash())
this.vmTraces[this.processingHash] = { this.vmTraces[this.processingHash] = {
@ -116,15 +119,18 @@ export class Web3VmProvider {
this.txsReceipt[this.processingHash] = tx this.txsReceipt[this.processingHash] = tx
this.storageCache[this.processingHash] = {} this.storageCache[this.processingHash] = {}
if (data.to) { if (data.to) {
this.vm.stateManager.dumpStorage(data.to).then((storage) => { try {
const storage = await this.vm.stateManager.dumpStorage(data.to)
this.storageCache[this.processingHash][tx['to']] = storage this.storageCache[this.processingHash][tx['to']] = storage
this.lastProcessedStorageTxHash[tx['to']] = this.processingHash this.lastProcessedStorageTxHash[tx['to']] = this.processingHash
}) } catch (e) {
console.log(e)
}
} }
this.processingIndex = 0 this.processingIndex = 0
} }
txProcessed (data) { async txProcessed (data) {
const lastOp = this.vmTraces[this.processingHash].structLogs[this.processingIndex - 1] const lastOp = this.vmTraces[this.processingHash].structLogs[this.processingIndex - 1]
if (lastOp) { if (lastOp) {
lastOp.error = lastOp.op !== 'RETURN' && lastOp.op !== 'STOP' && lastOp.op !== 'thisDESTRUCT' lastOp.error = lastOp.op !== 'RETURN' && lastOp.op !== 'STOP' && lastOp.op !== 'thisDESTRUCT'
@ -168,7 +174,7 @@ export class Web3VmProvider {
this.previousDepth = 0 this.previousDepth = 0
} }
pushTrace (data) { async pushTrace (data) {
const depth = data.depth + 1 // geth starts the depth from 1 const depth = data.depth + 1 // geth starts the depth from 1
if (!this.processingHash) { if (!this.processingHash) {
console.log('no tx processing') console.log('no tx processing')
@ -205,10 +211,13 @@ export class Web3VmProvider {
this.processingAddress = toChecksumAddress(this.processingAddress) this.processingAddress = toChecksumAddress(this.processingAddress)
if (!this.storageCache[this.processingHash][this.processingAddress]) { if (!this.storageCache[this.processingHash][this.processingAddress]) {
const account = Address.fromString(this.processingAddress) const account = Address.fromString(this.processingAddress)
this.vm.stateManager.dumpStorage(account).then((storage) => { try {
const storage = await this.vm.stateManager.dumpStorage(account)
this.storageCache[this.processingHash][this.processingAddress] = storage this.storageCache[this.processingHash][this.processingAddress] = storage
this.lastProcessedStorageTxHash[this.processingAddress] = this.processingHash this.lastProcessedStorageTxHash[this.processingAddress] = this.processingHash
}) } catch (e) {
console.log(e)
}
} }
} }
} }

Loading…
Cancel
Save