Skip to content

Commit

Permalink
sort data into bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
aalu1418 committed Apr 15, 2024
1 parent 9ee28ec commit 8a7274f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
28 changes: 27 additions & 1 deletion pkg/monitoring/source_txdetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,22 @@ func (f *txDetailsSourceFactory) NewSource(cfg commonMonitoring.Params) (commonM
return nil, fmt.Errorf("expected feedConfig to be of type config.SolanaFeedConfig not %T", cfg.FeedConfig)
}

// TODO: build map for looking up nodes
// build map for looking up node pubkey -> operator name
nodes := map[solana.PublicKey]string{}
solanaNodeConfigs, err := config.MakeSolanaNodeConfigs(cfg.Nodes)
if err != nil {
return nil, fmt.Errorf("MakeSolanaNodeConfigs: %w", err)
}
for _, c := range solanaNodeConfigs {
key, err := c.PublicKey()
if err != nil {
return nil, fmt.Errorf("Could not parse public key (%s: %s): %w", c.GetName(), c.GetAccount(), err)
}
nodes[key] = c.GetName()
}

return &txDetailsSource{
nodes: nodes,
source: &txResultsSource{
client: f.client,
log: f.log,
Expand Down Expand Up @@ -82,6 +95,19 @@ func (s *txDetailsSource) Fetch(ctx context.Context) (interface{}, error) {

// append to TxDetails
details.Count += 1

// signatures are ordered with the latest first
if res.Err == nil && details.ObsLatest == 0 {
details.ObsLatest = res.ObservationCount // only supports single feed result
}

if res.Err != nil {
details.ObsFailed = append(details.ObsFailed, res.ObservationCount)
} else {
details.ObsSuccess = append(details.ObsSuccess, res.ObservationCount)
}
details.ObsAll = append(details.ObsAll, res.ObservationCount)

}

return details, nil
Expand Down
26 changes: 10 additions & 16 deletions pkg/monitoring/types/txdetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
solanaGo "github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/rpc"

commonMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring"
"github.com/smartcontractkit/libocr/offchainreporting2/types"

"github.com/smartcontractkit/chainlink-solana/pkg/solana"
Expand All @@ -22,35 +21,30 @@ var (
type TxDetails struct {
Count int // total signatures processed

// PerOperator categorizes TxResults based on sender/operator
PerOperator map[string]commonMonitoring.TxResults
// TODO: PerOperator categorizes TxResults based on sender/operator
// PerOperator map[string]commonMonitoring.TxResults

// observation counts within each report
latestSet bool
ObsLatest uint8 // number of observations in latest included report/tx
ObsAll []int // observations across all seen txs/reports from operators
ObsSuccess []int // observations included in successful reports
ObsFailed []int // observations included in failed reports
ObsLatest uint8 // number of observations in latest included report/tx
ObsAll []uint8 // observations across all seen txs/reports from operators
ObsSuccess []uint8 // observations included in successful reports
ObsFailed []uint8 // observations included in failed reports

// TODO: implement - parse fee using shared logic from fee/computebudget.go
// FeeAvg
// FeeSuccessAvg
// FeeFailedAvg
}

func (d TxDetails) SetLatest(obs uint8) {

}

type ParsedTx struct {
Err interface{}
Fee uint64

Sender solanaGo.PublicKey
Operator string // human readable name associated to public key

// report information - can support batched with slice
ObservationCount []uint8
// report information - only supports single report per tx
ObservationCount uint8
}

// ParseTxResult parses the GetTransaction RPC response
Expand Down Expand Up @@ -107,7 +101,7 @@ func ParseTx(tx *solanaGo.Transaction, nodes map[solanaGo.PublicKey]string, prog
return ParsedTx{}, fmt.Errorf("unknown public key: %s", sender)
}

obsCount := []uint8{}
var obsCount uint8
var totalErr error
for _, instruction := range tx.Message.Instructions {
// protect against invalid index
Expand All @@ -126,7 +120,7 @@ func ParseTx(tx *solanaGo.Transaction, nodes map[solanaGo.PublicKey]string, prog
totalErr = errors.Join(totalErr, fmt.Errorf("%w (%+v)", err, instruction))
continue
}
obsCount = append(obsCount, count)
obsCount = count
}

// find compute budget program instruction
Expand Down

0 comments on commit 8a7274f

Please sign in to comment.