bridge: type alias for readiness components

This commit is contained in:
Leo 2020-11-29 13:30:18 +01:00 committed by Leopold Schabel
parent c31777d1b3
commit 120dfab49e
6 changed files with 23 additions and 12 deletions

View File

@ -174,10 +174,10 @@ func runBridge(cmd *cobra.Command, args []string) {
ipfslog.SetAllLoggers(lvl) ipfslog.SetAllLoggers(lvl)
// Register components for readiness checks. // Register components for readiness checks.
readiness.RegisterComponent("ethSyncing") readiness.RegisterComponent(common.ReadinessEthSyncing)
readiness.RegisterComponent("solanaSyncing") readiness.RegisterComponent(common.ReadinessSolanaSyncing)
if *terraSupport { if *terraSupport {
readiness.RegisterComponent("terraSyncing") readiness.RegisterComponent(common.ReadinessTerraSyncing)
} }
// In devnet mode, we automatically set a number of flags that rely on deterministic keys. // In devnet mode, we automatically set a number of flags that rely on deterministic keys.

View File

@ -0,0 +1,9 @@
package common
import "github.com/certusone/wormhole/bridge/pkg/readiness"
const (
ReadinessEthSyncing readiness.Component = "ethSyncing"
ReadinessSolanaSyncing readiness.Component = "solanaSyncing"
ReadinessTerraSyncing readiness.Component = "terraSyncing"
)

View File

@ -179,7 +179,7 @@ func (e *EthBridgeWatcher) Run(ctx context.Context) error {
start := time.Now() start := time.Now()
logger.Info("processing new header", zap.Stringer("block", ev.Number)) logger.Info("processing new header", zap.Stringer("block", ev.Number))
readiness.SetReady("ethSyncing") readiness.SetReady(common.ReadinessEthSyncing)
e.pendingLocksGuard.Lock() e.pendingLocksGuard.Lock()

View File

@ -16,21 +16,23 @@ var (
registry = map[string]bool{} registry = map[string]bool{}
) )
type Component string
// RegisterComponent registers the given component name such that it is required to be ready for the global check to succeed. // RegisterComponent registers the given component name such that it is required to be ready for the global check to succeed.
func RegisterComponent(component string) { func RegisterComponent(component Component) {
mu.Lock() mu.Lock()
if _, ok := registry[component]; ok { if _, ok := registry[string(component)]; ok {
panic("component already registered") panic("component already registered")
} }
registry[component] = false registry[string(component)] = false
mu.Unlock() mu.Unlock()
} }
// SetReady sets the given global component state. // SetReady sets the given global component state.
func SetReady(component string) { func SetReady(component Component) {
mu.Lock() mu.Lock()
if !registry[component] { if !registry[string(component)] {
registry[component] = true registry[string(component)] = true
} }
mu.Unlock() mu.Unlock()
} }

View File

@ -65,7 +65,7 @@ func (e *SolanaBridgeWatcher) Run(ctx context.Context) error {
if err != nil { if err != nil {
return fmt.Errorf("failed to get balance: %v", err) return fmt.Errorf("failed to get balance: %v", err)
} }
readiness.SetReady("solanaSyncing") readiness.SetReady(common.ReadinessSolanaSyncing)
logger.Info("account balance", zap.Uint64("lamports", balance.Balance)) logger.Info("account balance", zap.Uint64("lamports", balance.Balance))
go func() { go func() {

View File

@ -81,7 +81,7 @@ func (e *BridgeWatcher) Run(ctx context.Context) error {
} }
logger.Info("subscribed to new transaction events") logger.Info("subscribed to new transaction events")
readiness.SetReady("terraSyncing") readiness.SetReady(common.ReadinessTerraSyncing)
go func() { go func() {
defer close(errC) defer close(errC)