Skip to content

Commit

Permalink
Revert "Indexer: use logs of Tx to extract events and results (#776)" (
Browse files Browse the repository at this point in the history
…#836)

This reverts commit a2377c2.
  • Loading branch information
rozhkovdmitrii authored Jul 20, 2022
1 parent a2377c2 commit 36a7c15
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 355 deletions.
2 changes: 1 addition & 1 deletion .buildkite/steps/revision.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set ${NEON_EVM_COMMIT:=ed2de51b11cc676c9305eb660d66b2bd05796153}
set ${NEON_EVM_COMMIT:=latest}
set ${FAUCET_COMMIT:=latest}
export REVISION=${BUILDKITE_COMMIT}
export NEON_EVM_COMMIT
Expand Down
23 changes: 0 additions & 23 deletions proxy/common_neon/data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from dataclasses import dataclass, field
from typing import List, Optional


class NeonTxStatData:
Expand All @@ -12,24 +10,3 @@ def __init__(self, neon_tx_hash: str, neon_income: int, tx_type: str, is_cancele

def add_instruction(self, sol_tx_hash: str, sol_spent: int, steps: int, bpf: int) -> None:
self.instructions.append((sol_tx_hash, sol_spent, steps, bpf))


@dataclass
class NeonTxReturn:
exit_status: int = 0
gas_used: int = 0
return_value: Optional[bytes] = None


@dataclass
class NeonEvent:
address: Optional[bytes] = None
count_topics: int = 0
topics: Optional[List[bytes]] = None
log_data: Optional[bytes] = None


@dataclass
class NeonLogIx:
neon_return: Optional[NeonTxReturn] = None
neon_events: List[NeonEvent] = field(default_factory=list)
2 changes: 1 addition & 1 deletion proxy/common_neon/environment_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
SKIP_PREFLIGHT = os.environ.get("SKIP_PREFLIGHT", "NO") == "YES"
CONTRACT_EXTRA_SPACE = int(os.environ.get("CONTRACT_EXTRA_SPACE", 2048))
EVM_STEP_COUNT = int(os.environ.get("EVM_STEP_COUNT", 750)) # number of evm-steps, performed by one iteration
MAX_EVM_STEPS_TO_EXECUTE = int(os.environ.get("MAX_EVM_STEPS_TO_EXECUTE", 300000))
MAX_EVM_STEPS_TO_EXECUTE = int(os.environ.get("MAX_EVM_STEPS_TO_EXECUTE", 100000))
ENABLE_PRIVATE_API = os.environ.get("ENABLE_PRIVATE_API", "NO") == "YES"
GATHER_STATISTICS = os.environ.get("GATHER_STATISTICS", "NO") == "YES"
ALLOW_UNDERPRICED_TX_WITHOUT_CHAINID = os.environ.get("ALLOW_UNDERPRICED_TX_WITHOUT_CHAINID", "NO") == "YES"
Expand Down
124 changes: 0 additions & 124 deletions proxy/common_neon/evm_decoder.py

This file was deleted.

63 changes: 57 additions & 6 deletions proxy/common_neon/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from __future__ import annotations

from typing import Dict, Any, Optional, List

import json
from enum import Enum
import base58

from logged_groups import logged_group
from enum import Enum
from eth_utils import big_endian_to_int

from proxy.indexer.utils import SolanaIxSignInfo
# TODO: move it out from here

#TODO: move it out from here
from ..environment_data import EVM_LOADER_ID, LOG_FULL_OBJECT_INFO

from ..eth_proto import Trx as EthTx


Expand Down Expand Up @@ -80,7 +82,6 @@ def is_empty(self) -> bool:
return self.time is None


@logged_group("neon.Parser")
class NeonTxResultInfo:
def __init__(self):
self._set_defaults()
Expand All @@ -104,12 +105,44 @@ def _set_defaults(self):
self.block_hash = ''
self.idx = -1

def _decode_event(self, neon_sign, log, tx_idx):
log_idx = len(self.logs)
address = log[1:21]
count_topics = int().from_bytes(log[21:29], 'little')
topics = []
pos = 29
for _ in range(count_topics):
topic_bin = log[pos:pos + 32]
topics.append('0x' + topic_bin.hex())
pos += 32
data = log[pos:]
rec = {
'address': '0x' + address.hex(),
'topics': topics,
'data': '0x' + data.hex(),
'transactionLogIndex': hex(log_idx),
'transactionIndex': hex(tx_idx),
'logIndex': hex(log_idx),
'transactionHash': neon_sign,
# 'blockNumber': block_number, # set when transaction found
# 'blockHash': block_hash # set when transaction found
}
self.logs.append(rec)

def append_record(self, rec):
log_idx = len(self.logs)
rec['transactionLogIndex'] = hex(log_idx)
rec['logIndex'] = hex(log_idx)
self.logs.append(rec)

def _decode_return(self, log: bytes, ix_idx: int, tx: {}):
self.status = '0x1' if log[1] < 0xd0 else '0x0'
self.gas_used = hex(int.from_bytes(log[2:10], 'little'))
self.return_value = log[10:].hex()
self.sol_sign = tx['transaction']['signatures'][0]
self.slot = tx['slot']
self.idx = ix_idx

def set_result(self, sign: SolanaIxSignInfo, status, gas_used, return_value):
self.status = status
self.gas_used = gas_used
Expand All @@ -125,7 +158,25 @@ def fill_block_info(self, block: SolanaBlockInfo):
rec['blockHash'] = block.hash
rec['blockNumber'] = hex(block.slot)

def canceled(self, tx: Dict[Any, Any]):
def decode(self, neon_sign: str, tx: {}, ix_idx=-1) -> NeonTxResultInfo:
self._set_defaults()
meta_ixs = tx['meta']['innerInstructions']
msg = tx['transaction']['message']
accounts = msg['accountKeys']

for inner_ix in meta_ixs:
ix_idx = inner_ix['index']
for event in inner_ix['instructions']:
if accounts[event['programIdIndex']] == EVM_LOADER_ID:
log = base58.b58decode(event['data'])
evm_ix = int(log[0])
if evm_ix == 7:
self._decode_event(neon_sign, log, ix_idx)
elif evm_ix == 6:
self._decode_return(log, ix_idx, tx)
return self

def canceled(self, tx: {}):
self._set_defaults()
self.sol_sign = tx['transaction']['signatures'][0]
self.slot = tx['slot']
Expand Down
Loading

0 comments on commit 36a7c15

Please sign in to comment.