Skip to content

Commit ba1f157

Browse files
bors[bot]koko1123synzhu
authored
Merge #2321
2321: [Access node] Add random en lookup on receipt lookup failure r=smnzhu a=koko1123 Add logic to lookup random execution nodes on insufficient receipts instead of a blank list/custom error Co-authored-by: Amlandeep Bhadra <amlandeep1912@gmail.com> Co-authored-by: Simon Zhu <simon.zsiyan@gmail.com>
2 parents 8ddc01e + 10b7209 commit ba1f157

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

engine/access/rpc/backend/backend.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,13 @@ func executionNodesForBlockID(
394394
}
395395

396396
receiptCnt := len(executorIDs)
397-
// if less than minExecutionNodesCnt execution receipts have been received so far, then throw an error
397+
// if less than minExecutionNodesCnt execution receipts have been received so far, then return random ENs
398398
if receiptCnt < minExecutionNodesCnt {
399-
return flow.IdentityList{}, InsufficientExecutionReceipts{blockID: blockID, receiptCount: receiptCnt}
399+
newExecutorIDs, err := state.AtBlockID(blockID).Identities(filter.HasRole(flow.RoleExecution))
400+
if err != nil {
401+
return nil, fmt.Errorf("failed to retreive execution IDs for block ID %v: %w", blockID, err)
402+
}
403+
executorIDs = newExecutorIDs.NodeIDs()
400404
}
401405
}
402406

@@ -411,7 +415,7 @@ func executionNodesForBlockID(
411415

412416
if len(executionIdentitiesRandom) == 0 {
413417
return flow.IdentityList{},
414-
fmt.Errorf("no matching execution node could for block ID %v", blockID)
418+
fmt.Errorf("no matching execution node found for block ID %v", blockID)
415419
}
416420

417421
return executionIdentitiesRandom, nil
@@ -424,7 +428,7 @@ func findAllExecutionNodes(
424428
executionReceipts storage.ExecutionReceipts,
425429
log zerolog.Logger) (flow.IdentifierList, error) {
426430

427-
// lookup the receipts storage with the block ID
431+
// lookup the receipt's storage with the block ID
428432
allReceipts, err := executionReceipts.ByBlockID(blockID)
429433
if err != nil {
430434
return nil, fmt.Errorf("failed to retreive execution receipts for block ID %v: %w", blockID, err)

engine/access/rpc/backend/backend_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,18 @@ func (suite *Suite) TestExecutionNodesForBlockID() {
20232023
require.ElementsMatch(suite.T(), actualList, expectedENs)
20242024
}
20252025
}
2026+
// if we don't find sufficient receipts, executionNodesForBlockID should return a list of random ENs
2027+
suite.Run("insufficient receipts return random ENs in state", func() {
2028+
// return no receipts at all attempts
2029+
attempt1Receipts = flow.ExecutionReceiptList{}
2030+
attempt2Receipts = flow.ExecutionReceiptList{}
2031+
attempt3Receipts = flow.ExecutionReceiptList{}
2032+
suite.state.On("AtBlockID", mock.Anything).Return(suite.snapshot)
2033+
actualList, err := executionNodesForBlockID(context.Background(), block.ID(), suite.receipts, suite.state, suite.log)
2034+
require.NoError(suite.T(), err)
2035+
require.Equal(suite.T(), len(actualList), maxExecutionNodesCnt)
2036+
})
2037+
20262038
// if no preferred or fixed ENs are specified, the ExecutionNodesForBlockID function should
20272039
// return the exe node list without a filter
20282040
suite.Run("no preferred or fixed ENs", func() {

0 commit comments

Comments
 (0)