injection.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package processor
  2. import (
  3. "context"
  4. "encoding/hex"
  5. "github.com/prometheus/client_golang/prometheus"
  6. "github.com/ethereum/go-ethereum/crypto"
  7. "go.uber.org/zap"
  8. "github.com/certusone/wormhole/node/pkg/supervisor"
  9. "github.com/certusone/wormhole/node/pkg/vaa"
  10. )
  11. var (
  12. vaaInjectionsTotal = prometheus.NewCounter(
  13. prometheus.CounterOpts{
  14. Name: "wormhole_vaa_injections_total",
  15. Help: "Total number of injected VAA queued for broadcast",
  16. })
  17. )
  18. func init() {
  19. prometheus.MustRegister(vaaInjectionsTotal)
  20. }
  21. // handleInjection processes a pre-populated VAA injected locally.
  22. func (p *Processor) handleInjection(ctx context.Context, v *vaa.VAA) {
  23. // Generate digest of the unsigned VAA.
  24. digest, err := v.SigningMsg()
  25. if err != nil {
  26. panic(err)
  27. }
  28. // The internal originator is responsible for logging the full VAA, just log the digest here.
  29. supervisor.Logger(ctx).Info("signing injected VAA",
  30. zap.Stringer("digest", digest))
  31. // Sign the digest using our node's guardian key.
  32. s, err := crypto.Sign(digest.Bytes(), p.gk)
  33. if err != nil {
  34. panic(err)
  35. }
  36. p.logger.Info("observed and signed injected VAA",
  37. zap.String("digest", hex.EncodeToString(digest.Bytes())),
  38. zap.String("signature", hex.EncodeToString(s)))
  39. vaaInjectionsTotal.Inc()
  40. p.broadcastSignature(v, s)
  41. }