Skip to content

Commit 4218c2c

Browse files
committed
add to slow path (when GetTransactionResultsByBlockID has failed)
1 parent 64a5b88 commit 4218c2c

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

state/process.go

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,7 @@ outer:
201201
// the self-sealed root block of a spork (where a ZeroID is used for
202202
// the event collection hash).
203203
if !(spork.Prev != nil && height == spork.RootBlock) {
204-
// TODO(tav): We check for just one transaction in the system
205-
// collection. If this changes in the future, we will need to
206-
// update the logic here to speculatively fetch more transaction
207-
// results.
204+
// We always retrieve the first transaction of the system collection.
208205
txnIndex++
209206
for {
210207
select {
@@ -225,6 +222,39 @@ outer:
225222
col.txnResults = append(col.txnResults, txnResult)
226223
break
227224
}
225+
if spork.Version >= 8 {
226+
// check if the first tx in the system collection contains events indicating scheduled transactions were run
227+
// We are already on the slow path where GetTransactionsByBlockID/GetTransactionResultsByBlockID has failed
228+
systemTxEvents := col.txnResults[len(col.txnResults)-1].Events
229+
scheduledTxs := 0
230+
for _, event := range systemTxEvents {
231+
if strings.HasSuffix(event.Type, ".FlowTransactionScheduler.PendingExecution") {
232+
scheduledTxs++
233+
}
234+
}
235+
for range scheduledTxs {
236+
txnIndex++
237+
for {
238+
select {
239+
case <-ctx.Done():
240+
return
241+
default:
242+
}
243+
client := spork.AccessNodes.Client()
244+
txnResult, err := client.TransactionResult(ctx, hash, uint32(txnIndex))
245+
if err != nil {
246+
log.Errorf(
247+
"Failed to fetch transaction result at index %d in block %x at height %d: %s",
248+
txnIndex, hash, height, err,
249+
)
250+
time.Sleep(time.Second)
251+
continue
252+
}
253+
col.txnResults = append(col.txnResults, txnResult)
254+
break
255+
}
256+
}
257+
}
228258
}
229259
} else {
230260
col := &collectionData{}

0 commit comments

Comments
 (0)