Commit d7098151 authored by obscuren's avatar obscuren

Added trans state and removed watch address etc

The transient state can be used to test out changes before committing
them to the proc state. The transient state is currently being used by
the gui to support proper nonce updating without having to wait for a
block. This used to be done by a cached state mechanism which can now
safely by removed.
parent f0440e85
...@@ -50,6 +50,10 @@ type StateManager struct { ...@@ -50,6 +50,10 @@ type StateManager struct {
// Comparative state it used for comparing and validating end // Comparative state it used for comparing and validating end
// results // results
compState *State compState *State
// Transiently state. The trans state isn't ever saved, validated and
// it could be used for setting account nonces without effecting
// the main states.
transState *State
manifest *Manifest manifest *Manifest
} }
...@@ -65,6 +69,8 @@ func NewStateManager(ethereum EthManager) *StateManager { ...@@ -65,6 +69,8 @@ func NewStateManager(ethereum EthManager) *StateManager {
manifest: NewManifest(), manifest: NewManifest(),
} }
sm.procState = ethereum.BlockChain().CurrentBlock.State() sm.procState = ethereum.BlockChain().CurrentBlock.State()
sm.transState = sm.procState.Copy()
return sm return sm
} }
...@@ -72,22 +78,8 @@ func (sm *StateManager) ProcState() *State { ...@@ -72,22 +78,8 @@ func (sm *StateManager) ProcState() *State {
return sm.procState return sm.procState
} }
// Watches any given address and puts it in the address state store func (sm *StateManager) TransState() *State {
func (sm *StateManager) WatchAddr(addr []byte) *CachedStateObject { return sm.transState
//XXX account := sm.bc.CurrentBlock.state.GetAccount(addr)
account := sm.procState.GetAccount(addr)
return sm.stateObjectCache.Add(addr, account)
}
func (sm *StateManager) GetAddrState(addr []byte) *CachedStateObject {
account := sm.stateObjectCache.Get(addr)
if account == nil {
a := sm.procState.GetAccount(addr)
account = &CachedStateObject{Nonce: a.Nonce, Object: a}
}
return account
} }
func (sm *StateManager) BlockChain() *BlockChain { func (sm *StateManager) BlockChain() *BlockChain {
......
...@@ -148,8 +148,7 @@ func (pool *TxPool) ValidateTransaction(tx *Transaction) error { ...@@ -148,8 +148,7 @@ func (pool *TxPool) ValidateTransaction(tx *Transaction) error {
} }
// Get the sender // Get the sender
accountState := pool.Ethereum.StateManager().GetAddrState(tx.Sender()) sender := pool.Ethereum.StateManager().procState.GetAccount(tx.Sender())
sender := accountState.Object
totAmount := new(big.Int).Add(tx.Value, new(big.Int).Mul(TxFee, TxFeeRat)) totAmount := new(big.Int).Add(tx.Value, new(big.Int).Mul(TxFee, TxFeeRat))
// Make sure there's enough in the sender's account. Having insufficient // Make sure there's enough in the sender's account. Having insufficient
......
...@@ -92,7 +92,14 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, in ...@@ -92,7 +92,14 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, in
hash = ethutil.FromHex(recipient) hash = ethutil.FromHex(recipient)
} }
keyPair, err := ethchain.NewKeyPairFromSec([]byte(ethutil.FromHex(key))) var keyPair *ethchain.KeyPair
var err error
if key[0:2] == "0x" {
keyPair, err = ethchain.NewKeyPairFromSec([]byte(ethutil.FromHex(key[0:2])))
} else {
keyPair, err = ethchain.NewKeyPairFromSec([]byte(ethutil.FromHex(key)))
}
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -132,8 +139,11 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, in ...@@ -132,8 +139,11 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, in
tx = ethchain.NewTransactionMessage(hash, value, gas, gasPrice, ethutil.FromHex(initStr)) tx = ethchain.NewTransactionMessage(hash, value, gas, gasPrice, ethutil.FromHex(initStr))
} }
acc := lib.stateManager.GetAddrState(keyPair.Address()) acc := lib.stateManager.TransState().GetStateObject(keyPair.Address())
//acc := lib.stateManager.GetAddrState(keyPair.Address())
tx.Nonce = acc.Nonce tx.Nonce = acc.Nonce
lib.stateManager.TransState().SetStateObject(acc)
tx.Sign(keyPair.PrivateKey) tx.Sign(keyPair.PrivateKey)
lib.txPool.QueueTransaction(tx) lib.txPool.QueueTransaction(tx)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment