@@ -870,9 +870,18 @@ func (m *FollowerState) epochPhaseMetricsAndEventsOnBlockFinalized(block *flow.B
870870 events []func (),
871871 err error ,
872872) {
873- // track service event driven metrics and protocol events that should be emitted
874- for _ , seal := range block .Payload .Seals {
875873
874+ // block payload may not specify seals in order, so order them by block height before processing
875+ orderedSeals , err := protocol .OrderedSeals (block .Payload , m .headers )
876+ if err != nil {
877+ if errors .Is (err , storage .ErrNotFound ) {
878+ return nil , nil , fmt .Errorf ("ordering seals: parent payload contains seals for unknown block: %s" , err .Error ())
879+ }
880+ return nil , nil , fmt .Errorf ("unexpected error ordering seals: %w" , err )
881+ }
882+
883+ // track service event driven metrics and protocol events that should be emitted
884+ for _ , seal := range orderedSeals {
876885 result , err := m .results .ByID (seal .ResultID )
877886 if err != nil {
878887 return nil , nil , fmt .Errorf ("could not retrieve result (id=%x) for seal (id=%x): %w" , seal .ResultID , seal .ID (), err )
@@ -976,7 +985,7 @@ func (m *FollowerState) epochStatus(block *flow.Header, epochFallbackTriggered b
976985// correctness of the service event before processing it.
977986// Consequently, any change to the protocol state introduced by a service event
978987// emitted during execution of block A would only become visible when querying
979- // C or its descendants.
988+ // C or its descendants.
980989//
981990// This method will only apply service-event-induced state changes when the
982991// input block has the form of block C (ie. contains a seal for a block in
0 commit comments