Fixes for PV41/42

* Don't expand mem on empty value
* Removed all coinbase logs for PV42
* Removed C++ bug stuff for LOG*
This commit is contained in:
obscuren 2014-11-14 13:47:12 +01:00
parent 20d518ee95
commit f6e55962a8
7 changed files with 34 additions and 29 deletions

View File

@ -200,7 +200,7 @@ func (self *BlockPool) DistributeHashes() {
} else if lastFetchFailed || item.peer == nil { } else if lastFetchFailed || item.peer == nil {
// Find a suitable, available peer // Find a suitable, available peer
eachPeer(self.eth.peers, func(p *Peer, v *list.Element) { eachPeer(self.eth.peers, func(p *Peer, v *list.Element) {
if peer == nil && len(dist[p]) < amount/peerLen { if peer == nil && len(dist[p]) < amount/peerLen && p.statusKnown {
peer = p peer = p
} }
}) })

View File

@ -217,13 +217,13 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
txSha := DeriveSha(block.transactions) txSha := DeriveSha(block.transactions)
if bytes.Compare(txSha, block.TxSha) != 0 { if bytes.Compare(txSha, block.TxSha) != 0 {
err = fmt.Errorf("Error validating transaction sha. Received %x, got %x", block.TxSha, txSha) err = fmt.Errorf("Error validating transaction root. Received %x, got %x", block.TxSha, txSha)
return return
} }
receiptSha := DeriveSha(receipts) receiptSha := DeriveSha(receipts)
if bytes.Compare(receiptSha, block.ReceiptSha) != 0 { if bytes.Compare(receiptSha, block.ReceiptSha) != 0 {
err = fmt.Errorf("Error validating receipt sha. Received %x, got %x", block.ReceiptSha, receiptSha) err = fmt.Errorf("Error validating receipt root. Received %x, got %x", block.ReceiptSha, receiptSha)
return return
} }
@ -238,7 +238,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
return return
} }
block.SetReceipts(receipts) block.receipts = receipts
rbloom := CreateBloom(block) rbloom := CreateBloom(block)
if bytes.Compare(rbloom, block.LogsBloom) != 0 { if bytes.Compare(rbloom, block.LogsBloom) != 0 {
err = fmt.Errorf("unable to replicate block's bloom: %x", rbloom) 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
messages := state.Manifest().Messages messages := state.Manifest().Messages
state.Manifest().Reset() state.Manifest().Reset()
/* chainlogger.Infof("Processed block #%d (%x...)\n", block.Number, block.Hash()[0:4])
sm.eth.ChainManager().SetTotalDifficulty(td)
sm.eth.ChainManager().add(block)
sm.eth.EventMux().Post(NewBlockEvent{block})
sm.eth.EventMux().Post(messages)
*/
sm.transState = state.Copy() sm.transState = state.Copy()

View File

@ -10,7 +10,6 @@ import (
func CreateBloom(block *Block) []byte { func CreateBloom(block *Block) []byte {
bin := new(big.Int) bin := new(big.Int)
bin.Or(bin, bloom9(crypto.Sha3(block.Coinbase)))
for _, receipt := range block.Receipts() { for _, receipt := range block.Receipts() {
bin.Or(bin, LogsBloom(receipt.logs)) bin.Or(bin, LogsBloom(receipt.logs))
} }

View File

@ -24,7 +24,7 @@ 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 = 41 ProtocolVersion = 42
// Current P2P version // Current P2P version
P2PVersion = 2 P2PVersion = 2
// Ethereum network version // Ethereum network version

View File

@ -34,11 +34,13 @@ func (self *Execution) Exec(codeAddr []byte, caller ClosureRef) ([]byte, error)
func (self *Execution) exec(code, caddr []byte, caller ClosureRef) (ret []byte, err error) { func (self *Execution) exec(code, caddr []byte, caller ClosureRef) (ret []byte, err error) {
env := self.vm.Env() env := self.vm.Env()
vmlogger.Debugf("pre state %x\n", env.State().Root())
snapshot := env.State().Copy() snapshot := env.State().Copy()
defer func() { defer func() {
if IsDepthErr(err) || IsOOGErr(err) { if IsDepthErr(err) || IsOOGErr(err) {
env.State().Set(snapshot) env.State().Set(snapshot)
} }
vmlogger.Debugf("post state %x\n", env.State().Root())
}() }()
msg := env.State().Manifest().AddMessage(&state.Message{ msg := env.State().Manifest().AddMessage(&state.Message{

View File

@ -107,20 +107,26 @@ type Memory struct {
store []byte store []byte
} }
func NewMemory() *Memory {
return &Memory{nil}
}
func (m *Memory) Set(offset, size int64, value []byte) { func (m *Memory) Set(offset, size int64, value []byte) {
totSize := offset + size if len(value) > 0 {
lenSize := int64(len(m.store) - 1) totSize := offset + size
if totSize > lenSize { lenSize := int64(len(m.store) - 1)
// Calculate the diff between the sizes if totSize > lenSize {
diff := totSize - lenSize // Calculate the diff between the sizes
if diff > 0 { diff := totSize - lenSize
// Create a new empty slice and append it if diff > 0 {
newSlice := make([]byte, diff-1) // Create a new empty slice and append it
// Resize slice newSlice := make([]byte, diff-1)
m.store = append(m.store, newSlice...) // Resize slice
m.store = append(m.store, newSlice...)
}
} }
copy(m.store[offset:offset+size], value)
} }
copy(m.store[offset:offset+size], value)
} }
func (m *Memory) Resize(size uint64) { func (m *Memory) Resize(size uint64) {

View File

@ -61,7 +61,7 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
op OpCode op OpCode
destinations = analyseJumpDests(closure.Code) destinations = analyseJumpDests(closure.Code)
mem = &Memory{} mem = NewMemory()
stack = NewStack() stack = NewStack()
pc = big.NewInt(0) pc = big.NewInt(0)
step = 0 step = 0
@ -169,8 +169,6 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
gas.Set(GasLog) gas.Set(GasLog)
addStepGasUsage(new(big.Int).Mul(big.NewInt(int64(n)), GasLog)) addStepGasUsage(new(big.Int).Mul(big.NewInt(int64(n)), GasLog))
addStepGasUsage(new(big.Int).Add(mSize, mStart)) addStepGasUsage(new(big.Int).Add(mSize, mStart))
// BUG in C++
//gas.Set(ethutil.Big1)
// Gas only // Gas only
case STOP: case STOP:
gas.Set(ethutil.Big0) gas.Set(ethutil.Big0)
@ -263,11 +261,14 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
memGasUsage.Div(memGasUsage, u256(32)) memGasUsage.Div(memGasUsage, u256(32))
addStepGasUsage(memGasUsage) addStepGasUsage(memGasUsage)
mem.Resize(newMemSize.Uint64())
} }
} }
self.Printf("(pc) %-3d -o- %-14s", pc, op.String()) self.Printf("(pc) %-3d -o- %-14s", pc, op.String())
self.Printf(" (g) %-3v (%v)", gas, closure.Gas) self.Printf(" (m) %-4d (s) %-4d (g) %-3v (%v)", mem.Len(), stack.Len(), gas, closure.Gas)
if !closure.UseGas(gas) { if !closure.UseGas(gas) {
self.Endl() self.Endl()
@ -279,8 +280,6 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
return closure.Return(nil), OOG(gas, tmp) return closure.Return(nil), OOG(gas, tmp)
} }
mem.Resize(newMemSize.Uint64())
switch op { switch op {
// 0x20 range // 0x20 range
case ADD: case ADD:
@ -622,6 +621,8 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
code := closure.Args[cOff : cOff+l] code := closure.Args[cOff : cOff+l]
mem.Set(mOff, l, code) mem.Set(mOff, l, code)
self.Printf(" => [%v, %v, %v] %x", mOff, cOff, l, code[cOff:cOff+l])
case CODESIZE, EXTCODESIZE: case CODESIZE, EXTCODESIZE:
var code []byte var code []byte
if op == EXTCODESIZE { if op == EXTCODESIZE {
@ -663,6 +664,8 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
codeCopy := code[cOff : cOff+l] codeCopy := code[cOff : cOff+l]
mem.Set(mOff, l, codeCopy) mem.Set(mOff, l, codeCopy)
self.Printf(" => [%v, %v, %v] %x", mOff, cOff, l, code[cOff:cOff+l])
case GASPRICE: case GASPRICE:
stack.Push(closure.Price) stack.Push(closure.Price)