|
|
|
@ -45,7 +45,6 @@ import ( |
|
|
|
|
"github.com/harmony-one/harmony/core/state" |
|
|
|
|
"github.com/harmony-one/harmony/core/types" |
|
|
|
|
"github.com/harmony-one/harmony/core/vm" |
|
|
|
|
"github.com/harmony-one/harmony/hmy/tracers" |
|
|
|
|
"github.com/harmony-one/harmony/internal/params" |
|
|
|
|
"github.com/harmony-one/harmony/internal/utils" |
|
|
|
|
"github.com/harmony-one/harmony/numeric" |
|
|
|
@ -167,7 +166,6 @@ type BlockChain struct { |
|
|
|
|
processor Processor // block processor interface
|
|
|
|
|
validator Validator // block and state validator interface
|
|
|
|
|
vmConfig vm.Config |
|
|
|
|
traceDB string |
|
|
|
|
badBlocks *lru.Cache // Bad block cache
|
|
|
|
|
shouldPreserve func(*types.Block) bool // Function used to determine whether should preserve the given block.
|
|
|
|
|
pendingSlashes slash.Records |
|
|
|
@ -179,7 +177,7 @@ type BlockChain struct { |
|
|
|
|
// Processor.
|
|
|
|
|
func NewBlockChain( |
|
|
|
|
db ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, |
|
|
|
|
engine consensus_engine.Engine, vmConfig vm.Config, traceDB string, |
|
|
|
|
engine consensus_engine.Engine, vmConfig vm.Config, |
|
|
|
|
shouldPreserve func(block *types.Block) bool, |
|
|
|
|
) (*BlockChain, error) { |
|
|
|
|
if cacheConfig == nil { |
|
|
|
@ -230,7 +228,6 @@ func NewBlockChain( |
|
|
|
|
blockAccumulatorCache: blockAccumulatorCache, |
|
|
|
|
engine: engine, |
|
|
|
|
vmConfig: vmConfig, |
|
|
|
|
traceDB: traceDB, |
|
|
|
|
badBlocks: badBlocks, |
|
|
|
|
pendingSlashes: slash.Records{}, |
|
|
|
|
maxGarbCollectedBlkNum: -1, |
|
|
|
@ -258,8 +255,6 @@ func NewBlockChain( |
|
|
|
|
return bc, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var randname = time.Now().Nanosecond() |
|
|
|
|
|
|
|
|
|
// ValidateNewBlock validates new block.
|
|
|
|
|
func (bc *BlockChain) ValidateNewBlock(block *types.Block) error { |
|
|
|
|
state, err := state.New(bc.CurrentBlock().Root(), bc.stateCache) |
|
|
|
@ -1289,7 +1284,13 @@ func (bc *BlockChain) GetMaxGarbageCollectedBlockNumber() int64 { |
|
|
|
|
//
|
|
|
|
|
// After insertion is done, all accumulated events will be fired.
|
|
|
|
|
func (bc *BlockChain) InsertChain(chain types.Blocks, verifyHeaders bool) (int, error) { |
|
|
|
|
n, events, logs, err := bc.insertChain(chain, verifyHeaders) |
|
|
|
|
n, events, logs, err := bc.insertChain(chain, verifyHeaders, nil) |
|
|
|
|
bc.PostChainEvents(events, logs) |
|
|
|
|
return n, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (bc *BlockChain) InsertAndTraceChain(chain types.Blocks, verifyHeaders bool, tracers []*vm.Config) (int, error) { |
|
|
|
|
n, events, logs, err := bc.insertChain(chain, verifyHeaders, tracers) |
|
|
|
|
bc.PostChainEvents(events, logs) |
|
|
|
|
return n, err |
|
|
|
|
} |
|
|
|
@ -1297,7 +1298,7 @@ func (bc *BlockChain) InsertChain(chain types.Blocks, verifyHeaders bool) (int, |
|
|
|
|
// insertChain will execute the actual chain insertion and event aggregation. The
|
|
|
|
|
// only reason this method exists as a separate one is to make locking cleaner
|
|
|
|
|
// with deferred statements.
|
|
|
|
|
func (bc *BlockChain) insertChain(chain types.Blocks, verifyHeaders bool) (int, []interface{}, []*types.Log, error) { |
|
|
|
|
func (bc *BlockChain) insertChain(chain types.Blocks, verifyHeaders bool, tracers []*vm.Config) (int, []interface{}, []*types.Log, error) { |
|
|
|
|
// Sanity check that we have something meaningful to import
|
|
|
|
|
if len(chain) == 0 { |
|
|
|
|
return 0, nil, nil, nil |
|
|
|
@ -1425,7 +1426,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifyHeaders bool) (int, |
|
|
|
|
if len(winner) > 0 { |
|
|
|
|
// Import all the pruned blocks to make the state available
|
|
|
|
|
bc.chainmu.Unlock() |
|
|
|
|
_, evs, logs, err := bc.insertChain(winner, true /* verifyHeaders */) |
|
|
|
|
_, evs, logs, err := bc.insertChain(winner, true /* verifyHeaders */, nil) |
|
|
|
|
bc.chainmu.Lock() |
|
|
|
|
events, coalescedLogs = evs, logs |
|
|
|
|
|
|
|
|
@ -1452,11 +1453,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifyHeaders bool) (int, |
|
|
|
|
return i, events, coalescedLogs, err |
|
|
|
|
} |
|
|
|
|
vmConfig := bc.vmConfig |
|
|
|
|
if bc.traceDB != "" { |
|
|
|
|
vmConfig = vm.Config{ |
|
|
|
|
Debug: true, |
|
|
|
|
Tracer: &tracers.ParityBlockTracer{}, |
|
|
|
|
} |
|
|
|
|
if len(tracers) > i && tracers[i] != nil { |
|
|
|
|
vmConfig = *tracers[i] |
|
|
|
|
} |
|
|
|
|
// Process block using the parent state as reference point.
|
|
|
|
|
receipts, cxReceipts, logs, usedGas, payout, err := bc.processor.Process( |
|
|
|
@ -1480,19 +1478,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifyHeaders bool) (int, |
|
|
|
|
status, err := bc.WriteBlockWithState( |
|
|
|
|
block, receipts, cxReceipts, payout, state, |
|
|
|
|
) |
|
|
|
|
if bc.traceDB != "" { |
|
|
|
|
if tracer, ok := vmConfig.Tracer.(*tracers.ParityBlockTracer); ok { |
|
|
|
|
result := make([]json.RawMessage, 0) |
|
|
|
|
var err error |
|
|
|
|
if block.Transactions().Len() > 0 { |
|
|
|
|
result, err = tracer.GetResult() |
|
|
|
|
} |
|
|
|
|
if err == nil { |
|
|
|
|
b, _ := json.Marshal(result) |
|
|
|
|
fmt.Println(block.NumberU64(), string(b)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if err != nil { |
|
|
|
|
return i, events, coalescedLogs, err |
|
|
|
|
} |
|
|
|
|