Skip to content

Commit 21d9a78

Browse files
alanchchenmarkya0616
authored andcommitted
Merge pull request #121 from getamis/feature/verify-refactoring
consensus/istanbul: refactor backend verify function
2 parents 9f2d8c6 + d1680d5 commit 21d9a78

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

consensus/istanbul/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type Backend interface {
4646

4747
// Verify verifies the proposal. If a consensus.ErrFutureBlock error is returned,
4848
// the time difference of the proposal and current time is also returned.
49-
Verify(Proposal) (error, time.Duration)
49+
Verify(Proposal) (time.Duration, error)
5050

5151
// Sign signs input data with the backend's private key
5252
Sign([]byte) ([]byte, error)

consensus/istanbul/backend/backend.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,23 +182,23 @@ func (sb *backend) EventMux() *event.TypeMux {
182182
}
183183

184184
// Verify implements istanbul.Backend.Verify
185-
func (sb *backend) Verify(proposal istanbul.Proposal) (error, time.Duration) {
185+
func (sb *backend) Verify(proposal istanbul.Proposal) (time.Duration, error) {
186186
// Check if the proposal is a valid block
187187
block := &types.Block{}
188188
block, ok := proposal.(*types.Block)
189189
if !ok {
190190
sb.logger.Error("Invalid proposal, %v", proposal)
191-
return errInvalidProposal, 0
191+
return 0, errInvalidProposal
192192
}
193193
// verify the header of proposed block
194194
err := sb.VerifyHeader(sb.chain, block.Header(), false)
195195
// ignore errEmptyCommittedSeals error because we don't have the committed seals yet
196196
if err == nil || err == errEmptyCommittedSeals {
197-
return nil, 0
197+
return 0, nil
198198
} else if err == consensus.ErrFutureBlock {
199-
return consensus.ErrFutureBlock, time.Unix(block.Header().Time.Int64(), 0).Sub(now())
199+
return time.Unix(block.Header().Time.Int64(), 0).Sub(now()), consensus.ErrFutureBlock
200200
}
201-
return err, 0
201+
return 0, err
202202
}
203203

204204
// Sign implements istanbul.Backend.Sign

consensus/istanbul/core/preprepare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (c *core) handlePreprepare(msg *message, src istanbul.Validator) error {
6767
}
6868

6969
// Verify the proposal we received
70-
if err, duration := c.backend.Verify(preprepare.Proposal); err != nil {
70+
if duration, err := c.backend.Verify(preprepare.Proposal); err != nil {
7171
logger.Warn("Failed to verify proposal", "err", err, "duration", duration)
7272
// if it's a future block, we will handle it again after the duration
7373
if err == consensus.ErrFutureBlock {

consensus/istanbul/core/testbackend_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ func (self *testSystemBackend) Commit(proposal istanbul.Proposal, seals [][]byte
106106
return nil
107107
}
108108

109-
func (self *testSystemBackend) Verify(proposal istanbul.Proposal) (error, time.Duration) {
110-
return nil, 0
109+
func (self *testSystemBackend) Verify(proposal istanbul.Proposal) (time.Duration, error) {
110+
return 0, nil
111111
}
112112

113113
func (self *testSystemBackend) Sign(data []byte) ([]byte, error) {

0 commit comments

Comments
 (0)