Numerous fixes for consensus.

* Removed (buged) C++ specific gas specification for LOG*
* Fixed LOG* where mstart went after msize
*
poc8
obscuren 10 years ago
parent 60cdb1148c
commit 20d518ee95
  1. 8
      chain/block_manager.go
  2. 8
      chain/chain_manager.go
  3. 2
      chain/filter.go
  4. 1
      chain/receipt.go
  5. 25
      chain/state_transition.go
  6. 6
      ethereum.go
  7. 2
      peer.go
  8. 10
      vm/vm_debug.go

@ -161,7 +161,6 @@ done:
cumulative := new(big.Int).Set(totalUsedGas.Add(totalUsedGas, txGas))
bloom := ethutil.LeftPadBytes(LogsBloom(state.Logs()).Bytes(), 64)
receipt := &Receipt{ethutil.CopyBytes(state.Root()), cumulative, bloom, state.Logs()}
fmt.Println(receipt)
// Notify all subscribers
go self.eth.EventMux().Post(TxPostEvent{tx})
@ -215,7 +214,6 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
if err != nil {
return
}
//block.SetReceipts(receipts)
txSha := DeriveSha(block.transactions)
if bytes.Compare(txSha, block.TxSha) != 0 {
@ -240,8 +238,10 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
return
}
if bytes.Compare(CreateBloom(block), block.LogsBloom) != 0 {
err = errors.New("Unable to replicate block's bloom")
block.SetReceipts(receipts)
rbloom := CreateBloom(block)
if bytes.Compare(rbloom, block.LogsBloom) != 0 {
err = fmt.Errorf("unable to replicate block's bloom: %x", rbloom)
return
}

@ -206,7 +206,7 @@ func (bc *ChainManager) add(block *Block) {
ethutil.Config.Db.Put(block.Hash(), encodedBlock)
ethutil.Config.Db.Put([]byte("LastBlock"), encodedBlock)
chainlogger.Infof("Imported block #%d (%x...)\n", block.Number, block.Hash()[0:4])
//chainlogger.Infof("Imported block #%d (%x...)\n", block.Number, block.Hash()[0:4])
}
func (self *ChainManager) CalcTotalDiff(block *Block) (*big.Int, error) {
@ -333,6 +333,12 @@ func (self *ChainManager) InsertChain(chain *BlockChain) {
self.Ethereum.EventMux().Post(NewBlockEvent{link.block})
self.Ethereum.EventMux().Post(link.messages)
}
b, e := chain.Front(), chain.Back()
if b != nil && e != nil {
front, back := b.Value.(*link).block, e.Value.(*link).block
chainlogger.Infof("Imported %d blocks. #%v (%x) / %#v (%x)", chain.Len(), front.Number, front.Hash()[0:4], back.Number, back.Hash()[0:4])
}
}
func (self *ChainManager) TestChain(chain *BlockChain) (td *big.Int, err error) {

@ -2,7 +2,6 @@ package chain
import (
"bytes"
"fmt"
"math"
"math/big"
@ -102,7 +101,6 @@ func (self *Filter) Find() []*state.Message {
// Use bloom filtering to see if this block is interesting given the
// current parameters
if self.bloomFilter(block) {
fmt.Println("block", block.Number, "has something interesting")
// Get the messages of the block
msgs, err := self.eth.BlockManager().GetMessages(block)
if err != nil {

@ -35,7 +35,6 @@ func (self *Receipt) RlpValueDecode(decoder *ethutil.Value) {
}
func (self *Receipt) RlpData() interface{} {
fmt.Println(self.logs.RlpData())
return []interface{}{self.PostState, self.CumulativeGasUsed, self.Bloom, self.logs.RlpData()}
}

@ -231,6 +231,31 @@ func (self *StateTransition) TransitionState() (err error) {
}
}
/*
* XXX The following _should_ replace the above transaction
* execution (also for regular calls. Will replace / test next
* phase
*/
/*
// Execute transaction
if tx.CreatesContract() {
self.rec = MakeContract(tx, self.state)
}
address := self.Receiver().Address()
evm := vm.New(NewEnv(state, self.tx, self.block), vm.DebugVmTy)
exe := NewExecution(evm, address, self.tx.Data, self.gas, self.gas.Price, self.tx.Value)
ret, err := msg.Exec(address, self.Sender())
if err != nil {
statelogger.Debugln(err)
} else {
if tx.CreatesContract() {
self.Receiver().Code = ret
}
msg.Output = ret
}
*/
// Add default LOG. Default = big(sender.addr) + 1
//addr := ethutil.BigD(receiver.Address())
//self.state.AddLog(&state.Log{ethutil.U256(addr.Add(addr, ethutil.Big1)).Bytes(), [][]byte{sender.Address()}, nil})

@ -233,7 +233,7 @@ func (s *Ethereum) ConnectToPeer(addr string) error {
if s.peers.Len() < s.MaxPeers {
var alreadyConnected bool
ahost, _, _ := net.SplitHostPort(addr)
ahost, aport, _ := net.SplitHostPort(addr)
var chost string
ips, err := net.LookupIP(ahost)
@ -273,9 +273,9 @@ func (s *Ethereum) ConnectToPeer(addr string) error {
if p.conn == nil {
return
}
phost, _, _ := net.SplitHostPort(p.conn.RemoteAddr().String())
phost, pport, _ := net.SplitHostPort(p.conn.RemoteAddr().String())
if phost == chost {
if phost == chost && pport == aport {
alreadyConnected = true
//loggerger.Debugf("Peer %s already added.\n", chost)
return

@ -24,7 +24,7 @@ const (
// The size of the output buffer for writing messages
outputBufferSize = 50
// Current protocol version
ProtocolVersion = 40
ProtocolVersion = 41
// Current P2P version
P2PVersion = 2
// Ethereum network version

@ -169,6 +169,8 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
gas.Set(GasLog)
addStepGasUsage(new(big.Int).Mul(big.NewInt(int64(n)), GasLog))
addStepGasUsage(new(big.Int).Add(mSize, mStart))
// BUG in C++
//gas.Set(ethutil.Big1)
// Gas only
case STOP:
gas.Set(ethutil.Big0)
@ -732,12 +734,16 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
case LOG0, LOG1, LOG2, LOG3, LOG4:
n := int(op - LOG0)
topics := make([][]byte, n)
mSize, mStart := stack.Pop().Int64(), stack.Pop().Int64()
mStart, mSize := stack.Pop().Int64(), stack.Pop().Int64()
data := mem.Geti(mStart, mSize)
for i := 0; i < n; i++ {
topics[i] = stack.Pop().Bytes()
}
self.env.AddLog(&state.Log{closure.Address(), topics, data})
log := &state.Log{closure.Address(), topics, data}
self.env.AddLog(log)
self.Printf(" => %v", log)
case MLOAD:
offset := stack.Pop()
val := ethutil.BigD(mem.Get(offset.Int64(), 32))

Loading…
Cancel
Save