Upped protocol version for VM change

This commit is contained in:
obscuren 2014-09-18 01:02:15 +02:00
parent b3834d8272
commit f3a93b046e
5 changed files with 118 additions and 89 deletions

@ -5,5 +5,3 @@ import (
) )
var BlockReward *big.Int = big.NewInt(1.5e+18) var BlockReward *big.Int = big.NewInt(1.5e+18)
var UncleReward *big.Int = big.NewInt(1.125e+18)
var UncleInclusionReward *big.Int = big.NewInt(1.875e+17)

@ -92,6 +92,13 @@ func (cache *Cache) Get(key []byte) *ethutil.Value {
data, _ := cache.db.Get(key) data, _ := cache.db.Get(key)
// Create the cached value // Create the cached value
value := ethutil.NewValueFromBytes(data) value := ethutil.NewValueFromBytes(data)
defer func() {
if r := recover(); r != nil {
fmt.Println("RECOVER GET", cache, cache.nodes)
panic("bye")
}
}()
// Create caching node // Create caching node
cache.nodes[string(key)] = NewNode(key, value, false) cache.nodes[string(key)] = NewNode(key, value, false)

@ -872,8 +872,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
default: default:
vmlogger.Debugf("(pc) %-3v Invalid opcode %x\n", pc, op) vmlogger.Debugf("(pc) %-3v Invalid opcode %x\n", pc, op)
// XXX Really? //panic(fmt.Sprintf("Invalid opcode %x", op))
closure.UseGas(closure.Gas)
return closure.Return(nil), fmt.Errorf("Invalid opcode %x", op) return closure.Return(nil), fmt.Errorf("Invalid opcode %x", op)
} }

@ -24,7 +24,7 @@ func NewSimpleClientIdentity(clientIdentifier string, version string, customIden
version: version, version: version,
customIdentifier: customIdentifier, customIdentifier: customIdentifier,
os: runtime.GOOS, os: runtime.GOOS,
implementation: "Go", implementation: runtime.Version(),
} }
return clientIdentity return clientIdentity

193
peer.go

