injection.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/bridge/pkg/supervisor"
  9. "github.com/certusone/wormhole/bridge/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. // Check if we're in the guardian set.
  24. us, ok := p.gs.KeyIndex(p.ourAddr)
  25. if !ok {
  26. p.logger.Error("we're not in the guardian set - refusing to sign",
  27. zap.Uint32("index", p.gs.Index),
  28. zap.Stringer("our_addr", p.ourAddr),
  29. zap.Any("set", p.gs.KeysAsHexStrings()))
  30. return
  31. }
  32. // Generate digest of the unsigned VAA.
  33. digest, err := v.SigningMsg()
  34. if err != nil {
  35. panic(err)
  36. }
  37. // The internal originator is responsible for logging the full VAA, just log the digest here.
  38. supervisor.Logger(ctx).Info("signing injected VAA",
  39. zap.Stringer("digest", digest))
  40. // Sign the digest using our node's guardian key.
  41. s, err := crypto.Sign(digest.Bytes(), p.gk)
  42. if err != nil {
  43. panic(err)
  44. }
  45. p.logger.Info("observed and signed injected VAA",
  46. zap.String("digest", hex.EncodeToString(digest.Bytes())),
  47. zap.String("signature", hex.EncodeToString(s)),
  48. zap.Int("our_index", us))
  49. vaaInjectionsTotal.Inc()
  50. p.broadcastSignature(v, s)
  51. }