aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAlexandre Van de Sande <alex.vandesande@ethdev.com>2015-03-04 21:04:07 +0800
committerAlexandre Van de Sande <alex.vandesande@ethdev.com>2015-03-04 21:04:07 +0800
commit5f25c117eb6a1145b18fc13ebc03e4dc570b908e (patch)
treef5296850d29c08179ac9f51c925463d880e2db08 /core
parentcf880f78d5e85d563654ac8277c1d51bf8c382c2 (diff)
parenta56243075a7527d65d14c4cf3480029feb0a1e3f (diff)
downloaddexon-5f25c117eb6a1145b18fc13ebc03e4dc570b908e.tar
dexon-5f25c117eb6a1145b18fc13ebc03e4dc570b908e.tar.gz
dexon-5f25c117eb6a1145b18fc13ebc03e4dc570b908e.tar.bz2
dexon-5f25c117eb6a1145b18fc13ebc03e4dc570b908e.tar.lz
dexon-5f25c117eb6a1145b18fc13ebc03e4dc570b908e.tar.xz
dexon-5f25c117eb6a1145b18fc13ebc03e4dc570b908e.tar.zst
dexon-5f25c117eb6a1145b18fc13ebc03e4dc570b908e.zip
Merge branch 'develop' into ui
Diffstat (limited to 'core')
-rw-r--r--core/block_processor.go15
-rw-r--r--core/chain_manager.go31
-rw-r--r--core/filter.go35
-rw-r--r--core/genesis.go2
-rw-r--r--core/state_transition.go4
5 files changed, 64 insertions, 23 deletions
diff --git a/core/block_processor.go b/core/block_processor.go
index fd591a29d..7eaeb5be0 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -48,9 +48,8 @@ type BlockProcessor struct {
func NewBlockProcessor(db ethutil.Database, txpool *TxPool, chainManager *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
sm := &BlockProcessor{
- db: db,
- mem: make(map[string]*big.Int),
- //Pow: &ethash.Ethash{},
+ db: db,
+ mem: make(map[string]*big.Int),
Pow: ezp.New(),
bc: chainManager,
eventMux: eventMux,
@@ -62,7 +61,7 @@ func NewBlockProcessor(db ethutil.Database, txpool *TxPool, chainManager *ChainM
func (sm *BlockProcessor) TransitionState(statedb *state.StateDB, parent, block *types.Block, transientProcess bool) (receipts types.Receipts, err error) {
coinbase := statedb.GetOrNewStateObject(block.Header().Coinbase)
- coinbase.SetGasPool(CalcGasLimit(parent, block))
+ coinbase.SetGasPool(block.Header().GasLimit)
// Process the transactions on to parent state
receipts, _, _, _, err = sm.ApplyTransactions(coinbase, statedb, block, block.Transactions(), transientProcess)
@@ -100,7 +99,8 @@ func (self *BlockProcessor) ApplyTransaction(coinbase *state.StateObject, stated
// Notify all subscribers
if !transientProcess {
go self.eventMux.Post(TxPostEvent{tx})
- go self.eventMux.Post(statedb.Logs())
+ logs := statedb.Logs()
+ go self.eventMux.Post(logs)
}
return receipt, txGas, err
@@ -247,6 +247,11 @@ func (sm *BlockProcessor) ValidateBlock(block, parent *types.Block) error {
return fmt.Errorf("Difficulty check failed for block %v, %v", block.Header().Difficulty, expd)
}
+ expl := CalcGasLimit(parent, block)
+ if expl.Cmp(block.Header().GasLimit) != 0 {
+ return fmt.Errorf("GasLimit check failed for block %v, %v", block.Header().GasLimit, expl)
+ }
+
if block.Time() < parent.Time() {
return ValidationError("Block timestamp not after prev block (%v - %v)", block.Header().Time, parent.Header().Time)
}
diff --git a/core/chain_manager.go b/core/chain_manager.go
index 9ef091c3c..959bfd398 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -85,12 +85,14 @@ type ChainManager struct {
lastBlockHash []byte
transState *state.StateDB
+ txState *state.StateDB
}
func NewChainManager(db ethutil.Database, mux *event.TypeMux) *ChainManager {
bc := &ChainManager{db: db, genesisBlock: GenesisBlock(db), eventMux: mux}
bc.setLastBlock()
bc.transState = bc.State().Copy()
+ bc.txState = bc.State().Copy()
return bc
}
@@ -138,6 +140,19 @@ func (self *ChainManager) TransState() *state.StateDB {
return self.transState
}
+func (self *ChainManager) TxState() *state.StateDB {
+ self.tsmu.RLock()
+ defer self.tsmu.RUnlock()
+
+ return self.txState
+}
+
+func (self *ChainManager) setTxState(state *state.StateDB) {
+ self.tsmu.Lock()
+ defer self.tsmu.Unlock()
+ self.txState = state
+}
+
func (self *ChainManager) setTransState(statedb *state.StateDB) {
self.transState = statedb
}
@@ -268,7 +283,6 @@ func (self *ChainManager) GetBlockHashesFromHash(hash []byte, max uint64) (chain
break
}
}
- fmt.Printf("get hash %x (%d)\n", hash, len(chain))
return
}
@@ -363,6 +377,8 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
defer self.tsmu.Unlock()
for _, 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)
if err != nil {
if IsKnownBlockErr(err) {
@@ -377,11 +393,15 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
}
block.Td = td
- var chain, split bool
+ var canonical, split bool
self.mu.Lock()
{
+ // Write block to database. Eventually we'll have to improve on this and throw away blocks that are
+ // not in the canonical chain.
self.write(block)
cblock := self.currentBlock
+ // Compare the TD of the last known block in the canonical chain to make sure it's greater.
+ // At this point it's possible that a different chain (fork) becomes the new canonical chain.
if td.Cmp(self.td) > 0 {
if block.Header().Number.Cmp(new(big.Int).Add(cblock.Header().Number, ethutil.Big1)) < 0 {
chainlogger.Infof("Split detected. New head #%v (%x) TD=%v, was #%v (%x) TD=%v\n", block.Header().Number, block.Hash()[:4], td, cblock.Header().Number, cblock.Hash()[:4], self.td)
@@ -391,17 +411,18 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
self.setTotalDifficulty(td)
self.insert(block)
- chain = true
+ canonical = true
}
}
self.mu.Unlock()
- if chain {
+ if canonical {
+ self.setTransState(state.New(block.Root(), self.db))
self.eventMux.Post(ChainEvent{block, td})
}
if split {
- self.setTransState(state.New(block.Root(), self.db))
+ self.setTxState(state.New(block.Root(), self.db))
self.eventMux.Post(ChainSplitEvent{block})
}
}
diff --git a/core/filter.go b/core/filter.go
index cdf7b282d..c61c9e998 100644
--- a/core/filter.go
+++ b/core/filter.go
@@ -17,7 +17,7 @@ type FilterOptions struct {
Latest int64
Address [][]byte
- Topics [][]byte
+ Topics [][][]byte
Skip int
Max int
@@ -31,7 +31,7 @@ type Filter struct {
skip int
address [][]byte
max int
- topics [][]byte
+ topics [][][]byte
BlockCallback func(*types.Block)
PendingCallback func(*types.Block)
@@ -44,6 +44,8 @@ func NewFilter(eth Backend) *Filter {
return &Filter{eth: eth}
}
+// SetOptions copies the filter options to the filter it self. The reason for this "silly" copy
+// is simply because named arguments in this case is extremely nice and readable.
func (self *Filter) SetOptions(options FilterOptions) {
self.earliest = options.Earliest
self.latest = options.Latest
@@ -69,7 +71,7 @@ func (self *Filter) SetAddress(addr [][]byte) {
self.address = addr
}
-func (self *Filter) SetTopics(topics [][]byte) {
+func (self *Filter) SetTopics(topics [][][]byte) {
self.topics = topics
}
@@ -149,10 +151,18 @@ Logs:
continue
}
- max := int(math.Min(float64(len(self.topics)), float64(len(log.Topics()))))
- for i := 0; i < max; i++ {
- if !bytes.Equal(log.Topics()[i], self.topics[i]) {
- continue Logs
+ logTopics := make([][]byte, len(self.topics))
+ copy(logTopics, log.Topics())
+
+ for i, topics := range self.topics {
+ for _, topic := range topics {
+ var match bool
+ if bytes.Equal(log.Topics()[i], topic) {
+ match = true
+ }
+ if !match {
+ continue Logs
+ }
}
}
@@ -177,8 +187,15 @@ func (self *Filter) bloomFilter(block *types.Block) bool {
}
}
- for _, topic := range self.topics {
- if !types.BloomLookup(block.Bloom(), topic) {
+ for _, sub := range self.topics {
+ var included bool
+ for _, topic := range sub {
+ if types.BloomLookup(block.Bloom(), topic) {
+ included = true
+ break
+ }
+ }
+ if !included {
return false
}
}
diff --git a/core/genesis.go b/core/genesis.go
index 75b4fc100..decffc541 100644
--- a/core/genesis.go
+++ b/core/genesis.go
@@ -51,8 +51,6 @@ func GenesisBlock(db ethutil.Database) *types.Block {
statedb.Sync()
genesis.Header().Root = statedb.Root()
- fmt.Printf("+++ genesis +++\nRoot: %x\nHash: %x\n", genesis.Header().Root, genesis.Hash())
-
return genesis
}
diff --git a/core/state_transition.go b/core/state_transition.go
index 36ffa23d9..7331fdd4a 100644
--- a/core/state_transition.go
+++ b/core/state_transition.go
@@ -126,7 +126,7 @@ func (self *StateTransition) BuyGas() error {
self.AddGas(self.msg.Gas())
self.initialGas.Set(self.msg.Gas())
- sender.SubAmount(MessageGasValue(self.msg))
+ sender.SubBalance(MessageGasValue(self.msg))
return nil
}
@@ -251,7 +251,7 @@ func (self *StateTransition) RefundGas() {
coinbase, sender := self.Coinbase(), self.From()
// Return remaining gas
remaining := new(big.Int).Mul(self.gas, self.msg.GasPrice())
- sender.AddAmount(remaining)
+ sender.AddBalance(remaining)
uhalf := new(big.Int).Div(self.GasUsed(), ethutil.Big2)
for addr, ref := range self.state.Refunds() {