MCPcopy Create free account
hub / github.com/CPChain/chain / Process

Method Process

core/state_processor.go:68–107  ·  view source on GitHub ↗

Process processes the state changes according to the Cpchain rules by running the transaction messages using the pubStateDB and applying any rewards to both the processor (coinbase) and any included uncles. Process returns the public receipts, private receipts(if have) and logs accumulated during t

(block *types.Block, statedb *state.StateDB, statePrivDB *state.StateDB,
	remoteDB database.RemoteDatabase, cfg vm.Config)

Source from the content-addressed store, hash-verified

66// returns the amount of gas that was used in the process. If any of the
67// transactions failed to execute due to insufficient gas it will return an error.
68func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, statePrivDB *state.StateDB,
69 remoteDB database.RemoteDatabase, cfg vm.Config) (types.Receipts, types.Receipts, []*types.Log, uint64, error) {
70 var (
71 pubReceipts types.Receipts
72 privReceipts types.Receipts
73 usedGas = new(uint64)
74 header = block.Header()
75 allLogs []*types.Log
76 gp = new(GasPool).AddGas(block.GasLimit())
77
78 author = (*common.Address)(nil)
79 )
80
81 beneficiary, err := p.bc.Engine().Author(header)
82 if err == nil {
83 author = &beneficiary
84 }
85
86 // Iterate over and process the individual transactions
87 for i, tx := range block.Transactions() {
88 statedb.Prepare(tx.Hash(), block.Hash(), i)
89 statePrivDB.Prepare(tx.Hash(), block.Hash(), i)
90 pubReceipt, privReceipt, _, err := ApplyTransaction(p.config, p.bc, author, gp, statedb, statePrivDB, remoteDB, header, tx,
91 usedGas, cfg, p.accm)
92 if err != nil {
93 return nil, nil, nil, 0, err
94 }
95 pubReceipts = append(pubReceipts, pubReceipt)
96 if privReceipt != nil {
97 privReceipts = append(privReceipts, privReceipt)
98 }
99 allLogs = append(allLogs, pubReceipt.Logs...) // not include private receipt's logs.
100 // TODO: if need to add private receipt's logs to allLogs variable.
101 }
102 // Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
103 p.engine.Finalize(p.bc, header, statedb, block.Transactions(), []*types.Header{}, pubReceipts)
104
105 // TODO: if return private logs separately or merge them together as a whole logs collection?
106 return pubReceipts, privReceipts, allLogs, *usedGas, nil
107}
108
109// ApplyTransaction attempts to apply a transaction to the given state database
110// and uses the input parameters for its environment. It returns the receipt

Callers

nothing calls this directly

Calls 10

ApplyTransactionFunction · 0.85
HeaderMethod · 0.80
AddGasMethod · 0.80
TransactionsMethod · 0.80
PrepareMethod · 0.80
AuthorMethod · 0.65
EngineMethod · 0.65
HashMethod · 0.65
FinalizeMethod · 0.65
GasLimitMethod · 0.45

Tested by

no test coverage detected