From 3940a2462df791d6985228059402d2ed6fecbb5f Mon Sep 17 00:00:00 2001 From: pippellia-btc Date: Fri, 19 Sep 2025 17:34:03 +0200 Subject: [PATCH] added print stats to arbiter more validation for activation ratio changed > to >= for activation --- pkg/pipe/arbiter.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/pipe/arbiter.go b/pkg/pipe/arbiter.go index 2731265..b6dce64 100644 --- a/pkg/pipe/arbiter.go +++ b/pkg/pipe/arbiter.go @@ -24,6 +24,7 @@ type ArbiterConfig struct { Demotion float64 `envconfig:"ARBITER_DEMOTION"` PromotionWait time.Duration `envconfig:"ARBITER_PROMOTION_WAIT"` PingWait time.Duration `envconfig:"ARBITER_PING_WAIT"` + PrintStats bool `envconfig:"ARBITER_PRINT_STATS"` } func NewArbiterConfig() ArbiterConfig { @@ -33,6 +34,7 @@ func NewArbiterConfig() ArbiterConfig { Demotion: 1.05, PromotionWait: time.Hour, PingWait: time.Minute, + PrintStats: true, } } @@ -41,6 +43,10 @@ func (c ArbiterConfig) Validate() error { return errors.New("activation ratio cannot be negative") } + if c.Activation > 1 { + return errors.New("activation ratio cannot be greater than 1") + } + if c.Promotion < 0 { return errors.New("promotion multiplier cannot be negative") } @@ -73,6 +79,7 @@ func (c ArbiterConfig) Print() { fmt.Printf(" Demotion: %f\n", c.Demotion) fmt.Printf(" PromotionWait: %v\n", c.PromotionWait) fmt.Printf(" PingWait: %v\n", c.PingWait) + fmt.Printf(" PrintStats: %v\n", c.PrintStats) } // Arbiter activates when the % of walks changed is greater than a threshold. Then it: @@ -107,14 +114,17 @@ func Arbiter( changed := WalksTracker.Load() changeRatio := float64(changed) / float64(total) - if changeRatio > config.Activation { + if changeRatio >= config.Activation { promoted, demoted, err := arbiterScan(ctx, config, db, forward) if err != nil && ctx.Err() == nil { log.Printf("Arbiter: %v", err) } + if config.PrintStats { + log.Printf("Arbiter: promoted %d, demoted %d", promoted, demoted) + } + WalksTracker.Store(0) // resets tracker - log.Printf("Arbiter: promoted %d, demoted %d", promoted, demoted) } } }