Skip to content

Commit

Permalink
commit plugin: fix issue on WaitingForReportTransmission state (#88)
Browse files Browse the repository at this point in the history
The logic on the WaitingForReportTransmission state for detecting a transmitted report relies on the offRampNextSeqNums of the previous outcome. This value was never set on any outcome on any state. The plugin was never reaching the ReportTransmitted outcome. This PR fixes the issue mentioned above by properly setting the offRampNextSeqNums on each state.
  • Loading branch information
dimkouv authored Aug 28, 2024
1 parent 19e757f commit 442f1cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 17 additions & 5 deletions commit/outcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (p *Plugin) Outcome(
outcome = ReportRangesOutcome(commitQuery, consensusObservation)

case BuildingReport:
outcome = buildReport(commitQuery, consensusObservation)
outcome = buildReport(commitQuery, consensusObservation, previousOutcome)

case WaitingForReportTransmission:
outcome = checkForReportTransmission(
Expand Down Expand Up @@ -67,6 +67,7 @@ func ReportRangesOutcome(

observedOnRampMaxSeqNumsMap := consensusObservation.OnRampMaxSeqNums
observedOffRampNextSeqNumsMap := consensusObservation.OffRampNextSeqNums
offRampNextSeqNums := make([]plugintypes.SeqNumChain, 0)

for chainSel, offRampNextSeqNum := range observedOffRampNextSeqNumsMap {
onRampMaxSeqNum, exists := observedOnRampMaxSeqNumsMap[chainSel]
Expand All @@ -85,14 +86,23 @@ func ReportRangesOutcome(
}
rangesToReport = append(rangesToReport, chainRange)
}

offRampNextSeqNums = append(offRampNextSeqNums, plugintypes.SeqNumChain{
ChainSel: chainSel,
SeqNum: offRampNextSeqNum,
})
}

// deterministic outcome
sort.Slice(rangesToReport, func(i, j int) bool { return rangesToReport[i].ChainSel < rangesToReport[j].ChainSel })
sort.Slice(offRampNextSeqNums, func(i, j int) bool {
return offRampNextSeqNums[i].ChainSel < offRampNextSeqNums[j].ChainSel
})

outcome := Outcome{
OutcomeType: ReportIntervalsSelected,
RangesSelectedForReport: rangesToReport,
OffRampNextSeqNums: offRampNextSeqNums,
}

return outcome
Expand All @@ -103,6 +113,7 @@ func ReportRangesOutcome(
func buildReport(
_ Query,
consensusObservation ConsensusObservation,
prevOutcome Outcome,
) Outcome {
roots := maps.Values(consensusObservation.MerkleRoots)

Expand All @@ -114,10 +125,11 @@ func buildReport(
sort.Slice(roots, func(i, j int) bool { return roots[i].ChainSel < roots[j].ChainSel })

outcome := Outcome{
OutcomeType: outcomeType,
RootsToReport: roots,
GasPrices: consensusObservation.GasPricesArray(),
TokenPrices: consensusObservation.TokenPricesArray(),
OutcomeType: outcomeType,
RootsToReport: roots,
GasPrices: consensusObservation.GasPricesArray(),
TokenPrices: consensusObservation.TokenPricesArray(),
OffRampNextSeqNums: prevOutcome.OffRampNextSeqNums,
}

return outcome
Expand Down
4 changes: 2 additions & 2 deletions commit/outcome_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func Test_buildReport(t *testing.T) {
}

for i := 0; i < rounds; i++ {
report1 := buildReport(Query{}, obs)
report2 := buildReport(Query{}, obs)
report1 := buildReport(Query{}, obs, Outcome{})
report2 := buildReport(Query{}, obs, Outcome{})
require.Equal(t, report1, report2)
}
})
Expand Down

0 comments on commit 442f1cf

Please sign in to comment.