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.

47 lines
1.1 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. package types
  2. import (
  3. "context"
  4. "fmt"
  5. "time"
  6. tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
  7. )
  8. func makeCommit(blockID BlockID, height int64, round int32,
  9. voteSet *VoteSet, validators []PrivValidator, now time.Time) (*Commit, error) {
  10. // all sign
  11. for i := 0; i < len(validators); i++ {
  12. pubKey, err := validators[i].GetPubKey(context.Background())
  13. if err != nil {
  14. return nil, fmt.Errorf("can't get pubkey: %w", err)
  15. }
  16. vote := &Vote{
  17. ValidatorAddress: pubKey.Address(),
  18. ValidatorIndex: int32(i),
  19. Height: height,
  20. Round: round,
  21. Type: tmproto.PrecommitType,
  22. BlockID: blockID,
  23. Timestamp: now,
  24. }
  25. _, err = signAddVote(validators[i], vote, voteSet)
  26. if err != nil {
  27. return nil, err
  28. }
  29. }
  30. return voteSet.MakeCommit(), nil
  31. }
  32. func signAddVote(privVal PrivValidator, vote *Vote, voteSet *VoteSet) (signed bool, err error) {
  33. v := vote.ToProto()
  34. err = privVal.SignVote(context.Background(), voteSet.ChainID(), v)
  35. if err != nil {
  36. return false, err
  37. }
  38. vote.Signature = v.Signature
  39. return voteSet.AddVote(vote)
  40. }