diff options
author | Maran <maran.hidskes@gmail.com> | 2014-04-09 22:06:51 +0800 |
---|---|---|
committer | Maran <maran.hidskes@gmail.com> | 2014-04-09 22:06:51 +0800 |
commit | 335dc9e6874160bb1c1059d676e8842523a732e0 (patch) | |
tree | 9bea2807df997da3d3b4d0fe31dbb75db2a36866 | |
parent | 35a82f8f4a69019d72ff3379e0f61bf2be475e42 (diff) | |
parent | 6d28bf534f0fabb5740ef035b829e5edc4dc3131 (diff) | |
download | go-tangerine-335dc9e6874160bb1c1059d676e8842523a732e0.tar.gz go-tangerine-335dc9e6874160bb1c1059d676e8842523a732e0.tar.zst go-tangerine-335dc9e6874160bb1c1059d676e8842523a732e0.zip |
Merge branch 'develop' into feature/mnemonic
-rw-r--r-- | ethchain/block_chain.go | 2 | ||||
-rw-r--r-- | ethchain/state_manager.go | 20 | ||||
-rw-r--r-- | ethchain/transaction_pool.go | 6 | ||||
-rw-r--r-- | ethchain/vm_test.go | 15 | ||||
-rw-r--r-- | ethminer/miner.go | 1 |
5 files changed, 31 insertions, 13 deletions
diff --git a/ethchain/block_chain.go b/ethchain/block_chain.go index f621965ae..2a50ef687 100644 --- a/ethchain/block_chain.go +++ b/ethchain/block_chain.go @@ -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() diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go index 78fcb2c2f..4c001a387 100644 --- a/ethchain/state_manager.go +++ b/ethchain/state_manager.go @@ -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) } diff --git a/ethchain/transaction_pool.go b/ethchain/transaction_pool.go index 9acd39e31..0bcfe6923 100644 --- a/ethchain/transaction_pool.go +++ b/ethchain/transaction_pool.go @@ -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) diff --git a/ethchain/vm_test.go b/ethchain/vm_test.go index 838f12f56..85ec4c693 100644 --- a/ethchain/vm_test.go +++ b/ethchain/vm_test.go @@ -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) diff --git a/ethminer/miner.go b/ethminer/miner.go index 60af3ab31..d84977342 100644 --- a/ethminer/miner.go +++ b/ethminer/miner.go @@ -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") |