@@ -67,6 +67,16 @@ func (w *UpgradeWatcher) Start(ctx context.Context) error {
6767}
6868
6969func (w * UpgradeWatcher ) OnNewBlock (ctx context.Context , node * rpc.Node , evt * ctypes.ResultEvent ) error {
70+ blockEvent := evt .Data .(comettypes.EventDataNewBlock )
71+ block := blockEvent .Block
72+
73+ // Skip already processed blocks
74+ if w .latestBlockHeight >= block .Height {
75+ return nil
76+ }
77+
78+ w .latestBlockHeight = block .Height
79+
7080 // Ignore is webhook is not configured
7181 if w .webhook == nil {
7282 return nil
@@ -82,18 +92,8 @@ func (w *UpgradeWatcher) OnNewBlock(ctx context.Context, node *rpc.Node, evt *ct
8292 return nil
8393 }
8494
85- blockEvent := evt .Data .(comettypes.EventDataNewBlock )
86- block := blockEvent .Block
87-
88- // Skip already processed blocks
89- if w .latestBlockHeight >= block .Height {
90- return nil
91- }
92-
93- w .latestBlockHeight = block .Height
94-
9595 // Ignore if upgrade plan is for a future block
96- if block . Height < w .nextUpgradePlan .Height - 1 {
96+ if w . latestBlockHeight < w .nextUpgradePlan .Height - 1 {
9797 return nil
9898 }
9999
@@ -174,7 +174,7 @@ func (w *UpgradeWatcher) checkUpgradeProposalsV1(ctx context.Context, node *rpc.
174174 if err != nil {
175175 return nil , fmt .Errorf ("failed to extract upgrade plan: %w" , err )
176176 }
177- if plan != nil {
177+ if plan != nil && plan . Height > w . latestBlockHeight {
178178 return plan , nil
179179 }
180180 }
@@ -200,7 +200,7 @@ func (w *UpgradeWatcher) checkUpgradeProposalsV1Beta1(ctx context.Context, node
200200 if err != nil {
201201 return nil , fmt .Errorf ("failed to extract upgrade plan: %w" , err )
202202 }
203- if plan != nil {
203+ if plan != nil && plan . Height > w . latestBlockHeight {
204204 return plan , nil
205205 }
206206 }
0 commit comments