add eth tx hash into stateDB memory objefct

pull/3799/head
peekpi 3 years ago
parent aa33ca6696
commit b2f9b06d04
  1. 12
      core/state/statedb.go
  2. 3
      core/state_processor.go
  3. 1
      core/vm/interface.go
  4. 11
      hmy/tracer.go
  5. 2
      hmy/tracers/block_tracer.go

@ -90,7 +90,8 @@ type DB struct {
// The refund counter, also used by state transitioning.
refund uint64
thash, bhash common.Hash
thash, bhash common.Hash // thash means hmy tx hash
ethTxHash common.Hash // ethTxHash is eth tx hash, use by tracer
txIndex int
logs map[common.Hash][]*types.Log
logSize uint
@ -158,6 +159,7 @@ func (db *DB) Reset(root common.Hash) error {
db.stateValidators = make(map[common.Address]*stk.ValidatorWrapper)
db.thash = common.Hash{}
db.bhash = common.Hash{}
db.ethTxHash = common.Hash{}
db.txIndex = 0
db.logs = make(map[common.Hash][]*types.Log)
db.logSize = 0
@ -264,6 +266,10 @@ func (s *DB) TxHash() common.Hash {
return s.thash
}
func (s *DB) TxHashETH() common.Hash {
return s.ethTxHash
}
// BlockHash returns the current block hash set by Prepare.
func (db *DB) BlockHash() common.Hash {
return db.bhash
@ -747,6 +753,10 @@ func (db *DB) Prepare(thash, bhash common.Hash, ti int) {
db.txIndex = ti
}
func (db *DB) SetTxHashETH(ethTxHash common.Hash) {
db.ethTxHash = ethTxHash
}
func (db *DB) clearJournalAndRefund() {
if len(db.journal.entries) > 0 {
db.journal = newJournal()

@ -119,6 +119,9 @@ func (p *StateProcessor) Process(
// Iterate over and process the individual transactions
for i, tx := range block.Transactions() {
statedb.Prepare(tx.Hash(), block.Hash(), i)
if tx.IsEthCompatible() {
statedb.SetTxHashETH(tx.ConvertToEth().Hash())
}
receipt, cxReceipt, _, err := ApplyTransaction(
p.config, p.bc, &beneficiary, gp, statedb, header, tx, usedGas, cfg,
)

@ -79,6 +79,7 @@ type StateDB interface {
TxIndex() int
BlockHash() common.Hash
TxHash() common.Hash
TxHashETH() common.Hash // used by tracer
}
// CallContext provides a basic interface for the EVM calling conventions. The EVM

@ -379,9 +379,8 @@ traceLoop:
}
// Generate the next state snapshot fast without tracing
msg, _ := tx.AsMessage(signer)
ethTx := tx.ConvertToEth()
statedb.Prepare(ethTx.Hash(), blockHash, i)
statedb.Prepare(tx.Hash(), blockHash, i)
statedb.SetTxHashETH(tx.ConvertToEth().Hash())
vmctx := core.NewEVMContext(msg, block.Header(), hmy.BlockChain, nil)
res, err := hmy.TraceTx(ctx, msg, vmctx, statedb, config)
if err != nil {
@ -465,8 +464,9 @@ func (hmy *Harmony) TraceBlock(ctx context.Context, block *types.Block, config *
msg, _ := txs[task.index].AsMessage(signer)
vmctx := core.NewEVMContext(msg, block.Header(), hmy.BlockChain, nil)
ethTx := txs[task.index].ConvertToEth()
task.statedb.Prepare(ethTx.Hash(), blockHash, task.index)
tx := txs[task.index]
task.statedb.Prepare(tx.Hash(), blockHash, task.index)
task.statedb.SetTxHashETH(tx.ConvertToEth().Hash())
res, err := hmy.TraceTx(ctx, msg, vmctx, task.statedb, config)
if err != nil {
results[task.index] = &TxTraceResult{Error: err.Error()}
@ -489,6 +489,7 @@ func (hmy *Harmony) TraceBlock(ctx context.Context, block *types.Block, config *
// Generate the next state snapshot fast without tracing
msg, _ := tx.AsMessage(signer)
statedb.Prepare(tx.Hash(), block.Hash(), i)
statedb.SetTxHashETH(tx.ConvertToEth().Hash())
vmctx := core.NewEVMContext(msg, block.Header(), hmy.BlockChain, nil)
vmenv := vm.NewEVM(vmctx, statedb, hmy.BlockChain.Config(), vm.Config{})

@ -243,7 +243,7 @@ func (jst *ParityBlockTracer) CaptureStart(env *vm.EVM, from common.Address, to
jst.cur.value = (&big.Int{}).Set(value)
jst.cur.blockHash = env.StateDB.BlockHash()
jst.cur.transactionPosition = uint64(env.StateDB.TxIndex())
jst.cur.transactionHash = env.StateDB.TxHash()
jst.cur.transactionHash = env.StateDB.TxHashETH()
jst.cur.blockNumber = env.BlockNumber.Uint64()
jst.cur.descended = false
jst.cur.push(&jst.cur.action)

Loading…
Cancel
Save