MCPcopy Create free account
hub / github.com/erpc/erpc / Run

Method Run

consensus/executor.go:118–166  ·  view source on GitHub ↗

Run is the main entry point for the consensus executor. It delegates to executeConsensus which decouples caller-visible latency from analysis completion (see runAnalyzer).

(
	ctx context.Context,
	originalReq *common.NormalizedRequest,
	in inner,
)

Source from the content-addressed store, hash-verified

116// It delegates to executeConsensus which decouples caller-visible
117// latency from analysis completion (see runAnalyzer).
118func (e *executor) Run(
119 ctx context.Context,
120 originalReq *common.NormalizedRequest,
121 in inner,
122) (*common.NormalizedResponse, error) {
123 startTime := time.Now()
124
125 if originalReq == nil {
126 e.logger.Error().Msg("Unexpected nil request in consensus policy")
127 return in(ctx, originalReq)
128 }
129
130 // Tag-based participant quota (opt-in). Front-load enough tag-matching
131 // upstreams so the first maxParticipants drawn by the slots below
132 // include the configured minimum from each required group. Runs at the
133 // very top of consensus, before any participant slot consumes an
134 // upstream (req.UpstreamIdx is still 0), so the reorder takes effect.
135 // Best-effort: shortfalls fall through to lowParticipantsBehavior /
136 // agreementThreshold like organic low participation.
137 if len(e.config.requiredParticipants) > 0 {
138 if reordered := reorderForParticipantQuota(originalReq.Upstreams(), e.config.requiredParticipants); len(reordered) > 0 {
139 originalReq.SetUpstreams(reordered)
140 }
141 }
142
143 labels := e.extractMetricsLabels(ctx, originalReq)
144 ctx, consensusSpan := e.startConsensusSpan(ctx, labels)
145 defer consensusSpan.End()
146
147 lg := e.logger.With().
148 Interface("id", originalReq.ID()).
149 Str("component", "consensus").
150 Str("networkId", labels.networkId).
151 Logger()
152
153 out := e.executeConsensus(
154 ctx,
155 &lg,
156 originalReq,
157 labels,
158 in,
159 startTime,
160 consensusSpan,
161 )
162 if out == nil {
163 return nil, nil
164 }
165 return out.Result, out.Error
166}
167
168// executeConsensus decouples two distinct concerns:
169//

Callers 1

RunMethod · 0.95

Calls 10

extractMetricsLabelsMethod · 0.95
startConsensusSpanMethod · 0.95
executeConsensusMethod · 0.95
SetUpstreamsMethod · 0.80
EndMethod · 0.80
ErrorMethod · 0.65
LoggerMethod · 0.65
UpstreamsMethod · 0.45
IDMethod · 0.45

Tested by

no test coverage detected