diff --git a/consensus/istanbul/backend.go b/consensus/istanbul/backend.go index e5c37fb2dac4..393ed44a301e 100644 --- a/consensus/istanbul/backend.go +++ b/consensus/istanbul/backend.go @@ -46,7 +46,7 @@ type Backend interface { // Verify verifies the proposal. If a consensus.ErrFutureBlock error is returned, // the time difference of the proposal and current time is also returned. - Verify(Proposal) (error, time.Duration) + Verify(Proposal) (time.Duration, error) // Sign signs input data with the backend's private key Sign([]byte) ([]byte, error) diff --git a/consensus/istanbul/backend/backend.go b/consensus/istanbul/backend/backend.go index 73415c3ffd74..51d6cc2769ec 100644 --- a/consensus/istanbul/backend/backend.go +++ b/consensus/istanbul/backend/backend.go @@ -182,23 +182,23 @@ func (sb *backend) EventMux() *event.TypeMux { } // Verify implements istanbul.Backend.Verify -func (sb *backend) Verify(proposal istanbul.Proposal) (error, time.Duration) { +func (sb *backend) Verify(proposal istanbul.Proposal) (time.Duration, error) { // Check if the proposal is a valid block block := &types.Block{} block, ok := proposal.(*types.Block) if !ok { sb.logger.Error("Invalid proposal, %v", proposal) - return errInvalidProposal, 0 + return 0, errInvalidProposal } // verify the header of proposed block err := sb.VerifyHeader(sb.chain, block.Header(), false) // ignore errEmptyCommittedSeals error because we don't have the committed seals yet if err == nil || err == errEmptyCommittedSeals { - return nil, 0 + return 0, nil } else if err == consensus.ErrFutureBlock { - return consensus.ErrFutureBlock, time.Unix(block.Header().Time.Int64(), 0).Sub(now()) + return time.Unix(block.Header().Time.Int64(), 0).Sub(now()), consensus.ErrFutureBlock } - return err, 0 + return 0, err } // Sign implements istanbul.Backend.Sign diff --git a/consensus/istanbul/core/preprepare.go b/consensus/istanbul/core/preprepare.go index 66edad6e55f4..fa54e6f827e6 100644 --- a/consensus/istanbul/core/preprepare.go +++ b/consensus/istanbul/core/preprepare.go @@ -67,7 +67,7 @@ func (c *core) handlePreprepare(msg *message, src istanbul.Validator) error { } // Verify the proposal we received - if err, duration := c.backend.Verify(preprepare.Proposal); err != nil { + if duration, err := c.backend.Verify(preprepare.Proposal); err != nil { logger.Warn("Failed to verify proposal", "err", err, "duration", duration) // if it's a future block, we will handle it again after the duration if err == consensus.ErrFutureBlock { diff --git a/consensus/istanbul/core/testbackend_test.go b/consensus/istanbul/core/testbackend_test.go index 3b7a5aecefd1..5c32dec5adfe 100644 --- a/consensus/istanbul/core/testbackend_test.go +++ b/consensus/istanbul/core/testbackend_test.go @@ -106,8 +106,8 @@ func (self *testSystemBackend) Commit(proposal istanbul.Proposal, seals [][]byte return nil } -func (self *testSystemBackend) Verify(proposal istanbul.Proposal) (error, time.Duration) { - return nil, 0 +func (self *testSystemBackend) Verify(proposal istanbul.Proposal) (time.Duration, error) { + return 0, nil } func (self *testSystemBackend) Sign(data []byte) ([]byte, error) {