You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB

  1. package consensus
  2. import (
  3. . "github.com/tendermint/tendermint/blocks"
  4. db_ "github.com/tendermint/tendermint/db"
  5. . "github.com/tendermint/tendermint/state"
  6. )
  7. //-----------------------------------------------------------------------------
  8. type PrivValidator struct {
  9. PrivAccount
  10. db *db_.LevelDB
  11. }
  12. // Returns new signed blockParts.
  13. // If signatures already exist in proposal BlockParts,
  14. // e.g. a locked proposal from some prior round,
  15. // those signatures are overwritten.
  16. // Double signing (signing multiple proposals for the same height&round) results in an error.
  17. func (pv *PrivValidator) SignProposal(round uint16, proposal *BlockPartSet) (err error) {
  18. //TODO: prevent double signing.
  19. blockParts := proposal.BlockParts()
  20. for i, part := range blockParts {
  21. partHash := part.Hash()
  22. doc := GenBlockPartDocument(
  23. proposal.Height(), round, uint16(i), uint16(len(blockParts)), partHash)
  24. part.Signature = pv.Sign([]byte(doc))
  25. }
  26. return nil
  27. }
  28. // Modifies the vote object in memory.
  29. // Double signing results in an error.
  30. func (pv *PrivValidator) SignVote(vote *Vote) error {
  31. //TODO: prevent double signing.
  32. doc := GenVoteDocument(vote.Type, vote.Height, vote.Round, vote.Hash)
  33. vote.Signature = pv.Sign([]byte(doc))
  34. return nil
  35. }