Skip to content

Commit

Permalink
Remove complex ABI-based logging (ethereum#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcontracts authored Mar 23, 2021
1 parent 4ee9d3d commit 9e1ca7e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 34 deletions.
18 changes: 6 additions & 12 deletions accounts/abi/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type ABI struct {
Constructor Method
Methods map[string]Method
Events map[string]Event
MethodsById map[[4]byte]*Method
}

// JSON returns a parsed ABI interface and error if it failed.
Expand Down Expand Up @@ -121,7 +120,6 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
return err
}
abi.Methods = make(map[string]Method)
abi.MethodsById = make(map[[4]byte]*Method)
abi.Events = make(map[string]Event)
for _, field := range fields {
switch field.Type {
Expand All @@ -138,17 +136,13 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
_, ok = abi.Methods[name]
}
isConst := field.Constant || field.StateMutability == "pure" || field.StateMutability == "view"
method := Method{
abi.Methods[name] = Method{
Name: name,
RawName: field.Name,
Const: isConst,
Inputs: field.Inputs,
Outputs: field.Outputs,
}
abi.Methods[name] = method
// add method to the id cache
sigdata := method.ID()
abi.MethodsById[[4]byte{sigdata[0], sigdata[1], sigdata[2], sigdata[3]}] = &method
case "event":
name := field.Name
_, ok := abi.Events[name]
Expand All @@ -174,12 +168,12 @@ func (abi *ABI) MethodById(sigdata []byte) (*Method, error) {
if len(sigdata) < 4 {
return nil, fmt.Errorf("data too short (%d bytes) for abi method lookup", len(sigdata))
}

method, exist := abi.MethodsById[[4]byte{sigdata[0], sigdata[1], sigdata[2], sigdata[3]}]
if !exist {
return nil, fmt.Errorf("no method with id: %#x", sigdata[:4])
for _, method := range abi.Methods {
if bytes.Equal(method.ID(), sigdata[:4]) {
return &method, nil
}
}
return method, nil
return nil, fmt.Errorf("no method with id: %#x", sigdata[:4])
}

// EventByID looks an event up by its topic hash in the
Expand Down
23 changes: 1 addition & 22 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,7 @@ func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, err
// OVM_ENABLED
// Only log for non `eth_call`s
if evm.Context.EthCallSender == nil {
// Some simple logging here. First, check to see if we know about the address we're
// interacting with and try to log the input data.
var isUnknown = true
for name, account := range evm.chainConfig.StateDump.Accounts {
if contract.Address() == account.Address {
isUnknown = false
abi := &(account.ABI)
method, err := abi.MethodById(input)
if err != nil {
log.Debug("Calling Known Contract", "ID", evm.Id, "Name", name, "Message", err)
} else {
log.Debug("Calling Known Contract", "ID", evm.Id, "Name", name, "Method", method.RawName)
if method.RawName == "ovmREVERT" {
log.Debug("Contract Threw Exception", "ID", evm.Id, "asciified", string(input))
}
}
}
}
// We don't know the contract, so print some generic information.
if isUnknown {
log.Debug("Calling Unknown Contract", "ID", evm.Id, "Address", contract.Address().Hex())
}
log.Debug("Calling contract", "ID", evm.Id, "Address", contract.Address().Hex(), "Data", hexutil.Encode(input))
}

// Uncomment to make Safety checker always returns true.
Expand Down

0 comments on commit 9e1ca7e

Please sign in to comment.