aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/logger.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2016-10-31 19:07:43 +0800
committerGitHub <noreply@github.com>2016-10-31 19:07:43 +0800
commit4dc1fb923ab77fe564bdda25f36744dffa235045 (patch)
treece6de64598f42416dbffc1dff24904429f92031c /core/vm/logger.go
parentb8dec948d4d7d8257e63aeecf982c25aeec9a180 (diff)
parentbb6115b737a05e3b8bf70ff2ad74c703589627cb (diff)
downloadgo-tangerine-4dc1fb923ab77fe564bdda25f36744dffa235045.tar.gz
go-tangerine-4dc1fb923ab77fe564bdda25f36744dffa235045.tar.zst
go-tangerine-4dc1fb923ab77fe564bdda25f36744dffa235045.zip
Merge pull request #3064 from pirapira/limit_struct_logs
core/vm: add limit option to LogConfig
Diffstat (limited to 'core/vm/logger.go')
-rw-r--r--core/vm/logger.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/core/vm/logger.go b/core/vm/logger.go
index ae62b6b57..9e13d703b 100644
--- a/core/vm/logger.go
+++ b/core/vm/logger.go
@@ -42,6 +42,7 @@ type LogConfig struct {
DisableStack bool // disable stack capture
DisableStorage bool // disable storage capture
FullStorage bool // show full storage (slow)
+ Limit int // maximum length of output, but zero means unlimited
}
// StructLog is emitted to the Environment each cycle and lists information about the current internal state
@@ -64,7 +65,7 @@ type StructLog struct {
// Note that reference types are actual VM data structures; make copies
// if you need to retain them beyond the current call.
type Tracer interface {
- CaptureState(env Environment, pc uint64, op OpCode, gas, cost *big.Int, memory *Memory, stack *Stack, contract *Contract, depth int, err error)
+ CaptureState(env Environment, pc uint64, op OpCode, gas, cost *big.Int, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error
}
// StructLogger is an EVM state logger and implements Tracer.
@@ -93,7 +94,12 @@ func NewStructLogger(cfg *LogConfig) *StructLogger {
// captureState logs a new structured log message and pushes it out to the environment
//
// captureState also tracks SSTORE ops to track dirty values.
-func (l *StructLogger) CaptureState(env Environment, pc uint64, op OpCode, gas, cost *big.Int, memory *Memory, stack *Stack, contract *Contract, depth int, err error) {
+func (l *StructLogger) CaptureState(env Environment, pc uint64, op OpCode, gas, cost *big.Int, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error {
+ // check if already accumulated the specified number of logs
+ if l.cfg.Limit != 0 && l.cfg.Limit <= len(l.logs) {
+ return TraceLimitReachedError
+ }
+
// initialise new changed values storage container for this contract
// if not present.
if l.changedValues[contract.Address()] == nil {
@@ -152,6 +158,7 @@ func (l *StructLogger) CaptureState(env Environment, pc uint64, op OpCode, gas,
log := StructLog{pc, op, new(big.Int).Set(gas), cost, mem, stck, storage, env.Depth(), err}
l.logs = append(l.logs, log)
+ return nil
}
// StructLogs returns a list of captured log entries