Skip to content

Commit 41a14a6

Browse files
authored
simulators/eth2/testnet: Retry finality checkpoint query with different API method (#587)
simulators/eth2/testnet: Retry finality checkpoint query with different method
1 parent a0732ab commit 41a14a6

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

simulators/eth2/testnet/running_testnet.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,14 @@ func (t *Testnet) WaitForFinality(ctx context.Context) (common.Checkpoint, error
107107
}
108108

109109
var checkpoints eth2api.FinalityCheckpoints
110-
if exists, err := beaconapi.FinalityCheckpoints(ctx, b.API, eth2api.StateIdRoot(headInfo.Header.Message.StateRoot), &checkpoints); err != nil {
111-
ch <- res{err: fmt.Errorf("beacon %d: failed to poll finality checkpoint: %v", i, err)}
112-
return
113-
} else if !exists {
114-
ch <- res{err: fmt.Errorf("beacon %d: Expected state for head block", i)}
115-
return
110+
if exists, err := beaconapi.FinalityCheckpoints(ctx, b.API, eth2api.StateIdRoot(headInfo.Header.Message.StateRoot), &checkpoints); err != nil || !exists {
111+
if exists, err = beaconapi.FinalityCheckpoints(ctx, b.API, eth2api.StateIdSlot(headInfo.Header.Message.Slot), &checkpoints); err != nil {
112+
ch <- res{err: fmt.Errorf("beacon %d: failed to poll finality checkpoint: %v", i, err)}
113+
return
114+
} else if !exists {
115+
ch <- res{err: fmt.Errorf("beacon %d: Expected state for head block", i)}
116+
return
117+
}
116118
}
117119

118120
var versionedBlock eth2api.VersionedSignedBeaconBlock
@@ -139,14 +141,16 @@ func (t *Testnet) WaitForFinality(ctx context.Context) (common.Checkpoint, error
139141
finalized = shorten(checkpoints.Finalized.String())
140142
health, err := getHealth(ctx, b.API, t.spec, slot)
141143
if err != nil {
142-
ch <- res{err: fmt.Errorf("beacon %d: %s", i, err)}
144+
// warning is printed here instead because some clients
145+
// don't support the required REST endpoint.
146+
fmt.Printf("WARN: beacon %d: %s\n", i, err)
143147
}
144148

145-
ch <- res{i, fmt.Sprintf("beacon %d: slot=%d, head=%s, health=%.2f, exec_payload=%s, justified=%s, finalized=%s", i, slot, head, health, execution, justified, finalized), nil}
146-
147149
ep := t.spec.SlotToEpoch(slot)
148150
if ep > 4 && ep > checkpoints.Finalized.Epoch+2 {
149151
ch <- res{err: fmt.Errorf("failed to finalize, head slot %d (epoch %d) is more than 2 ahead of finality checkpoint %d", slot, ep, checkpoints.Finalized.Epoch)}
152+
} else {
153+
ch <- res{i, fmt.Sprintf("beacon %d: slot=%d, head=%s, health=%.2f, exec_payload=%s, justified=%s, finalized=%s", i, slot, head, health, execution, justified, finalized), nil}
150154
}
151155

152156
if (checkpoints.Finalized != common.Checkpoint{}) {

0 commit comments

Comments
 (0)