injection.go 1.3 KB

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