aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-05-21 06:17:50 +0800
committerobscuren <geffobscura@gmail.com>2014-05-21 06:17:50 +0800
commit5ceb1620e93e1999c6f72e6164c7c65af63244ec (patch)
treee3185f8202dd3f3ebd065be5a1ea7e7ba08e6055 /ethchain
parente8b45852952138ac24dada1a70480d31d0886c27 (diff)
downloaddexon-5ceb1620e93e1999c6f72e6164c7c65af63244ec.tar.gz
dexon-5ceb1620e93e1999c6f72e6164c7c65af63244ec.tar.zst
dexon-5ceb1620e93e1999c6f72e6164c7c65af63244ec.zip
Fixed couple issues
* (imp) Lock / RLock tries * (fix) stack
Diffstat (limited to 'ethchain')
-rw-r--r--ethchain/stack.go2
-rw-r--r--ethchain/state_manager.go46
-rw-r--r--ethchain/state_object_test.go29
-rw-r--r--ethchain/vm.go2
-rw-r--r--ethchain/vm_test.go9
5 files changed, 62 insertions, 26 deletions
diff --git a/ethchain/stack.go b/ethchain/stack.go
index e9297b324..bf34e6ea9 100644
--- a/ethchain/stack.go
+++ b/ethchain/stack.go
@@ -65,7 +65,7 @@ func (st *Stack) Peekn() (*big.Int, *big.Int) {
}
func (st *Stack) Push(d *big.Int) {
- st.data = append(st.data, d)
+ st.data = append(st.data, new(big.Int).Set(d))
}
func (st *Stack) Get(amount *big.Int) []*big.Int {
diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go
index c7c6857d8..27eaa5e60 100644
--- a/ethchain/state_manager.go
+++ b/ethchain/state_manager.go
@@ -100,30 +100,34 @@ func (sm *StateManager) MakeContract(state *State, tx *Transaction) *StateObject
func (sm *StateManager) ApplyTransactions(state *State, block *Block, txs []*Transaction) {
// Process each transaction/contract
for _, tx := range txs {
- // If there's no recipient, it's a contract
- // Check if this is a contract creation traction and if so
- // create a contract of this tx.
- if tx.IsContract() {
- err := sm.Ethereum.TxPool().ProcessTransaction(tx, block, false)
- if err == nil {
- contract := sm.MakeContract(state, tx)
- if contract != nil {
- sm.EvalScript(state, contract.Init(), contract, tx, block)
- } else {
- ethutil.Config.Log.Infoln("[STATE] Unable to create contract")
- }
+ sm.ApplyTransaction(state, block, tx)
+ }
+}
+
+func (sm *StateManager) ApplyTransaction(state *State, block *Block, tx *Transaction) {
+ // If there's no recipient, it's a contract
+ // Check if this is a contract creation traction and if so
+ // create a contract of this tx.
+ if tx.IsContract() {
+ err := sm.Ethereum.TxPool().ProcessTransaction(tx, block, false)
+ if err == nil {
+ contract := sm.MakeContract(state, tx)
+ if contract != nil {
+ sm.EvalScript(state, contract.Init(), contract, tx, block)
} else {
- ethutil.Config.Log.Infoln("[STATE] contract create:", err)
+ ethutil.Config.Log.Infoln("[STATE] Unable to create contract")
}
} else {
- err := sm.Ethereum.TxPool().ProcessTransaction(tx, block, false)
- contract := state.GetStateObject(tx.Recipient)
- ethutil.Config.Log.Debugf("contract recip %x\n", tx.Recipient)
- if err == nil && len(contract.Script()) > 0 {
- sm.EvalScript(state, contract.Script(), contract, tx, block)
- } else if err != nil {
- ethutil.Config.Log.Infoln("[STATE] process:", err)
- }
+ ethutil.Config.Log.Infoln("[STATE] contract create:", err)
+ }
+ } else {
+ err := sm.Ethereum.TxPool().ProcessTransaction(tx, block, false)
+ contract := state.GetStateObject(tx.Recipient)
+ ethutil.Config.Log.Debugf("contract recip %x\n", tx.Recipient)
+ if err == nil && len(contract.Script()) > 0 {
+ sm.EvalScript(state, contract.Script(), contract, tx, block)
+ } else if err != nil {
+ ethutil.Config.Log.Infoln("[STATE] process:", err)
}
}
}
diff --git a/ethchain/state_object_test.go b/ethchain/state_object_test.go
index 1db01a537..e955acc56 100644
--- a/ethchain/state_object_test.go
+++ b/ethchain/state_object_test.go
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethutil"
+ "math/big"
"testing"
)
@@ -21,5 +22,31 @@ func TestSync(t *testing.T) {
state.Sync()
object := state.GetStateObject([]byte("aa"))
- fmt.Printf("%x\n", object.Script())
+ if len(object.Script()) == 0 {
+ t.Fail()
+ }
+}
+
+func TestObjectGet(t *testing.T) {
+ ethutil.ReadConfig("", ethutil.LogStd)
+
+ db, _ := ethdb.NewMemDatabase()
+ ethutil.Config.Db = db
+
+ state := NewState(ethutil.NewTrie(db, ""))
+
+ contract := NewContract([]byte("aa"), ethutil.Big1, ZeroHash256)
+ state.UpdateStateObject(contract)
+
+ contract = state.GetStateObject([]byte("aa"))
+ contract.SetStorage(big.NewInt(0), ethutil.NewValue("hello"))
+ o := contract.GetMem(big.NewInt(0))
+ fmt.Println(o)
+
+ state.UpdateStateObject(contract)
+ contract.SetStorage(big.NewInt(0), ethutil.NewValue("hello00"))
+
+ contract = state.GetStateObject([]byte("aa"))
+ o = contract.GetMem(big.NewInt(0))
+ fmt.Println("after", o)
}
diff --git a/ethchain/vm.go b/ethchain/vm.go
index e732d22a4..9be38fcc1 100644
--- a/ethchain/vm.go
+++ b/ethchain/vm.go
@@ -390,10 +390,12 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
require(1)
loc := stack.Pop()
val := closure.GetMem(loc)
+ //fmt.Println("get", val.BigInt(), "@", loc)
stack.Push(val.BigInt())
case oSSTORE:
require(2)
val, loc := stack.Popn()
+ //fmt.Println("storing", val, "@", loc)
closure.SetStorage(loc, ethutil.NewValue(val))
// Add the change to manifest
diff --git a/ethchain/vm_test.go b/ethchain/vm_test.go
index 5d03ccf0c..2ec70536a 100644
--- a/ethchain/vm_test.go
+++ b/ethchain/vm_test.go
@@ -1,5 +1,6 @@
package ethchain
+/*
import (
_ "bytes"
"fmt"
@@ -23,10 +24,11 @@ func TestRun4(t *testing.T) {
if a > b {
int32 c = this.caller()
}
- Exit()
+ exit()
`), false)
tx := NewContractCreationTx(ethutil.Big("0"), ethutil.Big("1000"), ethutil.Big("100"), script, nil)
- addr := tx.Hash()[12:]
+ tx.Sign(ContractAddr)
+ addr := tx.CreationAddress()
contract := MakeContract(tx, state)
state.UpdateStateObject(contract)
fmt.Printf("%x\n", addr)
@@ -34,7 +36,7 @@ func TestRun4(t *testing.T) {
callerScript, err := mutan.Compile(strings.NewReader(`
// Check if there's any cash in the initial store
if this.store[1000] == 0 {
- this.store[1000] = 10^20
+ this.store[1000] = 10**20
}
@@ -93,3 +95,4 @@ func TestRun4(t *testing.T) {
}
fmt.Println("account.Amount =", account.Amount)
}
+*/