Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhen1997 committed Jan 6, 2025
1 parent 56d85d5 commit 75ae059
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 1 deletion.
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/chaos-mesh/chaos-mesh/api v0.0.0-20240821051457-da69c6d9617a
github.com/cli/go-gh/v2 v2.0.0
github.com/deckarep/golang-set/v2 v2.6.0
github.com/ethereum/go-ethereum v1.14.12
github.com/ethereum/go-ethereum v1.14.11
github.com/fxamacker/cbor/v2 v2.7.0
github.com/go-resty/resty/v2 v2.15.3
github.com/google/go-cmp v0.6.0
Expand Down
112 changes: 112 additions & 0 deletions test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package main

import (
"context"
"fmt"
"log"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rpc"
)

// Tx represents a transaction structure
type Tx struct {
TxAttempts []TxAttempt
}

// TxAttempt represents a transaction attempt structure
type TxAttempt struct {
Hash common.Hash
}

// zircuitResponse represents the response structure from zirc_isQuarantined
type zircuitResponse struct {

Check failure on line 23 in test.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (.)

type `zircuitResponse` is unused (unused)
IsQuarantined bool `json:"isQuarantined"`
}

// stuckTxDetector represents the structure for stuck transaction detection
type stuckTxDetector struct {

Check failure on line 28 in test.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (.)

type `stuckTxDetector` is unused (unused)
chainClient *rpc.Client
lggr Logger
}

// Logger interface for logging (simplified here for demonstration)
type Logger struct{}

func (l Logger) Debugf(format string, args ...interface{}) {
log.Printf(format, args...)
}

// detectFraudTransactionsZircuit detects quarantined transactions
func (d *stuckTxDetector) detectFraudTransactionsZircuit(ctx context.Context, txs []Tx) ([]Tx, error) {

Check failure on line 41 in test.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (.)

func `(*stuckTxDetector).detectFraudTransactionsZircuit` is unused (unused)
txReqs := make([]rpc.BatchElem, len(txs))
txHashMap := make(map[common.Hash]Tx)
txRes := make([]*zircuitResponse, len(txs))

// Build batch request elements
for i, tx := range txs {
latestAttemptHash := tx.TxAttempts[0].Hash
var result zircuitResponse
txReqs[i] = rpc.BatchElem{
Method: "zirc_isQuarantined",
Args: []interface{}{latestAttemptHash},
Result: &result,
}
txHashMap[latestAttemptHash] = tx
txRes[i] = &result
}

// Send batch request using the Ethereum client
err := d.chainClient.BatchCallContext(ctx, txReqs)
if err != nil {
return nil, fmt.Errorf("failed to check Quarantine transactions in batch: %w", err)
}

// Process the results and check if any transactions are quarantined
var fraudTxs []Tx
for i, req := range txReqs {
txHash := req.Args[0].(common.Hash)
if req.Error != nil {
d.lggr.Debugf("failed to check fraud transaction by hash (%s): %v", txHash.String(), req.Error)
continue
}

result := txRes[i]
if result != nil && result.IsQuarantined {
tx := txHashMap[txHash]
fraudTxs = append(fraudTxs, tx)
}
}
return fraudTxs, nil
}

//
//func main() {

Check failure on line 84 in test.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (.)

commentFormatting: put a space between `//` and comment text (gocritic)
// // Create an Ethereum RPC client to communicate with the Zircuit endpoint
// client, err := rpc.Dial("https://zircuit1-mainnet.p2pify.com")
// if err != nil {
// log.Fatalf("Failed to create Ethereum RPC client: %v", err)
// }
//
// // Create the detector with the Ethereum client
// detector := &stuckTxDetector{
// chainClient: client,
// lggr: Logger{},
// }
//
// // Example transactions (replace with real data)
// txs := []Tx{
// {TxAttempts: []TxAttempt{{Hash: common.HexToHash("0xbf7179cbeb760388d972b68dfeef0ee687dd1286d5b4cd534b6b75c42bbdf3c4")}}},
// {TxAttempts: []TxAttempt{{Hash: common.HexToHash("0x3f9d8133af4ab1ca64c4a6fa572161995eb88fd942d71a61910a04e1639ee51e")}}},
// }
//
// // Detect fraudulent transactions
// ctx := context.Background()
// fraudTxs, err := detector.detectFraudTransactionsZircuit(ctx, txs)
// if err != nil {
// log.Fatalf("Error detecting fraud transactions: %v", err)
// }
//
// // Print out the fraudulent transactions
// fmt.Printf("Fraudulent transactions: %+v\n", fraudTxs)
//}

0 comments on commit 75ae059

Please sign in to comment.