-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
220 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package commitrmnocb | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" | ||
) | ||
|
||
// Reports TODO: doc, metrics | ||
func (p *Plugin) Reports(seqNr uint64, outcomeBytes ocr3types.Outcome) ([]ocr3types.ReportWithInfo[[]byte], error) { | ||
outcome, err := DecodeCommitPluginOutcome(outcomeBytes) | ||
if err != nil { | ||
// TODO: metrics | ||
p.log.Errorw("failed to decode CommitPluginOutcome", "outcomeBytes", outcomeBytes, "err", err) | ||
return nil, fmt.Errorf("failed to decode CommitPluginOutcome: %w", err) | ||
} | ||
|
||
report := CommitPluginReport{ | ||
SignedRoots: outcome.SignedRootsToReport, | ||
GasPrices: outcome.GasPrices, | ||
TokenPrices: outcome.TokenPrices, | ||
} | ||
|
||
// TODO: log, metrics | ||
|
||
encodedReport, err := report.Encode() | ||
if err != nil { | ||
return nil, fmt.Errorf("encode commit plugin report: %w", err) | ||
} | ||
|
||
return []ocr3types.ReportWithInfo[[]byte]{{Report: encodedReport, Info: nil}}, nil | ||
} | ||
|
||
func (p *Plugin) ShouldAcceptAttestedReport( | ||
_ context.Context, _ uint64, r ocr3types.ReportWithInfo[[]byte], | ||
) (bool, error) { | ||
decodedReport, err := DecodeCommitPluginReport(r.Report) | ||
if err != nil { | ||
// TODO: metrics | ||
p.log.Errorw("failed to decode CommitPluginOutcome", "outcomeBytes", r.Report, "err", err) | ||
return false, err | ||
} | ||
|
||
if decodedReport.IsEmpty() { | ||
// TODO: metrics | ||
p.log.Warnf("found an empty report") | ||
return false, nil | ||
} | ||
|
||
return true, nil | ||
} | ||
|
||
func (p *Plugin) ShouldTransmitAcceptedReport( | ||
_ context.Context, _ uint64, r ocr3types.ReportWithInfo[[]byte], | ||
) (bool, error) { | ||
destChainSupported, err := p.supportsDestChain(p.nodeID) | ||
if err != nil { | ||
return false, fmt.Errorf("call to supportsDestChain failed: %w", err) | ||
} | ||
if !destChainSupported { | ||
p.log.Debugw("oracle does not support dest chain, skipping report transmission") | ||
return false, nil | ||
} | ||
|
||
decodedReport, err := DecodeCommitPluginReport(r.Report) | ||
if err != nil { | ||
return false, fmt.Errorf("decode commit plugin report: %w", err) | ||
} | ||
|
||
// TODO: metrics | ||
p.log.Debugw("transmitting report", | ||
"signedRoots", len(decodedReport.SignedRoots), | ||
"tokenPrices", len(decodedReport.TokenPrices), | ||
"gasPriceUpdates", len(decodedReport.GasPrices), | ||
) | ||
return true, nil | ||
} | ||
|
||
func (p *Plugin) Close() error { | ||
return nil | ||
} |
Oops, something went wrong.