From a853317421d483d7b8a84d3f1d586495d898de1b Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 29 Oct 2020 10:13:15 +0100 Subject: [PATCH] bridge: refactor out devnetVAASubmission in observation.go ghstack-source-id: 93e811b135cfcb141917b9e42eaa28d32e6621d9 Pull Request resolved: https://github.com/certusone/wormhole/pull/71 --- bridge/pkg/processor/observation.go | 43 +++++++++++++++++------------ bridge/pkg/processor/quorum.go | 2 +- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/bridge/pkg/processor/observation.go b/bridge/pkg/processor/observation.go index 00f8d7fd..8031a977 100644 --- a/bridge/pkg/processor/observation.go +++ b/bridge/pkg/processor/observation.go @@ -16,6 +16,8 @@ import ( "github.com/certusone/wormhole/bridge/pkg/vaa" ) +// handleObservation processes a remote VAA observation, verifies it, checks whether the VAA has met quorum, +// and assembles and submits a valid VAA if possible. func (p *Processor) handleObservation(ctx context.Context, m *gossipv1.LockupObservation) { // SECURITY: at this point, observations received from the p2p network are fully untrusted (all fields!) // @@ -137,24 +139,8 @@ func (p *Processor) handleObservation(ctx context.Context, m *gossipv1.LockupObs if t, ok := v.Payload.(*vaa.BodyTransfer); ok { switch { case t.TargetChain == vaa.ChainIDEthereum: - // In dev mode, submit VAA to Ethereum. For production, the bridge won't - // have an Ethereum account and the user retrieves the VAA and submits the transactions themselves. - if p.devnetMode { - timeout, cancel := context.WithTimeout(ctx, 15*time.Second) - tx, err := devnet.SubmitVAA(timeout, p.devnetEthRPC, signed) - cancel() - if err != nil { - if strings.Contains(err.Error(), "VAA was already executed") { - p.logger.Info("lockup already submitted to Ethereum by another node, ignoring", - zap.Error(err), zap.String("digest", hash)) - } else { - p.logger.Error("failed to submit lockup to Ethereum", - zap.Error(err), zap.String("digest", hash)) - } - break - } - p.logger.Info("lockup submitted to Ethereum", zap.Any("tx", tx), zap.String("digest", hash)) - } + // Check whether we run in devmode and submit the VAA ourselves, if so. + p.devnetVAASubmission(ctx, signed, hash) // Cross-submit to Solana for data availability fallthrough @@ -183,3 +169,24 @@ func (p *Processor) handleObservation(ctx context.Context, m *gossipv1.LockupObs } } } + +// devnetVAASubmission submits VAA to a local Ethereum devnet. For production, the bridge won't +// have an Ethereum account and the user retrieves the VAA and submits the transactions themselves. +func (p *Processor) devnetVAASubmission(ctx context.Context, signed *vaa.VAA, hash string) { + if p.devnetMode { + timeout, cancel := context.WithTimeout(ctx, 15*time.Second) + tx, err := devnet.SubmitVAA(timeout, p.devnetEthRPC, signed) + cancel() + if err != nil { + if strings.Contains(err.Error(), "VAA was already executed") { + p.logger.Info("lockup already submitted to Ethereum by another node, ignoring", + zap.Error(err), zap.String("digest", hash)) + } else { + p.logger.Error("failed to submit lockup to Ethereum", + zap.Error(err), zap.String("digest", hash)) + } + return + } + p.logger.Info("lockup submitted to Ethereum", zap.Any("tx", tx), zap.String("digest", hash)) + } +} diff --git a/bridge/pkg/processor/quorum.go b/bridge/pkg/processor/quorum.go index d70ed80f..45dd8510 100644 --- a/bridge/pkg/processor/quorum.go +++ b/bridge/pkg/processor/quorum.go @@ -1,6 +1,6 @@ package processor -// CalculateQuorum returns the minimum number of have that needs to sign a VAA for a given guardian set. +// CalculateQuorum returns the minimum number of guardians that need to sign a VAA for a given guardian set. // // The canonical source is the calculation in the contracts (solana/bridge/src/processor.rs and // ethereum/contracts/Wormhole.sol), and this needs to match the implementation in the contracts.