@@ -143,6 +143,9 @@ func (self *BlockProcessor) ApplyTransactions(coinbase *state.StateObject, state
143143 return receipts , handled , unhandled , erroneous , err
144144}
145145
146+ // Process block will attempt to process the given block's transactions and applies them
147+ // on top of the block's parent state (given it exists) and will return wether it was
148+ // successful or not.
146149func (sm * BlockProcessor ) Process (block * types.Block ) (td * big.Int , err error ) {
147150 // Processing a blocks may never happen simultaneously
148151 sm .mutex .Lock ()
@@ -158,14 +161,14 @@ func (sm *BlockProcessor) Process(block *types.Block) (td *big.Int, err error) {
158161 }
159162 parent := sm .bc .GetBlock (header .ParentHash )
160163
161- return sm .ProcessWithParent (block , parent )
164+ return sm .processWithParent (block , parent )
162165}
163166
164- func (sm * BlockProcessor ) ProcessWithParent (block , parent * types.Block ) (td * big.Int , err error ) {
167+ func (sm * BlockProcessor ) processWithParent (block , parent * types.Block ) (td * big.Int , err error ) {
165168 sm .lastAttemptedBlock = block
166169
170+ // Create a new state based on the parent's root (e.g., create copy)
167171 state := state .New (parent .Root (), sm .db )
168- //state := state.New(parent.Trie().Copy())
169172
170173 // Block validation
171174 if err = sm .ValidateBlock (block , parent ); err != nil {
@@ -179,31 +182,38 @@ func (sm *BlockProcessor) ProcessWithParent(block, parent *types.Block) (td *big
179182
180183 header := block .Header ()
181184
185+ // Validate the received block's bloom with the one derived from the generated receipts.
186+ // For valid blocks this should always validate to true.
182187 rbloom := types .CreateBloom (receipts )
183188 if bytes .Compare (rbloom , header .Bloom ) != 0 {
184189 err = fmt .Errorf ("unable to replicate block's bloom=%x" , rbloom )
185190 return
186191 }
187192
193+ // The transactions Trie's root (R = (Tr [[H1, T1], [H2, T2], ... [Hn, Tn]]))
194+ // can be used by light clients to make sure they've received the correct Txs
188195 txSha := types .DeriveSha (block .Transactions ())
189196 if bytes .Compare (txSha , header .TxHash ) != 0 {
190197 err = fmt .Errorf ("validating transaction root. received=%x got=%x" , header .TxHash , txSha )
191198 return
192199 }
193200
201+ // Tre receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, R1]]))
194202 receiptSha := types .DeriveSha (receipts )
195203 if bytes .Compare (receiptSha , header .ReceiptHash ) != 0 {
196204 fmt .Println ("receipts" , receipts )
197205 err = fmt .Errorf ("validating receipt root. received=%x got=%x" , header .ReceiptHash , receiptSha )
198206 return
199207 }
200208
209+ // Accumulate static rewards; block reward, uncle's and uncle inclusion.
201210 if err = sm .AccumulateRewards (state , block , parent ); err != nil {
202211 return
203212 }
204213
214+ // Commit state objects/accounts to a temporary trie (does not save)
215+ // used to calculate the state root.
205216 state .Update (ethutil .Big0 )
206-
207217 if ! bytes .Equal (header .Root , state .Root ()) {
208218 err = fmt .Errorf ("invalid merkle root. received=%x got=%x" , header .Root , state .Root ())
209219 return
@@ -213,10 +223,6 @@ func (sm *BlockProcessor) ProcessWithParent(block, parent *types.Block) (td *big
213223 td = CalculateTD (block , parent )
214224 // Sync the current block's state to the database
215225 state .Sync ()
216- // Set the block hashes for the current messages
217- state .Manifest ().SetHash (block .Hash ())
218- // Reset the manifest XXX We need this?
219- state .Manifest ().Reset ()
220226 // Remove transactions from the pool
221227 sm .txpool .RemoveSet (block .Transactions ())
222228
@@ -296,27 +302,6 @@ func (sm *BlockProcessor) AccumulateRewards(statedb *state.StateDB, block, paren
296302 return nil
297303}
298304
299- func (sm * BlockProcessor ) GetMessages (block * types.Block ) (messages []* state.Message , err error ) {
300- if ! sm .bc .HasBlock (block .Header ().ParentHash ) {
301- return nil , ParentError (block .Header ().ParentHash )
302- }
303-
304- sm .lastAttemptedBlock = block
305-
306- var (
307- parent = sm .bc .GetBlock (block .Header ().ParentHash )
308- //state = state.New(parent.Trie().Copy())
309- state = state .New (parent .Root (), sm .db )
310- )
311-
312- defer state .Reset ()
313-
314- sm .TransitionState (state , parent , block )
315- sm .AccumulateRewards (state , block , parent )
316-
317- return state .Manifest ().Messages , nil
318- }
319-
320305func (sm * BlockProcessor ) GetLogs (block * types.Block ) (logs state.Logs , err error ) {
321306 if ! sm .bc .HasBlock (block .Header ().ParentHash ) {
322307 return nil , ParentError (block .Header ().ParentHash )
0 commit comments