aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-19 23:59:13 +0800
committerobscuren <geffobscura@gmail.com>2015-03-19 23:59:13 +0800
commitb5a71d955cacec0c8f81fbcf36b6f3d6d60b4bb1 (patch)
tree9d94b69006029e91d7cdf2d0eb9d6d457d238671 /core
parentce063e8d9c2d26dd283a43b097903628225179ea (diff)
parente540a75030de611ca8cf0a70621421b6aa3fbebf (diff)
downloaddexon-b5a71d955cacec0c8f81fbcf36b6f3d6d60b4bb1.tar.gz
dexon-b5a71d955cacec0c8f81fbcf36b6f3d6d60b4bb1.tar.zst
dexon-b5a71d955cacec0c8f81fbcf36b6f3d6d60b4bb1.zip
merge
Diffstat (limited to 'core')
-rw-r--r--core/block_processor.go18
-rw-r--r--core/chain_makers.go2
-rw-r--r--core/chain_manager.go16
-rw-r--r--core/events.go29
-rw-r--r--core/filter.go4
-rw-r--r--core/types/common.go6
6 files changed, 44 insertions, 31 deletions
diff --git a/core/block_processor.go b/core/block_processor.go
index b12f88c47..99c5fea05 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -16,10 +16,6 @@ import (
"gopkg.in/fatih/set.v0"
)
-type PendingBlockEvent struct {
- Block *types.Block
-}
-
var statelogger = logger.NewLogger("BLOCK")
type BlockProcessor struct {
@@ -137,7 +133,7 @@ func (self *BlockProcessor) ApplyTransactions(coinbase *state.StateObject, state
block.Header().GasUsed = totalUsedGas
if transientProcess {
- go self.eventMux.Post(PendingBlockEvent{block})
+ go self.eventMux.Post(PendingBlockEvent{block, statedb.Logs()})
}
return receipts, handled, unhandled, erroneous, err
@@ -146,25 +142,25 @@ func (self *BlockProcessor) ApplyTransactions(coinbase *state.StateObject, state
// Process block will attempt to process the given block's transactions and applies them
// on top of the block's parent state (given it exists) and will return wether it was
// successful or not.
-func (sm *BlockProcessor) Process(block *types.Block) (td *big.Int, err error) {
+func (sm *BlockProcessor) Process(block *types.Block) (td *big.Int, logs state.Logs, err error) {
// Processing a blocks may never happen simultaneously
sm.mutex.Lock()
defer sm.mutex.Unlock()
header := block.Header()
if sm.bc.HasBlock(header.Hash()) {
- return nil, &KnownBlockError{header.Number, header.Hash()}
+ return nil, nil, &KnownBlockError{header.Number, header.Hash()}
}
if !sm.bc.HasBlock(header.ParentHash) {
- return nil, ParentError(header.ParentHash)
+ return nil, nil, ParentError(header.ParentHash)
}
parent := sm.bc.GetBlock(header.ParentHash)
return sm.processWithParent(block, parent)
}
-func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big.Int, err error) {
+func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big.Int, logs state.Logs, err error) {
sm.lastAttemptedBlock = block
// Create a new state based on the parent's root (e.g., create copy)
@@ -177,7 +173,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big
// There can be at most two uncles
if len(block.Uncles()) > 2 {
- return nil, ValidationError("Block can only contain one uncle (contained %v)", len(block.Uncles()))
+ return nil, nil, ValidationError("Block can only contain one uncle (contained %v)", len(block.Uncles()))
}
receipts, err := sm.TransitionState(state, parent, block, false)
@@ -236,7 +232,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big
chainlogger.Infof("processed block #%d (%x...)\n", header.Number, block.Hash().Bytes()[0:4])
- return td, nil
+ return td, state.Logs(), nil
}
// Validates the current block. Returns an error if the block was invalid,
diff --git a/core/chain_makers.go b/core/chain_makers.go
index 857af960c..e3001331c 100644
--- a/core/chain_makers.go
+++ b/core/chain_makers.go
@@ -93,7 +93,7 @@ func makeChain(bman *BlockProcessor, parent *types.Block, max int, db common.Dat
blocks := make(types.Blocks, max)
for i := 0; i < max; i++ {
block := makeBlock(bman, parent, i, db, seed)
- td, err := bman.processWithParent(block, parent)
+ td, _, err := bman.processWithParent(block, parent)
if err != nil {
fmt.Println("process with parent failed", err)
panic(err)
diff --git a/core/chain_manager.go b/core/chain_manager.go
index 4bf9e9aed..ff37ea28a 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -410,7 +410,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
for i, block := range chain {
// Call in to the block processor and check for errors. It's likely that if one block fails
// all others will fail too (unless a known block is returned).
- td, err := self.processor.Process(block)
+ td, logs, err := self.processor.Process(block)
if err != nil {
if IsKnownBlockErr(err) {
continue
@@ -438,29 +438,27 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
hash := block.Hash()
chainlogger.Infof("Split detected. New head #%v (%x) TD=%v, was #%v (%x) TD=%v\n", block.Header().Number, hash[:4], td, cblock.Header().Number, chash[:4], self.td)
- queue[i] = ChainSplitEvent{block}
+ queue[i] = ChainSplitEvent{block, logs}
queueEvent.splitCount++
}
self.setTotalDifficulty(td)
self.insert(block)
- /* XXX crashes
jsonlogger.LogJson(&logger.EthChainNewHead{
- BlockHash: common.Bytes2Hex(block.Hash()),
+ BlockHash: block.Hash().Hex(),
BlockNumber: block.Number(),
- ChainHeadHash: common.Bytes2Hex(cblock.Hash()),
- BlockPrevHash: common.Bytes2Hex(block.ParentHash()),
+ ChainHeadHash: cblock.Hash().Hex(),
+ BlockPrevHash: block.ParentHash().Hex(),
})
- */
self.setTransState(state.New(block.Root(), self.stateDb))
self.setTxState(state.New(block.Root(), self.stateDb))
- queue[i] = ChainEvent{block}
+ queue[i] = ChainEvent{block, logs}
queueEvent.canonicalCount++
} else {
- queue[i] = ChainSideEvent{block}
+ queue[i] = ChainSideEvent{block, logs}
queueEvent.sideCount++
}
}
diff --git a/core/events.go b/core/events.go
index 23678ef60..8c5fb592a 100644
--- a/core/events.go
+++ b/core/events.go
@@ -1,6 +1,9 @@
package core
-import "github.com/ethereum/go-ethereum/core/types"
+import (
+ "github.com/ethereum/go-ethereum/core/types"
+ "github.com/ethereum/go-ethereum/state"
+)
// TxPreEvent is posted when a transaction enters the transaction pool.
type TxPreEvent struct{ Tx *types.Transaction }
@@ -15,11 +18,25 @@ type NewBlockEvent struct{ Block *types.Block }
type NewMinedBlockEvent struct{ Block *types.Block }
// ChainSplit is posted when a new head is detected
-type ChainSplitEvent struct{ Block *types.Block }
-
-type ChainEvent struct{ Block *types.Block }
-
-type ChainSideEvent struct{ Block *types.Block }
+type ChainSplitEvent struct {
+ Block *types.Block
+ Logs state.Logs
+}
+
+type ChainEvent struct {
+ Block *types.Block
+ Logs state.Logs
+}
+
+type ChainSideEvent struct {
+ Block *types.Block
+ Logs state.Logs
+}
+
+type PendingBlockEvent struct {
+ Block *types.Block
+ Logs state.Logs
+}
type ChainHeadEvent struct{ Block *types.Block }
diff --git a/core/filter.go b/core/filter.go
index e08aac120..f1627636f 100644
--- a/core/filter.go
+++ b/core/filter.go
@@ -33,8 +33,8 @@ type Filter struct {
max int
topics [][]common.Hash
- BlockCallback func(*types.Block)
- PendingCallback func(*types.Block)
+ BlockCallback func(*types.Block, state.Logs)
+ PendingCallback func(*types.Block, state.Logs)
LogsCallback func(state.Logs)
}
diff --git a/core/types/common.go b/core/types/common.go
index ace9c2c4b..4e885c4c6 100644
--- a/core/types/common.go
+++ b/core/types/common.go
@@ -1,14 +1,16 @@
package types
import (
- "fmt"
"math/big"
+ "github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/common"
+
+ "fmt"
)
type BlockProcessor interface {
- Process(*Block) (*big.Int, error)
+ Process(*Block) (*big.Int, state.Logs, error)
}
const bloomLength = 256