Skip to content

Commit d80f8bd

Browse files
committed
Fixed issue in VM where LOG didn't pop anything of the stack
1 parent 3cf0477 commit d80f8bd

6 files changed

Lines changed: 56 additions & 48 deletions

File tree

‎block_pool.go‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,7 @@ func (self *BlockPool) FetchHashes(peer *Peer) bool {
9999
self.td = peer.td
100100

101101
if !self.HasLatestHash() {
102-
peer.doneFetchingHashes = false
103-
104-
const amount = 256
105-
peerlogger.Debugf("Fetching hashes (%d) %x...\n", amount, peer.lastReceivedHash[0:4])
106-
peer.QueueMessage(wire.NewMessage(wire.MsgGetBlockHashesTy, []interface{}{peer.lastReceivedHash, uint32(amount)}))
102+
self.fetchHashes()
107103
}
108104

109105
return true
@@ -112,6 +108,16 @@ func (self *BlockPool) FetchHashes(peer *Peer) bool {
112108
return false
113109
}
114110

111+
func (self *BlockPool) fetchHashes() {
112+
peer := self.peer
113+
114+
peer.doneFetchingHashes = false
115+
116+
const amount = 256
117+
peerlogger.Debugf("Fetching hashes (%d) %x...\n", amount, peer.lastReceivedHash[0:4])
118+
peer.QueueMessage(wire.NewMessage(wire.MsgGetBlockHashesTy, []interface{}{peer.lastReceivedHash, uint32(amount)}))
119+
}
120+
115121
func (self *BlockPool) AddHash(hash []byte, peer *Peer) {
116122
self.mut.Lock()
117123
defer self.mut.Unlock()
@@ -259,6 +265,13 @@ out:
259265
self.ChainLength = len(self.hashes)
260266
}
261267

268+
if self.peer != nil &&
269+
!self.peer.doneFetchingHashes &&
270+
time.Since(self.peer.lastHashAt) > 10*time.Second &&
271+
time.Since(self.peer.lastHashRequestedAt) > 5*time.Second {
272+
self.fetchHashes()
273+
}
274+
262275
/*
263276
if !self.fetchingHashes {
264277
blocks := self.Blocks()

‎core/block_manager.go‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
236236
return
237237
}
238238

239+
rbloom := types.CreateBloom(receipts)
240+
if bytes.Compare(rbloom, block.LogsBloom) != 0 {
241+
err = fmt.Errorf("unable to replicate block's bloom=%x", rbloom)
242+
return
243+
}
244+
239245
txSha := types.DeriveSha(block.Transactions())
240246
if bytes.Compare(txSha, block.TxSha) != 0 {
241247
err = fmt.Errorf("validating transaction root. received=%x got=%x", block.TxSha, txSha)
@@ -252,13 +258,6 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
252258
return
253259
}
254260

255-
//block.receipts = receipts // although this isn't necessary it be in the future
256-
rbloom := types.CreateBloom(receipts)
257-
if bytes.Compare(rbloom, block.LogsBloom) != 0 {
258-
err = fmt.Errorf("unable to replicate block's bloom=%x", rbloom)
259-
return
260-
}
261-
262261
state.Update(ethutil.Big0)
263262

264263
if !block.State().Cmp(state) {

‎core/types/bloom9.go‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@ func CreateBloom(receipts Receipts) []byte {
2020
func LogsBloom(logs state.Logs) *big.Int {
2121
bin := new(big.Int)
2222
for _, log := range logs {
23-
data := [][]byte{log.Address()}
24-
for _, topic := range log.Topics() {
25-
data = append(data, topic)
23+
data := make([][]byte, len(log.Topics())+1)
24+
data[0] = log.Address()
25+
26+
for i, topic := range log.Topics() {
27+
data[i+1] = topic
2628
}
2729

2830
for _, b := range data {
2931
bin.Or(bin, ethutil.BigD(bloom9(crypto.Sha3(b)).Bytes()))
3032
}
31-
32-
//if log.Data != nil {
33-
// data = append(data, log.Data)
34-
//}
3533
}
3634

3735
return bin

‎core/types/receipt.go‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,18 @@ func (self *Receipt) String() string {
6464

6565
type Receipts []*Receipt
6666

67+
func (self Receipts) RlpData() interface{} {
68+
data := make([]interface{}, len(self))
69+
for i, receipt := range self {
70+
data[i] = receipt.RlpData()
71+
}
72+
73+
return data
74+
}
75+
76+
func (self Receipts) RlpEncode() []byte {
77+
return ethutil.Encode(self.RlpData())
78+
}
79+
6780
func (self Receipts) Len() int { return len(self) }
6881
func (self Receipts) GetRlp(i int) []byte { return ethutil.Rlp(self[i]) }

‎peer.go‎

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424
// The size of the output buffer for writing messages
2525
outputBufferSize = 50
2626
// Current protocol version
27-
ProtocolVersion = 47
27+
ProtocolVersion = 48
2828
// Current P2P version
2929
P2PVersion = 2
3030
// Ethereum network version
@@ -129,9 +129,11 @@ type Peer struct {
129129
statusKnown bool
130130

131131
// Last received pong message
132-
lastPong int64
133-
lastBlockReceived time.Time
134-
doneFetchingHashes bool
132+
lastPong int64
133+
lastBlockReceived time.Time
134+
doneFetchingHashes bool
135+
lastHashAt time.Time
136+
lastHashRequestedAt time.Time
135137

136138
host []byte
137139
port uint16
@@ -327,19 +329,16 @@ out:
327329
}
328330
}
329331

332+
switch msg.Type {
333+
case wire.MsgGetBlockHashesTy:
334+
p.lastHashRequestedAt = time.Now()
335+
}
336+
330337
p.writeMessage(msg)
331338
p.lastSend = time.Now()
332339

333340
// Ping timer
334341
case <-pingTimer.C:
335-
/*
336-
timeSince := time.Since(time.Unix(p.lastPong, 0))
337-
if !p.pingStartTime.IsZero() && p.lastPong != 0 && timeSince > (pingPongTimer+30*time.Second) {
338-
peerlogger.Infof("Peer did not respond to latest pong fast enough, it took %s, disconnecting.\n", timeSince)
339-
p.Stop()
340-
return
341-
}
342-
*/
343342
p.writeMessage(wire.NewMessage(wire.MsgPingTy, ""))
344343
p.pingStartTime = time.Now()
345344

@@ -462,18 +461,6 @@ func (p *Peer) HandleInbound() {
462461
// TMP
463462
if p.statusKnown {
464463
switch msg.Type {
465-
/*
466-
case wire.MsgGetTxsTy:
467-
// Get the current transactions of the pool
468-
txs := p.ethereum.TxPool().CurrentTransactions()
469-
// Get the RlpData values from the txs
470-
txsInterface := make([]interface{}, len(txs))
471-
for i, tx := range txs {
472-
txsInterface[i] = tx.RlpData()
473-
}
474-
// Broadcast it back to the peer
475-
p.QueueMessage(wire.NewMessage(wire.MsgTxTy, txsInterface))
476-
*/
477464

478465
case wire.MsgGetBlockHashesTy:
479466
if msg.Data.Len() < 2 {
@@ -508,6 +495,7 @@ func (p *Peer) HandleInbound() {
508495
blockPool := p.ethereum.blockPool
509496

510497
foundCommonHash := false
498+
p.lastHashAt = time.Now()
511499

512500
it := msg.Data.NewIterator()
513501
for it.Next() {
@@ -524,9 +512,6 @@ func (p *Peer) HandleInbound() {
524512
}
525513

526514
if !foundCommonHash {
527-
//if !p.FetchHashes() {
528-
// p.doneFetchingHashes = true
529-
//}
530515
p.FetchHashes()
531516
} else {
532517
peerlogger.Infof("Found common hash (%x...)\n", p.lastReceivedHash[0:4])

‎vm/vm_debug.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,12 +744,12 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
744744
case LOG0, LOG1, LOG2, LOG3, LOG4:
745745
n := int(op - LOG0)
746746
topics := make([][]byte, n)
747-
mSize, mStart := stack.Pop().Int64(), stack.Pop().Int64()
748-
data := mem.Geti(mStart, mSize)
747+
mSize, mStart := stack.Popn()
749748
for i := 0; i < n; i++ {
750749
topics[i] = ethutil.LeftPadBytes(stack.Pop().Bytes(), 32)
751750
}
752751

752+
data := mem.Geti(mStart.Int64(), mSize.Int64())
753753
log := &Log{closure.Address(), topics, data}
754754
self.env.AddLog(log)
755755

0 commit comments

Comments
 (0)