diff --git a/consensus/istanbul/backend.go b/consensus/istanbul/backend.go index f5c23ee4c69d..94132dd4ab4a 100644 --- a/consensus/istanbul/backend.go +++ b/consensus/istanbul/backend.go @@ -58,9 +58,6 @@ type Backend interface { // the given validator CheckSignature(data []byte, addr common.Address, sig []byte) error - // GetProposer returns the proposer of the given block height - GetProposer(number uint64) common.Address - // LastProposal retrieves latest committed proposal and the address of proposer LastProposal() (Proposal, common.Address) } diff --git a/consensus/istanbul/backend/handler_test.go b/consensus/istanbul/backend/handler_test.go index 90435b0e46f5..690a586be8f3 100644 --- a/consensus/istanbul/backend/handler_test.go +++ b/consensus/istanbul/backend/handler_test.go @@ -20,13 +20,9 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus/istanbul" - "github.com/ethereum/go-ethereum/core/state" - "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/rlp" - "github.com/ethereum/go-ethereum/rpc" lru "github.com/hashicorp/golang-lru" ) @@ -74,64 +70,3 @@ func makeMsg(msgcode uint64, data interface{}) p2p.Msg { size, r, _ := rlp.EncodeToReader(data) return p2p.Msg{Code: msgcode, Size: uint32(size), Payload: r} } - -type MockIstanbulEngine struct{} - -func (m *MockIstanbulEngine) Author(header *types.Header) (common.Address, error) { - return common.Address{}, nil -} - -func (m *MockIstanbulEngine) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error { - return nil -} - -func (m *MockIstanbulEngine) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error) { - abort := make(chan struct{}) - results := make(chan error, len(headers)) - go func() { - for _ = range headers { - results <- nil - } - }() - return abort, results -} - -func (m *MockIstanbulEngine) VerifyUncles(chain consensus.ChainReader, block *types.Block) error { - return nil -} - -func (m *MockIstanbulEngine) VerifySeal(chain consensus.ChainReader, header *types.Header) error { - return nil -} - -func (m *MockIstanbulEngine) Prepare(chain consensus.ChainReader, header *types.Header) error { - return nil -} - -func (m *MockIstanbulEngine) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) { - return nil, nil -} - -func (m *MockIstanbulEngine) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error) { - return nil, nil -} - -func (m *MockIstanbulEngine) APIs(chain consensus.ChainReader) []rpc.API { - return []rpc.API{} -} - -func (m *MockIstanbulEngine) HandleMsg(addr common.Address, data []byte) error { - return nil -} - -func (m *MockIstanbulEngine) NewChainHead(block *types.Block) error { - return nil -} - -func (m *MockIstanbulEngine) Start(chain consensus.ChainReader, inserter func(types.Blocks) (int, error)) error { - return nil -} - -func (m *MockIstanbulEngine) Stop() error { - return nil -} diff --git a/consensus/istanbul/core/handler.go b/consensus/istanbul/core/handler.go index 3c4cb1a3d38c..b9556b7432ef 100644 --- a/consensus/istanbul/core/handler.go +++ b/consensus/istanbul/core/handler.go @@ -95,11 +95,19 @@ func (c *core) handleEvents() { c.storeRequestMsg(r) } case istanbul.MessageEvent: - c.handleMsg(ev.Payload) + if err := c.handleMsg(ev.Payload); err == nil { + c.backend.Gossip(c.valSet, ev.Payload) + } case backlogEvent: // No need to check signature for internal messages - c.handleCheckedMsg(ev.msg, ev.src) - + if err := c.handleCheckedMsg(ev.msg, ev.src); err == nil { + p, err := ev.msg.Payload() + if err != nil { + c.logger.Warn("Get message payload failed", "err", err) + continue + } + c.backend.Gossip(c.valSet, p) + } } case _, ok := <-c.timeoutSub.Chan(): if !ok { diff --git a/consensus/istanbul/core/preprepare.go b/consensus/istanbul/core/preprepare.go index 7b1fcf2ecd4a..a79bfc21f97a 100644 --- a/consensus/istanbul/core/preprepare.go +++ b/consensus/istanbul/core/preprepare.go @@ -56,7 +56,6 @@ func (c *core) handlePreprepare(msg *message, src istanbul.Validator) error { } // Ensure we have the same view with the PRE-PREPARE message - // If it is old message, see if we need to broadcast COMMIT if err := c.checkMessage(msgPreprepare, preprepare.View); err != nil { return err } diff --git a/consensus/istanbul/core/testbackend_test.go b/consensus/istanbul/core/testbackend_test.go index 86d9b6f74180..20fac716fe1d 100644 --- a/consensus/istanbul/core/testbackend_test.go +++ b/consensus/istanbul/core/testbackend_test.go @@ -138,10 +138,6 @@ func (self *testSystemBackend) NewRequest(request istanbul.Proposal) { }) } -func (self *testSystemBackend) GetProposer(number uint64) common.Address { - return common.Address{} -} - func (self *testSystemBackend) LastProposal() (istanbul.Proposal, common.Address) { return makeBlock(1), common.Address{} }