Skip to content
Prev Previous commit
Next Next commit
Merge branch 'develop' into 307_implement_withdraw_instruction
  • Loading branch information
Ivan Loboda committed Mar 7, 2022
commit 96d32706510dd5fa0dd2e9e913b7c128ba874a74
6 changes: 3 additions & 3 deletions proxy/common_neon/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def ether2program(ether):
return str(pda), nonce


class AccountInfo(NamedTuple):
class AccountInfoLayout(NamedTuple):
ether: eth_keys.PublicKey
balance: int
trx_count: int
Expand All @@ -65,11 +65,11 @@ def is_payed(self) -> bool:
return self.state != 0

@staticmethod
def frombytes(data):
def frombytes(data) -> AccountInfoLayout:
from .layouts import ACCOUNT_INFO_LAYOUT

cont = ACCOUNT_INFO_LAYOUT.parse(data)
return AccountInfo(
return AccountInfoLayout(
ether=cont.ether,
balance=int.from_bytes(cont.balance, "little"),
trx_count=int.from_bytes(cont.trx_count, "little"),
Expand Down
8 changes: 4 additions & 4 deletions proxy/common_neon/transaction_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from solana.blockhash import Blockhash
from solana.account import Account as SolanaAccount

from ..common_neon.address import accountWithSeed, EthereumAddress, ether2program
from .address import accountWithSeed, EthereumAddress, ether2program
from ..common_neon.errors import EthereumError
from .constants import STORAGE_SIZE, EMPTY_STORAGE_TAG, FINALIZED_STORAGE_TAG, ACCOUNT_SEED_VERSION
from .emulator_interactor import call_emulated
Expand Down Expand Up @@ -336,7 +336,7 @@ def _create_ether_account(self) -> PublicKey:
ether_address = self._resource.ether
solana_address = ether2program(ether_address)[0]

account_info = self._s.solana.get_multiple_accounts_info([solana_address])[0]
account_info = self._s.solana.get_account_info(solana_address)
if account_info is not None:
self.debug(f"Use existing ether account for resource {opkey}:{rid}")
return solana_address
Expand All @@ -345,11 +345,11 @@ def _create_ether_account(self) -> PublicKey:
stage = NeonCreateAccountTxStage(self._s, { "address": ether_address })
stage.balance = self._s.solana.get_multiple_rent_exempt_balances_for_size([stage.size])[0]
stage.build()

self.debug(f"Create new accounts for resource {opkey}:{rid}")
SolTxListSender(self._s, [stage.tx], NeonCreateAccountTxStage.NAME).send()

return solana_address
return solana_address

def _create_perm_accounts(self, seed_list):
tx = Transaction()
Expand Down
15 changes: 9 additions & 6 deletions proxy/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,15 @@ def read_sol_account(name) -> Optional[SolanaAccount]:

@logged_group("neon.Proxy")
def get_operator_ethereum_accounts(*, logger) -> [EthereumAddress]:
list = [] # TODO read from config
for _ in range(1, 15):
account = EthereumAddress.random()
list.append(account)

return list
accounts = []

for account in OPERATOR_GAS_ACCOUNTS.split(';'):
address = EthereumAddress(account)
logger.debug(f'Add gas account: {address}')

accounts.append(address)

return accounts

@logged_group("neon.Proxy")
class neon_cli(CliBase):
Expand Down
2 changes: 1 addition & 1 deletion proxy/indexer/airdropper.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def find_instructions(trx, predicate):
# Airdrop triggers on sequence:
# neon.CreateAccount -> neon.CreateERC20TokenAccount -> spl.Transfer (maybe shuffled)
# First: select all instructions that can form such chains
predicate = lambda instr: account_keys[instr['programIdIndex']] == self.evm_loader_id \
predicate = lambda instr: account_keys[instr['programIdIndex']] == EVM_LOADER_ID \
and base58.b58decode(instr['data'])[0] == 0x18
create_acc_list = find_instructions(trx, predicate)

Expand Down
4 changes: 0 additions & 4 deletions proxy/indexer/canceller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import traceback

from logged_groups import logged_group
from solana.rpc.api import Client
from solana.transaction import AccountMeta
from proxy.common_neon.neon_instruction import NeonInstruction
from proxy.common_neon.solana_interactor import SolanaInteractor, SolTxListSender
Expand All @@ -18,9 +17,6 @@ def __init__(self):
self.solana = SolanaInteractor(SOLANA_URL)
self.waiter = None
self._operator = self.signer.public_key()
self._client = Client(SOLANA_URL)

self.solana = SolanaInteractor(self._client)
self.builder = NeonInstruction(self._operator)

def unlock_accounts(self, blocked_storages):
Expand Down
17 changes: 5 additions & 12 deletions proxy/indexer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,8 @@ def get_req_id(self):


@logged_group("neon.Indexer")
def get_accounts_from_storage(client, storage_account, *, logger) -> [(bool, str)]:
opts = {
"encoding": "base64",
"commitment": "confirmed",
"dataSlice": {
"offset": 0,
"length": 2048,
}
}
result = client._provider.make_request("getAccountInfo", str(storage_account), opts)
def get_accounts_from_storage(solana: SolanaInteractor, storage_account, *, logger):
info = solana.get_account_info(storage_account, length=0)
# logger.debug("\n{}".format(json.dumps(result, indent=4, sort_keys=True)))

if info is None:
Expand All @@ -62,10 +54,11 @@ def get_accounts_from_storage(client, storage_account, *, logger) -> [(bool, str
storage = STORAGE_ACCOUNT_INFO_LAYOUT.parse(info.data[1:])
offset = 1 + STORAGE_ACCOUNT_INFO_LAYOUT.sizeof()
for _ in range(storage.accounts_len):
writable = (data[offset] > 0)
writable = (info.data[offset] > 0)
offset += 1

some_pubkey = PublicKey(data[offset:offset + 32])
some_pubkey = PublicKey(info.data[offset:offset + 32])
acc_list.append(str(some_pubkey))
offset += 32

acc_list.append((writable, str(some_pubkey)))
Expand Down
14 changes: 7 additions & 7 deletions proxy/plugin/solana_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from ..http.server import HttpWebServerBasePlugin, httpProtocolTypes
from typing import List, Tuple

from .solana_rest_api_tools import neon_config_load, estimate_gas
from .solana_rest_api_tools import neon_config_load
from ..common_neon.transaction_sender import NeonTxSender
from ..common_neon.solana_interactor import SolanaInteractor, SolTxError
from ..common_neon.address import EthereumAddress
Expand Down Expand Up @@ -128,11 +128,12 @@ def eth_getBalance(self, account, tag):
"""account - address to check for balance.
tag - integer block number, or the string "latest", "earliest" or "pending"
"""
eth_acc = EthereumAddress(account)
self.debug(f'eth_getBalance: {account} {eth_acc}')
self.debug(f'eth_getBalance: {account}')
try:
solana = SolanaInteractor(self._client)
acc_info = solana.get_neon_account_info(eth_acc)
acc_info = self._solana.get_account_info_layout(EthereumAddress(account))
if acc_info is None:
return hex(0)

return hex(acc_info.balance)
except Exception as err:
self.debug(f"eth_getBalance: Can't get account info: {err}")
Expand Down Expand Up @@ -270,8 +271,7 @@ def eth_call(self, obj, tag):
def eth_getTransactionCount(self, account, tag):
self.debug('eth_getTransactionCount: %s', account)
try:
solana = SolanaInteractor(self._client)
acc_info = solana.get_neon_account_info(EthereumAddress(account))
acc_info = self._solana.get_account_info_layout(EthereumAddress(account))
return hex(acc_info.trx_count)
except Exception as err:
self.debug(f"eth_getTransactionCount: Can't get account info: {err}")
Expand Down
23 changes: 1 addition & 22 deletions proxy/plugin/solana_rest_api_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
from solana.publickey import PublicKey
from logged_groups import logged_group

from ..common_neon.address import ether2program, EthereumAddress
from ..common_neon.emulator_interactor import call_emulated
from ..common_neon.utils import get_from_dict
from ..environment import read_elf_params, TIMEOUT_TO_RELOAD_NEON_CONFIG, EXTRA_GAS
from ..environment import read_elf_params, TIMEOUT_TO_RELOAD_NEON_CONFIG


@logged_group("neon.Proxy")
Expand All @@ -29,21 +26,3 @@ def neon_config_load(ethereum_model, *, logger):
'-' \
+ ethereum_model.neon_config_dict['NEON_REVISION']
logger.debug(ethereum_model.neon_config_dict)


def is_account_exists(client: SolanaClient, eth_account: EthereumAddress) -> bool:
pda_account, nonce = ether2program(eth_account)
info = client.get_account_info(pda_account, commitment=Confirmed)
value = get_from_dict(info, "result", "value")
return value is not None


@logged_group("neon.Proxy")
def estimate_gas(contract_id: str, caller_eth_account: EthereumAddress, data: str = None, value: str = None, *, logger):
result = call_emulated(contract_id, str(caller_eth_account), data, value)
used_gas = result.get("used_gas")
if used_gas is None:
logger.error(f"Failed estimate_gas, unexpected result, by contract_id: {contract_id}, caller_eth_account: "
f"{caller_eth_account}, data: {data}, value: {value}, emulation result: {result}")
raise Exception("Bad estimate_gas result")
return used_gas + EXTRA_GAS
2 changes: 1 addition & 1 deletion proxy/testing/test_eth_sendRawTransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def test_06_transfer_one_and_a_half_gweis(self):
bob_balance_after_transfer = proxy.eth.get_balance(eth_account_bob.address)
print('alice_balance_after_transfer:', alice_balance_after_transfer)
print('bob_balance_after_transfer:', bob_balance_after_transfer)
self.assertEqual(alice_balance_after_transfer, alice_balance_before_transfer - one_and_a_half_gweis)
self.assertEqual(alice_balance_after_transfer, alice_balance_before_transfer - one_and_a_half_gweis - gas_cost)
self.assertEqual(bob_balance_after_transfer, bob_balance_before_transfer + one_and_a_half_gweis)

@unittest.skip("a.i.")
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.