You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.4 KiB
46 lines
1.4 KiB
6 years ago
|
package worker
|
||
|
|
||
|
import (
|
||
|
"github.com/ethereum/go-ethereum/common"
|
||
|
"github.com/ethereum/go-ethereum/params"
|
||
|
"github.com/harmony-one/harmony/core"
|
||
|
"github.com/harmony-one/harmony/core/state"
|
||
|
"github.com/harmony-one/harmony/core/types"
|
||
|
"github.com/harmony-one/harmony/core/vm"
|
||
|
)
|
||
|
|
||
|
// environment is the worker's current environment and holds all of the current state information.
|
||
|
type environment struct {
|
||
|
signer types.Signer
|
||
|
|
||
|
state *state.StateDB // apply state changes here
|
||
|
tcount int // tx count in cycle
|
||
|
gasPool *core.GasPool // available gas used to pack transactions
|
||
|
|
||
|
header *types.Header
|
||
|
txs []*types.Transaction
|
||
|
receipts []*types.Receipt
|
||
|
}
|
||
|
|
||
|
// worker is the main object which takes care of submitting new work to consensus engine
|
||
|
// and gathering the sealing result.
|
||
|
type worker struct {
|
||
|
config *params.ChainConfig
|
||
|
chain *core.BlockChain
|
||
|
current *environment // An environment for current running cycle.
|
||
|
}
|
||
|
|
||
|
func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Address) ([]*types.Log, error) {
|
||
|
snap := w.current.state.Snapshot()
|
||
|
|
||
|
receipt, _, err := core.ApplyTransaction(w.config, w.chain, &coinbase, w.current.gasPool, w.current.state, w.current.header, tx, &w.current.header.GasUsed, vm.Config{})
|
||
|
if err != nil {
|
||
|
w.current.state.RevertToSnapshot(snap)
|
||
|
return nil, err
|
||
|
}
|
||
|
w.current.txs = append(w.current.txs, tx)
|
||
|
w.current.receipts = append(w.current.receipts, receipt)
|
||
|
|
||
|
return receipt.Logs, nil
|
||
|
}
|