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)
// Register components for readiness checks.
readiness.RegisterComponent("ethSyncing")
readiness.RegisterComponent("solanaSyncing")
readiness.RegisterComponent(common.ReadinessEthSyncing)
readiness.RegisterComponent(common.ReadinessSolanaSyncing)
if *terraSupport {
readiness.RegisterComponent("terraSyncing")
readiness.RegisterComponent(common.ReadinessTerraSyncing)
}
// 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()
logger.Info("processing new header", zap.Stringer("block", ev.Number))
readiness.SetReady("ethSyncing")
readiness.SetReady(common.ReadinessEthSyncing)
e.pendingLocksGuard.Lock()

View File

@ -16,21 +16,23 @@ var (
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.
func RegisterComponent(component string) {
func RegisterComponent(component Component) {
mu.Lock()
if _, ok := registry[component]; ok {
if _, ok := registry[string(component)]; ok {
panic("component already registered")
}
registry[component] = false
registry[string(component)] = false
mu.Unlock()
}
// SetReady sets the given global component state.
func SetReady(component string) {
func SetReady(component Component) {
mu.Lock()
if !registry[component] {
registry[component] = true
if !registry[string(component)] {
registry[string(component)] = true
}
mu.Unlock()
}

View File

@ -65,7 +65,7 @@ func (e *SolanaBridgeWatcher) Run(ctx context.Context) error {
if err != nil {
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))
go func() {

View File

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