ValidateBlockBody validates transactions in a block based on known states
(block *types.Block)
| 1256 | |
| 1257 | // ValidateBlockBody validates transactions in a block based on known states |
| 1258 | func (bc *BlockChain) ValidateBlockBody(block *types.Block) error { |
| 1259 | |
| 1260 | // before validate state, we first validate block body |
| 1261 | err := bc.Validator().ValidateBody(block) |
| 1262 | switch err { |
| 1263 | case ErrKnownBlock: |
| 1264 | default: |
| 1265 | return err |
| 1266 | } |
| 1267 | |
| 1268 | // create public and private state databases based on parent block |
| 1269 | parent := bc.GetBlock(block.ParentHash(), block.NumberU64()-1) |
| 1270 | pubState, err := state.New(parent.StateRoot(), bc.stateCache) |
| 1271 | if err != nil { |
| 1272 | return err |
| 1273 | } |
| 1274 | privState, err := state.New(GetPrivateStateRoot(bc.db, parent.StateRoot()), bc.privateStateCache) |
| 1275 | if err != nil { |
| 1276 | return err |
| 1277 | } |
| 1278 | |
| 1279 | // process transactions in the block and make changes to state DBs. |
| 1280 | pubReceipts, privReceipts, logs, usedGas, err := bc.processor.Process(block, pubState, privState, bc.remoteDB, |
| 1281 | bc.vmConfig) |
| 1282 | if err != nil { |
| 1283 | return err |
| 1284 | } |
| 1285 | |
| 1286 | // validate public state and public receipts |
| 1287 | // TODO: validate private state? |
| 1288 | err = bc.Validator().ValidateState(block, parent, pubState, pubReceipts, usedGas) |
| 1289 | if err != nil { |
| 1290 | return err |
| 1291 | } |
| 1292 | |
| 1293 | log.Debug("succeed to validate block body, caching receipts and states", "number", block.NumberU64(), "hash", block.Hash().Hex()) |
| 1294 | |
| 1295 | // do caches to reduce insertion time later, this is for Validators |
| 1296 | bc.srCache.add(block.Hash(), pubReceipts, privReceipts, pubState, privState, logs, usedGas) |
| 1297 | |
| 1298 | return nil |
| 1299 | } |
| 1300 | |
| 1301 | // insertChain will execute the actual chain insertion and event aggregation. The |
| 1302 | // only reason this method exists as a separate one is to make locking cleaner |
nothing calls this directly
no test coverage detected