From 091d80e4c6ec3cb92e301b6bff45d71ddfa7bc5c Mon Sep 17 00:00:00 2001 From: anjor Date: Mon, 9 Dec 2024 13:48:47 +0000 Subject: [PATCH] add filters --- grpc-server.go | 82 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 20 deletions(-) diff --git a/grpc-server.go b/grpc-server.go index 0a3c0e2c..b55f114c 100644 --- a/grpc-server.go +++ b/grpc-server.go @@ -733,8 +733,45 @@ func (multi *MultiEpoch) processSlotTransactions( gsfaReader *gsfa.GsfaReaderMultiepoch, ) error { - filterFunc := func(txn *ipldbindcode.Transaction) bool { - // fill this out + filterOutTxn := func(tx solana.Transaction, meta any) bool { + if filter == nil { + return true + } + + // add Vote + + if !(*filter.Failed) { // If failed is false, we should filter out failed transactions + err := getErr(meta) + if err != nil { + return false + } + } + + // AccountInclude is handled in the main function + + for _, acc := range filter.AccountExclude { + pkey := solana.MustPublicKeyFromBase58(acc) + ok, err := tx.HasAccount(pkey) + if err != nil { + klog.Errorf("Failed to check if transaction %v has account %s", tx, acc) + return false + } + if ok { // If any excluded account is present, filter out the transaction + return false + } + } + + for _, acc := range filter.AccountRequired { + pkey := solana.MustPublicKeyFromBase58(acc) + ok, err := tx.HasAccount(pkey) + if err != nil { + klog.Errorf("Failed to check if transaction %v has account %s", tx, acc) + return false + } + if !ok { // If any required account is missing, filter out the transaction + return false + } + } return true } @@ -771,7 +808,6 @@ func (multi *MultiEpoch) processSlotTransactions( return decoded, nil }, ) - if err != nil { return err } @@ -782,26 +818,32 @@ func (multi *MultiEpoch) processSlotTransactions( return status.Errorf(codes.NotFound, "Epoch %d is not available", epochNumber) } for _, txn := range txns { - txResp := new(old_faithful_grpc.TransactionResponse) - txResp.Transaction = new(old_faithful_grpc.Transaction) - { - pos, ok := txn.GetPositionIndex() - if ok { - txResp.Index = ptrToUint64(uint64(pos)) - txResp.Transaction.Index = ptrToUint64(uint64(pos)) - } - txResp.Transaction.Transaction, txResp.Transaction.Meta, err = getTransactionAndMetaFromNode(txn, epochHandler.GetDataFrameByCid) - if err != nil { - return status.Errorf(codes.Internal, "Failed to get transaction: %v", err) - } - txResp.Slot = uint64(txn.Slot) - // What to do for blocktime? + tx, meta, err := parseTransactionAndMetaFromNode(txn, epochHandler.GetDataFrameByCid) + if err != nil { + return status.Errorf(codes.Internal, "Failed to parse transaction from node: %v", err) } - // not sure how to apply more filters + if !filterOutTxn(tx, meta) { + + txResp := new(old_faithful_grpc.TransactionResponse) + txResp.Transaction = new(old_faithful_grpc.Transaction) + { + pos, ok := txn.GetPositionIndex() + if ok { + txResp.Index = ptrToUint64(uint64(pos)) + txResp.Transaction.Index = ptrToUint64(uint64(pos)) + } + txResp.Transaction.Transaction, txResp.Transaction.Meta, err = getTransactionAndMetaFromNode(txn, epochHandler.GetDataFrameByCid) + if err != nil { + return status.Errorf(codes.Internal, "Failed to get transaction: %v", err) + } + txResp.Slot = uint64(txn.Slot) + // What to do for blocktime? + } - if err := ser.Send(txResp); err != nil { - return err + if err := ser.Send(txResp); err != nil { + return err + } } } }