rm read hooks
This commit is contained in:
parent
7fb2688e3a
commit
3228063e63
|
@ -54,45 +54,24 @@ func (s *hookedStateDB) CreateContract(addr common.Address) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *hookedStateDB) GetBalance(addr common.Address) *uint256.Int {
|
func (s *hookedStateDB) GetBalance(addr common.Address) *uint256.Int {
|
||||||
bal := s.inner.GetBalance(addr)
|
return s.inner.GetBalance(addr)
|
||||||
if s.hooks.OnBalanceRead != nil {
|
|
||||||
s.hooks.OnBalanceRead(addr, bal.ToBig())
|
|
||||||
}
|
|
||||||
return bal
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *hookedStateDB) GetNonce(addr common.Address) uint64 {
|
func (s *hookedStateDB) GetNonce(addr common.Address) uint64 {
|
||||||
nonce := s.inner.GetNonce(addr)
|
return s.inner.GetNonce(addr)
|
||||||
if s.hooks.OnNonceRead != nil {
|
|
||||||
s.hooks.OnNonceRead(addr, nonce)
|
|
||||||
}
|
|
||||||
return nonce
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *hookedStateDB) GetCodeHash(addr common.Address) common.Hash {
|
func (s *hookedStateDB) GetCodeHash(addr common.Address) common.Hash {
|
||||||
codeHash := s.inner.GetCodeHash(addr)
|
return s.inner.GetCodeHash(addr)
|
||||||
if s.hooks.OnCodeHashRead != nil {
|
|
||||||
s.hooks.OnCodeHashRead(addr, codeHash)
|
|
||||||
}
|
|
||||||
return codeHash
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *hookedStateDB) GetCode(addr common.Address) []byte {
|
func (s *hookedStateDB) GetCode(addr common.Address) []byte {
|
||||||
code := s.inner.GetCode(addr)
|
return s.inner.GetCode(addr)
|
||||||
if s.hooks.OnCodeRead != nil {
|
|
||||||
s.hooks.OnCodeRead(addr, code)
|
|
||||||
}
|
|
||||||
return code
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *hookedStateDB) GetCodeSize(addr common.Address) int {
|
func (s *hookedStateDB) GetCodeSize(addr common.Address) int {
|
||||||
size := s.inner.GetCodeSize(addr)
|
return s.inner.GetCodeSize(addr)
|
||||||
if s.hooks.OnCodeRead != nil {
|
|
||||||
// GetCodeSize caches the code within the reader so this call is free.
|
|
||||||
code := s.inner.GetCode(addr)
|
|
||||||
s.hooks.OnCodeRead(addr, code)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *hookedStateDB) AddRefund(u uint64) {
|
func (s *hookedStateDB) AddRefund(u uint64) {
|
||||||
|
@ -112,11 +91,7 @@ func (s *hookedStateDB) GetCommittedState(addr common.Address, hash common.Hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *hookedStateDB) GetState(addr common.Address, hash common.Hash) common.Hash {
|
func (s *hookedStateDB) GetState(addr common.Address, hash common.Hash) common.Hash {
|
||||||
val := s.inner.GetState(addr, hash)
|
return s.inner.GetState(addr, hash)
|
||||||
if s.hooks.OnStorageRead != nil {
|
|
||||||
s.hooks.OnStorageRead(addr, hash, val)
|
|
||||||
}
|
|
||||||
return val
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *hookedStateDB) GetStorageRoot(addr common.Address) common.Hash {
|
func (s *hookedStateDB) GetStorageRoot(addr common.Address) common.Hash {
|
||||||
|
|
|
@ -90,12 +90,6 @@ func TestHooks(t *testing.T) {
|
||||||
"0xaa00000000000000000000000000000000000000.storage slot 0x0000000000000000000000000000000000000000000000000000000000000001: 0x0000000000000000000000000000000000000000000000000000000000000000 ->0x0000000000000000000000000000000000000000000000000000000000000011",
|
"0xaa00000000000000000000000000000000000000.storage slot 0x0000000000000000000000000000000000000000000000000000000000000001: 0x0000000000000000000000000000000000000000000000000000000000000000 ->0x0000000000000000000000000000000000000000000000000000000000000011",
|
||||||
"0xaa00000000000000000000000000000000000000.storage slot 0x0000000000000000000000000000000000000000000000000000000000000001: 0x0000000000000000000000000000000000000000000000000000000000000011 ->0x0000000000000000000000000000000000000000000000000000000000000022",
|
"0xaa00000000000000000000000000000000000000.storage slot 0x0000000000000000000000000000000000000000000000000000000000000001: 0x0000000000000000000000000000000000000000000000000000000000000011 ->0x0000000000000000000000000000000000000000000000000000000000000022",
|
||||||
"log 100",
|
"log 100",
|
||||||
"0xaa00000000000000000000000000000000000000.balance read: 50",
|
|
||||||
"0xaa00000000000000000000000000000000000000.nonce read: 1337",
|
|
||||||
"0xaa00000000000000000000000000000000000000.code read: [19 37]",
|
|
||||||
"0xaa00000000000000000000000000000000000000.storage read 0x0000000000000000000000000000000000000000000000000000000000000001: 0x0000000000000000000000000000000000000000000000000000000000000022",
|
|
||||||
"0xaa00000000000000000000000000000000000000.code read: [19 37]",
|
|
||||||
"0xaa00000000000000000000000000000000000000.code hash read: 0xa12ae05590de0c93a00bc7ac773c2fdb621e44f814985e72194f921c0050f728",
|
|
||||||
}
|
}
|
||||||
emitF := func(format string, a ...any) {
|
emitF := func(format string, a ...any) {
|
||||||
result = append(result, fmt.Sprintf(format, a...))
|
result = append(result, fmt.Sprintf(format, a...))
|
||||||
|
@ -116,21 +110,6 @@ func TestHooks(t *testing.T) {
|
||||||
OnLog: func(log *types.Log) {
|
OnLog: func(log *types.Log) {
|
||||||
emitF("log %v", log.TxIndex)
|
emitF("log %v", log.TxIndex)
|
||||||
},
|
},
|
||||||
OnBalanceRead: func(addr common.Address, bal *big.Int) {
|
|
||||||
emitF("%v.balance read: %v", addr, bal)
|
|
||||||
},
|
|
||||||
OnNonceRead: func(addr common.Address, nonce uint64) {
|
|
||||||
emitF("%v.nonce read: %v", addr, nonce)
|
|
||||||
},
|
|
||||||
OnCodeRead: func(addr common.Address, code []byte) {
|
|
||||||
emitF("%v.code read: %v", addr, code)
|
|
||||||
},
|
|
||||||
OnStorageRead: func(addr common.Address, slot common.Hash, value common.Hash) {
|
|
||||||
emitF("%v.storage read %v: %v", addr, slot, value)
|
|
||||||
},
|
|
||||||
OnCodeHashRead: func(addr common.Address, hash common.Hash) {
|
|
||||||
emitF("%v.code hash read: %v", addr, hash)
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
sdb.AddBalance(common.Address{0xaa}, uint256.NewInt(100), tracing.BalanceChangeUnspecified)
|
sdb.AddBalance(common.Address{0xaa}, uint256.NewInt(100), tracing.BalanceChangeUnspecified)
|
||||||
sdb.SubBalance(common.Address{0xaa}, uint256.NewInt(50), tracing.BalanceChangeTransfer)
|
sdb.SubBalance(common.Address{0xaa}, uint256.NewInt(50), tracing.BalanceChangeTransfer)
|
||||||
|
@ -143,12 +122,6 @@ func TestHooks(t *testing.T) {
|
||||||
sdb.AddLog(&types.Log{
|
sdb.AddLog(&types.Log{
|
||||||
Address: common.Address{0xbb},
|
Address: common.Address{0xbb},
|
||||||
})
|
})
|
||||||
sdb.GetBalance(common.Address{0xaa})
|
|
||||||
sdb.GetNonce(common.Address{0xaa})
|
|
||||||
sdb.GetCode(common.Address{0xaa})
|
|
||||||
sdb.GetState(common.Address{0xaa}, common.HexToHash("0x01"))
|
|
||||||
sdb.GetCodeSize(common.Address{0xaa})
|
|
||||||
sdb.GetCodeHash(common.Address{0xaa})
|
|
||||||
for i, want := range wants {
|
for i, want := range wants {
|
||||||
if have := result[i]; have != want {
|
if have := result[i]; have != want {
|
||||||
t.Fatalf("error event %d, have\n%v\nwant%v\n", i, have, want)
|
t.Fatalf("error event %d, have\n%v\nwant%v\n", i, have, want)
|
||||||
|
|
|
@ -174,21 +174,6 @@ type (
|
||||||
// LogHook is called when a log is emitted.
|
// LogHook is called when a log is emitted.
|
||||||
LogHook = func(log *types.Log)
|
LogHook = func(log *types.Log)
|
||||||
|
|
||||||
// BalanceReadHook is called when EVM reads the balance of an account.
|
|
||||||
BalanceReadHook = func(addr common.Address, bal *big.Int)
|
|
||||||
|
|
||||||
// NonceReadHook is called when EVM reads the nonce of an account.
|
|
||||||
NonceReadHook = func(addr common.Address, nonce uint64)
|
|
||||||
|
|
||||||
// CodeReadHook is called when EVM reads the code of an account.
|
|
||||||
CodeReadHook = func(addr common.Address, code []byte)
|
|
||||||
|
|
||||||
// CodeHashReadHook is called when EVM reads the code hash of an account.
|
|
||||||
CodeHashReadHook = func(addr common.Address, hash common.Hash)
|
|
||||||
|
|
||||||
// StorageReadHook is called when EVM reads a storage slot of an account.
|
|
||||||
StorageReadHook = func(addr common.Address, slot, value common.Hash)
|
|
||||||
|
|
||||||
// BlockHashReadHook is called when EVM reads the blockhash of a block.
|
// BlockHashReadHook is called when EVM reads the blockhash of a block.
|
||||||
BlockHashReadHook = func(blockNumber uint64, hash common.Hash)
|
BlockHashReadHook = func(blockNumber uint64, hash common.Hash)
|
||||||
)
|
)
|
||||||
|
@ -218,12 +203,6 @@ type Hooks struct {
|
||||||
OnCodeChange CodeChangeHook
|
OnCodeChange CodeChangeHook
|
||||||
OnStorageChange StorageChangeHook
|
OnStorageChange StorageChangeHook
|
||||||
OnLog LogHook
|
OnLog LogHook
|
||||||
// State reads
|
|
||||||
OnBalanceRead BalanceReadHook
|
|
||||||
OnNonceRead NonceReadHook
|
|
||||||
OnCodeRead CodeReadHook
|
|
||||||
OnCodeHashRead CodeHashReadHook
|
|
||||||
OnStorageRead StorageReadHook
|
|
||||||
// Block hash read
|
// Block hash read
|
||||||
OnBlockHashRead BlockHashReadHook
|
OnBlockHashRead BlockHashReadHook
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,11 +57,6 @@ func newNoopTracer(_ json.RawMessage) (*tracing.Hooks, error) {
|
||||||
OnCodeChange: t.OnCodeChange,
|
OnCodeChange: t.OnCodeChange,
|
||||||
OnStorageChange: t.OnStorageChange,
|
OnStorageChange: t.OnStorageChange,
|
||||||
OnLog: t.OnLog,
|
OnLog: t.OnLog,
|
||||||
OnBalanceRead: t.OnBalanceRead,
|
|
||||||
OnNonceRead: t.OnNonceRead,
|
|
||||||
OnCodeRead: t.OnCodeRead,
|
|
||||||
OnCodeHashRead: t.OnCodeHashRead,
|
|
||||||
OnStorageRead: t.OnStorageRead,
|
|
||||||
OnBlockHashRead: t.OnBlockHashRead,
|
OnBlockHashRead: t.OnBlockHashRead,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -114,16 +109,6 @@ func (t *noop) OnLog(l *types.Log) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *noop) OnBalanceRead(addr common.Address, bal *big.Int) {}
|
|
||||||
|
|
||||||
func (t *noop) OnNonceRead(addr common.Address, nonce uint64) {}
|
|
||||||
|
|
||||||
func (t *noop) OnCodeRead(addr common.Address, code []byte) {}
|
|
||||||
|
|
||||||
func (t *noop) OnCodeHashRead(addr common.Address, hash common.Hash) {}
|
|
||||||
|
|
||||||
func (t *noop) OnStorageRead(addr common.Address, slot, val common.Hash) {}
|
|
||||||
|
|
||||||
func (t *noop) OnBlockHashRead(number uint64, hash common.Hash) {}
|
func (t *noop) OnBlockHashRead(number uint64, hash common.Hash) {}
|
||||||
|
|
||||||
func (t *noop) OnGasChange(old, new uint64, reason tracing.GasChangeReason) {
|
func (t *noop) OnGasChange(old, new uint64, reason tracing.GasChangeReason) {
|
||||||
|
|
Loading…
Reference in New Issue