mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-11 14:33:52 +00:00
opt: upgrade blockResult process flow (#68)
* upgrade blockResult process flow * fix format optimization
This commit is contained in:
parent
a96775b3ff
commit
40e8f088b6
3 changed files with 16 additions and 11 deletions
|
|
@ -1188,17 +1188,17 @@ func (bc *BlockChain) writeKnownBlock(block *types.Block) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteBlockWithState writes the block and all associated state to the database.
|
// WriteBlockWithState writes the block and all associated state to the database.
|
||||||
func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, blockResult *types.BlockResult, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) {
|
func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, evmTraces []*types.ExecutionResult, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) {
|
||||||
if !bc.chainmu.TryLock() {
|
if !bc.chainmu.TryLock() {
|
||||||
return NonStatTy, errInsertionInterrupted
|
return NonStatTy, errInsertionInterrupted
|
||||||
}
|
}
|
||||||
defer bc.chainmu.Unlock()
|
defer bc.chainmu.Unlock()
|
||||||
return bc.writeBlockWithState(block, receipts, logs, blockResult, state, emitHeadEvent)
|
return bc.writeBlockWithState(block, receipts, logs, evmTraces, state, emitHeadEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeBlockWithState writes the block and all associated state to the database,
|
// writeBlockWithState writes the block and all associated state to the database,
|
||||||
// but is expects the chain mutex to be held.
|
// but is expects the chain mutex to be held.
|
||||||
func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, blockResult *types.BlockResult, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) {
|
func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, evmTraces []*types.ExecutionResult, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) {
|
||||||
if bc.insertStopped() {
|
if bc.insertStopped() {
|
||||||
return NonStatTy, errInsertionInterrupted
|
return NonStatTy, errInsertionInterrupted
|
||||||
}
|
}
|
||||||
|
|
@ -1320,8 +1320,9 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
|
||||||
bc.futureBlocks.Remove(block.Hash())
|
bc.futureBlocks.Remove(block.Hash())
|
||||||
|
|
||||||
// Fill blockResult content
|
// Fill blockResult content
|
||||||
if blockResult != nil {
|
var blockResult *types.BlockResult
|
||||||
bc.writeBlockResult(state, block, blockResult)
|
if evmTraces != nil {
|
||||||
|
blockResult = bc.writeBlockResult(state, block, evmTraces)
|
||||||
bc.blockResultCache.Add(block.Hash(), blockResult)
|
bc.blockResultCache.Add(block.Hash(), blockResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1345,7 +1346,10 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill blockResult content
|
// Fill blockResult content
|
||||||
func (bc *BlockChain) writeBlockResult(state *state.StateDB, block *types.Block, blockResult *types.BlockResult) {
|
func (bc *BlockChain) writeBlockResult(state *state.StateDB, block *types.Block, evmTraces []*types.ExecutionResult) *types.BlockResult {
|
||||||
|
blockResult := &types.BlockResult{
|
||||||
|
ExecutionResults: evmTraces,
|
||||||
|
}
|
||||||
coinbase := types.AccountProofWrapper{
|
coinbase := types.AccountProofWrapper{
|
||||||
Address: block.Coinbase(),
|
Address: block.Coinbase(),
|
||||||
Nonce: state.GetNonce(block.Coinbase()),
|
Nonce: state.GetNonce(block.Coinbase()),
|
||||||
|
|
@ -1396,6 +1400,7 @@ func (bc *BlockChain) writeBlockResult(state *state.StateDB, block *types.Block,
|
||||||
evmTrace.ByteCode = hexutil.Encode(tx.Data())
|
evmTrace.ByteCode = hexutil.Encode(tx.Data())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return blockResult
|
||||||
}
|
}
|
||||||
|
|
||||||
// addFutureBlock checks if the block is within the max allowed window to get
|
// addFutureBlock checks if the block is within the max allowed window to get
|
||||||
|
|
|
||||||
|
|
@ -181,7 +181,7 @@ func (l *StructLogger) CaptureState(pc uint64, op OpCode, gas, cost uint64, scop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
recordStorageDetail bool = false
|
recordStorageDetail bool
|
||||||
storage Storage
|
storage Storage
|
||||||
storageKey common.Hash
|
storageKey common.Hash
|
||||||
storageValue common.Hash
|
storageValue common.Hash
|
||||||
|
|
@ -189,12 +189,12 @@ func (l *StructLogger) CaptureState(pc uint64, op OpCode, gas, cost uint64, scop
|
||||||
if !l.cfg.DisableStorage {
|
if !l.cfg.DisableStorage {
|
||||||
if op == SLOAD && stack.len() >= 1 {
|
if op == SLOAD && stack.len() >= 1 {
|
||||||
recordStorageDetail = true
|
recordStorageDetail = true
|
||||||
storageKey = common.Hash(stack.data[stack.len()-1].Bytes32())
|
storageKey = stack.data[stack.len()-1].Bytes32()
|
||||||
storageValue = l.env.StateDB.GetState(contract.Address(), storageKey)
|
storageValue = l.env.StateDB.GetState(contract.Address(), storageKey)
|
||||||
} else if op == SSTORE && stack.len() >= 2 {
|
} else if op == SSTORE && stack.len() >= 2 {
|
||||||
recordStorageDetail = true
|
recordStorageDetail = true
|
||||||
storageKey = common.Hash(stack.data[stack.len()-1].Bytes32())
|
storageKey = stack.data[stack.len()-1].Bytes32()
|
||||||
storageValue = common.Hash(stack.data[stack.len()-2].Bytes32())
|
storageValue = stack.data[stack.len()-2].Bytes32()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
extraData := types.NewExtraData()
|
extraData := types.NewExtraData()
|
||||||
|
|
|
||||||
|
|
@ -668,7 +668,7 @@ func (w *worker) resultLoop() {
|
||||||
logs = append(logs, receipt.Logs...)
|
logs = append(logs, receipt.Logs...)
|
||||||
}
|
}
|
||||||
// Commit block and state to database.
|
// Commit block and state to database.
|
||||||
_, err := w.chain.WriteBlockWithState(block, receipts, logs, &types.BlockResult{ExecutionResults: evmTraces}, task.state, true)
|
_, err := w.chain.WriteBlockWithState(block, receipts, logs, evmTraces, task.state, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed writing block to chain", "err", err)
|
log.Error("Failed writing block to chain", "err", err)
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue