From 5ebae82eeb3f5ecdffb96f9d692523d0b0d4f759 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 2 Dec 2014 12:23:27 +0100 Subject: Additional logging and removed temp merged mining options. --- chain/block_manager.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'chain/block_manager.go') diff --git a/chain/block_manager.go b/chain/block_manager.go index c1a28e423..9133475b6 100644 --- a/chain/block_manager.go +++ b/chain/block_manager.go @@ -185,8 +185,7 @@ func (sm *BlockManager) Process(block *Block) (td *big.Int, msgs state.Messages, defer sm.mutex.Unlock() if sm.bc.HasBlock(block.Hash()) { - fmt.Println("already having this block") - return nil, nil, nil + return nil, nil, &KnownBlockError{block.Number, block.Hash()} } if !sm.bc.HasBlock(block.PrevHash) { @@ -233,12 +232,10 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me // Block validation if err = sm.ValidateBlock(block, parent); err != nil { - statelogger.Errorln("validating block:", err) return } if err = sm.AccumelateRewards(state, block, parent); err != nil { - statelogger.Errorln("accumulating reward", err) return } @@ -271,7 +268,6 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me sm.transState = state.Copy() sm.eth.TxPool().RemoveSet(block.Transactions()) - fmt.Println("TD", td) return td, messages, nil } else { -- cgit From 0a22dc2ce5d0e69004272f44af972e387144c126 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 2 Dec 2014 22:22:43 +0100 Subject: Check coinbase for from/to inclusion --- chain/block_manager.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'chain/block_manager.go') diff --git a/chain/block_manager.go b/chain/block_manager.go index 9133475b6..fe84a94ca 100644 --- a/chain/block_manager.go +++ b/chain/block_manager.go @@ -275,16 +275,24 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me } } -func (sm *BlockManager) ApplyDiff(state *state.State, parent, block *Block) (receipts Receipts, err error) { - coinbase := state.GetOrNewStateObject(block.Coinbase) +func (sm *BlockManager) ApplyDiff(statedb *state.State, parent, block *Block) (receipts Receipts, err error) { + coinbase := statedb.GetOrNewStateObject(block.Coinbase) coinbase.SetGasPool(block.CalcGasLimit(parent)) // Process the transactions on to current block - receipts, _, _, _, err = sm.ProcessTransactions(coinbase, state, block, parent, block.Transactions()) + receipts, _, _, _, err = sm.ProcessTransactions(coinbase, statedb, block, parent, block.Transactions()) if err != nil { return nil, err } + statedb.Manifest().AddMessage(&state.Message{ + To: block.Coinbase, From: block.Coinbase, + Input: nil, + Origin: nil, + Block: block.Hash(), Timestamp: block.Time, Coinbase: block.Coinbase, Number: block.Number, + Value: new(big.Int), + }) + return receipts, nil } @@ -303,9 +311,6 @@ func (sm *BlockManager) CalculateTD(block *Block) (*big.Int, bool) { // is greater than the previous. if td.Cmp(sm.bc.TD) > 0 { return td, true - - // Set the new total difficulty back to the block chain - //sm.bc.SetTotalDifficulty(td) } return nil, false -- cgit From f7789220862f67c2aadaf7b6a44fcd54152dd234 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 2 Dec 2014 22:37:45 +0100 Subject: Set proper message value --- chain/block_manager.go | 56 ++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 27 deletions(-) (limited to 'chain/block_manager.go') diff --git a/chain/block_manager.go b/chain/block_manager.go index fe84a94ca..d89789255 100644 --- a/chain/block_manager.go +++ b/chain/block_manager.go @@ -117,6 +117,19 @@ func (sm *BlockManager) ChainManager() *ChainManager { return sm.bc } +func (sm *BlockManager) TransitionState(statedb *state.State, parent, block *Block) (receipts Receipts, err error) { + coinbase := statedb.GetOrNewStateObject(block.Coinbase) + coinbase.SetGasPool(block.CalcGasLimit(parent)) + + // Process the transactions on to current block + receipts, _, _, _, err = sm.ProcessTransactions(coinbase, statedb, block, parent, block.Transactions()) + if err != nil { + return nil, err + } + + return receipts, nil +} + func (self *BlockManager) ProcessTransactions(coinbase *state.StateObject, state *state.State, block, parent *Block, txs Transactions) (Receipts, Transactions, Transactions, Transactions, error) { var ( receipts Receipts @@ -124,6 +137,7 @@ func (self *BlockManager) ProcessTransactions(coinbase *state.StateObject, state erroneous Transactions totalUsedGas = big.NewInt(0) err error + cumulativeSum = new(big.Int) ) done: @@ -155,6 +169,7 @@ done: } txGas.Sub(txGas, st.gas) + cumulativeSum.Add(cumulativeSum, new(big.Int).Mul(txGas, tx.GasPrice)) // Update the state with pending changes state.Update(txGas) @@ -174,6 +189,7 @@ done: } } + block.Reward = cumulativeSum block.GasUsed = totalUsedGas return receipts, handled, unhandled, erroneous, err @@ -211,7 +227,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me fmt.Printf("## %x %x ##\n", block.Hash(), block.Number) } - _, err = sm.ApplyDiff(state, parent, block) + _, err = sm.TransitionState(state, parent, block) if err != nil { return } @@ -275,27 +291,6 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me } } -func (sm *BlockManager) ApplyDiff(statedb *state.State, parent, block *Block) (receipts Receipts, err error) { - coinbase := statedb.GetOrNewStateObject(block.Coinbase) - coinbase.SetGasPool(block.CalcGasLimit(parent)) - - // Process the transactions on to current block - receipts, _, _, _, err = sm.ProcessTransactions(coinbase, statedb, block, parent, block.Transactions()) - if err != nil { - return nil, err - } - - statedb.Manifest().AddMessage(&state.Message{ - To: block.Coinbase, From: block.Coinbase, - Input: nil, - Origin: nil, - Block: block.Hash(), Timestamp: block.Time, Coinbase: block.Coinbase, Number: block.Number, - Value: new(big.Int), - }) - - return receipts, nil -} - func (sm *BlockManager) CalculateTD(block *Block) (*big.Int, bool) { uncleDiff := new(big.Int) for _, uncle := range block.Uncles { @@ -345,7 +340,7 @@ func (sm *BlockManager) ValidateBlock(block, parent *Block) error { return nil } -func (sm *BlockManager) AccumelateRewards(state *state.State, block, parent *Block) error { +func (sm *BlockManager) AccumelateRewards(statedb *state.State, block, parent *Block) error { reward := new(big.Int).Set(BlockReward) knownUncles := ethutil.Set(parent.Uncles) @@ -374,17 +369,25 @@ func (sm *BlockManager) AccumelateRewards(state *state.State, block, parent *Blo r := new(big.Int) r.Mul(BlockReward, big.NewInt(15)).Div(r, big.NewInt(16)) - uncleAccount := state.GetAccount(uncle.Coinbase) + uncleAccount := statedb.GetAccount(uncle.Coinbase) uncleAccount.AddAmount(r) reward.Add(reward, new(big.Int).Div(BlockReward, big.NewInt(32))) } // Get the account associated with the coinbase - account := state.GetAccount(block.Coinbase) + account := statedb.GetAccount(block.Coinbase) // Reward amount of ether to the coinbase address account.AddAmount(reward) + statedb.Manifest().AddMessage(&state.Message{ + To: block.Coinbase, From: block.Coinbase, + Input: nil, + Origin: nil, + Block: block.Hash(), Timestamp: block.Time, Coinbase: block.Coinbase, Number: block.Number, + Value: new(big.Int).Add(reward, block.Reward), + }) + return nil } @@ -402,8 +405,7 @@ func (sm *BlockManager) GetMessages(block *Block) (messages []*state.Message, er defer state.Reset() - sm.ApplyDiff(state, parent, block) - + sm.TransitionState(state, parent, block) sm.AccumelateRewards(state, block, parent) return state.Manifest().Messages, nil -- cgit