aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-11-19 02:44:17 +0800
committerobscuren <geffobscura@gmail.com>2014-11-19 02:44:17 +0800
commitf8d0cd9906a1ec4a4a1e95868a279312363f8b49 (patch)
tree04bb1876142343c69a3542d0dbebe7cbefd68105
parenta1b6a9ac29d0aa8d29a2c0535bafdb5fe4d4830b (diff)
downloaddexon-f8d0cd9906a1ec4a4a1e95868a279312363f8b49.tar.gz
dexon-f8d0cd9906a1ec4a4a1e95868a279312363f8b49.tar.zst
dexon-f8d0cd9906a1ec4a4a1e95868a279312363f8b49.zip
Added a callback mechanism to chain adding.
Not sure if this is the right approach. Why? BlockChain shouldn't need the "Ethereum" object. BlockChain shouldn't need to worry about notifying listeners or message propagation.
-rw-r--r--block_pool.go14
-rw-r--r--chain/chain_manager.go6
-rw-r--r--miner/miner.go7
-rw-r--r--peer.go3
4 files changed, 17 insertions, 13 deletions
diff --git a/block_pool.go b/block_pool.go
index dcddca58e..38302a4c7 100644
--- a/block_pool.go
+++ b/block_pool.go
@@ -13,6 +13,7 @@ import (
"github.com/ethereum/go-ethereum/chain/types"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
+ "github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/wire"
)
@@ -310,10 +311,6 @@ out:
}
}
- // TODO figure out whether we were catching up
- // If caught up and just a new block has been propagated:
- // sm.eth.EventMux().Post(NewBlockEvent{block})
- // otherwise process and don't emit anything
if len(blocks) > 0 {
chainManager := self.eth.ChainManager()
// Test and import
@@ -335,10 +332,13 @@ out:
self.peer = nil
} else {
if !chain.IsTDError(err) {
- chainManager.InsertChain(bchain)
- for _, block := range blocks {
+ chainManager.InsertChain(bchain, func(block *types.Block, messages state.Messages) {
+ self.eth.EventMux().Post(chain.NewBlockEvent{block})
+ self.eth.EventMux().Post(messages)
+
self.Remove(block.Hash())
- }
+ })
+
}
}
}
diff --git a/chain/chain_manager.go b/chain/chain_manager.go
index 11df4e17e..970fa5377 100644
--- a/chain/chain_manager.go
+++ b/chain/chain_manager.go
@@ -271,14 +271,14 @@ func (self *ChainManager) NewIterator(startHash []byte) *ChainIterator {
}
// This function assumes you've done your checking. No checking is done at this stage anymore
-func (self *ChainManager) InsertChain(chain *BlockChain) {
+func (self *ChainManager) InsertChain(chain *BlockChain, call func(*types.Block, state.Messages)) {
for e := chain.Front(); e != nil; e = e.Next() {
link := e.Value.(*link)
self.add(link.block)
self.SetTotalDifficulty(link.td)
- //self.eth.EventMux().Post(NewBlockEvent{link.block})
- //self.eth.EventMux().Post(link.messages)
+
+ call(link.block, link.messages)
}
b, e := chain.Front(), chain.Back()
diff --git a/miner/miner.go b/miner/miner.go
index b25e25357..795385424 100644
--- a/miner/miner.go
+++ b/miner/miner.go
@@ -29,6 +29,7 @@ import (
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/chain/types"
@@ -218,8 +219,10 @@ func (self *Miner) mine() {
if err != nil {
minerlogger.Infoln(err)
} else {
- chainMan.InsertChain(lchain)
- //self.eth.EventMux().Post(chain.NewBlockEvent{block})
+ chainMan.InsertChain(lchain, func(block *types.Block, _ state.Messages) {
+ self.eth.EventMux().Post(chain.NewBlockEvent{block})
+ })
+
self.eth.Broadcast(wire.MsgBlockTy, []interface{}{block.Value().Val})
minerlogger.Infof("🔨 Mined block %x\n", block.Hash())
diff --git a/peer.go b/peer.go
index fa73da21a..ff3593604 100644
--- a/peer.go
+++ b/peer.go
@@ -11,6 +11,7 @@ import (
"strings"
"sync/atomic"
"time"
+
"github.com/ethereum/go-ethereum/chain/types"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
@@ -23,7 +24,7 @@ const (
// The size of the output buffer for writing messages
outputBufferSize = 50
// Current protocol version
- ProtocolVersion = 42
+ ProtocolVersion = 43
// Current P2P version
P2PVersion = 2
// Ethereum network version