5
5
"encoding/json"
6
6
"errors"
7
7
"fmt"
8
+ "math/big"
8
9
9
10
"github.com/ethereum/go-ethereum/common"
10
11
"github.com/shopspring/decimal"
@@ -30,10 +31,11 @@ var (
30
31
31
32
type ReportCodecPremiumLegacy struct {
32
33
logger.Logger
34
+ donID uint32
33
35
}
34
36
35
- func NewReportCodecPremiumLegacy (lggr logger.Logger ) ReportCodecPremiumLegacy {
36
- return ReportCodecPremiumLegacy {logger .Sugared (lggr ).Named ("ReportCodecPremiumLegacy" )}
37
+ func NewReportCodecPremiumLegacy (lggr logger.Logger , donID uint32 ) ReportCodecPremiumLegacy {
38
+ return ReportCodecPremiumLegacy {logger .Sugared (lggr ).Named ("ReportCodecPremiumLegacy" ), donID }
37
39
}
38
40
39
41
type ReportFormatEVMPremiumLegacyOpts struct {
@@ -119,7 +121,7 @@ func (r ReportCodecPremiumLegacy) Pack(digest types.ConfigDigest, seqNr uint64,
119
121
ss = append (ss , s )
120
122
vs [i ] = v
121
123
}
122
- reportCtx := LegacyReportContext (digest , seqNr )
124
+ reportCtx := LegacyReportContext (digest , seqNr , r . donID )
123
125
rawReportCtx := evmutil .RawReportContext (reportCtx )
124
126
125
127
payload , err := mercury .PayloadTypes .Pack (rawReportCtx , []byte (report ), rs , ss , vs )
@@ -181,9 +183,25 @@ func extractPrice(price llo.StreamValue) (decimal.Decimal, error) {
181
183
}
182
184
}
183
185
184
- // TODO: Consider embedding the DON ID here?
185
- // MERC-3524
186
- var LLOExtraHash = common .HexToHash ("0x0000000000000000000000000000000000000000000000000000000000000001" )
186
+ const PluginVersion uint32 = 1 // the legacy mercury plugin is 0
187
+
188
+ // Uniquely identifies this as LLO plugin, rather than the legacy plugin (which
189
+ // uses all zeroes).
190
+ //
191
+ // This is quite a hack but serves the purpose of uniquely identifying
192
+ // dons/plugin versions to the mercury server without having to modify any
193
+ // existing tooling or breaking backwards compatibility. It should be safe
194
+ // since the DonID is encoded into the config digest anyway so report context
195
+ // is already dependent on it, and all LLO jobs in the same don are expected to
196
+ // have the same don ID set.
197
+ //
198
+ // Packs donID+pluginVersion as (uint32, uint32), for example donID=2,
199
+ // PluginVersion=1 Yields:
200
+ // 0x0000000000000000000000000000000000000000000000000000000200000001
201
+ func LLOExtraHash (donID uint32 ) common.Hash {
202
+ combined := uint64 (donID )<< 32 | uint64 (PluginVersion )
203
+ return common .BigToHash (new (big.Int ).SetUint64 (combined ))
204
+ }
187
205
188
206
func SeqNrToEpochAndRound (seqNr uint64 ) (epoch uint32 , round uint8 ) {
189
207
// Simulate 256 rounds/epoch
@@ -192,14 +210,14 @@ func SeqNrToEpochAndRound(seqNr uint64) (epoch uint32, round uint8) {
192
210
return
193
211
}
194
212
195
- func LegacyReportContext (cd ocr2types.ConfigDigest , seqNr uint64 ) ocr2types.ReportContext {
213
+ func LegacyReportContext (cd ocr2types.ConfigDigest , seqNr uint64 , donID uint32 ) ocr2types.ReportContext {
196
214
epoch , round := SeqNrToEpochAndRound (seqNr )
197
215
return ocr2types.ReportContext {
198
216
ReportTimestamp : ocr2types.ReportTimestamp {
199
217
ConfigDigest : cd ,
200
218
Epoch : uint32 (epoch ),
201
219
Round : uint8 (round ),
202
220
},
203
- ExtraHash : LLOExtraHash , // ExtraHash is always zero for mercury, we use LLOExtraHash here to differentiate from the legacy plugin
221
+ ExtraHash : LLOExtraHash ( donID ) , // ExtraHash is always zero for mercury, we use LLOExtraHash here to differentiate from the legacy plugin
204
222
}
205
223
}
0 commit comments