bridge: refactor out devnetVAASubmission in observation.go

ghstack-source-id: 93e811b135
Pull Request resolved: https://github.com/certusone/wormhole/pull/71
This commit is contained in:
Leo 2020-10-29 10:13:15 +01:00
parent aa33dc4565
commit a853317421
2 changed files with 26 additions and 19 deletions

View File

@ -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))
}
}

View File

@ -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.