eth: rename rewind to reexec to make it more obvious

This commit is contained in:
Péter Szilágyi 2017-12-20 16:56:45 +02:00
parent 1a4a187675
commit 8ce0b32704

View file

@ -47,9 +47,10 @@ const (
// by default before being forcefully aborted. // by default before being forcefully aborted.
defaultTraceTimeout = 5 * time.Second defaultTraceTimeout = 5 * time.Second
// defaultTraceRewind is the number of blocks the tracer is willing to rewind // defaultTraceReexec is the number of blocks the tracer is willing to go back
// and regenerate to produce the state necessary to run a specific transaction. // and reexecute to produce missing historical state necessary to run a specific
defaultTraceRewind = uint64(128) // trace.
defaultTraceReexec = uint64(128)
) )
// TraceConfig holds extra parameters to trace functions. // TraceConfig holds extra parameters to trace functions.
@ -57,7 +58,7 @@ type TraceConfig struct {
*vm.LogConfig *vm.LogConfig
Tracer *string Tracer *string
Timeout *string Timeout *string
Rewind *uint64 Reexec *uint64
} }
// txTraceResult is the result of a single transaction trace. // txTraceResult is the result of a single transaction trace.
@ -99,7 +100,7 @@ type ephemeralDatabase struct {
} }
func (db *ephemeralDatabase) Put(key []byte, value []byte) error { return db.memdb.Put(key, value) } func (db *ephemeralDatabase) Put(key []byte, value []byte) error { return db.memdb.Put(key, value) }
func (db *ephemeralDatabase) Delete(key []byte) error { panic("delete not supported") } func (db *ephemeralDatabase) Delete(key []byte) error { return errors.New("delete not supported") }
func (db *ephemeralDatabase) Close() { db.memdb.Close() } func (db *ephemeralDatabase) Close() { db.memdb.Close() }
func (db *ephemeralDatabase) NewBatch() ethdb.Batch { func (db *ephemeralDatabase) NewBatch() ethdb.Batch {
return db.memdb.NewBatch() return db.memdb.NewBatch()
@ -201,13 +202,13 @@ func (api *PrivateDebugAPI) traceChain(ctx context.Context, start, end *types.Bl
} }
statedb, err := state.New(start.Root(), state.NewDatabase(db)) statedb, err := state.New(start.Root(), state.NewDatabase(db))
if err != nil { if err != nil {
// If the starting state is missing, allow some number of blocks to be rewound // If the starting state is missing, allow some number of blocks to be reexecuted
rewind := defaultTraceRewind reexec := defaultTraceReexec
if config.Rewind != nil { if config.Reexec != nil {
rewind = *config.Rewind reexec = *config.Reexec
} }
// Find the most recent block that has the state available // Find the most recent block that has the state available
for i := uint64(0); i < rewind; i++ { for i := uint64(0); i < reexec; i++ {
start = api.eth.blockchain.GetBlock(start.ParentHash(), start.NumberU64()-1) start = api.eth.blockchain.GetBlock(start.ParentHash(), start.NumberU64()-1)
if start == nil { if start == nil {
break break
@ -319,7 +320,7 @@ func (api *PrivateDebugAPI) traceChain(ctx context.Context, start, end *types.Bl
failed = fmt.Errorf("block #%d not found", number) failed = fmt.Errorf("block #%d not found", number)
break break
} }
// Send the block over to the concurrent tracers (if not in the rewind phase) // Send the block over to the concurrent tracers (if not in the fast-forward phase)
if number > origin { if number > origin {
txs := block.Transactions() txs := block.Transactions()
@ -463,11 +464,11 @@ func (api *PrivateDebugAPI) traceBlock(ctx context.Context, block *types.Block,
if parent == nil { if parent == nil {
return nil, fmt.Errorf("parent %x not found", block.ParentHash()) return nil, fmt.Errorf("parent %x not found", block.ParentHash())
} }
rewind := defaultTraceRewind reexec := defaultTraceReexec
if config.Rewind != nil { if config.Reexec != nil {
rewind = *config.Rewind reexec = *config.Reexec
} }
statedb, err := api.computeStateDB(parent, rewind) statedb, err := api.computeStateDB(parent, reexec)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -534,14 +535,14 @@ func (api *PrivateDebugAPI) traceBlock(ctx context.Context, block *types.Block,
// computeStateDB retrieves the state database associated with a certain block. // computeStateDB retrieves the state database associated with a certain block.
// If no state is locally available for the given block, a number of blocks are // If no state is locally available for the given block, a number of blocks are
// attempted to be rewound and replayed to regenerate the desired state. // attempted to be reexecuted to generate the desired state.
func (api *PrivateDebugAPI) computeStateDB(block *types.Block, rewind uint64) (*state.StateDB, error) { func (api *PrivateDebugAPI) computeStateDB(block *types.Block, reexec uint64) (*state.StateDB, error) {
// If we have the state fully available, use that // If we have the state fully available, use that
statedb, err := api.eth.blockchain.StateAt(block.Root()) statedb, err := api.eth.blockchain.StateAt(block.Root())
if err == nil { if err == nil {
return statedb, nil return statedb, nil
} }
// Otherwise try to rewind blocks until we find a state or reach our limit // Otherwise try to reexec blocks until we find a state or reach our limit
origin := block.NumberU64() origin := block.NumberU64()
memdb, _ := ethdb.NewMemDatabase() memdb, _ := ethdb.NewMemDatabase()
@ -549,7 +550,7 @@ func (api *PrivateDebugAPI) computeStateDB(block *types.Block, rewind uint64) (*
diskdb: api.eth.ChainDb(), diskdb: api.eth.ChainDb(),
memdb: memdb, memdb: memdb,
} }
for i := uint64(0); i < rewind; i++ { for i := uint64(0); i < reexec; i++ {
block = api.eth.blockchain.GetBlock(block.ParentHash(), block.NumberU64()-1) block = api.eth.blockchain.GetBlock(block.ParentHash(), block.NumberU64()-1)
if block == nil { if block == nil {
break break
@ -617,11 +618,11 @@ func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, hash common.Ha
if tx == nil { if tx == nil {
return nil, fmt.Errorf("transaction %x not found", hash) return nil, fmt.Errorf("transaction %x not found", hash)
} }
rewind := defaultTraceRewind reexec := defaultTraceReexec
if config.Rewind != nil { if config.Reexec != nil {
rewind = *config.Rewind reexec = *config.Reexec
} }
msg, vmctx, statedb, err := api.computeTxEnv(blockHash, int(index), rewind) msg, vmctx, statedb, err := api.computeTxEnv(blockHash, int(index), reexec)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -691,7 +692,7 @@ func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, v
} }
// computeTxEnv returns the execution environment of a certain transaction. // computeTxEnv returns the execution environment of a certain transaction.
func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, rewind uint64) (core.Message, vm.Context, *state.StateDB, error) { func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, reexec uint64) (core.Message, vm.Context, *state.StateDB, error) {
// Create the parent state database // Create the parent state database
block := api.eth.blockchain.GetBlockByHash(blockHash) block := api.eth.blockchain.GetBlockByHash(blockHash)
if block == nil { if block == nil {
@ -701,7 +702,7 @@ func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, rew
if parent == nil { if parent == nil {
return nil, vm.Context{}, nil, fmt.Errorf("parent %x not found", block.ParentHash()) return nil, vm.Context{}, nil, fmt.Errorf("parent %x not found", block.ParentHash())
} }
statedb, err := api.computeStateDB(parent, rewind) statedb, err := api.computeStateDB(parent, reexec)
if err != nil { if err != nil {
return nil, vm.Context{}, nil, err return nil, vm.Context{}, nil, err
} }