@ -24,9 +24,11 @@ const (
// The size of the output buffer for writing messages // The size of the output buffer for writing messages
outputBufferSize = 50 outputBufferSize = 50
// Current protocol version // Current protocol version
ProtocolVersion = 32 ProtocolVersion = 33
// Current P2P version // Current P2P version
P2PVersion = 0 P2PVersion = 0
// Ethereum network version
NetVersion = 0
// Interval for ping/pong message // Interval for ping/pong message
pingPongTimer = 2 * time.Second pingPongTimer = 2 * time.Second
) )
@ -72,7 +74,7 @@ func (d DiscReason) String() string {
type Caps byte type Caps byte
const ( const (
CapPeerDiscTy = 1 << iota CapPeerDiscTy Caps = 1 << iota
CapTxTy CapTxTy
CapChainTy CapChainTy
@ -309,6 +311,14 @@ out:
select { select {
// Main message queue. All outbound messages are processed through here // Main message queue. All outbound messages are processed through here
case msg := <-p.outputQueue: case msg := <-p.outputQueue:
if !p.statusKnown {
switch msg.Type {
case ethwire.MsgGetTxsTy, ethwire.MsgGetBlockHashesTy, ethwire.MsgGetBlocksTy, ethwire.MsgBlockHashesTy, ethwire.MsgBlockTy:
peerlogger.Debugln("Blocked outgoing [eth] message to peer without the [eth] cap.")
break
}
}
p.writeMessage(msg) p.writeMessage(msg)
p.lastSend = time.Now() p.lastSend = time.Now()
@ -435,100 +445,106 @@ func (p *Peer) HandleInbound() {
case ethwire.MsgStatusTy: case ethwire.MsgStatusTy:
// Handle peer's status msg // Handle peer's status msg
p.handleStatus(msg) p.handleStatus(msg)
case ethwire.MsgGetTxsTy: }
// Get the current transactions of the pool
txs := p.ethereum.TxPool().CurrentTransactions()
// Get the RlpData values from the txs
txsInterface := make([]interface{}, len(txs))
for i, tx := range txs {
txsInterface[i] = tx.RlpData()
}
// Broadcast it back to the peer
p.QueueMessage(ethwire.NewMessage(ethwire.MsgTxTy, txsInterface))
case ethwire.MsgGetBlockHashesTy: // TMP
if msg.Data.Len() < 2 { if p.statusKnown {
peerlogger.Debugln("err: argument length invalid ", msg.Data.Len()) switch msg.Type {
} case ethwire.MsgGetTxsTy:
// Get the current transactions of the pool
hash := msg.Data.Get(0).Bytes() txs := p.ethereum.TxPool().CurrentTransactions()
amount := msg.Data.Get(1).Uint() // Get the RlpData values from the txs
txsInterface := make([]interface{}, len(txs))
hashes := p.ethereum.BlockChain().GetChainHashesFromHash(hash, amount) for i, tx := range txs {
txsInterface[i] = tx.RlpData()
p.QueueMessage(ethwire.NewMessage(ethwire.MsgBlockHashesTy, ethutil.ByteSliceToInterface(hashes)))
case ethwire.MsgGetBlocksTy:
// Limit to max 300 blocks
max := int(math.Min(float64(msg.Data.Len()), 300.0))
var blocks []interface{}
for i := 0; i < max; i++ {
hash := msg.Data.Get(i).Bytes()
block := p.ethereum.BlockChain().GetBlock(hash)
if block != nil {
blocks = append(blocks, block.Value().Raw())
} }
} // Broadcast it back to the peer
p.QueueMessage(ethwire.NewMessage(ethwire.MsgTxTy, txsInterface))
p.QueueMessage(ethwire.NewMessage(ethwire.MsgBlockTy, blocks)) case ethwire.MsgGetBlockHashesTy:
if msg.Data.Len() < 2 {
case ethwire.MsgBlockHashesTy: peerlogger.Debugln("err: argument length invalid ", msg.Data.Len())
p.catchingUp = true
blockPool := p.ethereum.blockPool
foundCommonHash := false
it := msg.Data.NewIterator()
for it.Next() {
hash := it.Value().Bytes()
if blockPool.HasCommonHash(hash) {
foundCommonHash = true
break
} }
blockPool.AddHash(hash) hash := msg.Data.Get(0).Bytes()
amount := msg.Data.Get(1).Uint()
p.lastReceivedHash = hash hashes := p.ethereum.BlockChain().GetChainHashesFromHash(hash, amount)
p.lastBlockReceived = time.Now() p.QueueMessage(ethwire.NewMessage(ethwire.MsgBlockHashesTy, ethutil.ByteSliceToInterface(hashes)))
}
if foundCommonHash { case ethwire.MsgGetBlocksTy:
p.FetchBlocks() // Limit to max 300 blocks
} else { max := int(math.Min(float64(msg.Data.Len()), 300.0))
p.FetchHashes() var blocks []interface{}
}
case ethwire.MsgBlockTy: for i := 0; i < max; i++ {
p.catchingUp = true hash := msg.Data.Get(i).Bytes()
block := p.ethereum.BlockChain().GetBlock(hash)
if block != nil {
blocks = append(blocks, block.Value().Raw())
}
}
blockPool := p.ethereum.blockPool p.QueueMessage(ethwire.NewMessage(ethwire.MsgBlockTy, blocks))
it := msg.Data.NewIterator() case ethwire.MsgBlockHashesTy:
for it.Next() { p.catchingUp = true
block := ethchain.NewBlockFromRlpValue(it.Value())
//fmt.Printf("%v %x - %x\n", block.Number, block.Hash()[0:4], block.PrevHash[0:4])
blockPool.SetBlock(block, p) blockPool := p.ethereum.blockPool
p.lastBlockReceived = time.Now() foundCommonHash := false
}
var err error it := msg.Data.NewIterator()
blockPool.CheckLinkAndProcess(func(block *ethchain.Block) { for it.Next() {
err = p.ethereum.StateManager().Process(block, false) hash := it.Value().Bytes()
})
if err != nil { if blockPool.HasCommonHash(hash) {
peerlogger.Infoln(err) foundCommonHash = true
} else {
// Don't trigger if there's just one block. break
if blockPool.Len() != 0 && msg.Data.Len() > 1 { }
blockPool.AddHash(hash)
p.lastReceivedHash = hash
p.lastBlockReceived = time.Now()
}
if foundCommonHash {
p.FetchBlocks() p.FetchBlocks()
} else {
p.FetchHashes()
}
case ethwire.MsgBlockTy:
p.catchingUp = true
blockPool := p.ethereum.blockPool
it := msg.Data.NewIterator()
for it.Next() {
block := ethchain.NewBlockFromRlpValue(it.Value())
//fmt.Printf("%v %x - %x\n", block.Number, block.Hash()[0:4], block.PrevHash[0:4])
blockPool.SetBlock(block, p)
p.lastBlockReceived = time.Now()
}
var err error
blockPool.CheckLinkAndProcess(func(block *ethchain.Block) {
err = p.ethereum.StateManager().Process(block, false)
})
if err != nil {
peerlogger.Infoln(err)
} else {
// Don't trigger if there's just one block.
if blockPool.Len() != 0 && msg.Data.Len() > 1 {
p.FetchBlocks()
}
} }
} }
} }
@ -645,10 +661,9 @@ func (p *Peer) pushPeers() {
} }
func (self *Peer) pushStatus() { func (self *Peer) pushStatus() {
const netVersion = 0
msg := ethwire.NewMessage(ethwire.MsgStatusTy, []interface{}{ msg := ethwire.NewMessage(ethwire.MsgStatusTy, []interface{}{
uint32(ProtocolVersion), uint32(ProtocolVersion),
uint32(netVersion), uint32(NetVersion),
self.ethereum.BlockChain().TD, self.ethereum.BlockChain().TD,
self.ethereum.BlockChain().CurrentBlock.Hash(), self.ethereum.BlockChain().CurrentBlock.Hash(),
self.ethereum.BlockChain().Genesis().Hash(), self.ethereum.BlockChain().Genesis().Hash(),
@ -669,7 +684,17 @@ func (self *Peer) handleStatus(msg *ethwire.Msg) {
) )
if bytes.Compare(self.ethereum.BlockChain().Genesis().Hash(), genesis) != 0 { if bytes.Compare(self.ethereum.BlockChain().Genesis().Hash(), genesis) != 0 {
ethlogger.Warnf("Invalid genisis hash %x. Disabling [ETH]\n", genesis) ethlogger.Warnf("Invalid genisis hash %x. Disabling [eth]\n", genesis)
return
}
if netVersion != NetVersion {
ethlogger.Warnf("Invalid network version %d. Disabling [eth]\n", netVersion)
return
}
if protoVersion != ProtocolVersion {
ethlogger.Warnf("Invalid protocol version %d. Disabling [eth]\n", protoVersion)
return return
} }
@ -687,7 +712,7 @@ func (self *Peer) handleStatus(msg *ethwire.Msg) {
self.FetchHashes() self.FetchHashes()
} }
ethlogger.Infof("Peer is [ETH] capable. (TD = %v ~ %x) %d / %d", self.td, self.bestHash, protoVersion, netVersion) ethlogger.Infof("Peer is [eth] capable. (TD = %v ~ %x) %d / %d", self.td, self.bestHash, protoVersion, netVersion)
} }