Skip to content

Commit

Permalink
miner: enable private transactions in worker
Browse files Browse the repository at this point in the history
  • Loading branch information
markya0616 authored and yutelin committed Sep 2, 2017
1 parent 470ade5 commit 98200b1
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,16 @@ func newWorker(config *params.ChainConfig, engine consensus.Engine, coinbase com
fullValidation: false,
}

if !config.IsQuorum {
if _, ok := engine.(consensus.Istanbul); ok || !config.IsQuorum {
// Subscribe TxPreEvent for tx pool
worker.txSub = eth.TxPool().SubscribeTxPreEvent(worker.txCh)
// Subscribe events for blockchain
worker.chainHeadSub = eth.BlockChain().SubscribeChainHeadEvent(worker.chainHeadCh)
worker.chainSideSub = eth.BlockChain().SubscribeChainSideEvent(worker.chainSideCh)
go worker.update()

go worker.wait()
worker.commitNewWork()
}

return worker
Expand Down Expand Up @@ -312,6 +315,7 @@ func (self *worker) wait() {
go self.mux.Post(core.NewMinedBlockEvent{Block: block})
} else {
work.state.CommitTo(self.chainDb, self.config.IsEIP158(block.Number()))
work.privateState.CommitTo(self.chainDb, self.config.IsEIP158(block.Number()))
stat, err := self.chain.WriteBlock(block)
if err != nil {
log.Error("Failed writing block to chain", "err", err)
Expand Down Expand Up @@ -607,14 +611,20 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB

func (env *Work) commitTransaction(tx *types.Transaction, bc *core.BlockChain, coinbase common.Address, gp *core.GasPool) (error, []*types.Log) {
snap := env.state.Snapshot()
privateSnap := env.privateState.Snapshot()

receipt, _, _, err := core.ApplyTransaction(env.config, bc, &coinbase, gp, env.state, env.privateState, env.header, tx, env.header.GasUsed, vm.Config{})
receipt, privateReceipt, _, err := core.ApplyTransaction(env.config, bc, &coinbase, gp, env.state, env.privateState, env.header, tx, env.header.GasUsed, vm.Config{})
if err != nil {
env.state.RevertToSnapshot(snap)
env.privateState.RevertToSnapshot(privateSnap)
return err, nil
}
env.txs = append(env.txs, tx)
env.receipts = append(env.receipts, receipt)

return nil, receipt.Logs
logs := receipt.Logs
if privateReceipt != nil {
logs = append(receipt.Logs, privateReceipt.Logs...)
}
return nil, logs
}

0 comments on commit 98200b1

Please sign in to comment.