Skip to content

Commit

Permalink
#246 Reject unprofitable transactions (min_gas_price) (#257)
Browse files Browse the repository at this point in the history
* min gas_price impl

* skip test_canceled

* unskip test_canceled
  • Loading branch information
sinev-valentine authored Nov 2, 2021
1 parent 21b3b63 commit 1f6b2f1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
7 changes: 5 additions & 2 deletions proxy/plugin/solana_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import threading
from .solana_rest_api_tools import EthereumAddress, create_account_with_seed, evm_loader_id, getTokens, \
getAccountInfo, solana_cli, call_signed, solana_url, call_emulated, \
Trx, EthereumError, create_collateral_pool_address, getTokenAddr, STORAGE_SIZE, neon_config_load
Trx, EthereumError, create_collateral_pool_address, getTokenAddr, STORAGE_SIZE, neon_config_load, MINIMAL_GAS_PRICE
from solana.rpc.commitment import Commitment, Confirmed
from web3 import Web3
import logging
Expand Down Expand Up @@ -113,7 +113,7 @@ def net_version(self):
return str(int(chainId,base=16))

def eth_gasPrice(self):
return hex(1*10**9)
return hex(MINIMAL_GAS_PRICE)

def eth_estimateGas(self, param):
try:
Expand Down Expand Up @@ -387,6 +387,9 @@ def eth_sendRawTransaction(self, rawTrx):
logger.debug('eth_sendRawTransaction rawTrx=%s', rawTrx)
trx = EthTrx.fromString(bytearray.fromhex(rawTrx[2:]))
logger.debug("%s", json.dumps(trx.as_dict(), cls=JsonEncoder, indent=3))
if trx.gasPrice < MINIMAL_GAS_PRICE:
raise Exception("The transaction gasPrice is less then the minimum allowable value ({}<{})".format(trx.gasPrice, MINIMAL_GAS_PRICE))

eth_signature = '0x' + bytes(Web3.keccak(bytes.fromhex(rawTrx[2:]))).hex()

sender = trx.sender()
Expand Down
1 change: 1 addition & 0 deletions proxy/plugin/solana_rest_api_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
USE_COMBINED_START_CONTINUE = os.environ.get("USE_COMBINED_START_CONTINUE", "YES") == "YES"
CONTINUE_COUNT_FACTOR = int(os.environ.get("CONTINUE_COUNT_FACTOR", "3"))
TIMEOUT_TO_RELOAD_NEON_CONFIG = int(os.environ.get("TIMEOUT_TO_RELOAD_NEON_CONFIG", "3600"))
MINIMAL_GAS_PRICE=int(os.environ.get("MINIMAL_GAS_PRICE", 1))*10**9

ACCOUNT_SEED_VERSION=b'\1'

Expand Down
4 changes: 4 additions & 0 deletions proxy/run-proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if [ "$CONFIG" == "ci" ]; then
[[ -z "$NEON_CLI_TIMEOUT" ]] && export NEON_CLI_TIMEOUT="0.5"
[[ -z "$USE_COMBINED_START_CONTINUE" ]] && export USE_COMBINED_START_CONTINUE="YES"
[[ -z "$CONTINUE_COUNT_FACTOR" ]] && export CONTINUE_COUNT_FACTOR="3"
[[ -z "$MINIMAL_GAS_PRICE" ]] && export MINIMAL_GAS_PRICE=0
elif [ "$CONFIG" == "local" ]; then
[[ -z "$SOLANA_URL" ]] && export SOLANA_URL="http://localhost:8899"
[[ -z "$EVM_LOADER" ]] && export EVM_LOADER=deploy
Expand All @@ -24,6 +25,7 @@ elif [ "$CONFIG" == "local" ]; then
[[ -z "$NEON_CHAIN_ID" ]] && export NEON_CHAIN_ID=0x6f
[[ -z "$EXTRA_GAS" ]] && export EXTRA_GAS=0
[[ -z "$NEON_CLI_TIMEOUT" ]] && export NEON_CLI_TIMEOUT="0.9"
[[ -z "$MINIMAL_GAS_PRICE" ]] && export MINIMAL_GAS_PRICE=0
elif [ "$CONFIG" == "devnet" ]; then
[[ -z "$SOLANA_URL" ]] && export SOLANA_URL="https://api.devnet.solana.com"
[[ -z "$EVM_LOADER" ]] && export EVM_LOADER=eeLSJgWzzxrqKv1UxtRVVH8FX3qCQWUs9QuAjJpETGU
Expand All @@ -33,6 +35,7 @@ elif [ "$CONFIG" == "devnet" ]; then
[[ -z "$NEON_CHAIN_ID" ]] && export NEON_CHAIN_ID=0x6e
[[ -z "$EXTRA_GAS" ]] && export EXTRA_GAS=90000
[[ -z "$NEON_CLI_TIMEOUT" ]] && export NEON_CLI_TIMEOUT="10"
[[ -z "$MINIMAL_GAS_PRICE" ]] && export MINIMAL_GAS_PRICE=1
elif [ "$CONFIG" == "testnet" ]; then
[[ -z "$SOLANA_URL" ]] && export SOLANA_URL="https://api.testnet.solana.com"
[[ -z "$EVM_LOADER" ]] && export EVM_LOADER=eeLSJgWzzxrqKv1UxtRVVH8FX3qCQWUs9QuAjJpETGU
Expand All @@ -42,6 +45,7 @@ elif [ "$CONFIG" == "testnet" ]; then
[[ -z "$NEON_CHAIN_ID" ]] && export NEON_CHAIN_ID=0x6f
[[ -z "$EXTRA_GAS" ]] && export EXTRA_GAS=90000
[[ -z "$NEON_CLI_TIMEOUT" ]] && export NEON_CLI_TIMEOUT="15"
[[ -z "$MINIMAL_GAS_PRICE" ]] && export MINIMAL_GAS_PRICE="1"
elif [ "$CONFIG" != "custom" ]; then
exit 1
fi
Expand Down
4 changes: 2 additions & 2 deletions proxy/test_cancel_hanged.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys

from proxy.plugin.solana_rest_api_tools import sysinstruct, ETH_TOKEN_MINT_ID, system, send_transaction
from proxy.plugin.solana_rest_api_tools import sysinstruct, ETH_TOKEN_MINT_ID, system, send_transaction, MINIMAL_GAS_PRICE

sys.path.append("/spl/bin/")
os.environ['SOLANA_URL'] = "http://solana:8899"
Expand Down Expand Up @@ -149,7 +149,7 @@ def deploy_contract(self):
def create_hanged_transaction(self):
print("\ncommit_two_event_trx")
right_nonce = proxy.eth.get_transaction_count(proxy.eth.default_account)
trx_store = self.storage_contract.functions.addReturnEventTwice(1, 1).buildTransaction({'nonce': right_nonce})
trx_store = self.storage_contract.functions.addReturnEventTwice(1, 1).buildTransaction({'nonce': right_nonce, 'gasPrice': MINIMAL_GAS_PRICE})
trx_store_signed = proxy.eth.account.sign_transaction(trx_store, eth_account.key)

(from_addr, sign, msg) = make_instruction_data_from_tx(trx_store_signed.rawTransaction.hex())
Expand Down

0 comments on commit 1f6b2f1

Please sign in to comment.