aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--block_pool.go27
-rw-r--r--cmd/ethereum/main.go2
-rw-r--r--cmd/mist/assets/qml/views/wallet.qml23
-rw-r--r--cmd/mist/gui.go33
-rw-r--r--cmd/mist/main.go2
-rw-r--r--cmd/utils/cmd.go2
-rw-r--r--core/block_manager.go39
-rw-r--r--core/chain_manager.go29
-rw-r--r--core/transaction_pool.go10
-rw-r--r--core/types/bloom9.go12
-rw-r--r--core/types/receipt.go13
-rw-r--r--crypto/key_manager.go4
-rw-r--r--ethutil/script_unix.go42
-rw-r--r--ethutil/script_windows.go23
-rw-r--r--miner/miner.go25
-rw-r--r--peer.go40
-rw-r--r--vm/vm_debug.go12
-rw-r--r--vm/vm_test.go15
-rw-r--r--xeth/pipe.go8
19 files changed, 160 insertions, 201 deletions
diff --git a/block_pool.go b/block_pool.go
index 95c766e53..803927f21 100644
--- a/block_pool.go
+++ b/block_pool.go
@@ -88,7 +88,7 @@ func (self *BlockPool) FetchHashes(peer *Peer) bool {
if (self.peer == nil && peer.td.Cmp(highestTd) >= 0) || (self.peer != nil && peer.td.Cmp(self.peer.td) > 0) || self.peer == peer {
if self.peer != peer {
- poollogger.Debugf("Found better suitable peer (%v vs %v)\n", self.td, peer.td)
+ poollogger.Infof("Found better suitable peer (%v vs %v)\n", self.td, peer.td)
if self.peer != nil {
self.peer.doneFetchingHashes = true
@@ -99,11 +99,7 @@ func (self *BlockPool) FetchHashes(peer *Peer) bool {
self.td = peer.td
if !self.HasLatestHash() {
- peer.doneFetchingHashes = false
-
- const amount = 256
- peerlogger.Debugf("Fetching hashes (%d) %x...\n", amount, peer.lastReceivedHash[0:4])
- peer.QueueMessage(wire.NewMessage(wire.MsgGetBlockHashesTy, []interface{}{peer.lastReceivedHash, uint32(amount)}))
+ self.fetchHashes()
}
return true
@@ -112,6 +108,16 @@ func (self *BlockPool) FetchHashes(peer *Peer) bool {
return false
}
+func (self *BlockPool) fetchHashes() {
+ peer := self.peer
+
+ peer.doneFetchingHashes = false
+
+ const amount = 256
+ peerlogger.Debugf("Fetching hashes (%d) %x...\n", amount, peer.lastReceivedHash[0:4])
+ peer.QueueMessage(wire.NewMessage(wire.MsgGetBlockHashesTy, []interface{}{peer.lastReceivedHash, uint32(amount)}))
+}
+
func (self *BlockPool) AddHash(hash []byte, peer *Peer) {
self.mut.Lock()
defer self.mut.Unlock()
@@ -148,7 +154,7 @@ func (self *BlockPool) addBlock(b *types.Block, peer *Peer, newBlock bool) {
fmt.Println("1.", !self.eth.ChainManager().HasBlock(b.PrevHash), ethutil.Bytes2Hex(b.Hash()[0:4]), ethutil.Bytes2Hex(b.PrevHash[0:4]))
fmt.Println("2.", self.pool[string(b.PrevHash)] == nil)
fmt.Println("3.", !self.fetchingHashes)
- if !self.eth.ChainManager().HasBlock(b.PrevHash) && self.pool[string(b.PrevHash)] == nil && !self.fetchingHashes {
+ if !self.eth.ChainManager().HasBlock(b.PrevHash) /*&& self.pool[string(b.PrevHash)] == nil*/ && !self.fetchingHashes {
poollogger.Infof("Unknown chain, requesting (%x...)\n", b.PrevHash[0:4])
peer.QueueMessage(wire.NewMessage(wire.MsgGetBlockHashesTy, []interface{}{b.Hash(), uint32(256)}))
}
@@ -259,6 +265,13 @@ out:
self.ChainLength = len(self.hashes)
}
+ if self.peer != nil &&
+ !self.peer.doneFetchingHashes &&
+ time.Since(self.peer.lastHashAt) > 10*time.Second &&
+ time.Since(self.peer.lastHashRequestedAt) > 5*time.Second {
+ self.fetchHashes()
+ }
+
/*
if !self.fetchingHashes {
blocks := self.Blocks()
diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go
index c39f904fb..43551fb3a 100644
--- a/cmd/ethereum/main.go
+++ b/cmd/ethereum/main.go
@@ -30,7 +30,7 @@ import (
const (
ClientIdentifier = "Ethereum(G)"
- Version = "0.7.7"
+ Version = "0.7.9"
)
var clilogger = logger.NewLogger("CLI")
diff --git a/cmd/mist/assets/qml/views/wallet.qml b/cmd/mist/assets/qml/views/wallet.qml
index 9ffb1024d..9727ef35c 100644
--- a/cmd/mist/assets/qml/views/wallet.qml
+++ b/cmd/mist/assets/qml/views/wallet.qml
@@ -148,17 +148,21 @@ Rectangle {
id: txTableView
anchors.fill : parent
TableViewColumn{ role: "num" ; title: "#" ; width: 30 }
- TableViewColumn{ role: "from" ; title: "From" ; width: 280 }
- TableViewColumn{ role: "to" ; title: "To" ; width: 280 }
+ TableViewColumn{ role: "from" ; title: "From" ; width: 340 }
+ TableViewColumn{ role: "to" ; title: "To" ; width: 340 }
TableViewColumn{ role: "value" ; title: "Amount" ; width: 100 }
model: ListModel {
id: txModel
Component.onCompleted: {
- var filter = ethx.watch({latest: -1, from: eth.key().address});
- filter.changed(addTxs)
-
- addTxs(filter.messages())
+ var me = eth.key().address;
+ var filterTo = ethx.watch({latest: -1, to: me});
+ var filterFrom = ethx.watch({latest: -1, from: me});
+ filterTo.changed(addTxs)
+ filterFrom.changed(addTxs)
+
+ addTxs(filterTo.messages())
+ addTxs(filterFrom.messages())
}
function addTxs(messages) {
@@ -167,7 +171,12 @@ Rectangle {
for(var i = 0; i < messages.length; i++) {
var message = messages.get(i);
var to = eth.lookupName(message.to);
- var from = eth.lookupName(message.from);
+ var from;
+ if(message.from.length == 0) {
+ from = "- MINED -";
+ } else {
+ from = eth.lookupName(message.from);
+ }
txModel.insert(0, {num: txModel.count, from: from, to: to, value: eth.numberToHuman(message.value)})
}
}
diff --git a/cmd/mist/gui.go b/cmd/mist/gui.go
index e58e349d1..0b03cdc1b 100644
--- a/cmd/mist/gui.go
+++ b/cmd/mist/gui.go
@@ -389,7 +389,6 @@ func (gui *Gui) update() {
gui.loadAddressBook()
gui.loadMergedMiningOptions()
gui.setPeerInfo()
- //gui.readPreviousTransactions()
}()
for _, plugin := range gui.plugins {
@@ -404,7 +403,6 @@ func (gui *Gui) update() {
state := gui.eth.BlockManager().TransState()
- unconfirmedFunds := new(big.Int)
gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.address()).Balance())))
lastBlockLabel := gui.getObjectByName("lastBlockLabel")
@@ -418,9 +416,6 @@ func (gui *Gui) update() {
core.TxPostEvent{},
)
- // nameReg := gui.pipe.World().Config().Get("NameReg")
- // mux.Subscribe("object:"+string(nameReg.Address()), objectChan)
-
go func() {
defer events.Unsubscribe()
for {
@@ -438,15 +433,15 @@ func (gui *Gui) update() {
case core.TxPreEvent:
tx := ev.Tx
- object := state.GetAccount(gui.address())
- if bytes.Compare(tx.Sender(), gui.address()) == 0 {
- unconfirmedFunds.Sub(unconfirmedFunds, tx.Value)
- } else if bytes.Compare(tx.Recipient, gui.address()) == 0 {
- unconfirmedFunds.Add(unconfirmedFunds, tx.Value)
- }
+ tstate := gui.eth.BlockManager().TransState()
+ cstate := gui.eth.BlockManager().CurrentState()
+
+ taccount := tstate.GetAccount(gui.address())
+ caccount := cstate.GetAccount(gui.address())
+ unconfirmedFunds := new(big.Int).Sub(taccount.Balance(), caccount.Balance())
- gui.setWalletValue(object.Balance(), unconfirmedFunds)
+ gui.setWalletValue(taccount.Balance(), unconfirmedFunds)
gui.insertTransaction("pre", tx)
case core.TxPostEvent:
@@ -456,32 +451,18 @@ func (gui *Gui) update() {
if bytes.Compare(tx.Sender(), gui.address()) == 0 {
object.SubAmount(tx.Value)
- //gui.getObjectByName("transactionView").Call("addTx", xeth.NewJSTx(tx), "send")
gui.txDb.Put(tx.Hash(), tx.RlpEncode())
} else if bytes.Compare(tx.Recipient, gui.address()) == 0 {
object.AddAmount(tx.Value)
- //gui.getObjectByName("transactionView").Call("addTx", xeth.NewJSTx(tx), "recv")
gui.txDb.Put(tx.Hash(), tx.RlpEncode())
}
gui.setWalletValue(object.Balance(), nil)
state.UpdateStateObject(object)
- // case object:
- // gui.loadAddressBook()
-
case eth.PeerListEvent:
gui.setPeerInfo()
-
- /*
- case miner.Event:
- if ev.Type == miner.Started {
- gui.miner = ev.Miner
- } else {
- gui.miner = nil
- }
- */
}
case <-peerUpdateTicker.C:
diff --git a/cmd/mist/main.go b/cmd/mist/main.go
index 8c46de6d9..14336b4e8 100644
--- a/cmd/mist/main.go
+++ b/cmd/mist/main.go
@@ -31,7 +31,7 @@ import (
const (
ClientIdentifier = "Mist"
- Version = "0.7.7"
+ Version = "0.7.9"
)
var ethereum *eth.Ethereum
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index d9b26c701..db7bcd35e 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -145,7 +145,6 @@ func NewDatabase() ethutil.Database {
}
func NewClientIdentity(clientIdentifier, version, customIdentifier string) *wire.SimpleClientIdentity {
- clilogger.Infoln("identity created")
return wire.NewSimpleClientIdentity(clientIdentifier, version, customIdentifier)
}
@@ -240,6 +239,7 @@ func KeyTasks(keyManager *crypto.KeyManager, KeyRing string, GenAddr bool, Secre
exit(err)
}
}
+ clilogger.Infof("Main address %x\n", keyManager.Address())
}
func StartRpc(ethereum *eth.Ethereum, RpcPort int) {
diff --git a/core/block_manager.go b/core/block_manager.go
index c2ffc7ae0..4c1cea35a 100644
--- a/core/block_manager.go
+++ b/core/block_manager.go
@@ -123,7 +123,7 @@ func (sm *BlockManager) TransitionState(statedb *state.StateDB, parent, block *t
coinbase.SetGasPool(block.CalcGasLimit(parent))
// Process the transactions on to current block
- receipts, _, _, _, err = sm.ProcessTransactions(coinbase, statedb, block, parent, block.Transactions())
+ receipts, _, _, _, err = sm.ApplyTransactions(coinbase, statedb, block, block.Transactions(), false)
if err != nil {
return nil, err
}
@@ -131,7 +131,7 @@ func (sm *BlockManager) TransitionState(statedb *state.StateDB, parent, block *t
return receipts, nil
}
-func (self *BlockManager) ProcessTransactions(coinbase *state.StateObject, state *state.StateDB, block, parent *types.Block, txs types.Transactions) (types.Receipts, types.Transactions, types.Transactions, types.Transactions, error) {
+func (self *BlockManager) ApplyTransactions(coinbase *state.StateObject, state *state.StateDB, block *types.Block, txs types.Transactions, transientProcess bool) (types.Receipts, types.Transactions, types.Transactions, types.Transactions, error) {
var (
receipts types.Receipts
handled, unhandled types.Transactions
@@ -180,7 +180,9 @@ done:
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
// Notify all subscribers
- go self.eth.EventMux().Post(TxPostEvent{tx})
+ if !transientProcess {
+ go self.eth.EventMux().Post(TxPostEvent{tx})
+ }
receipts = append(receipts, receipt)
handled = append(handled, tx)
@@ -229,38 +231,33 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
return
}
- _, err = sm.TransitionState(state, parent, block)
+ receipts, err := sm.TransitionState(state, parent, block)
if err != nil {
return
}
+ rbloom := types.CreateBloom(receipts)
+ if bytes.Compare(rbloom, block.LogsBloom) != 0 {
+ err = fmt.Errorf("unable to replicate block's bloom=%x", rbloom)
+ return
+ }
+
txSha := types.DeriveSha(block.Transactions())
if bytes.Compare(txSha, block.TxSha) != 0 {
err = fmt.Errorf("validating transaction root. received=%x got=%x", block.TxSha, txSha)
return
}
- /*
- receiptSha := types.DeriveSha(receipts)
- if bytes.Compare(receiptSha, block.ReceiptSha) != 0 {
- err = fmt.Errorf("validating receipt root. received=%x got=%x", block.ReceiptSha, receiptSha)
- return
- }
- */
+ receiptSha := types.DeriveSha(receipts)
+ if bytes.Compare(receiptSha, block.ReceiptSha) != 0 {
+ err = fmt.Errorf("validating receipt root. received=%x got=%x", block.ReceiptSha, receiptSha)
+ return
+ }
if err = sm.AccumelateRewards(state, block, parent); err != nil {
return
}
- /*
- //block.receipts = receipts // although this isn't necessary it be in the future
- rbloom := types.CreateBloom(receipts)
- if bytes.Compare(rbloom, block.LogsBloom) != 0 {
- err = fmt.Errorf("unable to replicate block's bloom=%x", rbloom)
- return
- }
- */
-
state.Update(ethutil.Big0)
if !block.State().Cmp(state) {
@@ -378,7 +375,7 @@ func (sm *BlockManager) AccumelateRewards(statedb *state.StateDB, block, parent
account.AddAmount(reward)
statedb.Manifest().AddMessage(&state.Message{
- To: block.Coinbase, From: block.Coinbase,
+ To: block.Coinbase,
Input: nil,
Origin: nil,
Block: block.Hash(), Timestamp: block.Time, Coinbase: block.Coinbase, Number: block.Number,
diff --git a/core/chain_manager.go b/core/chain_manager.go
index 7acd171ec..150139def 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -125,7 +125,8 @@ func (bc *ChainManager) Reset() {
bc.genesisBlock.Trie().Sync()
// Prepare the genesis block
- bc.add(bc.genesisBlock)
+ bc.write(bc.genesisBlock)
+ bc.insert(bc.genesisBlock)
bc.CurrentBlock = bc.genesisBlock
bc.SetTotalDifficulty(ethutil.Big("0"))
@@ -134,18 +135,18 @@ func (bc *ChainManager) Reset() {
bc.TD = ethutil.BigD(ethutil.Config.Db.LastKnownTD())
}
-// Add a block to the chain and record addition information
-func (bc *ChainManager) add(block *types.Block) {
- bc.writeBlockInfo(block)
-
+func (bc *ChainManager) insert(block *types.Block) {
+ encodedBlock := block.RlpEncode()
+ ethutil.Config.Db.Put([]byte("LastBlock"), encodedBlock)
bc.CurrentBlock = block
bc.LastBlockHash = block.Hash()
+}
+
+func (bc *ChainManager) write(block *types.Block) {
+ bc.writeBlockInfo(block)
encodedBlock := block.RlpEncode()
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])
}
// Accessors
@@ -266,8 +267,16 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
return err
}
- self.add(block)
- self.SetTotalDifficulty(td)
+ self.write(block)
+ if td.Cmp(self.TD) > 0 {
+ if block.Number.Cmp(new(big.Int).Add(self.CurrentBlock.Number, ethutil.Big1)) < 0 {
+ chainlogger.Infof("Split detected. New head #%v (%x), was #%v (%x)\n", block.Number, block.Hash()[:4], self.CurrentBlock.Number, self.CurrentBlock.Hash()[:4])
+ }
+
+ self.SetTotalDifficulty(td)
+ self.insert(block)
+ }
+
self.eventMux.Post(NewBlockEvent{block})
self.eventMux.Post(messages)
}
diff --git a/core/transaction_pool.go b/core/transaction_pool.go
index abacb14f1..1d1f478e4 100644
--- a/core/transaction_pool.go
+++ b/core/transaction_pool.go
@@ -115,10 +115,6 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
return fmt.Errorf("tx.v != (28 || 27)")
}
- if tx.GasPrice.Cmp(MinGasPrice) < 0 {
- return fmt.Errorf("Gas price to low. Require %v > Got %v", MinGasPrice, tx.GasPrice)
- }
-
// Get the sender
sender := pool.Ethereum.BlockManager().CurrentState().GetAccount(tx.Sender())
@@ -164,11 +160,15 @@ func (self *TxPool) Add(tx *types.Transaction) error {
txplogger.Debugf("(t) %x => %x (%v) %x\n", tx.Sender()[:4], tmp, tx.Value, tx.Hash())
// Notify the subscribers
- self.Ethereum.EventMux().Post(TxPreEvent{tx})
+ go self.Ethereum.EventMux().Post(TxPreEvent{tx})
return nil
}
+func (self *TxPool) Size() int {
+ return self.pool.Len()
+}
+
func (pool *TxPool) CurrentTransactions() []*types.Transaction {
pool.mutex.Lock()
defer pool.mutex.Unlock()
diff --git a/core/types/bloom9.go b/core/types/bloom9.go
index d04656b0d..c1841e553 100644
--- a/core/types/bloom9.go
+++ b/core/types/bloom9.go
@@ -20,18 +20,16 @@ func CreateBloom(receipts Receipts) []byte {
func LogsBloom(logs state.Logs) *big.Int {
bin := new(big.Int)
for _, log := range logs {
- data := [][]byte{log.Address()}
- for _, topic := range log.Topics() {
- data = append(data, topic)
+ data := make([][]byte, len(log.Topics())+1)
+ data[0] = log.Address()
+
+ for i, topic := range log.Topics() {
+ data[i+1] = topic
}
for _, b := range data {
bin.Or(bin, ethutil.BigD(bloom9(crypto.Sha3(b)).Bytes()))
}
-
- //if log.Data != nil {
- // data = append(data, log.Data)
- //}
}
return bin
diff --git a/core/types/receipt.go b/core/types/receipt.go
index 25fa8fb07..bac64e41d 100644
--- a/core/types/receipt.go
+++ b/core/types/receipt.go
@@ -64,5 +64,18 @@ func (self *Receipt) String() string {
type Receipts []*Receipt
+func (self Receipts) RlpData() interface{} {
+ data := make([]interface{}, len(self))
+ for i, receipt := range self {
+ data[i] = receipt.RlpData()
+ }
+
+ return data
+}
+
+func (self Receipts) RlpEncode() []byte {
+ return ethutil.Encode(self.RlpData())
+}
+
func (self Receipts) Len() int { return len(self) }
func (self Receipts) GetRlp(i int) []byte { return ethutil.Rlp(self[i]) }
diff --git a/crypto/key_manager.go b/crypto/key_manager.go
index cc2b9ff90..326e559e0 100644
--- a/crypto/key_manager.go
+++ b/crypto/key_manager.go
@@ -5,8 +5,11 @@ import (
"sync"
"github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/logger"
)
+var keylogger = logger.NewLogger("KEY")
+
type KeyManager struct {
keyRing *KeyRing
session string
@@ -104,6 +107,7 @@ func (k *KeyManager) Init(session string, cursor int, force bool) error {
}
if keyRing == nil {
keyRing = NewGeneratedKeyRing(1)
+ keylogger.Infof("Created keypair. Private key: %x\n", keyRing.keys[0].PrivateKey)
}
return k.reset(session, cursor, keyRing)
}
diff --git a/ethutil/script_unix.go b/ethutil/script_unix.go
index 6827d4e2f..9250dda57 100644
--- a/ethutil/script_unix.go
+++ b/ethutil/script_unix.go
@@ -2,47 +2,17 @@
package ethutil
-import (
- "fmt"
- "strings"
-
- "github.com/ethereum/serpent-go"
- "github.com/obscuren/mutan"
- "github.com/obscuren/mutan/backends"
-)
+import "github.com/ethereum/serpent-go"
// General compile function
func Compile(script string, silent bool) (ret []byte, err error) {
if len(script) > 2 {
- line := strings.Split(script, "\n")[0]
-
- if len(line) > 1 && line[0:2] == "#!" {
- switch line {
- case "#!serpent":
- byteCode, err := serpent.Compile(script)
- if err != nil {
- return nil, err
- }
-
- return byteCode, nil
- }
- } else {
-
- compiler := mutan.NewCompiler(backend.NewEthereumBackend())
- compiler.Silent = silent
- byteCode, errors := compiler.Compile(strings.NewReader(script))
- if len(errors) > 0 {
- var errs string
- for _, er := range errors {
- if er != nil {
- errs += er.Error()
- }
- }
- return nil, fmt.Errorf("%v", errs)
- }
-
- return byteCode, nil
+ byteCode, err := serpent.Compile(script)
+ if err != nil {
+ return nil, err
}
+
+ return byteCode, nil
}
return nil, nil
diff --git a/ethutil/script_windows.go b/ethutil/script_windows.go
index ef239cd51..1dedc5f60 100644
--- a/ethutil/script_windows.go
+++ b/ethutil/script_windows.go
@@ -2,31 +2,10 @@
package ethutil
-import (
- "fmt"
- "strings"
-
- "github.com/obscuren/mutan"
- "github.com/obscuren/mutan/backends"
-)
-
// General compile function
func Compile(script string, silent bool) (ret []byte, err error) {
if len(script) > 2 {
- compiler := mutan.NewCompiler(backend.NewEthereumBackend())
- compiler.Silent = silent
- byteCode, errors := compiler.Compile(strings.NewReader(script))
- if len(errors) > 0 {
- var errs string
- for _, er := range errors {
- if er != nil {
- errs += er.Error()
- }
- }
- return nil, fmt.Errorf("%v", errs)
- }
-
- return byteCode, nil
+ return nil, nil
}
return nil, nil
diff --git a/miner/miner.go b/miner/miner.go
index 589144c0c..4f677cbef 100644
--- a/miner/miner.go
+++ b/miner/miner.go
@@ -167,7 +167,6 @@ out:
}
func (self *Miner) reset() {
- println("reset")
close(self.powQuitCh)
self.powQuitCh = make(chan struct{})
}
@@ -192,7 +191,7 @@ func (self *Miner) mine() {
// Accumulate all valid transactions and apply them to the new state
// Error may be ignored. It's not important during mining
- receipts, txs, _, erroneous, err := blockManager.ProcessTransactions(coinbase, block.State(), block, block, transactions)
+ receipts, txs, _, erroneous, err := blockManager.ApplyTransactions(coinbase, block.State(), block, transactions, true)
if err != nil {
minerlogger.Debugln(err)
}
@@ -228,23 +227,33 @@ func (self *Miner) mine() {
func (self *Miner) finiliseTxs() types.Transactions {
// Sort the transactions by nonce in case of odd network propagation
- var txs types.Transactions
+ actualSize := len(self.localTxs) // See copy below
+ txs := make(types.Transactions, actualSize+self.eth.TxPool().Size())
state := self.eth.BlockManager().TransState()
// XXX This has to change. Coinbase is, for new, same as key.
key := self.eth.KeyManager()
- for _, ltx := range self.localTxs {
+ for i, ltx := range self.localTxs {
tx := types.NewTransactionMessage(ltx.To, ethutil.Big(ltx.Value), ethutil.Big(ltx.Gas), ethutil.Big(ltx.GasPrice), ltx.Data)
tx.Nonce = state.GetNonce(self.Coinbase)
state.SetNonce(self.Coinbase, tx.Nonce+1)
tx.Sign(key.PrivateKey())
- txs = append(txs, tx)
+ txs[i] = tx
}
- txs = append(txs, self.eth.TxPool().CurrentTransactions()...)
- sort.Sort(types.TxByNonce{txs})
+ // Faster than append
+ for _, tx := range self.eth.TxPool().CurrentTransactions() {
+ if tx.GasPrice.Cmp(self.MinAcceptedGasPrice) >= 0 {
+ txs[actualSize] = tx
+ actualSize++
+ }
+ }
+
+ newTransactions := make(types.Transactions, actualSize)
+ copy(newTransactions, txs[:actualSize])
+ sort.Sort(types.TxByNonce{newTransactions})
- return txs
+ return newTransactions
}
diff --git a/peer.go b/peer.go
index bf84f6e35..46ac65247 100644
--- a/peer.go
+++ b/peer.go
@@ -24,7 +24,7 @@ const (
// The size of the output buffer for writing messages
outputBufferSize = 50
// Current protocol version
- ProtocolVersion = 47
+ ProtocolVersion = 48
// Current P2P version
P2PVersion = 2
// Ethereum network version
@@ -129,9 +129,11 @@ type Peer struct {
statusKnown bool
// Last received pong message
- lastPong int64
- lastBlockReceived time.Time
- doneFetchingHashes bool
+ lastPong int64
+ lastBlockReceived time.Time
+ doneFetchingHashes bool
+ lastHashAt time.Time
+ lastHashRequestedAt time.Time
host []byte
port uint16
@@ -327,19 +329,16 @@ out:
}
}
+ switch msg.Type {
+ case wire.MsgGetBlockHashesTy:
+ p.lastHashRequestedAt = time.Now()
+ }
+
p.writeMessage(msg)
p.lastSend = time.Now()
// Ping timer
case <-pingTimer.C:
- /*
- timeSince := time.Since(time.Unix(p.lastPong, 0))
- if !p.pingStartTime.IsZero() && p.lastPong != 0 && timeSince > (pingPongTimer+30*time.Second) {
- peerlogger.Infof("Peer did not respond to latest pong fast enough, it took %s, disconnecting.\n", timeSince)
- p.Stop()
- return
- }
- */
p.writeMessage(wire.NewMessage(wire.MsgPingTy, ""))
p.pingStartTime = time.Now()
@@ -462,18 +461,6 @@ func (p *Peer) HandleInbound() {
// TMP
if p.statusKnown {
switch msg.Type {
- /*
- case wire.MsgGetTxsTy:
- // Get the current transactions of the pool
- txs := p.ethereum.TxPool().CurrentTransactions()
- // Get the RlpData values from the txs
- txsInterface := make([]interface{}, len(txs))
- for i, tx := range txs {
- txsInterface[i] = tx.RlpData()
- }
- // Broadcast it back to the peer
- p.QueueMessage(wire.NewMessage(wire.MsgTxTy, txsInterface))
- */
case wire.MsgGetBlockHashesTy:
if msg.Data.Len() < 2 {
@@ -508,6 +495,7 @@ func (p *Peer) HandleInbound() {
blockPool := p.ethereum.blockPool
foundCommonHash := false
+ p.lastHashAt = time.Now()
it := msg.Data.NewIterator()
for it.Next() {
@@ -524,9 +512,6 @@ func (p *Peer) HandleInbound() {
}
if !foundCommonHash {
- //if !p.FetchHashes() {
- // p.doneFetchingHashes = true
- //}
p.FetchHashes()
} else {
peerlogger.Infof("Found common hash (%x...)\n", p.lastReceivedHash[0:4])
@@ -756,7 +741,6 @@ func (p *Peer) handleHandshake(msg *wire.Msg) {
// Check correctness of p2p protocol version
if p2pVersion != P2PVersion {
- fmt.Println(p)
peerlogger.Debugf("Invalid P2P version. Require protocol %d, received %d\n", P2PVersion, p2pVersion)
p.Stop()
return
diff --git a/vm/vm_debug.go b/vm/vm_debug.go
index 0a541a769..be1c59339 100644
--- a/vm/vm_debug.go
+++ b/vm/vm_debug.go
@@ -166,13 +166,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
case EXP:
require(2)
- exp := new(big.Int).Set(stack.data[stack.Len()-2])
- nbytes := 0
- for exp.Cmp(ethutil.Big0) > 0 {
- nbytes += 1
- exp.Rsh(exp, 8)
- }
- gas.Set(big.NewInt(int64(nbytes + 1)))
+ gas.Set(big.NewInt(int64(len(stack.data[stack.Len()-2].Bytes()) + 1)))
// Gas only
case STOP:
gas.Set(ethutil.Big0)
@@ -744,12 +738,12 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
case LOG0, LOG1, LOG2, LOG3, LOG4:
n := int(op - LOG0)
topics := make([][]byte, n)
- mSize, mStart := stack.Pop().Int64(), stack.Pop().Int64()
- data := mem.Geti(mStart, mSize)
+ mSize, mStart := stack.Popn()
for i := 0; i < n; i++ {
topics[i] = ethutil.LeftPadBytes(stack.Pop().Bytes(), 32)
}
+ data := mem.Geti(mStart.Int64(), mSize.Int64())
log := &Log{closure.Address(), topics, data}
self.env.AddLog(log)
diff --git a/vm/vm_test.go b/vm/vm_test.go
index 19aa171a6..84ebf378f 100644
--- a/vm/vm_test.go
+++ b/vm/vm_test.go
@@ -13,7 +13,6 @@ import (
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/trie"
checker "gopkg.in/check.v1"
- // "github.com/obscuren/mutan"
)
type VmSuite struct{}
@@ -68,24 +67,18 @@ func setup(level logger.LogLevel, typ Type) (*Closure, VirtualMachine) {
}
func (s *VmSuite) TestDebugVm(c *checker.C) {
- // if mutan.Version < "0.6" {
- // t.Skip("skipping for mutan version", mutan.Version, " < 0.6")
- // }
closure, vm := setup(logger.DebugLevel, DebugVmTy)
ret, _, e := closure.Call(vm, nil)
c.Assert(e, checker.NotNil)
- c.Skip("Depends on mutan")
+ c.Skip("Depends on mutan. Requires serpent implementation")
c.Assert(ret, checker.DeepEquals, big9)
}
func (s *VmSuite) TestVm(c *checker.C) {
- // if mutan.Version < "0.6" {
- // t.Skip("skipping for mutan version", mutan.Version, " < 0.6")
- // }
closure, vm := setup(logger.DebugLevel, StandardVmTy)
ret, _, e := closure.Call(vm, nil)
c.Assert(e, checker.NotNil)
- c.Skip("Depends on mutan")
+ c.Skip("Depends on mutan. Requires serpent implementation")
c.Assert(ret, checker.DeepEquals, big9)
}
@@ -142,7 +135,7 @@ func (s *VmSuite) TestBuildInSha256(c *checker.C) {
`, DebugVmTy)
exp := crypto.Sha256(ethutil.LeftPadBytes([]byte{42}, 32))
- c.Skip("Depends on mutan")
+ c.Skip("Depends on mutan. Requires serpent implementation")
c.Assert(ret, checker.DeepEquals, exp)
}
@@ -157,7 +150,7 @@ func (s *VmSuite) TestBuildInRipemd(c *checker.C) {
`, DebugVmTy)
exp := ethutil.RightPadBytes(crypto.Ripemd160(ethutil.LeftPadBytes([]byte{42}, 32)), 32)
- c.Skip("Depends on mutan")
+ c.Skip("Depends on mutan. Requires serpent implementation")
c.Assert(ret, checker.DeepEquals, exp)
}
diff --git a/xeth/pipe.go b/xeth/pipe.go
index 6da92cd23..2ca8134ce 100644
--- a/xeth/pipe.go
+++ b/xeth/pipe.go
@@ -136,11 +136,17 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et
tx.Nonce = nonce
tx.Sign(key.PrivateKey)
+
+ // Do some pre processing for our "pre" events and hooks
+ block := self.blockChain.NewBlock(key.Address())
+ coinbase := state.GetStateObject(key.Address())
+ coinbase.SetGasPool(block.GasLimit)
+ self.blockManager.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true)
+
err := self.obj.TxPool().Add(tx)
if err != nil {
return nil, err
}
-
state.SetNonce(key.Address(), nonce+1)
if contractCreation {