broadcast.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package processor
  2. import (
  3. "encoding/hex"
  4. "time"
  5. ethcommon "github.com/ethereum/go-ethereum/common"
  6. "github.com/ethereum/go-ethereum/crypto"
  7. "google.golang.org/protobuf/proto"
  8. gossipv1 "github.com/certusone/wormhole/bridge/pkg/proto/gossip/v1"
  9. "github.com/certusone/wormhole/bridge/pkg/vaa"
  10. )
  11. func (p *Processor) broadcastSignature(v *vaa.VAA, signature []byte) {
  12. digest, err := v.SigningMsg()
  13. if err != nil {
  14. panic(err)
  15. }
  16. obsv := gossipv1.SignedObservation{
  17. Addr: crypto.PubkeyToAddress(p.gk.PublicKey).Bytes(),
  18. Hash: digest.Bytes(),
  19. Signature: signature,
  20. }
  21. w := gossipv1.GossipMessage{Message: &gossipv1.GossipMessage_SignedObservation{SignedObservation: &obsv}}
  22. msg, err := proto.Marshal(&w)
  23. if err != nil {
  24. panic(err)
  25. }
  26. p.sendC <- msg
  27. // Store our VAA in case we're going to submit it to Solana
  28. hash := hex.EncodeToString(digest.Bytes())
  29. if p.state.vaaSignatures[hash] == nil {
  30. p.state.vaaSignatures[hash] = &vaaState{
  31. firstObserved: time.Now(),
  32. signatures: map[ethcommon.Address][]byte{},
  33. }
  34. }
  35. p.state.vaaSignatures[hash].ourVAA = v
  36. p.state.vaaSignatures[hash].ourMsg = msg
  37. // Fast path for our own signature
  38. go func() { p.obsvC <- &obsv }()
  39. }