-
Notifications
You must be signed in to change notification settings - Fork 15
Moved Generalized WT out, created chain-specific injected processors #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
0f516d6
Added injected df decoder
silaslenihan deda7c5
extracted metadata to common
silaslenihan 34ec523
moved Metadata to this repo
silaslenihan 5af65e1
Refactored for processor injection and restructured code
silaslenihan 5aca00f
added emitterAwareProcessor
silaslenihan f66fc9c
moved dfprocessor to chainlink-evm
silaslenihan 003bec7
address feedback
silaslenihan 7ac775b
updated data feeds ns
silaslenihan 13c83b4
Restructured code
silaslenihan 4531fbe
Added product specific processor, passing target config values to Wri…
silaslenihan 7d23f69
Refactored to use common Metadata type
silaslenihan 6c82a7c
Updated WriteConfirmed to extract only processor from report
silaslenihan 021079f
Moved all chain-agnostic WT code to chainlink-framework
silaslenihan aea94cd
bumped go.mod
silaslenihan 0a50d80
Enabled CCIP in DF processor
silaslenihan f23deca
bumped go.mod
silaslenihan 64efeba
bumped go.mod
silaslenihan 896cbc3
bumped go.mod
silaslenihan b7fec1d
Added POR report processor
silaslenihan 110c0cb
fixed lint
silaslenihan 0d42405
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan c2f891d
bumped go.mod
silaslenihan 600c679
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan ffeb92e
Removed processor Name()
silaslenihan 4c7249c
Added config for write target polling
silaslenihan 3dd961e
fixed config tests
silaslenihan d4d11a4
bumped go.mod
silaslenihan a91625a
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan 8be5634
fixed test
silaslenihan af9ef3b
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan 19809e2
changed default TxAcceptanceState to 2
silaslenihan a8dd460
shifted bundle to slot 9 in proto
silaslenihan c099eb3
bump go.mod
silaslenihan 02928f9
fixed config test
silaslenihan 494a451
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan 8b3653c
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan 744075c
Refactored processor logic to be cleaner and injectible
silaslenihan e96ee74
Fixed lint
silaslenihan d64b26d
Fixed config
silaslenihan 66f2310
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan 0199af8
Revert "pkg/chains/legacyevm: reduce LegacyChains to ChainService (#92)"
silaslenihan 000554f
Revert "pkg/chains/legacyevm: reduce LegacyChains to ChainService (#92)"
silaslenihan f0685c0
Merge branch 'fix/inject-df-decoder' of github.com:smartcontractkit/c…
silaslenihan 6506229
Reapply "pkg/chains/legacyevm: reduce LegacyChains to ChainService (#…
silaslenihan fd1b021
bumped go mod
silaslenihan 4590ac0
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan 5033db9
moved datafeeds protos to chainlink-framework
silaslenihan a702de8
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan 18c1ea9
bumped go.mod
silaslenihan 9cd2ef6
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan 95cf323
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan 6f7a456
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,159 @@ | ||
| package datafeeds | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "math" | ||
| "math/big" | ||
|
|
||
| "github.com/ethereum/go-ethereum/accounts/abi" | ||
| "google.golang.org/protobuf/proto" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-common/pkg/beholder" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-framework/capabilities/writetarget/monitoring/pb/common" | ||
| df "github.com/smartcontractkit/chainlink-framework/capabilities/writetarget/monitoring/pb/data-feeds/on-chain/registry" | ||
| wt "github.com/smartcontractkit/chainlink-framework/capabilities/writetarget/monitoring/pb/platform" | ||
| "github.com/smartcontractkit/chainlink-framework/capabilities/writetarget/report/platform" | ||
| ) | ||
|
|
||
| // EVM POR specific processor decodes writes as 'data-feeds.registry.FeedUpdated' messages + metrics | ||
| type Processor struct { | ||
silaslenihan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| emitter beholder.ProtoEmitter | ||
| metrics *df.Metrics | ||
| schema abi.Arguments | ||
| decodeReport func(*wt.WriteConfirmed, []byte, abi.Arguments) ([]*df.FeedUpdated, error) | ||
| } | ||
|
|
||
| func NewProcessor(metrics *df.Metrics, emitter beholder.ProtoEmitter, schema abi.Arguments, decodeReport func(*wt.WriteConfirmed, []byte, abi.Arguments) ([]*df.FeedUpdated, error)) *Processor { | ||
| return &Processor{ | ||
| metrics: metrics, | ||
| emitter: emitter, | ||
| schema: schema, | ||
| decodeReport: decodeReport, | ||
| } | ||
| } | ||
|
|
||
| func (p *Processor) Process(ctx context.Context, m proto.Message, attrKVs ...any) error { | ||
| // Switch on the type of the proto.Message | ||
| switch msg := m.(type) { | ||
| case *wt.WriteConfirmed: | ||
| updates, err := p.DecodeAsFeedUpdated(msg) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to decode as 'data-feeds.registry.df.FeedUpdated': %w", err) | ||
| } | ||
| for _, update := range updates { | ||
| err = p.emitter.EmitWithLog(ctx, update, attrKVs...) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to emit with log: %w", err) | ||
| } | ||
| // Process emit and derive metrics | ||
| err = p.metrics.OnFeedUpdated(ctx, update, attrKVs...) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to publish feed updated metrics: %w", err) | ||
| } | ||
| } | ||
| return nil | ||
| default: | ||
| return nil // fallthrough | ||
| } | ||
| } | ||
|
|
||
| func GetSchema(typ string, internalType string, components []abi.ArgumentMarshaling) abi.Arguments { | ||
| result, err := abi.NewType(typ, internalType, components) | ||
| if err != nil { | ||
| panic(fmt.Sprintf("Unexpected error during abi.NewType: %s", err)) | ||
| } | ||
| return abi.Arguments([]abi.Argument{ | ||
| { | ||
| // This defines the array of tuple records. | ||
| Type: result, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func (p *Processor) DecodeAsFeedUpdated(m *wt.WriteConfirmed) ([]*df.FeedUpdated, error) { | ||
| // Decode the confirmed report (WT -> DF contract event) | ||
| r, err := platform.Decode(m.Report) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to decode report: %w", err) | ||
| } | ||
|
|
||
| msgs, err := p.decodeReport(m, r.Data, p.schema) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to decode Data Feeds report: %w", err) | ||
| } | ||
|
|
||
| return msgs, nil | ||
| } | ||
|
|
||
| // newdf.FeedUpdated creates a df.FeedUpdated from the given common parameters. | ||
| // If includeTxInfo is true, TxSender and TxReceiver are set. | ||
| func NewFeedUpdated( | ||
| m *wt.WriteConfirmed, | ||
| feedID FeedID, | ||
| observationsTimestamp uint32, | ||
| benchmarkPrice *big.Int, | ||
| bundle []byte, | ||
| report []byte, | ||
| includeTxInfo bool, | ||
| ) *df.FeedUpdated { | ||
| fu := &df.FeedUpdated{ | ||
| FeedId: feedID.String(), | ||
| ObservationsTimestamp: observationsTimestamp, | ||
| Benchmark: benchmarkPrice.Bytes(), | ||
| Bundle: bundle, | ||
| Report: report, | ||
| BenchmarkVal: ToBenchmarkVal(feedID, benchmarkPrice), | ||
|
|
||
| // Head data - when was the event produced on-chain | ||
| BlockData: m.BlockData, | ||
|
|
||
| ExecutionContext: m.ExecutionContext, | ||
| } | ||
|
|
||
| if includeTxInfo { | ||
| fu.TransactionData = &common.TransactionData{ | ||
| TxSender: m.Transmitter, | ||
| TxReceiver: m.Forwarder, | ||
| } | ||
| } | ||
|
|
||
| return fu | ||
| } | ||
|
|
||
| // ToBenchmarkVal returns the benchmark i192 on-chain value decoded as an double (float64), scaled by number of decimals (e.g., 1e-18) | ||
| // Where the number of decimals is extracted from the feed ID. | ||
| // | ||
| // This is the largest type Prometheus supports, and this conversion can overflow but so far was sufficient | ||
| // for most use-cases. For big numbers, benchmark bytes should be used instead. | ||
| // | ||
| // Returns `math.NaN()` if report data type not a number, or `+/-Inf` if number doesn't fit in double. | ||
| func ToBenchmarkVal(feedID FeedID, val *big.Int) float64 { | ||
| // Return NaN if the value is nil | ||
| if val == nil { | ||
| return math.NaN() | ||
| } | ||
|
|
||
| // Get the number of decimals from the feed ID | ||
| t := feedID.GetDataType() | ||
| decimals, isNumber := GetDecimals(t) | ||
|
|
||
| // Return NaN if the value is not a number | ||
| if !isNumber { | ||
| return math.NaN() | ||
| } | ||
|
|
||
| // Convert the i192 to a big Float, scaled by the number of decimals | ||
| valF := new(big.Float).SetInt(val) | ||
|
|
||
| if decimals > 0 { | ||
| denominator := big.NewFloat(math.Pow10(int(decimals))) | ||
| valF = new(big.Float).Quo(valF, denominator) | ||
| } | ||
|
|
||
| // Notice: this can overflow, but so far was sufficient for most use-cases | ||
| // On overflow, returns +/-Inf (valid Prometheus value) | ||
| valRes, _ := valF.Float64() | ||
| return valRes | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.