Skip to content

Commit f6e5596

Browse files
committed
Fixes for PV41/42
* Don't expand mem on empty value * Removed all coinbase logs for PV42 * Removed C++ bug stuff for LOG*
1 parent 20d518e commit f6e5596

7 files changed

Lines changed: 34 additions & 29 deletions

File tree

‎block_pool.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func (self *BlockPool) DistributeHashes() {
200200
} else if lastFetchFailed || item.peer == nil {
201201
// Find a suitable, available peer
202202
eachPeer(self.eth.peers, func(p *Peer, v *list.Element) {
203-
if peer == nil && len(dist[p]) < amount/peerLen {
203+
if peer == nil && len(dist[p]) < amount/peerLen && p.statusKnown {
204204
peer = p
205205
}
206206
})

‎chain/block_manager.go‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,13 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
217217

218218
txSha := DeriveSha(block.transactions)
219219
if bytes.Compare(txSha, block.TxSha) != 0 {
220-
err = fmt.Errorf("Error validating transaction sha. Received %x, got %x", block.TxSha, txSha)
220+
err = fmt.Errorf("Error validating transaction root. Received %x, got %x", block.TxSha, txSha)
221221
return
222222
}
223223

224224
receiptSha := DeriveSha(receipts)
225225
if bytes.Compare(receiptSha, block.ReceiptSha) != 0 {
226-
err = fmt.Errorf("Error validating receipt sha. Received %x, got %x", block.ReceiptSha, receiptSha)
226+
err = fmt.Errorf("Error validating receipt root. Received %x, got %x", block.ReceiptSha, receiptSha)
227227
return
228228
}
229229

@@ -238,7 +238,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
238238
return
239239
}
240240

241-
block.SetReceipts(receipts)
241+
block.receipts = receipts
242242
rbloom := CreateBloom(block)
243243
if bytes.Compare(rbloom, block.LogsBloom) != 0 {
244244
err = fmt.Errorf("unable to replicate block's bloom: %x", rbloom)
@@ -260,12 +260,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
260260
messages := state.Manifest().Messages
261261
state.Manifest().Reset()
262262

263-
/*
264-
sm.eth.ChainManager().SetTotalDifficulty(td)
265-
sm.eth.ChainManager().add(block)
266-
sm.eth.EventMux().Post(NewBlockEvent{block})
267-
sm.eth.EventMux().Post(messages)
268-
*/
263+
chainlogger.Infof("Processed block #%d (%x...)\n", block.Number, block.Hash()[0:4])
269264

270265
sm.transState = state.Copy()
271266

‎chain/bloom9.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
func CreateBloom(block *Block) []byte {
1212
bin := new(big.Int)
13-
bin.Or(bin, bloom9(crypto.Sha3(block.Coinbase)))
1413
for _, receipt := range block.Receipts() {
1514
bin.Or(bin, LogsBloom(receipt.logs))
1615
}

‎peer.go‎

Lines changed: 1 addition & 1 deletion
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 = 41
27+
ProtocolVersion = 42
2828
// Current P2P version
2929
P2PVersion = 2
3030
// Ethereum network version

‎vm/execution.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ func (self *Execution) Exec(codeAddr []byte, caller ClosureRef) ([]byte, error)
3434
func (self *Execution) exec(code, caddr []byte, caller ClosureRef) (ret []byte, err error) {
3535
env := self.vm.Env()
3636

37+
vmlogger.Debugf("pre state %x\n", env.State().Root())
3738
snapshot := env.State().Copy()
3839
defer func() {
3940
if IsDepthErr(err) || IsOOGErr(err) {
4041
env.State().Set(snapshot)
4142
}
43+
vmlogger.Debugf("post state %x\n", env.State().Root())
4244
}()
4345

4446
msg := env.State().Manifest().AddMessage(&state.Message{

‎vm/stack.go‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,26 @@ type Memory struct {
107107
store []byte
108108
}
109109

110+
func NewMemory() *Memory {
111+
return &Memory{nil}
112+
}
113+
110114
func (m *Memory) Set(offset, size int64, value []byte) {
111-
totSize := offset + size
112-
lenSize := int64(len(m.store) - 1)
113-
if totSize > lenSize {
114-
// Calculate the diff between the sizes
115-
diff := totSize - lenSize
116-
if diff > 0 {
117-
// Create a new empty slice and append it
118-
newSlice := make([]byte, diff-1)
119-
// Resize slice
120-
m.store = append(m.store, newSlice...)
115+
if len(value) > 0 {
116+
totSize := offset + size
117+
lenSize := int64(len(m.store) - 1)
118+
if totSize > lenSize {
119+
// Calculate the diff between the sizes
120+
diff := totSize - lenSize
121+
if diff > 0 {
122+
// Create a new empty slice and append it
123+
newSlice := make([]byte, diff-1)
124+
// Resize slice
125+
m.store = append(m.store, newSlice...)
126+
}
121127
}
128+
copy(m.store[offset:offset+size], value)
122129
}
123-
copy(m.store[offset:offset+size], value)
124130
}
125131

126132
func (m *Memory) Resize(size uint64) {

‎vm/vm_debug.go‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
6161
op OpCode
6262

6363
destinations = analyseJumpDests(closure.Code)
64-
mem = &Memory{}
64+
mem = NewMemory()
6565
stack = NewStack()
6666
pc = big.NewInt(0)
6767
step = 0
@@ -169,8 +169,6 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
169169
gas.Set(GasLog)
170170
addStepGasUsage(new(big.Int).Mul(big.NewInt(int64(n)), GasLog))
171171
addStepGasUsage(new(big.Int).Add(mSize, mStart))
172-
// BUG in C++
173-
//gas.Set(ethutil.Big1)
174172
// Gas only
175173
case STOP:
176174
gas.Set(ethutil.Big0)
@@ -263,11 +261,14 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
263261
memGasUsage.Div(memGasUsage, u256(32))
264262

265263
addStepGasUsage(memGasUsage)
264+
265+
mem.Resize(newMemSize.Uint64())
266266
}
267+
267268
}
268269

269270
self.Printf("(pc) %-3d -o- %-14s", pc, op.String())
270-
self.Printf(" (g) %-3v (%v)", gas, closure.Gas)
271+
self.Printf(" (m) %-4d (s) %-4d (g) %-3v (%v)", mem.Len(), stack.Len(), gas, closure.Gas)
271272

272273
if !closure.UseGas(gas) {
273274
self.Endl()
@@ -279,8 +280,6 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
279280
return closure.Return(nil), OOG(gas, tmp)
280281
}
281282

282-
mem.Resize(newMemSize.Uint64())
283-
284283
switch op {
285284
// 0x20 range
286285
case ADD:
@@ -622,6 +621,8 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
622621
code := closure.Args[cOff : cOff+l]
623622

624623
mem.Set(mOff, l, code)
624+
625+
self.Printf(" => [%v, %v, %v] %x", mOff, cOff, l, code[cOff:cOff+l])
625626
case CODESIZE, EXTCODESIZE:
626627
var code []byte
627628
if op == EXTCODESIZE {
@@ -663,6 +664,8 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
663664
codeCopy := code[cOff : cOff+l]
664665

665666
mem.Set(mOff, l, codeCopy)
667+
668+
self.Printf(" => [%v, %v, %v] %x", mOff, cOff, l, code[cOff:cOff+l])
666669
case GASPRICE:
667670
stack.Push(closure.Price)
668671

0 commit comments

Comments
 (0)