aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-10-02 23:03:15 +0800
committerobscuren <geffobscura@gmail.com>2014-10-02 23:03:15 +0800
commit82be3054961864dfd5bbeaec2ab961f593203dbf (patch)
treeefde516d8219f253f2bc87f26ad6d4169c2dc587
parenta34a971b508e1bc1fbeb3c2d02cbb8686d2491d8 (diff)
downloaddexon-82be3054961864dfd5bbeaec2ab961f593203dbf.tar.gz
dexon-82be3054961864dfd5bbeaec2ab961f593203dbf.tar.zst
dexon-82be3054961864dfd5bbeaec2ab961f593203dbf.zip
Fixed inconsistencies
-rw-r--r--ethchain/state_manager.go17
-rw-r--r--ethchain/state_transition.go4
-rw-r--r--ethchain/transaction.go11
-rw-r--r--ethpipe/js_pipe.go6
-rw-r--r--ethpipe/js_types.go8
-rw-r--r--ethpipe/pipe.go10
-rw-r--r--ethvm/vm.go6
7 files changed, 37 insertions, 25 deletions
diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go
index f38666572..93fd1ec58 100644
--- a/ethchain/state_manager.go
+++ b/ethchain/state_manager.go
@@ -104,18 +104,21 @@ func (self *StateManager) Stop() {
}
func (self *StateManager) updateThread() {
- blockChan := self.eth.Eventer().Register("block")
+ blockChan := self.eth.Eventer().Register("blocks")
out:
for {
select {
case event := <-blockChan:
- block := event.Data.(*Block)
- err := self.Process(block, false)
- if err != nil {
- statelogger.Infoln(err)
- statelogger.Debugf("Block #%v failed (%x...)\n", block.Number, block.Hash()[0:4])
- statelogger.Debugln(block)
+ blocks := event.Data.(Blocks)
+ for _, block := range blocks {
+ err := self.Process(block, false)
+ if err != nil {
+ statelogger.Infoln(err)
+ statelogger.Debugf("Block #%v failed (%x...)\n", block.Number, block.Hash()[0:4])
+ statelogger.Debugln(block)
+ break
+ }
}
case <-self.quit:
diff --git a/ethchain/state_transition.go b/ethchain/state_transition.go
index 096464963..fbb729950 100644
--- a/ethchain/state_transition.go
+++ b/ethchain/state_transition.go
@@ -292,9 +292,9 @@ func (self *StateTransition) Eval(msg *ethstate.Message, script []byte, context
func MakeContract(tx *Transaction, state *ethstate.State) *ethstate.StateObject {
// Create contract if there's no recipient
if tx.IsContract() {
- addr := tx.CreationAddress()
+ addr := tx.CreationAddress(state)
- contract := state.NewStateObject(addr)
+ contract := state.GetOrNewStateObject(addr)
contract.InitCode = tx.Data
contract.State = ethstate.New(ethtrie.New(ethutil.Config.Db, ""))
diff --git a/ethchain/transaction.go b/ethchain/transaction.go
index e7e8f3a9f..ae77ee58d 100644
--- a/ethchain/transaction.go
+++ b/ethchain/transaction.go
@@ -6,6 +6,7 @@ import (
"math/big"
"github.com/ethereum/eth-go/ethcrypto"
+ "github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethutil"
"github.com/obscuren/secp256k1-go"
)
@@ -77,8 +78,14 @@ func (tx *Transaction) IsContract() bool {
return tx.CreatesContract()
}
-func (tx *Transaction) CreationAddress() []byte {
- return ethcrypto.Sha3Bin(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce}).Encode())[12:]
+func (tx *Transaction) CreationAddress(state *ethstate.State) []byte {
+ // Generate a new address
+ addr := ethcrypto.Sha3Bin(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce}).Encode())[12:]
+ //for i := uint64(0); state.GetStateObject(addr) != nil; i++ {
+ // addr = ethcrypto.Sha3Bin(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce + i}).Encode())[12:]
+ //}
+
+ return addr
}
func (tx *Transaction) Signature(key []byte) []byte {
diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go
index 96990b671..24a553dad 100644
--- a/ethpipe/js_pipe.go
+++ b/ethpipe/js_pipe.go
@@ -233,16 +233,16 @@ func (self *JSPipe) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr
self.obj.TxPool().QueueTransaction(tx)
if contractCreation {
- logger.Infof("Contract addr %x", tx.CreationAddress())
+ logger.Infof("Contract addr %x", tx.CreationAddress(self.World().State()))
}
- return NewJSReciept(contractCreation, tx.CreationAddress(), tx.Hash(), keyPair.Address()), nil
+ return NewJSReciept(contractCreation, tx.CreationAddress(self.World().State()), tx.Hash(), keyPair.Address()), nil
}
func (self *JSPipe) PushTx(txStr string) (*JSReceipt, error) {
tx := ethchain.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr))
self.obj.TxPool().QueueTransaction(tx)
- return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(), tx.Hash(), tx.Sender()), nil
+ return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(self.World().State()), tx.Hash(), tx.Sender()), nil
}
func (self *JSPipe) CompileMutan(code string) string {
diff --git a/ethpipe/js_types.go b/ethpipe/js_types.go
index cf5686a4b..ca85da85a 100644
--- a/ethpipe/js_types.go
+++ b/ethpipe/js_types.go
@@ -35,7 +35,7 @@ func NewJSBlock(block *ethchain.Block) *JSBlock {
var ptxs []JSTransaction
for _, tx := range block.Transactions() {
- ptxs = append(ptxs, *NewJSTx(tx))
+ ptxs = append(ptxs, *NewJSTx(tx, block.State()))
}
list := ethutil.NewList(ptxs)
@@ -64,7 +64,7 @@ func (self *JSBlock) GetTransaction(hash string) *JSTransaction {
return nil
}
- return NewJSTx(tx)
+ return NewJSTx(tx, self.ref.State())
}
type JSTransaction struct {
@@ -83,11 +83,11 @@ type JSTransaction struct {
Confirmations int `json:"confirmations"`
}
-func NewJSTx(tx *ethchain.Transaction) *JSTransaction {
+func NewJSTx(tx *ethchain.Transaction, state *ethstate.State) *JSTransaction {
hash := ethutil.Bytes2Hex(tx.Hash())
receiver := ethutil.Bytes2Hex(tx.Recipient)
if receiver == "0000000000000000000000000000000000000000" {
- receiver = ethutil.Bytes2Hex(tx.CreationAddress())
+ receiver = ethutil.Bytes2Hex(tx.CreationAddress(state))
}
sender := ethutil.Bytes2Hex(tx.Sender())
createsContract := tx.CreatesContract()
diff --git a/ethpipe/pipe.go b/ethpipe/pipe.go
index 7c3f491d3..f57b56ea0 100644
--- a/ethpipe/pipe.go
+++ b/ethpipe/pipe.go
@@ -143,9 +143,10 @@ func (self *Pipe) Transact(key *ethcrypto.KeyPair, rec []byte, value, gas, price
self.obj.TxPool().QueueTransaction(tx)
if contractCreation {
- logger.Infof("Contract addr %x", tx.CreationAddress())
+ addr := tx.CreationAddress(self.World().State())
+ logger.Infof("Contract addr %x\n", addr)
- return tx.CreationAddress(), nil
+ return addr, nil
}
return tx.Hash(), nil
@@ -154,8 +155,9 @@ func (self *Pipe) Transact(key *ethcrypto.KeyPair, rec []byte, value, gas, price
func (self *Pipe) PushTx(tx *ethchain.Transaction) ([]byte, error) {
self.obj.TxPool().QueueTransaction(tx)
if tx.Recipient == nil {
- logger.Infof("Contract addr %x", tx.CreationAddress())
- return tx.CreationAddress(), nil
+ addr := tx.CreationAddress(self.World().State())
+ logger.Infof("Contract addr %x\n", addr)
+ return addr, nil
}
return tx.Hash(), nil
}
diff --git a/ethvm/vm.go b/ethvm/vm.go
index bb14d75da..4f0e41e5c 100644
--- a/ethvm/vm.go
+++ b/ethvm/vm.go
@@ -763,9 +763,9 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
// Generate a new address
addr := ethcrypto.CreateAddress(closure.Address(), closure.object.Nonce)
- for i := uint64(0); self.env.State().GetStateObject(addr) != nil; i++ {
- ethcrypto.CreateAddress(closure.Address(), closure.object.Nonce+i)
- }
+ //for i := uint64(0); self.env.State().GetStateObject(addr) != nil; i++ {
+ // ethcrypto.CreateAddress(closure.Address(), closure.object.Nonce+i)
+ //}
closure.object.Nonce++
self.Printf(" (*) %x", addr).Endl()