From c7ef120806324ec6f0b10173f52095416058e3ff Mon Sep 17 00:00:00 2001 From: bruce-riley <96066700+bruce-riley@users.noreply.github.com> Date: Fri, 30 Jun 2023 09:38:08 -0500 Subject: [PATCH] Node: Drop inbound signed vaas with quorum faster (#3150) Change-Id: I1ec23694031ecf8474ca2d4da5280eef39dd8edb --- node/pkg/processor/observation.go | 30 +++++++++++++++--------------- node/pkg/processor/processor.go | 5 +++++ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/node/pkg/processor/observation.go b/node/pkg/processor/observation.go index d3f4ae39d..5d1b788cb 100644 --- a/node/pkg/processor/observation.go +++ b/node/pkg/processor/observation.go @@ -227,6 +227,21 @@ func (p *Processor) handleInboundSignedVAAWithQuorum(ctx context.Context, m *gos return } + // Check if we already store this VAA + _, err = p.getSignedVAA(*db.VaaIDFromVAA(v)) + if err == nil { + p.logger.Debug("ignored SignedVAAWithQuorum message for VAA we already stored", + zap.String("vaaID", string(db.VaaIDFromVAA(v).Bytes())), + ) + return + } else if err != db.ErrVAANotFound { + p.logger.Error("failed to look up VAA in database", + zap.String("vaaID", string(db.VaaIDFromVAA(v).Bytes())), + zap.Error(err), + ) + return + } + // Calculate digest for logging digest := v.SigningDigest() hash := hex.EncodeToString(digest.Bytes()) @@ -258,21 +273,6 @@ func (p *Processor) handleInboundSignedVAAWithQuorum(ctx context.Context, m *gos // - the signature's addresses match the node's current guardian set // - enough signatures are present for the VAA to reach quorum - // Check if we already store this VAA - _, err = p.getSignedVAA(*db.VaaIDFromVAA(v)) - if err == nil { - p.logger.Debug("ignored SignedVAAWithQuorum message for VAA we already store", - zap.String("digest", hash), - ) - return - } else if err != db.ErrVAANotFound { - p.logger.Error("failed to look up VAA in database", - zap.String("digest", hash), - zap.Error(err), - ) - return - } - // Store signed VAA in database. p.logger.Info("storing inbound signed VAA with quorum", zap.String("digest", hash), diff --git a/node/pkg/processor/processor.go b/node/pkg/processor/processor.go index f47211fb0..18de99465 100644 --- a/node/pkg/processor/processor.go +++ b/node/pkg/processor/processor.go @@ -265,6 +265,7 @@ func (p *Processor) storeSignedVAA(v *vaa.VAA) error { } func (p *Processor) getSignedVAA(id db.VAAID) (*vaa.VAA, error) { + if id.EmitterChain == vaa.ChainIDPythNet { key := fmt.Sprintf("%v/%v", id.EmitterAddress, id.Sequence) ret, exists := p.pythnetVaas[key] @@ -275,6 +276,10 @@ func (p *Processor) getSignedVAA(id db.VAAID) (*vaa.VAA, error) { return nil, db.ErrVAANotFound } + if p.db == nil { + return nil, db.ErrVAANotFound + } + vb, err := p.db.GetSignedVAABytes(id) if err != nil { return nil, err