Merge branch 'develop' into feature/mnemonic

This commit is contained in:
Maran 2014-04-09 10:06:51 -04:00
commit 335dc9e687
5 changed files with 31 additions and 13 deletions

View File

@ -169,6 +169,8 @@ func (bc *BlockChain) ResetTillBlockHash(hash []byte) error {
bc.LastBlockHash = bc.genesisBlock.Hash()
bc.LastBlockNumber = 1
} else {
// TODO: Somehow this doesn't really give the right numbers, double check.
// TODO: Change logs into debug lines
returnTo = bc.GetBlock(hash)
bc.CurrentBlock = returnTo
bc.LastBlockHash = returnTo.Hash()

View File

@ -112,13 +112,18 @@ func (sm *StateManager) ApplyTransactions(block *Block, txs []*Transaction) {
// Figure out if the address this transaction was sent to is a
// contract or an actual account. In case of a contract, we process that
// contract instead of moving funds between accounts.
var err error
if contract := sm.procState.GetContract(tx.Recipient); contract != nil {
sm.ProcessContract(contract, tx, block)
} else {
err := sm.Ethereum.TxPool().ProcessTransaction(tx, block)
if err != nil {
ethutil.Config.Log.Infoln("[STATE]", err)
err = sm.Ethereum.TxPool().ProcessTransaction(tx, block, true)
if err == nil {
sm.ProcessContract(contract, tx, block)
}
} else {
err = sm.Ethereum.TxPool().ProcessTransaction(tx, block, false)
}
if err != nil {
ethutil.Config.Log.Infoln("[STATE]", err)
}
}
}
@ -283,7 +288,7 @@ func (sm *StateManager) AccumelateRewards(block *Block) error {
// Reward amount of ether to the coinbase address
addr.AddFee(CalculateBlockReward(block, len(block.Uncles)))
var acc []byte
acc := make([]byte, len(block.Coinbase))
copy(acc, block.Coinbase)
sm.procState.UpdateAccount(acc, addr)
@ -323,4 +328,7 @@ func (sm *StateManager) ProcessContract(contract *Contract, tx *Transaction, blo
txData: nil,
})
closure.Call(vm, nil)
// Update the account (refunds)
sm.procState.UpdateAccount(tx.Sender(), caller)
}

View File

@ -90,7 +90,7 @@ func (pool *TxPool) addTransaction(tx *Transaction) {
// Process transaction validates the Tx and processes funds from the
// sender to the recipient.
func (pool *TxPool) ProcessTransaction(tx *Transaction, block *Block) (err error) {
func (pool *TxPool) ProcessTransaction(tx *Transaction, block *Block, toContract bool) (err error) {
defer func() {
if r := recover(); r != nil {
log.Println(r)
@ -108,7 +108,7 @@ func (pool *TxPool) ProcessTransaction(tx *Transaction, block *Block) (err error
}
if sender.Nonce != tx.Nonce {
return fmt.Errorf("[TXPL] Invalid account nonce, state nonce is %d transactoin nonce is %d instead", 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
@ -119,6 +119,8 @@ func (pool *TxPool) ProcessTransaction(tx *Transaction, block *Block) (err error
if bytes.Compare(tx.Recipient, tx.Sender()) == 0 {
// Subtract the fee
sender.Amount.Sub(sender.Amount, new(big.Int).Mul(TxFee, TxFeeRat))
} else if toContract {
sender.Amount.Sub(sender.Amount, new(big.Int).Mul(TxFee, TxFeeRat))
} else {
// Subtract the amount from the senders account
sender.Amount.Sub(sender.Amount, totAmount)

View File

@ -83,18 +83,23 @@ func TestRun4(t *testing.T) {
state := NewState(ethutil.NewTrie(db, ""))
asm, err := mutan.Compile(strings.NewReader(`
a = 10
b = 10
int32 a = 10
int32 b = 10
if a == b {
c = 10
int32 c = 10
if c == 10 {
d = 1000
e = 10
int32 d = 1000
int32 e = 10
}
}
store[0] = 20
store[a] = 20
store[b] = this.caller()
int8[10] ret
int8[10] arg
call(1234, 0, 100000000, arg, ret)
`), false)
if err != nil {
fmt.Println(err)

View File

@ -105,6 +105,7 @@ func (miner *Miner) listener() {
if found == false {
log.Println("[MINER] We did not know about this transaction, adding")
miner.txs = append(miner.txs, tx)
miner.block = miner.ethereum.BlockChain().NewBlock(miner.coinbase, miner.txs)
miner.block.SetTransactions(miner.txs)
} else {
log.Println("[MINER] We already had this transaction, ignoring")