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