-
Notifications
You must be signed in to change notification settings - Fork 43
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
3 changed files
with
151 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package monitoring | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/gagliardetto/solana-go/rpc" | ||
commonMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring" | ||
|
||
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/config" | ||
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/types" | ||
) | ||
|
||
func NewTxDetailsSourceFactory(client ChainReader, log commonMonitoring.Logger) commonMonitoring.SourceFactory { | ||
return &txDetailsSourceFactory{client, log} | ||
} | ||
|
||
type txDetailsSourceFactory struct { | ||
client ChainReader | ||
log commonMonitoring.Logger | ||
} | ||
|
||
func (f *txDetailsSourceFactory) NewSource(cfg commonMonitoring.Params) (commonMonitoring.Source, error) { | ||
solanaFeedConfig, ok := cfg.FeedConfig.(config.SolanaFeedConfig) | ||
if !ok { | ||
return nil, fmt.Errorf("expected feedConfig to be of type config.SolanaFeedConfig not %T", cfg.FeedConfig) | ||
} | ||
|
||
return &txDetailsSource{ | ||
client: f.client, | ||
sigSource: &txResultsSource{ | ||
client: f.client, | ||
log: f.log, | ||
feedConfig: solanaFeedConfig, | ||
}, | ||
}, nil | ||
} | ||
|
||
func (f *txDetailsSourceFactory) GetType() string { | ||
return types.TxDetailsType | ||
} | ||
|
||
type txDetailsSource struct { | ||
client ChainReader | ||
sigSource *txResultsSource // reuse underlying logic for getting signatures | ||
} | ||
|
||
func (s *txDetailsSource) Fetch(ctx context.Context) (interface{}, error) { | ||
_, sigs, err := s.sigSource.fetch(ctx) | ||
if err != nil { | ||
return types.TxDetails{}, err | ||
} | ||
if len(sigs) == 0 { | ||
return types.TxDetails{}, nil | ||
} | ||
|
||
for _, sig := range sigs { | ||
if sig == nil { | ||
continue // skip for nil signatures | ||
} | ||
|
||
// TODO: async? | ||
tx, err := s.client.GetTransaction(ctx, sig.Signature, &rpc.GetTransactionOpts{}) | ||
if err != nil { | ||
return types.TxDetails{}, err | ||
} | ||
if tx == nil { | ||
return types.TxDetails{}, fmt.Errorf("GetTransaction returned nil") | ||
} | ||
|
||
// TODO: parse transaction | ||
|
||
// TODO: filter signatures/transactions based on known operator/sender | ||
|
||
// TODO: parse observations from remaining transactions | ||
|
||
// TODO: add to proper list for averaging | ||
} | ||
|
||
return types.TxDetails{}, nil | ||
} |
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,60 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gagliardetto/solana-go" | ||
"github.com/gagliardetto/solana-go/rpc" | ||
) | ||
|
||
var ( | ||
TxDetailsType = "txdetails" | ||
) | ||
|
||
// TxDetails expands on TxResults and contains additional detail on a set of tx signatures specific to solana | ||
type TxDetails struct { | ||
count int // total signatures processed | ||
|
||
// TODO: PerOperator categorizes TxResults based on sender/operator | ||
// PerOperator map[string]commonMonitoring.TxResults | ||
|
||
// observation counts within each report | ||
obsLatest int // number of observations in latest included report/tx | ||
obsAvg int // average number of observations across all seen txs/reports from operators | ||
obsSuccessAvg int // average number of observations included in successful reports | ||
obsFailedAvg int // average number of observations included in failed reports | ||
|
||
// TODO: implement - parse fee using shared logic from fee/computebudget.go | ||
// feeAvg | ||
// feeSuccessAvg | ||
// feeFailedAvg | ||
} | ||
|
||
type ParsedTx struct { | ||
Err interface{} | ||
Fee uint64 | ||
|
||
Sender solana.PublicKey | ||
|
||
// report information | ||
ObservationCount int | ||
} | ||
|
||
func ParseTx(txResult *rpc.GetTransactionResult) (ParsedTx, error) { | ||
out := ParsedTx{} | ||
if txResult == nil { | ||
return out, fmt.Errorf("txResult is nil") | ||
} | ||
if txResult.Meta == nil { | ||
return out, fmt.Errorf("txResult.Meta is nil") | ||
} | ||
|
||
out.Err = txResult.Meta.Err | ||
out.Fee = txResult.Meta.Fee | ||
|
||
// determine sender | ||
|
||
// find OCR2 transmit instruction | ||
|
||
return out, nil | ||
} |