2020-11-19 03:53:19 -08:00
|
|
|
package processor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/hex"
|
2021-01-24 08:20:04 -08:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2021-07-23 07:06:35 -07:00
|
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
2020-11-19 03:53:19 -08:00
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2021-08-26 01:35:09 -07:00
|
|
|
"github.com/certusone/wormhole/node/pkg/supervisor"
|
|
|
|
"github.com/certusone/wormhole/node/pkg/vaa"
|
2020-11-19 03:53:19 -08:00
|
|
|
)
|
|
|
|
|
2021-01-24 08:20:04 -08:00
|
|
|
var (
|
2021-07-23 07:06:35 -07:00
|
|
|
vaaInjectionsTotal = promauto.NewCounter(
|
2021-01-24 08:20:04 -08:00
|
|
|
prometheus.CounterOpts{
|
|
|
|
Name: "wormhole_vaa_injections_total",
|
|
|
|
Help: "Total number of injected VAA queued for broadcast",
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2020-11-19 03:53:19 -08:00
|
|
|
// handleInjection processes a pre-populated VAA injected locally.
|
|
|
|
func (p *Processor) handleInjection(ctx context.Context, v *vaa.VAA) {
|
|
|
|
// Generate digest of the unsigned VAA.
|
2021-12-19 08:13:28 -08:00
|
|
|
digest := v.SigningMsg()
|
2020-11-19 03:53:19 -08:00
|
|
|
|
|
|
|
// The internal originator is responsible for logging the full VAA, just log the digest here.
|
|
|
|
supervisor.Logger(ctx).Info("signing injected VAA",
|
|
|
|
zap.Stringer("digest", digest))
|
|
|
|
|
|
|
|
// Sign the digest using our node's guardian key.
|
|
|
|
s, err := crypto.Sign(digest.Bytes(), p.gk)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
p.logger.Info("observed and signed injected VAA",
|
|
|
|
zap.String("digest", hex.EncodeToString(digest.Bytes())),
|
2021-01-24 08:51:21 -08:00
|
|
|
zap.String("signature", hex.EncodeToString(s)))
|
2020-11-19 03:53:19 -08:00
|
|
|
|
2021-01-24 08:20:04 -08:00
|
|
|
vaaInjectionsTotal.Inc()
|
2021-10-01 00:33:03 -07:00
|
|
|
p.broadcastSignature(v, s, nil)
|
2020-11-19 03:53:19 -08:00
|
|
|
}
|