Skip to content

Commit

Permalink
consensus: allow validator error to print validator address
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann committed May 31, 2023
1 parent 82f6c9b commit 011c3f1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ var (
errBlockHashInconsistent = errors.New("the block hash is inconsistent")

// errUnauthorizedValidator is returned if a header is signed by a non-authorized entity.
errUnauthorizedValidator = errors.New("unauthorized validator")
errUnauthorizedValidator = func(val string) error {
return errors.New("unauthorized validator: " + val)
}

// errCoinBaseMisMatch is returned if a header's coinbase do not match with signature
errCoinBaseMisMatch = errors.New("coinbase do not match with signature")
Expand Down Expand Up @@ -752,7 +754,7 @@ func (p *Parlia) verifySeal(chain consensus.ChainHeaderReader, header *types.Hea
}

if _, ok := snap.Validators[signer]; !ok {
return errUnauthorizedValidator
return errUnauthorizedValidator(signer.String())
}

if snap.SignRecently(signer) {
Expand Down Expand Up @@ -1298,7 +1300,7 @@ func (p *Parlia) Seal(chain consensus.ChainHeaderReader, block *types.Block, res

// Bail out if we're unauthorized to sign a block
if _, authorized := snap.Validators[val]; !authorized {
return errUnauthorizedValidator
return errUnauthorizedValidator(val.Hex())
}

// If we're amongst the recent signers, wait for the next block
Expand Down Expand Up @@ -1408,7 +1410,7 @@ func (p *Parlia) SignRecently(chain consensus.ChainReader, parent *types.Block)

// Bail out if we're unauthorized to sign a block
if _, authorized := snap.Validators[p.val]; !authorized {
return true, errUnauthorizedValidator
return true, errUnauthorizedValidator(p.val.String())
}

return snap.SignRecently(p.val), nil
Expand Down
2 changes: 1 addition & 1 deletion consensus/parlia/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (s *Snapshot) apply(headers []*types.Header, chain consensus.ChainHeaderRea
return nil, err
}
if _, ok := snap.Validators[validator]; !ok {
return nil, errUnauthorizedValidator
return nil, errUnauthorizedValidator(validator.String())
}
for _, recent := range snap.Recents {
if recent == validator {
Expand Down
2 changes: 1 addition & 1 deletion core/rawdb/freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,5 +597,5 @@ func gcKvStore(db ethdb.KeyValueStore, ancients []common.Hash, first uint64, fro
if n := len(ancients); n > 0 {
context = append(context, []interface{}{"hash", ancients[n-1]}...)
}
log.Debug("Deep froze chain segment", context...)
log.Info("Deep froze chain segment", context...)
}

0 comments on commit 011c3f1

Please sign in to comment.