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:
parent
aa33dc4565
commit
a853317421
|
@ -16,6 +16,8 @@ import (
|
||||||
"github.com/certusone/wormhole/bridge/pkg/vaa"
|
"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) {
|
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!)
|
// 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 {
|
if t, ok := v.Payload.(*vaa.BodyTransfer); ok {
|
||||||
switch {
|
switch {
|
||||||
case t.TargetChain == vaa.ChainIDEthereum:
|
case t.TargetChain == vaa.ChainIDEthereum:
|
||||||
// In dev mode, submit VAA to Ethereum. For production, the bridge won't
|
// Check whether we run in devmode and submit the VAA ourselves, if so.
|
||||||
// have an Ethereum account and the user retrieves the VAA and submits the transactions themselves.
|
p.devnetVAASubmission(ctx, signed, hash)
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cross-submit to Solana for data availability
|
// Cross-submit to Solana for data availability
|
||||||
fallthrough
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package processor
|
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
|
// 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.
|
// ethereum/contracts/Wormhole.sol), and this needs to match the implementation in the contracts.
|
||||||
|
|
Loading…
Reference in New Issue