Fixed bug where logging could crash client during tx adding

This commit is contained in:
obscuren 2015-01-02 22:19:58 +01:00
parent 5c82fdc243
commit 16f417f5af
5 changed files with 24 additions and 24 deletions

View File

@ -86,6 +86,7 @@ func (self *JSRepl) Stop() {
}
func (self *JSRepl) parseInput(code string) {
value, err := self.re.Run(code)
if err != nil {
fmt.Println(err)

View File

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
"gopkg.in/fatih/set.v0"
@ -107,7 +108,14 @@ func (self *TxPool) Add(tx *types.Transaction) error {
self.addTransaction(tx)
txplogger.Debugf("(t) %x => %x (%v) %x\n", tx.From()[:4], tx.To()[:4], tx.Value, tx.Hash())
var to string
if len(tx.To()) > 0 {
to = ethutil.Bytes2Hex(tx.To()[:4])
} else {
to = "[NEW_CONTRACT]"
}
txplogger.Debugf("(t) %x => %s (%v) %x\n", tx.From()[:4], to, tx.Value, tx.Hash())
// Notify the subscribers
go self.eventMux.Post(TxPreEvent{tx})

View File

@ -234,8 +234,10 @@ func (self *Ethereum) txBroadcastLoop() {
func (self *Ethereum) blockBroadcastLoop() {
// automatically stops if unsubscribe
for obj := range self.txSub.Chan() {
event := obj.(core.NewMinedBlockEvent)
self.server.Broadcast("eth", NewBlockMsg, event.Block.RlpData())
switch ev := obj.(type) {
case core.NewMinedBlockEvent:
self.server.Broadcast("eth", NewBlockMsg, ev.Block.RlpData())
}
}
}

View File

@ -72,15 +72,21 @@ type JSEthereum struct {
ethereum *eth.Ethereum
}
func (self *JSEthereum) GetBlock(hash string) otto.Value {
return self.toVal(&JSBlock{self.JSXEth.BlockByHash(hash), self})
func (self *JSEthereum) Block(v interface{}) otto.Value {
if number, ok := v.(int64); ok {
return self.toVal(&JSBlock{self.JSXEth.BlockByNumber(int32(number)), self})
} else if hash, ok := v.(string); ok {
return self.toVal(&JSBlock{self.JSXEth.BlockByHash(hash), self})
}
return otto.UndefinedValue()
}
func (self *JSEthereum) GetPeers() otto.Value {
func (self *JSEthereum) Peers() otto.Value {
return self.toVal(self.JSXEth.Peers())
}
func (self *JSEthereum) GetKey() otto.Value {
func (self *JSEthereum) Key() otto.Value {
return self.toVal(self.JSXEth.Key())
}
@ -88,10 +94,6 @@ func (self *JSEthereum) GetStateObject(addr string) otto.Value {
return self.toVal(&JSStateObject{xeth.NewJSObject(self.JSXEth.World().SafeGet(ethutil.Hex2Bytes(addr))), self})
}
func (self *JSEthereum) Peers() otto.Value {
return self.toVal(self.JSXEth.Peers())
}
func (self *JSEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) otto.Value {
r, err := self.JSXEth.Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr)
if err != nil {
@ -103,18 +105,6 @@ func (self *JSEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr,
return self.toVal(r)
}
func (self *JSEthereum) Create(key, valueStr, gasStr, gasPriceStr, scriptStr string) otto.Value {
r, err := self.JSXEth.Transact(key, "", valueStr, gasStr, gasPriceStr, scriptStr)
if err != nil {
fmt.Println(err)
return otto.UndefinedValue()
}
return self.toVal(r)
}
func (self *JSEthereum) toVal(v interface{}) otto.Value {
result, err := self.vm.ToValue(v)

View File

@ -12,7 +12,6 @@ func analyseJumpDests(code []byte) (dests *set.Set) {
a := uint64(op) - uint64(PUSH1) + 1
pc += a
//lp = true
case JUMPDEST:
dests.Add(pc)
}