From 9f514e27865c8b83d8ca4785ccc0e324902b7a7e Mon Sep 17 00:00:00 2001 From: Hendrik Hofstadt Date: Thu, 15 Apr 2021 11:36:29 +0200 Subject: [PATCH] rename ChainLock to MessagePublication Change-Id: If74e74c00957c202c7de1cc61204b6cc12ad3a8a --- bridge/cmd/guardiand/bridge.go | 2 +- bridge/pkg/common/bridgewatcher.go | 2 +- bridge/pkg/common/chainlock.go | 23 +++++-------------- bridge/pkg/ethereum/watcher.go | 8 +++---- .../pkg/processor/{lockup.go => message.go} | 14 ++++------- bridge/pkg/processor/processor.go | 4 ++-- bridge/pkg/solana/client.go | 20 ++++++++-------- bridge/pkg/solana/submitter.go | 8 +++---- bridge/pkg/terra/watcher.go | 6 ++--- 9 files changed, 36 insertions(+), 51 deletions(-) rename bridge/pkg/processor/{lockup.go => message.go} (88%) diff --git a/bridge/cmd/guardiand/bridge.go b/bridge/cmd/guardiand/bridge.go index 7fd01af3..b362f0c9 100644 --- a/bridge/cmd/guardiand/bridge.go +++ b/bridge/cmd/guardiand/bridge.go @@ -331,7 +331,7 @@ func runBridge(cmd *cobra.Command, args []string) { defer rootCtxCancel() // Ethereum lock event channel - lockC := make(chan *common.ChainLock) + lockC := make(chan *common.MessagePublication) // Ethereum incoming guardian set updates setC := make(chan *common.GuardianSet) diff --git a/bridge/pkg/common/bridgewatcher.go b/bridge/pkg/common/bridgewatcher.go index b6531d55..3270f4d2 100644 --- a/bridge/pkg/common/bridgewatcher.go +++ b/bridge/pkg/common/bridgewatcher.go @@ -1,5 +1,5 @@ package common type BridgeWatcher interface { - WatchLockups(events chan *ChainLock) error + WatchLockups(events chan *MessagePublication) error } diff --git a/bridge/pkg/common/chainlock.go b/bridge/pkg/common/chainlock.go index 4d47c819..6cbbcc68 100644 --- a/bridge/pkg/common/chainlock.go +++ b/bridge/pkg/common/chainlock.go @@ -1,29 +1,18 @@ package common import ( - "math/big" + "github.com/certusone/wormhole/bridge/pkg/vaa" "time" "github.com/ethereum/go-ethereum/common" - - "github.com/certusone/wormhole/bridge/pkg/vaa" ) -type ChainLock struct { +type MessagePublication struct { TxHash common.Hash // TODO: rename to identifier? on Solana, this isn't actually the tx hash Timestamp time.Time - Nonce uint32 - - SourceAddress vaa.Address - TargetAddress vaa.Address - - SourceChain vaa.ChainID - TargetChain vaa.ChainID - - TokenChain vaa.ChainID - TokenAddress vaa.Address - TokenDecimals uint8 - - Amount *big.Int + Nonce uint32 + EmitterChain vaa.ChainID + EmitterAddress vaa.Address + Payload []byte } diff --git a/bridge/pkg/ethereum/watcher.go b/bridge/pkg/ethereum/watcher.go index 2050b214..765b38ac 100644 --- a/bridge/pkg/ethereum/watcher.go +++ b/bridge/pkg/ethereum/watcher.go @@ -76,17 +76,17 @@ type ( pendingLocks map[eth_common.Hash]*pendingLock pendingLocksGuard sync.Mutex - lockChan chan *common.ChainLock + lockChan chan *common.MessagePublication setChan chan *common.GuardianSet } pendingLock struct { - lock *common.ChainLock + lock *common.MessagePublication height uint64 } ) -func NewEthBridgeWatcher(url string, bridge eth_common.Address, minConfirmations uint64, lockEvents chan *common.ChainLock, setEvents chan *common.GuardianSet) *EthBridgeWatcher { +func NewEthBridgeWatcher(url string, bridge eth_common.Address, minConfirmations uint64, lockEvents chan *common.MessagePublication, setEvents chan *common.GuardianSet) *EthBridgeWatcher { return &EthBridgeWatcher{url: url, bridge: bridge, minConfirmations: minConfirmations, lockChan: lockEvents, setChan: setEvents, pendingLocks: map[eth_common.Hash]*pendingLock{}} } @@ -179,7 +179,7 @@ func (e *EthBridgeWatcher) Run(ctx context.Context) error { return } - lock := &common.ChainLock{ + lock := &common.MessagePublication{ TxHash: ev.Raw.TxHash, Timestamp: time.Unix(int64(b.Time()), 0), Nonce: ev.Nonce, diff --git a/bridge/pkg/processor/lockup.go b/bridge/pkg/processor/message.go similarity index 88% rename from bridge/pkg/processor/lockup.go rename to bridge/pkg/processor/message.go index 2568b775..70101e32 100644 --- a/bridge/pkg/processor/lockup.go +++ b/bridge/pkg/processor/message.go @@ -39,15 +39,11 @@ func init() { // handleLockup processes a lockup received from a chain and instantiates our deterministic copy of the VAA. A lockup // event may be received multiple times until it has been successfully completed. -func (p *Processor) handleLockup(ctx context.Context, k *common.ChainLock) { - supervisor.Logger(ctx).Info("lockup confirmed", - zap.Stringer("source_chain", k.SourceChain), - zap.Stringer("target_chain", k.TargetChain), - zap.Stringer("source_addr", k.SourceAddress), - zap.Stringer("target_addr", k.TargetAddress), - zap.Stringer("token_chain", k.TokenChain), - zap.Stringer("token_addr", k.TokenAddress), - zap.Stringer("amount", k.Amount), +func (p *Processor) handleLockup(ctx context.Context, k *common.MessagePublication) { + supervisor.Logger(ctx).Info("message publication confirmed", + zap.Stringer("emitter_chain", k.EmitterChain), + zap.Stringer("emitter_address", k.EmitterAddress), + zap.Uint32("nonce", k.Nonce), zap.Stringer("txhash", k.TxHash), zap.Time("timestamp", k.Timestamp), ) diff --git a/bridge/pkg/processor/processor.go b/bridge/pkg/processor/processor.go index de29ac1a..e4a3915f 100644 --- a/bridge/pkg/processor/processor.go +++ b/bridge/pkg/processor/processor.go @@ -52,7 +52,7 @@ type ( type Processor struct { // lockC is a channel of observed chain lockups - lockC chan *common.ChainLock + lockC chan *common.MessagePublication // setC is a channel of guardian set updates setC chan *common.GuardianSet @@ -97,7 +97,7 @@ type Processor struct { func NewProcessor( ctx context.Context, - lockC chan *common.ChainLock, + lockC chan *common.MessagePublication, setC chan *common.GuardianSet, sendC chan []byte, obsvC chan *gossipv1.SignedObservation, diff --git a/bridge/pkg/solana/client.go b/bridge/pkg/solana/client.go index 8529ae58..4a89922b 100644 --- a/bridge/pkg/solana/client.go +++ b/bridge/pkg/solana/client.go @@ -21,10 +21,10 @@ import ( ) type SolanaWatcher struct { - bridge solana.PublicKey - wsUrl string - rpcUrl string - lockEvent chan *common.ChainLock + bridge solana.PublicKey + wsUrl string + rpcUrl string + messageEvent chan *common.MessagePublication } var ( @@ -63,8 +63,8 @@ func init() { prometheus.MustRegister(queryLatency) } -func NewSolanaWatcher(wsUrl, rpcUrl string, bridgeAddress solana.PublicKey, lockEvents chan *common.ChainLock) *SolanaWatcher { - return &SolanaWatcher{bridge: bridgeAddress, wsUrl: wsUrl, rpcUrl: rpcUrl, lockEvent: lockEvents} +func NewSolanaWatcher(wsUrl, rpcUrl string, bridgeAddress solana.PublicKey, messageEvents chan *common.MessagePublication) *SolanaWatcher { + return &SolanaWatcher{bridge: bridgeAddress, wsUrl: wsUrl, rpcUrl: rpcUrl, messageEvent: messageEvents} } func (s *SolanaWatcher) Run(ctx context.Context) error { @@ -107,7 +107,7 @@ func (s *SolanaWatcher) Run(ctx context.Context) error { logger.Info("current Solana height", zap.Uint64("slot", uint64(slot))) - // Find TransferOutProposal accounts without a VAA + // Find MessagePublicationAccount accounts without a VAA rCtx, cancel = context.WithTimeout(ctx, time.Second*5) defer cancel() start = time.Now() @@ -116,7 +116,7 @@ func (s *SolanaWatcher) Run(ctx context.Context) error { Commitment: rpc.CommitmentMax, // TODO: deprecated, use Finalized Filters: []rpc.RPCFilter{ { - DataSize: 1184, // Search for TransferOutProposal accounts + DataSize: 1184, // Search for MessagePublicationAccount accounts }, { Memcmp: &rpc.RPCFilterMemcmp{ @@ -159,7 +159,7 @@ func (s *SolanaWatcher) Run(ctx context.Context) error { var txHash eth_common.Hash copy(txHash[:], acc.Pubkey[:]) - lock := &common.ChainLock{ + lock := &common.MessagePublication{ TxHash: txHash, Timestamp: proposal.LockupTime, Nonce: proposal.Nonce, @@ -175,7 +175,7 @@ func (s *SolanaWatcher) Run(ctx context.Context) error { solanaLockupsConfirmed.Inc() logger.Info("found lockup without VAA", zap.Stringer("lockup_address", acc.Pubkey)) - s.lockEvent <- lock + s.messageEvent <- lock } }() } diff --git a/bridge/pkg/solana/submitter.go b/bridge/pkg/solana/submitter.go index 2fcc09c6..cb87125c 100644 --- a/bridge/pkg/solana/submitter.go +++ b/bridge/pkg/solana/submitter.go @@ -44,13 +44,13 @@ type ( SolanaVAASubmitter struct { url string - lockChan chan *common.ChainLock - vaaChan chan *vaa.VAA + messageChan chan *common.MessagePublication + vaaChan chan *vaa.VAA } ) -func NewSolanaVAASubmitter(url string, lockEvents chan *common.ChainLock, vaaQueue chan *vaa.VAA) *SolanaVAASubmitter { - return &SolanaVAASubmitter{url: url, lockChan: lockEvents, vaaChan: vaaQueue} +func NewSolanaVAASubmitter(url string, lockEvents chan *common.MessagePublication, vaaQueue chan *vaa.VAA) *SolanaVAASubmitter { + return &SolanaVAASubmitter{url: url, messageChan: lockEvents, vaaChan: vaaQueue} } func (e *SolanaVAASubmitter) Run(ctx context.Context) error { diff --git a/bridge/pkg/terra/watcher.go b/bridge/pkg/terra/watcher.go index 09e62057..9dce4d3e 100644 --- a/bridge/pkg/terra/watcher.go +++ b/bridge/pkg/terra/watcher.go @@ -31,7 +31,7 @@ type ( urlLCD string bridge string - lockChan chan *common.ChainLock + lockChan chan *common.MessagePublication setChan chan *common.GuardianSet } ) @@ -78,7 +78,7 @@ type clientRequest struct { } // NewTerraBridgeWatcher creates a new terra bridge watcher -func NewTerraBridgeWatcher(urlWS string, urlLCD string, bridge string, lockEvents chan *common.ChainLock, setEvents chan *common.GuardianSet) *BridgeWatcher { +func NewTerraBridgeWatcher(urlWS string, urlLCD string, bridge string, lockEvents chan *common.MessagePublication, setEvents chan *common.GuardianSet) *BridgeWatcher { return &BridgeWatcher{urlWS: urlWS, urlLCD: urlLCD, bridge: bridge, lockChan: lockEvents, setChan: setEvents} } @@ -220,7 +220,7 @@ func (e *BridgeWatcher) Run(ctx context.Context) error { logger.Error("cannot decode hex", zap.String("value", txHash.String())) continue } - lock := &common.ChainLock{ + lock := &common.MessagePublication{ TxHash: txHashValue, Timestamp: time.Unix(blockTime.Int(), 0), Nonce: uint32(nonce.Uint()),