@@ -27,6 +27,7 @@ import (
2727 "github.com/ethereum/go-ethereum/consensus/istanbul"
2828 istanbulCore "github.com/ethereum/go-ethereum/consensus/istanbul/core"
2929 "github.com/ethereum/go-ethereum/consensus/istanbul/validator"
30+ "github.com/ethereum/go-ethereum/core"
3031 "github.com/ethereum/go-ethereum/core/types"
3132 "github.com/ethereum/go-ethereum/crypto"
3233 "github.com/ethereum/go-ethereum/ethdb"
@@ -69,7 +70,10 @@ type backend struct {
6970 logger log.Logger
7071 db ethdb.Database
7172 chain consensus.ChainReader
72- inserter func (types.Blocks ) (int , error )
73+ // commitProposedWork tries to commit the transactions in proposed block into chain DB
74+ commitProposedWork func (* types.Block ) error
75+ // writeProposedWork tries to write the proposed block into chain DB
76+ writeProposedWork func (* types.Block ) bool
7377
7478 // the channels for istanbul engine notifications
7579 commitCh chan * types.Block
@@ -151,12 +155,13 @@ func (sb *backend) Commit(proposal istanbul.Proposal, seals [][]byte) error {
151155 if sb .proposedBlockHash == block .Hash () {
152156 // feed block hash to Seal() and wait the Seal() result
153157 sb .commitCh <- block
154- // TODO: how do we check the block is inserted correctly?
158+ go sb . eventMux . Post (core. NewMinedBlockEvent { Block : block })
155159 return nil
156160 }
157- // if I'm not a proposer, insert the block directly and broadcast NewCommittedEvent
158- if _ , err := sb .inserter (types.Blocks {block }); err != nil {
159- return err
161+ if result := sb .writeProposedWork (block ); ! result {
162+ // if I'm not a proposer, insert the block directly and broadcast NewCommittedEvent
163+ sb .logger .Warn ("Write work failed" )
164+ return nil
160165 }
161166 msg := istanbul.NewCommittedEvent {
162167 Block : block ,
@@ -190,12 +195,12 @@ func (sb *backend) Verify(proposal istanbul.Proposal) (time.Duration, error) {
190195 // verify the header of proposed block
191196 err := sb .VerifyHeader (sb .chain , block .Header (), false )
192197 // ignore errEmptyCommittedSeals error because we don't have the committed seals yet
193- if err == nil || err == errEmptyCommittedSeals {
194- return 0 , nil
195- } else if err == consensus .ErrFutureBlock {
198+ if err == consensus .ErrFutureBlock {
196199 return time .Unix (block .Header ().Time .Int64 (), 0 ).Sub (now ()), consensus .ErrFutureBlock
200+ } else if err != nil && err != errEmptyCommittedSeals {
201+ return 0 , err
197202 }
198- return 0 , err
203+ return 0 , sb . commitProposedWork ( block )
199204}
200205
201206// Sign implements istanbul.Backend.Sign
0 commit comments