Push down flashbots checking logic

This commit is contained in:
Willian Mitsuda 2022-08-23 16:11:02 -03:00
parent c365bde784
commit 21a549b3e1
No known key found for this signature in database
5 changed files with 35 additions and 64 deletions

View File

@ -11,6 +11,7 @@ export enum Direction {
} }
export enum Flags { export enum Flags {
// Means the transaction internal sends ETH to the miner, e.g. flashbots
MINER, MINER,
} }

View File

@ -16,7 +16,7 @@ import TransactionItemFiatFee from "./TransactionItemFiatFee";
import { ProcessedTransaction } from "../types"; import { ProcessedTransaction } from "../types";
import { FeeDisplay } from "./useFeeToggler"; import { FeeDisplay } from "./useFeeToggler";
import { RuntimeContext } from "../useRuntime"; import { RuntimeContext } from "../useRuntime";
import { useHasCode } from "../useErigonHooks"; import { useHasCode, useSendsToMiner } from "../useErigonHooks";
import { formatValue } from "../components/formatter"; import { formatValue } from "../components/formatter";
type TransactionItemProps = { type TransactionItemProps = {
@ -36,6 +36,7 @@ const TransactionItem: React.FC<TransactionItemProps> = ({
tx.to ?? undefined, tx.to ?? undefined,
tx.blockNumber - 1 tx.blockNumber - 1
); );
const [sendsToMiner] = useSendsToMiner(provider, tx.hash, tx.miner);
let direction: Direction | undefined; let direction: Direction | undefined;
if (selectedAddress) { if (selectedAddress) {
@ -53,7 +54,7 @@ const TransactionItem: React.FC<TransactionItemProps> = ({
} }
} }
const flash = tx.gasPrice.isZero() && tx.internalMinerInteraction; const flash = tx.gasPrice.isZero() && sendsToMiner;
return ( return (
<div <div
@ -91,7 +92,7 @@ const TransactionItem: React.FC<TransactionItemProps> = ({
<span> <span>
<TransactionDirection <TransactionDirection
direction={direction} direction={direction}
flags={tx.internalMinerInteraction ? Flags.MINER : undefined} flags={sendsToMiner ? Flags.MINER : undefined}
/> />
</span> </span>
</span> </span>

View File

@ -1,4 +1,4 @@
import React, { useContext, useMemo, useState } from "react"; import React, { useContext, useState } from "react";
import { Tab } from "@headlessui/react"; import { Tab } from "@headlessui/react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCheckCircle } from "@fortawesome/free-solid-svg-icons/faCheckCircle"; import { faCheckCircle } from "@fortawesome/free-solid-svg-icons/faCheckCircle";
@ -43,7 +43,7 @@ import {
useTransactionDescription as useSourcifyTransactionDescription, useTransactionDescription as useSourcifyTransactionDescription,
} from "../sourcify/useSourcify"; } from "../sourcify/useSourcify";
import { RuntimeContext } from "../useRuntime"; import { RuntimeContext } from "../useRuntime";
import { useInternalOperations, useTransactionError } from "../useErigonHooks"; import { useSendsToMiner, useTransactionError } from "../useErigonHooks";
import { useChainInfo } from "../useChainInfo"; import { useChainInfo } from "../useChainInfo";
import { useETHUSDOracle } from "../usePriceOracle"; import { useETHUSDOracle } from "../usePriceOracle";
@ -67,19 +67,11 @@ const Details: React.FC<DetailsProps> = ({ txData }) => {
txData.value txData.value
); );
const internalOps = useInternalOperations(provider, txData); const [sendsEthToMiner, internalOps] = useSendsToMiner(
const sendsEthToMiner = useMemo(() => { provider,
if (!txData || !internalOps) { txData.confirmedData ? txData.transactionHash : undefined,
return false; txData.confirmedData?.miner
} );
for (const t of internalOps) {
if (t.to === txData.confirmedData?.miner) {
return true;
}
}
return false;
}, [txData, internalOps]);
const metadata = useSourcifyMetadata(txData?.to, provider?.network.chainId); const metadata = useSourcifyMetadata(txData?.to, provider?.network.chainId);

View File

@ -18,7 +18,6 @@ export type ProcessedTransaction = {
from?: string; from?: string;
to: string | null; to: string | null;
createdContractAddress?: string; createdContractAddress?: string;
internalMinerInteraction?: boolean;
value: BigNumber; value: BigNumber;
fee: BigNumber; fee: BigNumber;
gasPrice: BigNumber; gasPrice: BigNumber;

View File

@ -140,27 +140,6 @@ export const useBlockTransactions = (
.reverse(); .reverse();
setTxs(rawTxs); setTxs(rawTxs);
setTotalTxs(result.fullblock.transactionCount); setTotalTxs(result.fullblock.transactionCount);
const checkTouchMinerAddr = await Promise.all(
rawTxs.map(async (res) => {
const ops = await getInternalOperations(provider, res.hash);
return (
ops.findIndex(
(op) =>
op.type === OperationType.TRANSFER &&
res.miner !== undefined &&
res.miner === getAddress(op.to)
) !== -1
);
})
);
const processedTxs = rawTxs.map(
(r, i): ProcessedTransaction => ({
...r,
internalMinerInteraction: checkTouchMinerAddr[i],
})
);
setTxs(processedTxs);
}; };
readBlock(); readBlock();
}, [provider, blockNumber, pageNumber, pageSize]); }, [provider, blockNumber, pageNumber, pageSize]);
@ -308,34 +287,13 @@ export const useTxData = (
return txData; return txData;
}; };
// TODO: convert caller to hooks and remove this function
const getInternalOperations = async (
provider: JsonRpcProvider,
txHash: string
) => {
const rawTransfers = await provider.send("ots_getInternalOperations", [
txHash,
]);
const _transfers: InternalOperation[] = [];
for (const t of rawTransfers) {
_transfers.push({
type: t.type,
from: getAddress(t.from),
to: getAddress(t.to),
value: t.value,
});
}
return _transfers;
};
export const useInternalOperations = ( export const useInternalOperations = (
provider: JsonRpcProvider | undefined, provider: JsonRpcProvider | undefined,
txData: TransactionData | undefined | null txHash: string | undefined
): InternalOperation[] | undefined => { ): InternalOperation[] | undefined => {
const { data, error } = useSWRImmutable( const { data, error } = useSWRImmutable(
provider !== undefined && txData?.confirmedData provider !== undefined && txHash !== undefined
? ["ots_getInternalOperations", txData.transactionHash] ? ["ots_getInternalOperations", txHash]
: null, : null,
providerFetcher(provider) providerFetcher(provider)
); );
@ -359,6 +317,26 @@ export const useInternalOperations = (
return _transfers; return _transfers;
}; };
export const useSendsToMiner = (
provider: JsonRpcProvider | undefined,
txHash: string | undefined,
miner: string | undefined
): [boolean, InternalOperation[]] | [undefined, undefined] => {
const ops = useInternalOperations(provider, txHash);
if (ops === undefined) {
return [undefined, undefined];
}
const send =
ops.findIndex(
(op) =>
op.type === OperationType.TRANSFER &&
miner !== undefined &&
miner === getAddress(op.to)
) !== -1;
return [send, ops];
};
export type TraceEntry = { export type TraceEntry = {
type: string; type: string;
depth: number; depth: number;