aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-04-24 06:00:50 +0800
committerobscuren <geffobscura@gmail.com>2014-04-24 06:00:50 +0800
commit1c85d8c66b9db23687b0446b4a7e97e3e61fe188 (patch)
tree18b53dd3377e082d15185f1cb2c5d255975e0310
parent0651af9dfd701ba09e6c734f21eff85f61454476 (diff)
downloaddexon-1c85d8c66b9db23687b0446b4a7e97e3e61fe188.tar
dexon-1c85d8c66b9db23687b0446b4a7e97e3e61fe188.tar.gz
dexon-1c85d8c66b9db23687b0446b4a7e97e3e61fe188.tar.bz2
dexon-1c85d8c66b9db23687b0446b4a7e97e3e61fe188.tar.lz
dexon-1c85d8c66b9db23687b0446b4a7e97e3e61fe188.tar.xz
dexon-1c85d8c66b9db23687b0446b4a7e97e3e61fe188.tar.zst
dexon-1c85d8c66b9db23687b0446b4a7e97e3e61fe188.zip
Minor improvements and bug fixes
* Fixed VM base bug
-rw-r--r--ethchain/state.go4
-rw-r--r--ethchain/state_manager.go2
-rw-r--r--ethchain/transaction_pool.go8
-rw-r--r--ethchain/vm.go6
4 files changed, 12 insertions, 8 deletions
diff --git a/ethchain/state.go b/ethchain/state.go
index 655848932..fa63accf8 100644
--- a/ethchain/state.go
+++ b/ethchain/state.go
@@ -34,12 +34,12 @@ func (s *State) Reset() {
// Syncs the trie and all siblings
func (s *State) Sync() {
- s.trie.Sync()
-
// Sync all nested states
for _, state := range s.states {
state.Sync()
}
+
+ s.trie.Sync()
}
// Purges the current trie.
diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go
index 668a44c3f..29c3cd16b 100644
--- a/ethchain/state_manager.go
+++ b/ethchain/state_manager.go
@@ -117,6 +117,7 @@ func (sm *StateManager) ApplyTransactions(block *Block, txs []*Transaction) {
contract := sm.MakeContract(tx)
if contract != nil {
sm.EvalScript(contract.Init(), contract, tx, block)
+ fmt.Printf("state root of contract %x\n", contract.State().Root())
} else {
ethutil.Config.Log.Infoln("[STATE] Unable to create contract")
}
@@ -332,4 +333,5 @@ func (sm *StateManager) EvalScript(script []byte, object *StateObject, tx *Trans
// Update the account (refunds)
sm.procState.UpdateStateObject(caller)
+ sm.procState.UpdateStateObject(object)
}
diff --git a/ethchain/transaction_pool.go b/ethchain/transaction_pool.go
index 957381ac7..91fad2635 100644
--- a/ethchain/transaction_pool.go
+++ b/ethchain/transaction_pool.go
@@ -100,6 +100,10 @@ func (pool *TxPool) ProcessTransaction(tx *Transaction, block *Block, toContract
// Get the sender
sender := block.state.GetAccount(tx.Sender())
+ if sender.Nonce != tx.Nonce {
+ return fmt.Errorf("[TXPL] Invalid account nonce, state nonce is %d transaction nonce is %d instead", sender.Nonce, tx.Nonce)
+ }
+
// Make sure there's enough in the sender's account. Having insufficient
// funds won't invalidate this transaction but simple ignores it.
totAmount := new(big.Int).Add(tx.Value, new(big.Int).Mul(TxFee, TxFeeRat))
@@ -107,10 +111,6 @@ func (pool *TxPool) ProcessTransaction(tx *Transaction, block *Block, toContract
return fmt.Errorf("[TXPL] Insufficient amount in sender's (%x) account", tx.Sender())
}
- if sender.Nonce != tx.Nonce {
- return fmt.Errorf("[TXPL] Invalid account nonce, state nonce is %d transaction nonce is %d instead", sender.Nonce, tx.Nonce)
- }
-
// Get the receiver
receiver := block.state.GetAccount(tx.Recipient)
sender.Nonce += 1
diff --git a/ethchain/vm.go b/ethchain/vm.go
index 90b591f50..7df63b181 100644
--- a/ethchain/vm.go
+++ b/ethchain/vm.go
@@ -82,14 +82,15 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
pc := big.NewInt(0)
// Current step count
step := 0
- // The base for all big integer arithmetic
- base := new(big.Int)
if ethutil.Config.Debug {
ethutil.Config.Log.Debugf("# op\n")
}
for {
+ // The base for all big integer arithmetic
+ base := new(big.Int)
+
step++
// Get the memory location of pc
val := closure.Get(pc)
@@ -390,6 +391,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
require(1)
loc := stack.Pop()
val := closure.GetMem(loc)
+ fmt.Printf("load %x = %v\n", loc.Bytes(), val.BigInt())
stack.Push(val.BigInt())
case oSSTORE:
require(2)