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.

66 lines
1.4 KiB

  1. package certifiers
  2. import (
  3. "bytes"
  4. "github.com/pkg/errors"
  5. "github.com/tendermint/tendermint/types"
  6. certerr "github.com/tendermint/tendermint/certifiers/errors"
  7. )
  8. var _ Certifier = &Static{}
  9. // Static assumes a static set of validators, set on
  10. // initilization and checks against them.
  11. // The signatures on every header is checked for > 2/3 votes
  12. // against the known validator set upon Certify
  13. //
  14. // Good for testing or really simple chains. Building block
  15. // to support real-world functionality.
  16. type Static struct {
  17. chainID string
  18. vSet *types.ValidatorSet
  19. vhash []byte
  20. }
  21. func NewStatic(chainID string, vals *types.ValidatorSet) *Static {
  22. return &Static{
  23. chainID: chainID,
  24. vSet: vals,
  25. }
  26. }
  27. func (c *Static) ChainID() string {
  28. return c.chainID
  29. }
  30. func (c *Static) Validators() *types.ValidatorSet {
  31. return c.vSet
  32. }
  33. func (c *Static) Hash() []byte {
  34. if len(c.vhash) == 0 {
  35. c.vhash = c.vSet.Hash()
  36. }
  37. return c.vhash
  38. }
  39. func (c *Static) Certify(commit Commit) error {
  40. // do basic sanity checks
  41. err := commit.ValidateBasic(c.chainID)
  42. if err != nil {
  43. return err
  44. }
  45. // make sure it has the same validator set we have (static means static)
  46. if !bytes.Equal(c.Hash(), commit.Header.ValidatorsHash) {
  47. return certerr.ErrValidatorsChanged()
  48. }
  49. // then make sure we have the proper signatures for this
  50. err = c.vSet.VerifyCommit(c.chainID, commit.Commit.BlockID,
  51. commit.Header.Height, commit.Commit)
  52. return errors.WithStack(err)
  53. }