From f19ef6c6ad5837f2cda87f95de815215f23d795b Mon Sep 17 00:00:00 2001 From: Dmitriy Borisenko Date: Mon, 8 Nov 2021 21:02:08 +0300 Subject: [PATCH 01/10] #272 get free accounts on each call --- proxy/core/acceptor/pool.py | 1 + proxy/plugin/solana_rest_api.py | 31 ++++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/proxy/core/acceptor/pool.py b/proxy/core/acceptor/pool.py index beaa0733e..e6d846290 100644 --- a/proxy/core/acceptor/pool.py +++ b/proxy/core/acceptor/pool.py @@ -27,6 +27,7 @@ LOCK = multiprocessing.Lock() proxy_id_glob = multiprocessing.Value('i', 0) +proxy_used_id_glob = multiprocessing.Array('i', 1024) class AcceptorPool: diff --git a/proxy/plugin/solana_rest_api.py b/proxy/plugin/solana_rest_api.py index 7d1abb36e..c5bc56f6f 100644 --- a/proxy/plugin/solana_rest_api.py +++ b/proxy/plugin/solana_rest_api.py @@ -31,7 +31,7 @@ from solana.rpc.commitment import Commitment, Confirmed from web3 import Web3 import logging -from ..core.acceptor.pool import proxy_id_glob +from ..core.acceptor.pool import proxy_id_glob, proxy_used_id_glob import os from ..indexer.utils import get_trx_results, LogDB from sqlitedict import SqliteDict @@ -46,12 +46,20 @@ EXTRA_GAS = int(os.environ.get("EXTRA_GAS", "0")) class PermanentAccounts: - def __init__(self, client, signer, proxy_id): + def __init__(self, client, signer): + with proxy_used_id_glob.get_lock(): + for index in range(len(proxy_used_id_glob)): + if proxy_used_id_glob[index] == 0: + proxy_used_id_glob[index] = 1 + self.proxy_id = index + break + + logger.debug("LOCK RESOURCES {}".format(self.proxy_id)) + self.operator = signer.public_key() self.operator_token = getTokenAddr(self.operator) - self.proxy_id = proxy_id - proxy_id_bytes = proxy_id.to_bytes((proxy_id.bit_length() + 7) // 8, 'big') + proxy_id_bytes = self.proxy_id.to_bytes((self.proxy_id.bit_length() + 7) // 8, 'big') storage_seed = keccak_256(b"storage" + proxy_id_bytes).hexdigest()[:32] storage_seed = bytes(storage_seed, 'utf8') @@ -61,10 +69,18 @@ def __init__(self, client, signer, proxy_id): holder_seed = bytes(holder_seed, 'utf8') self.holder = create_account_with_seed(client, funding=signer, base=signer, seed=holder_seed, storage_size=STORAGE_SIZE) - collateral_pool_index = proxy_id % 4 + collateral_pool_index = self.proxy_id % 10 self.collateral_pool_index_buf = collateral_pool_index.to_bytes(4, 'little') self.collateral_pool_address = create_collateral_pool_address(collateral_pool_index) + def __del__(self): + logger.debug("FREE RESOURCES {}".format(self.proxy_id)) + + with proxy_used_id_glob.get_lock(): + if proxy_used_id_glob[self.proxy_id] == 1: + proxy_used_id_glob[self.proxy_id] = 0 + else: + raise Exception("Proxy resource id ({}) is locked.".format(self.proxy_id)) class EthereumModel: def __init__(self): @@ -98,7 +114,7 @@ def __init__(self): proxy_id_glob.value += 1 logger.debug("worker id {}".format(self.proxy_id)) - self.perm_accs = PermanentAccounts(self.client, self.signer, self.proxy_id) + # self.perm_accs = PermanentAccounts(self.client, self.signer, self.proxy_id) neon_config_load(self) pass @@ -415,7 +431,8 @@ def eth_sendRawTransaction(self, rawTrx): ] }) try: - signature = call_signed(self.signer, self.client, trx, self.perm_accs, steps=250) + perm_accs = PermanentAccounts(self.client, self.signer) + signature = call_signed(self.signer, self.client, trx, perm_accs, steps=250) logger.debug('Transaction signature: %s %s', signature, eth_signature) From 3182ee86a8e8f4b280ac3300be79f8e9c69e87c0 Mon Sep 17 00:00:00 2001 From: Dmitriy Borisenko Date: Tue, 9 Nov 2021 16:03:02 +0300 Subject: [PATCH 02/10] #272 create and delete account on every ethereum trx --- proxy/plugin/solana_rest_api.py | 28 +++++++++++++++--- proxy/plugin/solana_rest_api_tools.py | 41 +++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/proxy/plugin/solana_rest_api.py b/proxy/plugin/solana_rest_api.py index c5bc56f6f..4422cfb60 100644 --- a/proxy/plugin/solana_rest_api.py +++ b/proxy/plugin/solana_rest_api.py @@ -26,8 +26,9 @@ import traceback import threading from .solana_rest_api_tools import EthereumAddress, create_account_with_seed, getTokens, \ - getAccountInfo, call_signed, call_emulated, \ - Trx, EthereumError, create_collateral_pool_address, getTokenAddr, STORAGE_SIZE, neon_config_load, MINIMAL_GAS_PRICE + getAccountInfo, call_signed, call_emulated, create_multiple_accounts_with_seed, \ + Trx, EthereumError, create_collateral_pool_address, getTokenAddr, STORAGE_SIZE, \ + neon_config_load, MINIMAL_GAS_PRICE, refund_accounts from solana.rpc.commitment import Commitment, Confirmed from web3 import Web3 import logging @@ -56,6 +57,8 @@ def __init__(self, client, signer): logger.debug("LOCK RESOURCES {}".format(self.proxy_id)) + self.client = client + self.signer = signer self.operator = signer.public_key() self.operator_token = getTokenAddr(self.operator) @@ -63,11 +66,18 @@ def __init__(self, client, signer): storage_seed = keccak_256(b"storage" + proxy_id_bytes).hexdigest()[:32] storage_seed = bytes(storage_seed, 'utf8') - self.storage = create_account_with_seed(client, funding=signer, base=signer, seed=storage_seed, storage_size=STORAGE_SIZE) holder_seed = keccak_256(b"holder" + proxy_id_bytes).hexdigest()[:32] holder_seed = bytes(holder_seed, 'utf8') - self.holder = create_account_with_seed(client, funding=signer, base=signer, seed=holder_seed, storage_size=STORAGE_SIZE) + + accounts = create_multiple_accounts_with_seed( + client, + funding=signer, + base=signer, + seeds=[storage_seed, holder_seed], + sizes=[STORAGE_SIZE, STORAGE_SIZE]) + self.storage = accounts[0] + self.holder = accounts[1] collateral_pool_index = self.proxy_id % 10 self.collateral_pool_index_buf = collateral_pool_index.to_bytes(4, 'little') @@ -79,6 +89,16 @@ def __del__(self): with proxy_used_id_glob.get_lock(): if proxy_used_id_glob[self.proxy_id] == 1: proxy_used_id_glob[self.proxy_id] = 0 + + proxy_id_bytes = self.proxy_id.to_bytes((self.proxy_id.bit_length() + 7) // 8, 'big') + + storage_seed = keccak_256(b"storage" + proxy_id_bytes).hexdigest()[:32] + storage_seed = bytes(storage_seed, 'utf8') + + holder_seed = keccak_256(b"holder" + proxy_id_bytes).hexdigest()[:32] + holder_seed = bytes(holder_seed, 'utf8') + + refund_accounts(self.client, self.signer, [storage_seed, holder_seed]) else: raise Exception("Proxy resource id ({}) is locked.".format(self.proxy_id)) diff --git a/proxy/plugin/solana_rest_api_tools.py b/proxy/plugin/solana_rest_api_tools.py index ccde6f766..6d56d079f 100644 --- a/proxy/plugin/solana_rest_api_tools.py +++ b/proxy/plugin/solana_rest_api_tools.py @@ -173,6 +173,47 @@ def create_account_with_seed(client, funding, base, seed, storage_size): return account +def create_multiple_accounts_with_seed(client, funding, base, seeds, sizes): + accounts = [] + trx = Transaction() + + for seed, storage_size in zip(seeds, sizes): + account = accountWithSeed(base.public_key(), seed, PublicKey(evm_loader_id)) + accounts.append(account) + + if client.get_balance(account, commitment=Confirmed)['result']['value'] == 0: + minimum_balance = client.get_minimum_balance_for_rent_exemption(storage_size, commitment=Confirmed)["result"] + logger.debug("Minimum balance required for account {}".format(minimum_balance)) + + trx.add(createAccountWithSeedTrx(funding.public_key(), base.public_key(), seed, minimum_balance, storage_size, PublicKey(evm_loader_id))) + + if len(trx.instructions) > 0: + send_transaction(client, trx, funding) + + return accounts + + +def refund_accounts(client, owner, seeds): + trx = Transaction() + for seed in seeds: + account = accountWithSeed(owner.public_key(), seed, PublicKey(evm_loader_id)) + if client.get_balance(account, commitment=Confirmed)['result']['value'] != 0: + trx.add(make_refund_tx(account, owner, seed)) + + if len(trx.instructions) > 0: + send_transaction(client, trx, owner) + + +def make_refund_tx(del_key, owner, seed): + return TransactionInstruction( + program_id=PublicKey(evm_loader_id), + data=bytearray.fromhex("10") + bytes(seed, 'utf8'), + keys=[ + AccountMeta(pubkey=del_key, is_signer=False, is_writable=True), + AccountMeta(pubkey=owner.public_key(), is_signer=True, is_writable=True), + ]) + + def make_keccak_instruction_data(check_instruction_index, msg_len, data_start): if check_instruction_index > 255 and check_instruction_index < 0: raise Exception("Invalid index for instruction - {}".format(check_instruction_index)) From 5147cedd6d19d1d1d881bf967951b4fed8fde2eb Mon Sep 17 00:00:00 2001 From: Dmitriy Borisenko Date: Tue, 9 Nov 2021 16:10:01 +0300 Subject: [PATCH 03/10] #272 simplify index aquiring --- proxy/core/acceptor/pool.py | 1 - proxy/plugin/solana_rest_api.py | 34 +++++++++++---------------------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/proxy/core/acceptor/pool.py b/proxy/core/acceptor/pool.py index e6d846290..beaa0733e 100644 --- a/proxy/core/acceptor/pool.py +++ b/proxy/core/acceptor/pool.py @@ -27,7 +27,6 @@ LOCK = multiprocessing.Lock() proxy_id_glob = multiprocessing.Value('i', 0) -proxy_used_id_glob = multiprocessing.Array('i', 1024) class AcceptorPool: diff --git a/proxy/plugin/solana_rest_api.py b/proxy/plugin/solana_rest_api.py index 4422cfb60..eb0d2e791 100644 --- a/proxy/plugin/solana_rest_api.py +++ b/proxy/plugin/solana_rest_api.py @@ -32,7 +32,7 @@ from solana.rpc.commitment import Commitment, Confirmed from web3 import Web3 import logging -from ..core.acceptor.pool import proxy_id_glob, proxy_used_id_glob +from ..core.acceptor.pool import proxy_id_glob import os from ..indexer.utils import get_trx_results, LogDB from sqlitedict import SqliteDict @@ -48,14 +48,12 @@ class PermanentAccounts: def __init__(self, client, signer): - with proxy_used_id_glob.get_lock(): - for index in range(len(proxy_used_id_glob)): - if proxy_used_id_glob[index] == 0: - proxy_used_id_glob[index] = 1 - self.proxy_id = index - break + with proxy_id_glob.get_lock(): + self.proxy_id = proxy_id_glob.value + proxy_id_glob.value += 1 logger.debug("LOCK RESOURCES {}".format(self.proxy_id)) + logger.debug("worker id {}".format(self.proxy_id)) self.client = client self.signer = signer @@ -86,21 +84,15 @@ def __init__(self, client, signer): def __del__(self): logger.debug("FREE RESOURCES {}".format(self.proxy_id)) - with proxy_used_id_glob.get_lock(): - if proxy_used_id_glob[self.proxy_id] == 1: - proxy_used_id_glob[self.proxy_id] = 0 - - proxy_id_bytes = self.proxy_id.to_bytes((self.proxy_id.bit_length() + 7) // 8, 'big') + proxy_id_bytes = self.proxy_id.to_bytes((self.proxy_id.bit_length() + 7) // 8, 'big') - storage_seed = keccak_256(b"storage" + proxy_id_bytes).hexdigest()[:32] - storage_seed = bytes(storage_seed, 'utf8') + storage_seed = keccak_256(b"storage" + proxy_id_bytes).hexdigest()[:32] + storage_seed = bytes(storage_seed, 'utf8') - holder_seed = keccak_256(b"holder" + proxy_id_bytes).hexdigest()[:32] - holder_seed = bytes(holder_seed, 'utf8') + holder_seed = keccak_256(b"holder" + proxy_id_bytes).hexdigest()[:32] + holder_seed = bytes(holder_seed, 'utf8') - refund_accounts(self.client, self.signer, [storage_seed, holder_seed]) - else: - raise Exception("Proxy resource id ({}) is locked.".format(self.proxy_id)) + refund_accounts(self.client, self.signer, [storage_seed, holder_seed]) class EthereumModel: def __init__(self): @@ -129,10 +121,6 @@ def __init__(self): self.eth_sol_trx = SqliteDict(filename="local.db", tablename="ethereum_solana_transactions", autocommit=True, encode=json.dumps, decode=json.loads) self.sol_eth_trx = SqliteDict(filename="local.db", tablename="solana_ethereum_transactions", autocommit=True, encode=json.dumps, decode=json.loads) - with proxy_id_glob.get_lock(): - self.proxy_id = proxy_id_glob.value - proxy_id_glob.value += 1 - logger.debug("worker id {}".format(self.proxy_id)) # self.perm_accs = PermanentAccounts(self.client, self.signer, self.proxy_id) neon_config_load(self) From 4e82fb058669d4819bf5249a1ff53a7e57d359b0 Mon Sep 17 00:00:00 2001 From: Dmitriy Borisenko Date: Tue, 9 Nov 2021 16:37:54 +0300 Subject: [PATCH 04/10] #272 move realisation into *tools module --- proxy/core/acceptor/pool.py | 1 + proxy/plugin/solana_rest_api.py | 62 +++------------------------ proxy/plugin/solana_rest_api_tools.py | 61 +++++++++++++++++++++++--- 3 files changed, 64 insertions(+), 60 deletions(-) diff --git a/proxy/core/acceptor/pool.py b/proxy/core/acceptor/pool.py index beaa0733e..5f16a109b 100644 --- a/proxy/core/acceptor/pool.py +++ b/proxy/core/acceptor/pool.py @@ -27,6 +27,7 @@ LOCK = multiprocessing.Lock() proxy_id_glob = multiprocessing.Value('i', 0) +new_acc_id_glob = multiprocessing.Value('i', 0) class AcceptorPool: diff --git a/proxy/plugin/solana_rest_api.py b/proxy/plugin/solana_rest_api.py index eb0d2e791..1ff29cee8 100644 --- a/proxy/plugin/solana_rest_api.py +++ b/proxy/plugin/solana_rest_api.py @@ -25,10 +25,8 @@ import base58 import traceback import threading -from .solana_rest_api_tools import EthereumAddress, create_account_with_seed, getTokens, \ - getAccountInfo, call_signed, call_emulated, create_multiple_accounts_with_seed, \ - Trx, EthereumError, create_collateral_pool_address, getTokenAddr, STORAGE_SIZE, \ - neon_config_load, MINIMAL_GAS_PRICE, refund_accounts +from .solana_rest_api_tools import EthereumAddress, getTokens, getAccountInfo, \ + call_signed, call_emulated, EthereumError, neon_config_load, MINIMAL_GAS_PRICE from solana.rpc.commitment import Commitment, Confirmed from web3 import Web3 import logging @@ -46,54 +44,6 @@ EXTRA_GAS = int(os.environ.get("EXTRA_GAS", "0")) -class PermanentAccounts: - def __init__(self, client, signer): - with proxy_id_glob.get_lock(): - self.proxy_id = proxy_id_glob.value - proxy_id_glob.value += 1 - - logger.debug("LOCK RESOURCES {}".format(self.proxy_id)) - logger.debug("worker id {}".format(self.proxy_id)) - - self.client = client - self.signer = signer - self.operator = signer.public_key() - self.operator_token = getTokenAddr(self.operator) - - proxy_id_bytes = self.proxy_id.to_bytes((self.proxy_id.bit_length() + 7) // 8, 'big') - - storage_seed = keccak_256(b"storage" + proxy_id_bytes).hexdigest()[:32] - storage_seed = bytes(storage_seed, 'utf8') - - holder_seed = keccak_256(b"holder" + proxy_id_bytes).hexdigest()[:32] - holder_seed = bytes(holder_seed, 'utf8') - - accounts = create_multiple_accounts_with_seed( - client, - funding=signer, - base=signer, - seeds=[storage_seed, holder_seed], - sizes=[STORAGE_SIZE, STORAGE_SIZE]) - self.storage = accounts[0] - self.holder = accounts[1] - - collateral_pool_index = self.proxy_id % 10 - self.collateral_pool_index_buf = collateral_pool_index.to_bytes(4, 'little') - self.collateral_pool_address = create_collateral_pool_address(collateral_pool_index) - - def __del__(self): - logger.debug("FREE RESOURCES {}".format(self.proxy_id)) - - proxy_id_bytes = self.proxy_id.to_bytes((self.proxy_id.bit_length() + 7) // 8, 'big') - - storage_seed = keccak_256(b"storage" + proxy_id_bytes).hexdigest()[:32] - storage_seed = bytes(storage_seed, 'utf8') - - holder_seed = keccak_256(b"holder" + proxy_id_bytes).hexdigest()[:32] - holder_seed = bytes(holder_seed, 'utf8') - - refund_accounts(self.client, self.signer, [storage_seed, holder_seed]) - class EthereumModel: def __init__(self): # Initialize user account @@ -121,8 +71,11 @@ def __init__(self): self.eth_sol_trx = SqliteDict(filename="local.db", tablename="ethereum_solana_transactions", autocommit=True, encode=json.dumps, decode=json.loads) self.sol_eth_trx = SqliteDict(filename="local.db", tablename="solana_ethereum_transactions", autocommit=True, encode=json.dumps, decode=json.loads) + with proxy_id_glob.get_lock(): + self.proxy_id = proxy_id_glob.value + proxy_id_glob.value += 1 + logger.debug("worker id {}".format(self.proxy_id)) - # self.perm_accs = PermanentAccounts(self.client, self.signer, self.proxy_id) neon_config_load(self) pass @@ -439,8 +392,7 @@ def eth_sendRawTransaction(self, rawTrx): ] }) try: - perm_accs = PermanentAccounts(self.client, self.signer) - signature = call_signed(self.signer, self.client, trx, perm_accs, steps=250) + signature = call_signed(self.signer, self.client, trx, steps=250) logger.debug('Transaction signature: %s %s', signature, eth_signature) diff --git a/proxy/plugin/solana_rest_api_tools.py b/proxy/plugin/solana_rest_api_tools.py index 6d56d079f..473e77429 100644 --- a/proxy/plugin/solana_rest_api_tools.py +++ b/proxy/plugin/solana_rest_api_tools.py @@ -30,6 +30,7 @@ from web3.auto import w3 from proxy.environment import neon_cli, evm_loader_id, ETH_TOKEN_MINT_ID, COLLATERAL_POOL_BASE, read_elf_params from .eth_proto import Trx +from ..core.acceptor.pool import new_acc_id_glob logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) @@ -88,6 +89,55 @@ ] +class PermanentAccounts: + def __init__(self, client, signer): + with new_acc_id_glob.get_lock(): + self.acc_id = new_acc_id_glob.value + new_acc_id_glob.value += 1 + + logger.debug("LOCK RESOURCES {}".format(self.acc_id)) + logger.debug("worker id {}".format(self.acc_id)) + + self.client = client + self.signer = signer + self.operator = signer.public_key() + self.operator_token = getTokenAddr(self.operator) + + acc_id_bytes = self.acc_id.to_bytes((self.acc_id.bit_length() + 7) // 8, 'big') + + storage_seed = keccak_256(b"storage" + acc_id_bytes).hexdigest()[:32] + storage_seed = bytes(storage_seed, 'utf8') + + holder_seed = keccak_256(b"holder" + acc_id_bytes).hexdigest()[:32] + holder_seed = bytes(holder_seed, 'utf8') + + accounts = create_multiple_accounts_with_seed( + client, + funding=signer, + base=signer, + seeds=[storage_seed, holder_seed], + sizes=[STORAGE_SIZE, STORAGE_SIZE]) + self.storage = accounts[0] + self.holder = accounts[1] + + collateral_pool_index = self.acc_id % 10 + self.collateral_pool_index_buf = collateral_pool_index.to_bytes(4, 'little') + self.collateral_pool_address = create_collateral_pool_address(collateral_pool_index) + + def __del__(self): + logger.debug("FREE RESOURCES {}".format(self.acc_id)) + + acc_id_bytes = self.acc_id.to_bytes((self.acc_id.bit_length() + 7) // 8, 'big') + + storage_seed = keccak_256(b"storage" + acc_id_bytes).hexdigest()[:32] + storage_seed = bytes(storage_seed, 'utf8') + + holder_seed = keccak_256(b"holder" + acc_id_bytes).hexdigest()[:32] + holder_seed = bytes(holder_seed, 'utf8') + + refund_accounts(self.client, self.signer, [storage_seed, holder_seed]) + + class TransactionInfo: def __init__(self, caller_token, eth_accounts, nonce): self.caller_token = caller_token @@ -207,7 +257,7 @@ def refund_accounts(client, owner, seeds): def make_refund_tx(del_key, owner, seed): return TransactionInstruction( program_id=PublicKey(evm_loader_id), - data=bytearray.fromhex("10") + bytes(seed, 'utf8'), + data=bytearray.fromhex("10") + bytes(seed), keys=[ AccountMeta(pubkey=del_key, is_signer=False, is_writable=True), AccountMeta(pubkey=owner.public_key(), is_signer=True, is_writable=True), @@ -981,7 +1031,8 @@ def create_account_list_by_emulate(signer, client, ethTrx): return (trx_accs, sender_ether, trx) -def call_signed(signer, client, ethTrx, perm_accs, steps): +def call_signed(signer, client, ethTrx, steps): + perm_accs = PermanentAccounts(client, signer) (trx_accs, sender_ether, create_acc_trx) = create_account_list_by_emulate(signer, client, ethTrx) @@ -1065,7 +1116,7 @@ def call_signed_noniterative(signer, client, ethTrx, perm_accs, trx_accs, msg, c def call_signed_with_holder_acc(signer, client, ethTrx, perm_accs, trx_accs, steps, create_acc_trx): - write_trx_to_holder_account(signer, client, perm_accs.holder, perm_accs.proxy_id, ethTrx) + write_trx_to_holder_account(signer, client, perm_accs.holder, perm_accs.acc_id, ethTrx) if len(create_acc_trx.instructions): precall_txs = Transaction() @@ -1148,7 +1199,7 @@ def createERC20TokenAccountTrx(signer, token_info): -def write_trx_to_holder_account(signer, client, holder, proxy_id, ethTrx): +def write_trx_to_holder_account(signer, client, holder, acc_id, ethTrx): msg = ethTrx.signature() + len(ethTrx.unsigned_msg()).to_bytes(8, byteorder="little") + ethTrx.unsigned_msg() # Write transaction to transaction holder account @@ -1160,7 +1211,7 @@ def write_trx_to_holder_account(signer, client, holder, proxy_id, ethTrx): trx = Transaction() # logger.debug("sender_sol %s %s %s", sender_sol, holder, acc.public_key()) trx.add(TransactionInstruction(program_id=evm_loader_id, - data=write_holder_layout(proxy_id, offset, part), + data=write_holder_layout(acc_id, offset, part), keys=[ AccountMeta(pubkey=holder, is_signer=False, is_writable=True), AccountMeta(pubkey=signer.public_key(), is_signer=True, is_writable=False), From d30e1f2ccd7a308bcc5cb65a0766ea7d0ed4fce2 Mon Sep 17 00:00:00 2001 From: Dmitriy Borisenko Date: Thu, 11 Nov 2021 22:47:24 +0300 Subject: [PATCH 05/10] #272 lot of changes --- proxy/core/acceptor/pool.py | 2 + proxy/plugin/solana_rest_api_tools.py | 270 +++++++++++++++----------- 2 files changed, 157 insertions(+), 115 deletions(-) diff --git a/proxy/core/acceptor/pool.py b/proxy/core/acceptor/pool.py index 5f16a109b..dd4cdc59e 100644 --- a/proxy/core/acceptor/pool.py +++ b/proxy/core/acceptor/pool.py @@ -28,6 +28,8 @@ proxy_id_glob = multiprocessing.Value('i', 0) new_acc_id_glob = multiprocessing.Value('i', 0) +manager = multiprocessing.Manager() +acc_list_glob = manager.list() class AcceptorPool: diff --git a/proxy/plugin/solana_rest_api_tools.py b/proxy/plugin/solana_rest_api_tools.py index 473e77429..06118c673 100644 --- a/proxy/plugin/solana_rest_api_tools.py +++ b/proxy/plugin/solana_rest_api_tools.py @@ -30,7 +30,7 @@ from web3.auto import w3 from proxy.environment import neon_cli, evm_loader_id, ETH_TOKEN_MINT_ID, COLLATERAL_POOL_BASE, read_elf_params from .eth_proto import Trx -from ..core.acceptor.pool import new_acc_id_glob +from ..core.acceptor.pool import new_acc_id_glob, acc_list_glob logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) @@ -47,6 +47,8 @@ ACCOUNT_SEED_VERSION=b'\1' +COLLATERALL_POOL_MAX=10 + sysvarclock = "SysvarC1ock11111111111111111111111111111111" sysinstruct = "Sysvar1nstructions1111111111111111111111111" keccakprog = "KeccakSecp256k11111111111111111111111111111" @@ -91,58 +93,58 @@ class PermanentAccounts: def __init__(self, client, signer): - with new_acc_id_glob.get_lock(): - self.acc_id = new_acc_id_glob.value - new_acc_id_glob.value += 1 - - logger.debug("LOCK RESOURCES {}".format(self.acc_id)) - logger.debug("worker id {}".format(self.acc_id)) - - self.client = client - self.signer = signer - self.operator = signer.public_key() - self.operator_token = getTokenAddr(self.operator) - - acc_id_bytes = self.acc_id.to_bytes((self.acc_id.bit_length() + 7) // 8, 'big') - - storage_seed = keccak_256(b"storage" + acc_id_bytes).hexdigest()[:32] - storage_seed = bytes(storage_seed, 'utf8') - - holder_seed = keccak_256(b"holder" + acc_id_bytes).hexdigest()[:32] - holder_seed = bytes(holder_seed, 'utf8') - - accounts = create_multiple_accounts_with_seed( - client, - funding=signer, - base=signer, - seeds=[storage_seed, holder_seed], - sizes=[STORAGE_SIZE, STORAGE_SIZE]) - self.storage = accounts[0] - self.holder = accounts[1] - - collateral_pool_index = self.acc_id % 10 - self.collateral_pool_index_buf = collateral_pool_index.to_bytes(4, 'little') - self.collateral_pool_address = create_collateral_pool_address(collateral_pool_index) + while True: + with new_acc_id_glob.get_lock(): + try: + self.acc_id = acc_list_glob.pop(0) + except IndexError: + self.acc_id = new_acc_id_glob.value + new_acc_id_glob.value += 1 + + logger.debug("LOCK RESOURCES {}".format(self.acc_id)) + + self.operator = signer.public_key() + self.operator_token = getTokenAddr(self.operator) + + acc_id_bytes = self.acc_id.to_bytes((self.acc_id.bit_length() + 7) // 8, 'big') + + storage_seed = keccak_256(b"storage" + acc_id_bytes).hexdigest()[:32] + storage_seed = bytes(storage_seed, 'utf8') + + holder_seed = keccak_256(b"holder" + acc_id_bytes).hexdigest()[:32] + holder_seed = bytes(holder_seed, 'utf8') + + try: + self.storage, self.holder = create_multiple_accounts_with_seed( + client, + funding=signer, + base=signer, + seeds=[storage_seed, holder_seed], + sizes=[STORAGE_SIZE, STORAGE_SIZE] + ) + except Exception as err: + logger.warn("Account is locked err({}) id({}) owner({})".format(str(err), self.acc_id, signer.public_key())) + else: + break def __del__(self): logger.debug("FREE RESOURCES {}".format(self.acc_id)) - - acc_id_bytes = self.acc_id.to_bytes((self.acc_id.bit_length() + 7) // 8, 'big') - - storage_seed = keccak_256(b"storage" + acc_id_bytes).hexdigest()[:32] - storage_seed = bytes(storage_seed, 'utf8') - - holder_seed = keccak_256(b"holder" + acc_id_bytes).hexdigest()[:32] - holder_seed = bytes(holder_seed, 'utf8') - - refund_accounts(self.client, self.signer, [storage_seed, holder_seed]) + with new_acc_id_glob.get_lock(): + acc_list_glob.append(self.acc_id) class TransactionInfo: - def __init__(self, caller_token, eth_accounts, nonce): + def __init__(self, caller_token, eth_accounts, ethTrx): + self.ethTrx = ethTrx + self.caller_token = caller_token self.eth_accounts = eth_accounts - self.nonce = nonce + self.nonce = ethTrx.nonce + + hash = keccak_256(ethTrx.unsigned_msg()).digest() + collateral_pool_index = int().from_bytes(hash[:4], "little") % COLLATERALL_POOL_MAX + self.collateral_pool_index_buf = collateral_pool_index.to_bytes(4, 'little') + self.collateral_pool_address = create_collateral_pool_address(collateral_pool_index) class AccountInfo(NamedTuple): ether: eth_keys.PublicKey @@ -169,6 +171,33 @@ def write_holder_layout(nonce, offset, data): len(data).to_bytes(8, byteorder='little')+ data) +def get_account_info(client, storage_account): + opts = { + "encoding": "base64", + "commitment": "confirmed", + "dataSlice": { + "offset": 0, + "length": 16, + } + } + + result = client._provider.make_request("getAccountInfo", str(storage_account), opts) + logger.debug("\n{}".format(json.dumps(result, indent=4, sort_keys=True))) + + info = result['result']['value'] + if info is None: + logger.debug("Can't get information about {}".format(storage_account)) + return None + + data = base64.b64decode(info['data'][0]) + + empty = True if data[0] == 0 else False + lamports = info['lamports'] + owner = info['owner'] + + return (empty, lamports, owner) + + def accountWithSeed(base, seed, program): # logger.debug(type(base), str(base), type(seed), str(seed), type(program), str(program)) result = PublicKey(sha256(bytes(base) + bytes(seed) + bytes(program)).digest()) @@ -231,11 +260,21 @@ def create_multiple_accounts_with_seed(client, funding, base, seeds, sizes): account = accountWithSeed(base.public_key(), seed, PublicKey(evm_loader_id)) accounts.append(account) - if client.get_balance(account, commitment=Confirmed)['result']['value'] == 0: - minimum_balance = client.get_minimum_balance_for_rent_exemption(storage_size, commitment=Confirmed)["result"] + minimum_balance = client.get_minimum_balance_for_rent_exemption(storage_size, commitment=Confirmed)["result"] + + account_info = get_account_info(client, account) + if account_info is None: logger.debug("Minimum balance required for account {}".format(minimum_balance)) trx.add(createAccountWithSeedTrx(funding.public_key(), base.public_key(), seed, minimum_balance, storage_size, PublicKey(evm_loader_id))) + else: + (empty, lamports, owner) = account_info + if lamports < minimum_balance: + raise Exception("insufficient balance") + if PublicKey(owner) != PublicKey(evm_loader_id): + raise Exception("wrong owner") + if not empty: + raise Exception("not empty") if len(trx.instructions) > 0: send_transaction(client, trx, funding) @@ -243,27 +282,6 @@ def create_multiple_accounts_with_seed(client, funding, base, seeds, sizes): return accounts -def refund_accounts(client, owner, seeds): - trx = Transaction() - for seed in seeds: - account = accountWithSeed(owner.public_key(), seed, PublicKey(evm_loader_id)) - if client.get_balance(account, commitment=Confirmed)['result']['value'] != 0: - trx.add(make_refund_tx(account, owner, seed)) - - if len(trx.instructions) > 0: - send_transaction(client, trx, owner) - - -def make_refund_tx(del_key, owner, seed): - return TransactionInstruction( - program_id=PublicKey(evm_loader_id), - data=bytearray.fromhex("10") + bytes(seed), - keys=[ - AccountMeta(pubkey=del_key, is_signer=False, is_writable=True), - AccountMeta(pubkey=owner.public_key(), is_signer=True, is_writable=True), - ]) - - def make_keccak_instruction_data(check_instruction_index, msg_len, data_start): if check_instruction_index > 255 and check_instruction_index < 0: raise Exception("Invalid index for instruction - {}".format(check_instruction_index)) @@ -558,7 +576,7 @@ def call_continue_bucked(signer, client, perm_accs, trx_accs, steps): result_list = [] try: for index in range(continue_count): - trx = Transaction().add(make_continue_instruction(perm_accs, trx_accs, instruction_count, index)) + trx = Transaction().add(make_continue_instruction(signer, perm_accs, trx_accs, instruction_count, index)) result = client.send_transaction( trx, signer, @@ -589,7 +607,7 @@ def call_continue_bucked_0x0d(signer, client, perm_accs, trx_accs, steps, msg): result_list = [] try: for index in range(continue_count*CONTINUE_COUNT_FACTOR): - trx = Transaction().add(make_partial_call_or_continue_instruction_0x0d(perm_accs, trx_accs, instruction_count, msg, index)) + trx = Transaction().add(make_partial_call_or_continue_instruction_0x0d(signer, perm_accs, trx_accs, instruction_count, msg, index)) result = client.send_transaction( trx, signer, @@ -634,7 +652,7 @@ def sol_instr_10_continue(signer, client, perm_accs, trx_accs, initial_step_coun step_count = initial_step_count while step_count > 0: trx = Transaction() - trx.add(make_continue_instruction(perm_accs, trx_accs, step_count)) + trx.add(make_continue_instruction(signer, perm_accs, trx_accs, step_count)) logger.debug("Step count {}".format(step_count)) try: @@ -649,14 +667,17 @@ def sol_instr_10_continue(signer, client, perm_accs, trx_accs, initial_step_coun def sol_instr_21_cancel(signer, client, perm_accs, trx_accs): + operator = signer.public_key() + operator_token = getTokenAddr(operator) + trx = Transaction() trx.add(TransactionInstruction( program_id=evm_loader_id, data=bytearray.fromhex("15") + trx_accs.nonce.to_bytes(8, 'little'), keys=[ AccountMeta(pubkey=perm_accs.storage, is_signer=False, is_writable=True), - AccountMeta(pubkey=perm_accs.operator, is_signer=True, is_writable=True), - AccountMeta(pubkey=perm_accs.operator_token, is_signer=False, is_writable=True), + AccountMeta(pubkey=operator, is_signer=True, is_writable=True), + AccountMeta(pubkey=operator_token, is_signer=False, is_writable=True), AccountMeta(pubkey=trx_accs.caller_token, is_signer=False, is_writable=True), AccountMeta(pubkey=incinerator, is_signer=False, is_writable=True), AccountMeta(pubkey=system, is_signer=False, is_writable=False), @@ -672,17 +693,20 @@ def sol_instr_21_cancel(signer, client, perm_accs, trx_accs): return result['result']['transaction']['signatures'][0] -def make_partial_call_instruction(perm_accs, trx_accs, step_count, call_data): +def make_partial_call_instruction(signer, perm_accs, trx_accs, step_count, call_data): + operator = signer.public_key() + operator_token = getTokenAddr(operator) + return TransactionInstruction( program_id = evm_loader_id, - data = bytearray.fromhex("13") + perm_accs.collateral_pool_index_buf + step_count.to_bytes(8, byteorder="little") + call_data, + data = bytearray.fromhex("13") + trx_accs.collateral_pool_index_buf + step_count.to_bytes(8, byteorder="little") + call_data, keys = [ AccountMeta(pubkey=perm_accs.storage, is_signer=False, is_writable=True), AccountMeta(pubkey=sysinstruct, is_signer=False, is_writable=False), - AccountMeta(pubkey=perm_accs.operator, is_signer=True, is_writable=True), - AccountMeta(pubkey=perm_accs.collateral_pool_address, is_signer=False, is_writable=True), - AccountMeta(pubkey=perm_accs.operator_token, is_signer=False, is_writable=True), + AccountMeta(pubkey=operator, is_signer=True, is_writable=True), + AccountMeta(pubkey=trx_accs.collateral_pool_address, is_signer=False, is_writable=True), + AccountMeta(pubkey=operator_token, is_signer=False, is_writable=True), AccountMeta(pubkey=trx_accs.caller_token, is_signer=False, is_writable=True), AccountMeta(pubkey=system, is_signer=False, is_writable=False), @@ -693,8 +717,11 @@ def make_partial_call_instruction(perm_accs, trx_accs, step_count, call_data): ) -def make_partial_call_or_continue_instruction_0x0d(perm_accs, trx_accs, step_count, call_data, index=None): - data = bytearray.fromhex("0D") + perm_accs.collateral_pool_index_buf + step_count.to_bytes(8, byteorder="little") + call_data +def make_partial_call_or_continue_instruction_0x0d(signer, perm_accs, trx_accs, step_count, call_data, index=None): + operator = signer.public_key() + operator_token = getTokenAddr(operator) + + data = bytearray.fromhex("0D") + trx_accs.collateral_pool_index_buf + step_count.to_bytes(8, byteorder="little") + call_data if index: data = data + index.to_bytes(8, byteorder="little") return TransactionInstruction( @@ -704,9 +731,9 @@ def make_partial_call_or_continue_instruction_0x0d(perm_accs, trx_accs, step_cou AccountMeta(pubkey=perm_accs.storage, is_signer=False, is_writable=True), AccountMeta(pubkey=sysinstruct, is_signer=False, is_writable=False), - AccountMeta(pubkey=perm_accs.operator, is_signer=True, is_writable=True), - AccountMeta(pubkey=perm_accs.collateral_pool_address, is_signer=False, is_writable=True), - AccountMeta(pubkey=perm_accs.operator_token, is_signer=False, is_writable=True), + AccountMeta(pubkey=operator, is_signer=True, is_writable=True), + AccountMeta(pubkey=trx_accs.collateral_pool_address, is_signer=False, is_writable=True), + AccountMeta(pubkey=operator_token, is_signer=False, is_writable=True), AccountMeta(pubkey=trx_accs.caller_token, is_signer=False, is_writable=True), AccountMeta(pubkey=system, is_signer=False, is_writable=False), @@ -717,8 +744,11 @@ def make_partial_call_or_continue_instruction_0x0d(perm_accs, trx_accs, step_cou ) -def make_continue_instruction(perm_accs, trx_accs, step_count, index=None): - data = bytearray.fromhex("14") + perm_accs.collateral_pool_index_buf + step_count.to_bytes(8, byteorder="little") +def make_continue_instruction(signer, perm_accs, trx_accs, step_count, index=None): + operator = signer.public_key() + operator_token = getTokenAddr(operator) + + data = bytearray.fromhex("14") + trx_accs.collateral_pool_index_buf + step_count.to_bytes(8, byteorder="little") if index: data = data + index.to_bytes(8, byteorder="little") @@ -728,9 +758,9 @@ def make_continue_instruction(perm_accs, trx_accs, step_count, index=None): keys = [ AccountMeta(pubkey=perm_accs.storage, is_signer=False, is_writable=True), - AccountMeta(pubkey=perm_accs.operator, is_signer=True, is_writable=True), - AccountMeta(pubkey=perm_accs.collateral_pool_address, is_signer=False, is_writable=True), - AccountMeta(pubkey=perm_accs.operator_token, is_signer=False, is_writable=True), + AccountMeta(pubkey=operator, is_signer=True, is_writable=True), + AccountMeta(pubkey=trx_accs.collateral_pool_address, is_signer=False, is_writable=True), + AccountMeta(pubkey=operator_token, is_signer=False, is_writable=True), AccountMeta(pubkey=trx_accs.caller_token, is_signer=False, is_writable=True), AccountMeta(pubkey=system, is_signer=False, is_writable=False), @@ -741,17 +771,20 @@ def make_continue_instruction(perm_accs, trx_accs, step_count, index=None): ) -def make_call_from_account_instruction(perm_accs, trx_accs, step_count = 0): +def make_call_from_account_instruction(signer, perm_accs, trx_accs, step_count = 0): + operator = signer.public_key() + operator_token = getTokenAddr(operator) + return TransactionInstruction( program_id = evm_loader_id, - data = bytearray.fromhex("16") + perm_accs.collateral_pool_index_buf + step_count.to_bytes(8, byteorder="little"), + data = bytearray.fromhex("16") + trx_accs.collateral_pool_index_buf + step_count.to_bytes(8, byteorder="little"), keys = [ AccountMeta(pubkey=perm_accs.holder, is_signer=False, is_writable=True), AccountMeta(pubkey=perm_accs.storage, is_signer=False, is_writable=True), - AccountMeta(pubkey=perm_accs.operator, is_signer=True, is_writable=True), - AccountMeta(pubkey=perm_accs.collateral_pool_address, is_signer=False, is_writable=True), - AccountMeta(pubkey=perm_accs.operator_token, is_signer=False, is_writable=True), + AccountMeta(pubkey=operator, is_signer=True, is_writable=True), + AccountMeta(pubkey=trx_accs.collateral_pool_address, is_signer=False, is_writable=True), + AccountMeta(pubkey=operator_token, is_signer=False, is_writable=True), AccountMeta(pubkey=trx_accs.caller_token, is_signer=False, is_writable=True), AccountMeta(pubkey=system, is_signer=False, is_writable=False), @@ -762,15 +795,18 @@ def make_call_from_account_instruction(perm_accs, trx_accs, step_count = 0): ) -def make_05_call_instruction(perm_accs, trx_accs, call_data): +def make_05_call_instruction(signer, trx_accs, call_data): + operator = signer.public_key() + operator_token = getTokenAddr(operator) + return TransactionInstruction( program_id = evm_loader_id, - data = bytearray.fromhex("05") + perm_accs.collateral_pool_index_buf + call_data, + data = bytearray.fromhex("05") + trx_accs.collateral_pool_index_buf + call_data, keys = [ AccountMeta(pubkey=sysinstruct, is_signer=False, is_writable=False), - AccountMeta(pubkey=perm_accs.operator, is_signer=True, is_writable=True), - AccountMeta(pubkey=perm_accs.collateral_pool_address, is_signer=False, is_writable=True), - AccountMeta(pubkey=perm_accs.operator_token, is_signer=False, is_writable=True), + AccountMeta(pubkey=operator, is_signer=True, is_writable=True), + AccountMeta(pubkey=trx_accs.collateral_pool_address, is_signer=False, is_writable=True), + AccountMeta(pubkey=operator_token, is_signer=False, is_writable=True), AccountMeta(pubkey=trx_accs.caller_token, is_signer=False, is_writable=True), AccountMeta(pubkey=system, is_signer=False, is_writable=False), @@ -786,7 +822,7 @@ def simulate_continue_0x0d(signer, client, perm_accs, trx_accs, step_count, msg) blockhash = Blockhash(client.get_recent_blockhash(Confirmed)["result"]["value"]["blockhash"]) trx = Transaction(recent_blockhash = blockhash) for _ in range(continue_count): - trx.add(make_partial_call_or_continue_instruction_0x0d(perm_accs, trx_accs, step_count, msg)) + trx.add(make_partial_call_or_continue_instruction_0x0d(signer, perm_accs, trx_accs, step_count, msg)) trx.sign(signer) try: @@ -834,7 +870,7 @@ def simulate_continue(signer, client, perm_accs, trx_accs, step_count): blockhash = Blockhash(client.get_recent_blockhash(Confirmed)["result"]["value"]["blockhash"]) trx = Transaction(recent_blockhash = blockhash) for _ in range(continue_count): - trx.add(make_continue_instruction(perm_accs, trx_accs, step_count)) + trx.add(make_continue_instruction(signer, perm_accs, trx_accs, step_count)) trx.sign(signer) try: @@ -1026,13 +1062,12 @@ def create_account_list_by_emulate(signer, client, ethTrx): AccountMeta(pubkey=caller_token, is_signer=False, is_writable=True), ] + add_keys_05 - trx_accs = TransactionInfo(caller_token, eth_accounts, ethTrx.nonce) + trx_accs = TransactionInfo(caller_token, eth_accounts, ethTrx) return (trx_accs, sender_ether, trx) def call_signed(signer, client, ethTrx, steps): - perm_accs = PermanentAccounts(client, signer) (trx_accs, sender_ether, create_acc_trx) = create_account_list_by_emulate(signer, client, ethTrx) @@ -1045,7 +1080,7 @@ def call_signed(signer, client, ethTrx, steps): try: logger.debug("Try single trx call") - return call_signed_noniterative(signer, client, ethTrx, perm_accs, trx_accs, msg, create_acc_trx) + return call_signed_noniterative(signer, client, ethTrx, trx_accs, msg, create_acc_trx) except Exception as err: logger.debug(str(err)) if str(err).find("Program failed to complete") >= 0: @@ -1057,13 +1092,18 @@ def call_signed(signer, client, ethTrx, steps): else: raise - if call_from_holder: - return call_signed_with_holder_acc(signer, client, ethTrx, perm_accs, trx_accs, steps, create_acc_trx) - if call_iterative: - if USE_COMBINED_START_CONTINUE: - return call_signed_iterative_0x0d(signer, client, ethTrx, perm_accs, trx_accs, steps, msg, create_acc_trx) - else: - return call_signed_iterative(signer, client, ethTrx, perm_accs, trx_accs, steps, msg, create_acc_trx) + perm_accs = PermanentAccounts(client, signer) + + try: + if call_from_holder: + return call_signed_with_holder_acc(signer, client, ethTrx, perm_accs, trx_accs, steps, create_acc_trx) + if call_iterative: + if USE_COMBINED_START_CONTINUE: + return call_signed_iterative_0x0d(signer, client, ethTrx, perm_accs, trx_accs, steps, msg, create_acc_trx) + else: + return call_signed_iterative(signer, client, ethTrx, perm_accs, trx_accs, steps, msg, create_acc_trx) + finally: + del perm_accs def call_signed_iterative(signer, client, ethTrx, perm_accs, trx_accs, steps, msg, create_acc_trx): @@ -1075,7 +1115,7 @@ def call_signed_iterative(signer, client, ethTrx, perm_accs, trx_accs, steps, ms keys=[ AccountMeta(pubkey=keccakprog, is_signer=False, is_writable=False), ])) - precall_txs.add(make_partial_call_instruction(perm_accs, trx_accs, 0, msg)) + precall_txs.add(make_partial_call_instruction(signer, perm_accs, trx_accs, 0, msg)) logger.debug("Partial call") send_measured_transaction(client, precall_txs, signer) @@ -1092,7 +1132,7 @@ def call_signed_iterative_0x0d(signer, client, ethTrx, perm_accs, trx_accs, step keys=[ AccountMeta(pubkey=keccakprog, is_signer=False, is_writable=False), ])) - precall_txs.add(make_partial_call_or_continue_instruction_0x0d(perm_accs, trx_accs, steps, msg)) + precall_txs.add(make_partial_call_or_continue_instruction_0x0d(signer, perm_accs, trx_accs, steps, msg)) logger.debug("Partial call 0x0d") send_measured_transaction(client, precall_txs, signer) @@ -1100,7 +1140,7 @@ def call_signed_iterative_0x0d(signer, client, ethTrx, perm_accs, trx_accs, step return call_continue_0x0d(signer, client, perm_accs, trx_accs, steps, msg) -def call_signed_noniterative(signer, client, ethTrx, perm_accs, trx_accs, msg, create_acc_trx): +def call_signed_noniterative(signer, client, ethTrx, trx_accs, msg, create_acc_trx): call_txs_05 = Transaction() call_txs_05.add(create_acc_trx) call_txs_05.add(TransactionInstruction( @@ -1109,7 +1149,7 @@ def call_signed_noniterative(signer, client, ethTrx, perm_accs, trx_accs, msg, c keys=[ AccountMeta(pubkey=keccakprog, is_signer=False, is_writable=False), ])) - call_txs_05.add(make_05_call_instruction(perm_accs, trx_accs, msg)) + call_txs_05.add(make_05_call_instruction(signer, trx_accs, msg)) result = send_measured_transaction(client, call_txs_05, signer) return result['result']['transaction']['signatures'][0] @@ -1124,7 +1164,7 @@ def call_signed_with_holder_acc(signer, client, ethTrx, perm_accs, trx_accs, ste send_measured_transaction(client, precall_txs, signer) precall_txs = Transaction() - precall_txs.add(make_call_from_account_instruction(perm_accs, trx_accs)) + precall_txs.add(make_call_from_account_instruction(signer, perm_accs, trx_accs)) # ExecuteTrxFromAccountDataIterative logger.debug("ExecuteTrxFromAccountDataIterative:") From 16752564e4450613b1dcd175d30c88b76982e045 Mon Sep 17 00:00:00 2001 From: Dmitriy Borisenko Date: Thu, 11 Nov 2021 22:48:06 +0300 Subject: [PATCH 06/10] #272 better iterative tests --- .buildkite/steps/build-image.sh | 2 +- Dockerfile | 2 +- proxy/docker-compose-test.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.buildkite/steps/build-image.sh b/.buildkite/steps/build-image.sh index 1492f34ad..0e4243de9 100755 --- a/.buildkite/steps/build-image.sh +++ b/.buildkite/steps/build-image.sh @@ -3,7 +3,7 @@ set -euo pipefail REVISION=$(git rev-parse HEAD) -set ${SOLANA_REVISION:=v1.7.9-resources} +set ${SOLANA_REVISION:=v1.7.9-testnet} set ${EVM_LOADER_REVISION:=latest} # Refreshing neonlabsorg/solana:latest image is required to run .buildkite/steps/build-image.sh locally diff --git a/Dockerfile b/Dockerfile index 05b95bf18..6020dbec4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG SOLANA_REVISION=v1.7.9-resources +ARG SOLANA_REVISION=v1.7.9-testnet ARG EVM_LOADER_REVISION=latest FROM neonlabsorg/solana:${SOLANA_REVISION} AS cli diff --git a/proxy/docker-compose-test.yml b/proxy/docker-compose-test.yml index 55da74629..23e83b3b3 100644 --- a/proxy/docker-compose-test.yml +++ b/proxy/docker-compose-test.yml @@ -3,7 +3,7 @@ version: "2.1" services: solana: container_name: solana - image: neonlabsorg/solana:${SOLANA_REVISION:-v1.7.9-resources} + image: neonlabsorg/solana:${SOLANA_REVISION:-v1.7.9-testnet} environment: SOLANA_URL: http://solana:8899 RUST_LOG: solana_runtime::system_instruction_processor=trace,solana_runtime::message_processor=debug,solana_bpf_loader=debug,solana_rbpf=debug From a7dcb82c9a1117a6330c0c9bad5b0c7acaf07425 Mon Sep 17 00:00:00 2001 From: Dmitriy Borisenko Date: Thu, 11 Nov 2021 23:16:18 +0300 Subject: [PATCH 07/10] #272 merge fix --- proxy/plugin/solana_rest_api_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/plugin/solana_rest_api_tools.py b/proxy/plugin/solana_rest_api_tools.py index 0c985b982..6ebd6dc5c 100644 --- a/proxy/plugin/solana_rest_api_tools.py +++ b/proxy/plugin/solana_rest_api_tools.py @@ -135,7 +135,7 @@ def __del__(self): class TransactionInfo: def __init__(self, caller_token, eth_accounts, eth_trx): - self.ethTrx = eth_trx + self.eth_trx = eth_trx self.caller_token = caller_token self.eth_accounts = eth_accounts From fa54b95da1a2845510589ce2592af1d7923491bf Mon Sep 17 00:00:00 2001 From: Dmitriy Borisenko Date: Thu, 11 Nov 2021 23:34:49 +0300 Subject: [PATCH 08/10] #272 disabe combined instructions --- proxy/plugin/solana_rest_api_tools.py | 2 +- proxy/run-proxy.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/plugin/solana_rest_api_tools.py b/proxy/plugin/solana_rest_api_tools.py index 6ebd6dc5c..a3d4f2b01 100644 --- a/proxy/plugin/solana_rest_api_tools.py +++ b/proxy/plugin/solana_rest_api_tools.py @@ -40,7 +40,7 @@ NEW_USER_AIRDROP_AMOUNT = int(os.environ.get("NEW_USER_AIRDROP_AMOUNT", "0")) location_bin = ".deploy_contract.bin" confirmation_check_delay = float(os.environ.get("NEON_CONFIRMATION_CHECK_DELAY", "0.1")) -USE_COMBINED_START_CONTINUE = os.environ.get("USE_COMBINED_START_CONTINUE", "YES") == "YES" +USE_COMBINED_START_CONTINUE = os.environ.get("USE_COMBINED_START_CONTINUE", "NO") == "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 diff --git a/proxy/run-proxy.sh b/proxy/run-proxy.sh index ac01288a5..262ed2e1e 100755 --- a/proxy/run-proxy.sh +++ b/proxy/run-proxy.sh @@ -10,7 +10,7 @@ if [ "$CONFIG" == "ci" ]; then [[ -z "$NEW_USER_AIRDROP_AMOUNT" ]] && export NEW_USER_AIRDROP_AMOUNT=100 [[ -z "$EXTRA_GAS" ]] && export EXTRA_GAS=100000 [[ -z "$NEON_CLI_TIMEOUT" ]] && export NEON_CLI_TIMEOUT="0.5" - [[ -z "$USE_COMBINED_START_CONTINUE" ]] && export USE_COMBINED_START_CONTINUE="YES" + [[ -z "$USE_COMBINED_START_CONTINUE" ]] && export USE_COMBINED_START_CONTINUE="NO" [[ -z "$CONTINUE_COUNT_FACTOR" ]] && export CONTINUE_COUNT_FACTOR="3" [[ -z "$MINIMAL_GAS_PRICE" ]] && export MINIMAL_GAS_PRICE=0 [[ -z "$POSTGRES_HOST" ]] && export POSTGRES_HOST="postgres" From 40e1cac77f6036e0186fcd5f3f75efef3aee2e1d Mon Sep 17 00:00:00 2001 From: Dmitriy Borisenko Date: Thu, 11 Nov 2021 23:43:03 +0300 Subject: [PATCH 09/10] #272 back to resources --- .buildkite/steps/build-image.sh | 2 +- Dockerfile | 2 +- proxy/docker-compose-test.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.buildkite/steps/build-image.sh b/.buildkite/steps/build-image.sh index 0e4243de9..1492f34ad 100755 --- a/.buildkite/steps/build-image.sh +++ b/.buildkite/steps/build-image.sh @@ -3,7 +3,7 @@ set -euo pipefail REVISION=$(git rev-parse HEAD) -set ${SOLANA_REVISION:=v1.7.9-testnet} +set ${SOLANA_REVISION:=v1.7.9-resources} set ${EVM_LOADER_REVISION:=latest} # Refreshing neonlabsorg/solana:latest image is required to run .buildkite/steps/build-image.sh locally diff --git a/Dockerfile b/Dockerfile index 6020dbec4..05b95bf18 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG SOLANA_REVISION=v1.7.9-testnet +ARG SOLANA_REVISION=v1.7.9-resources ARG EVM_LOADER_REVISION=latest FROM neonlabsorg/solana:${SOLANA_REVISION} AS cli diff --git a/proxy/docker-compose-test.yml b/proxy/docker-compose-test.yml index 890080ca2..ba33fd034 100644 --- a/proxy/docker-compose-test.yml +++ b/proxy/docker-compose-test.yml @@ -3,7 +3,7 @@ version: "2.1" services: solana: container_name: solana - image: neonlabsorg/solana:${SOLANA_REVISION:-v1.7.9-testnet} + image: neonlabsorg/solana:${SOLANA_REVISION:-v1.7.9-resources} environment: SOLANA_URL: http://solana:8899 RUST_LOG: solana_runtime::system_instruction_processor=trace,solana_runtime::message_processor=debug,solana_bpf_loader=debug,solana_rbpf=debug From 494dfafa7fb3a1e2df43b85e7307f131d2a93eaf Mon Sep 17 00:00:00 2001 From: Dmitriy Borisenko Date: Fri, 12 Nov 2021 20:08:30 +0300 Subject: [PATCH 10/10] #272 return tag instead of emptiness flag --- proxy/plugin/solana_rest_api_tools.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/proxy/plugin/solana_rest_api_tools.py b/proxy/plugin/solana_rest_api_tools.py index a3d4f2b01..b4387e998 100644 --- a/proxy/plugin/solana_rest_api_tools.py +++ b/proxy/plugin/solana_rest_api_tools.py @@ -49,6 +49,8 @@ COLLATERALL_POOL_MAX=10 +EMPTY_STORAGE_TAG=0 + sysvarclock = "SysvarC1ock11111111111111111111111111111111" sysinstruct = "Sysvar1nstructions1111111111111111111111111" keccakprog = "KeccakSecp256k11111111111111111111111111111" @@ -191,11 +193,11 @@ def get_account_info(client, storage_account): data = base64.b64decode(info['data'][0]) - empty = True if data[0] == 0 else False + account_tag = data[0] lamports = info['lamports'] owner = info['owner'] - return (empty, lamports, owner) + return (account_tag, lamports, owner) def accountWithSeed(base, seed, program): @@ -268,12 +270,12 @@ def create_multiple_accounts_with_seed(client, funding, base, seeds, sizes): trx.add(createAccountWithSeedTrx(funding.public_key(), base.public_key(), seed, minimum_balance, storage_size, PublicKey(evm_loader_id))) else: - (empty, lamports, owner) = account_info + (tag, lamports, owner) = account_info if lamports < minimum_balance: raise Exception("insufficient balance") if PublicKey(owner) != PublicKey(evm_loader_id): raise Exception("wrong owner") - if not empty: + if tag != EMPTY_STORAGE_TAG: raise Exception("not empty") if len(trx.instructions) > 0: