Skip to content

Commit

Permalink
Deterministic custom transmission schedule (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkouv authored Dec 18, 2024
1 parent 5dc5b13 commit f742191
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/plugincommon/transmitters.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package plugincommon

import (
"fmt"
"sort"
"time"

"github.com/smartcontractkit/libocr/commontypes"
Expand Down Expand Up @@ -33,6 +34,9 @@ func GetTransmissionSchedule(
}
}

// transmissionSchedule must be deterministic
sort.Slice(transmitters, func(i, j int) bool { return transmitters[i] < transmitters[j] })

transmissionDelays := make([]time.Duration, len(transmitters))

for i := range transmissionDelays {
Expand Down
9 changes: 9 additions & 0 deletions internal/plugincommon/transmitters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ func TestGetTransmissionSchedule(t *testing.T) {
expectedError: true,
chainSupportReturnsError: true,
},
{
name: "determinism check",
allTheOracles: []commontypes.OracleID{3, 1, 2}, // <------ not ordered
oraclesSupportingDest: []commontypes.OracleID{1, 3},
transmissionDelayMultiplier: 5 * time.Second,
expectedTransmitters: []commontypes.OracleID{1, 3},
expectedTransmissionDelays: []time.Duration{5 * time.Second, 10 * time.Second},
expectedError: false,
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit f742191

Please sign in to comment.