Skip to content

Commit

Permalink
tx-skd-exec: firstly try to execute
Browse files Browse the repository at this point in the history
  • Loading branch information
afalaleev committed Dec 15, 2024
1 parent 04c447d commit 88cca2e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
14 changes: 11 additions & 3 deletions proxy/executor/ex_transaction_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import asyncio
import itertools
import logging
import time
from typing import ClassVar, Final, Sequence

from common.config.constants import ONE_BLOCK_SEC
from common.config.constants import ONE_BLOCK_SEC, MIN_FINALIZE_SEC
from common.ethereum.hash import EthTxHash
from common.neon.neon_program import NeonEvmIxCode, NeonBaseTxAccountSet
from common.neon.transaction_model import NeonSkdTxModel
Expand Down Expand Up @@ -185,10 +186,15 @@ async def _complete_neon_tx(_skd_tx: NeonSkdTxModel) -> None:

await self._complete_stuck_neon_tx_retry_loop(stuck_req, skd_tree_parser)

last_good_time = time.monotonic()
for retry in itertools.count():
if await skd_tree_parser.can_be_destroyed():
await self._destroy_tree_account(skd_tree_parser)
break
now = time.monotonic()
if (now - last_good_time) > MIN_FINALIZE_SEC:
await self._destroy_tree_account(skd_tree_parser)
break
else:
last_good_time = time.monotonic()

if retry > 0:
_LOG.debug("retry %d to execute NeonSkdTx %s", retry, skd_tree_parser.neon_tx_hash)
Expand Down Expand Up @@ -277,6 +283,8 @@ async def _complete_task_list(self) -> None:
await asyncio.gather(*task_list)

async def _destroy_tree_account(self, skd_tree_parser: NeonSkdTreeParser) -> None:
await skd_tree_parser.refresh()

stuck_tx = MpStuckTxModel.from_raw(skd_tree_parser.neon_tx_hash, SolPubKey.default())
stuck_req = CompleteStuckTxRequest(stuck_tx=stuck_tx)
op_res = await self._acquire_op_key(stuck_req.req_id, skd_tree_parser.chain_id)
Expand Down
6 changes: 5 additions & 1 deletion proxy/executor/skd_tree_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from common.ethereum.hash import EthTxHash
from common.neon.address import NeonAddress
from common.neon.skd_tree import NeonSkdTreeAddress
from common.neon.transaction_model import NeonSkdTxModel, NeonSkdTxStatus
from common.neon_rpc.api import NeonSkdTreeModel, NeonSkdTreeNodeModel
from common.solana.pubkey import SolPubKey
Expand Down Expand Up @@ -35,7 +36,7 @@ def chain_id(self) -> int:

@cached_property
def address(self) -> SolPubKey:
return self._tree.address
return NeonSkdTreeAddress.from_raw(self._payer, self._nonce).address

@ttl_cached_method(ttl_msec=10)
async def _refresh(self) -> None:
Expand All @@ -51,6 +52,9 @@ async def _refresh(self) -> None:
len(self._tree.node_list),
)

async def refresh(self) -> None:
await self._refresh()

@cached_method
async def _get_slot_out(self) -> int:
evm_cfg = await self._get_evm_cfg()
Expand Down
4 changes: 3 additions & 1 deletion proxy/mempool/transaction_skd_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from common.config.constants import ONE_BLOCK_SEC, MIN_FINALIZE_BLOCK
from common.ethereum.hash import EthTxHash
from common.neon.address import NeonAddress
from common.neon.transaction_model import NeonTxModel
from common.utils.cached import cached_property
from common.utils.json_logger import logging_context
from .server_abc import MempoolComponent, MempoolServerAbc
Expand Down Expand Up @@ -91,6 +92,7 @@ async def _scan_old_skd_tx(self) -> None:
if (token_gas_price := self._token_gas_price) is None:
return

min_exec_gas_price = token_gas_price.min_executable_gas_price
token = ExecTokenModel.from_raw(self._gas_price, token_gas_price)

slot_out = await self._get_slot_out()
Expand All @@ -99,7 +101,7 @@ async def _scan_old_skd_tx(self) -> None:
skd_tx_list = await self._db.get_old_neon_skd_tx_list_by_slot(min_slot, 100)

for skd_tx in skd_tx_list:
if skd_tx.rlp_tx:
if skd_tx.rlp_tx and NeonTxModel.from_raw(skd_tx).base_fee_per_gas > min_exec_gas_price:
mp_tx = MpTxModel.from_skd_tx(skd_tx, self._layer0_chain_id)
await self._exec_client.exec_tx(mp_tx, token)
else:
Expand Down

0 comments on commit 88cca2e

Please sign in to comment.