Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
90a4e56
#291 extract transaction sender class
otselnik Nov 14, 2021
143913b
#291 move perm accs to transaction sender
otselnik Nov 16, 2021
16c9bff
#291 fix state
otselnik Nov 22, 2021
f2c0303
#291 fix errors
otselnik Nov 23, 2021
57f3b53
Merge remote-tracking branch 'origin/develop' into 291_proxy_refactoring
otselnik Nov 23, 2021
3369f67
#291 merge fixes
otselnik Nov 23, 2021
af721bb
#291 refactoring
otselnik Nov 23, 2021
e512bb8
#291 move EXTRA_GAS to environment
otselnik Nov 23, 2021
8dc5e29
#291 capitalize CONFIRMATION_CHECK_DELAY
otselnik Nov 23, 2021
8dce2a5
#291 sort imports
otselnik Nov 23, 2021
cef8f21
#291 relative paths
otselnik Nov 24, 2021
1bf8383
#291 Should be fixed in #326
otselnik Nov 24, 2021
9672438
#291 testing chnages
otselnik Nov 24, 2021
2d42b73
fix storage account check
sinev-valentine Nov 24, 2021
ac2755c
Merge remote-tracking branch 'origin/develop' into 291_proxy_refactoring
otselnik Nov 24, 2021
3519c61
Merge branch '371_add_FinalizedStorage_to_check' into 291_proxy_refac…
otselnik Nov 24, 2021
bf313a2
#291 rename `trx_with_create_and_airdrop` -> `make_trx_with_create_an…
otselnik Nov 24, 2021
3093fcc
Merge remote-tracking branch 'origin/develop' into 291_proxy_refactoring
otselnik Nov 24, 2021
4d685db
#291 pull request fixes
otselnik Nov 25, 2021
6f63338
Merge remote-tracking branch 'origin/develop' into 291_proxy_refactoring
otselnik Nov 25, 2021
5ebf76a
Merge remote-tracking branch 'origin/develop' into 291_proxy_refactoring
otselnik Dec 2, 2021
b464b1e
#291 merge fix
otselnik Dec 2, 2021
75c8e9a
#291 rename operator and associated token accounts
otselnik Dec 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions proxy/common_neon/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ def __repr__(self):
def __bytes__(self): return self.data


def accountWithSeed(base, seed, program=PublicKey(EVM_LOADER_ID)):
result = PublicKey(sha256(bytes(base) + bytes(seed) + bytes(program)).digest())
logger.debug('accountWithSeed %s', str(result))
def accountWithSeed(base, seed):
result = PublicKey(sha256(bytes(base) + bytes(seed) + bytes(PublicKey(EVM_LOADER_ID))).digest())
return result


Expand Down
58 changes: 29 additions & 29 deletions proxy/common_neon/neon_instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
from solana.transaction import AccountMeta, TransactionInstruction, Transaction
from spl.token.constants import ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID
from spl.token.instructions import transfer2, Transfer2Params
from typing import Tuple

from .address import accountWithSeed, ether2program, getTokenAddr
from .address import accountWithSeed, ether2program, getTokenAddr, EthereumAddress
from .constants import SYSVAR_INSTRUCTION_PUBKEY, INCINERATOR_PUBKEY, KECCAK_PROGRAM, COLLATERALL_POOL_MAX
from .layouts import CREATE_ACCOUNT_LAYOUT
from ..environment import EVM_LOADER_ID, ETH_TOKEN_MINT_ID , COLLATERAL_POOL_BASE, NEW_USER_AIRDROP_AMOUNT
Expand Down Expand Up @@ -86,8 +87,8 @@ def make_keccak_instruction_data(check_instruction_index, msg_len, data_start):

class NeonInstruction:
def __init__(self, operator):
self.operator = operator
self.operator_token = getTokenAddr(self.operator)
self.operator_pda_account = operator
self.operator_associated_token_address = getTokenAddr(self.operator_pda_account)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest renaming back.
We can talk about PDA (Program Derived Address) account only when it is built this way. For the operator's account, it's not correct, because the operator uses their own Solana account, which can't be PDA. So, this name confuse.
Which information gives operator_associated_token_address? I think operator_neon_balance will be better in this case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right!
I propose instead of associated_token_address use operator_neon_address here and neon_address everywhere it is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, what in the end?
operator_associated_token_address -> operator_neon_balance
associated_token_address -> neon_address or neon_balance?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

operator_neon_address i think. getTokenAddr actually doesn't return a balance )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's stop on operator_neon_address



def init_eth_trx(self, eth_trx, eth_accounts, caller_token):
Expand All @@ -113,33 +114,33 @@ def init_iterative(self, storage, holder, perm_accs_id):

return self


def create_collateral_pool_address(self, collateral_pool_index):
@staticmethod
def create_collateral_pool_address(collateral_pool_index):
COLLATERAL_SEED_PREFIX = "collateral_seed_"
seed = COLLATERAL_SEED_PREFIX + str(collateral_pool_index)
return accountWithSeed(PublicKey(COLLATERAL_POOL_BASE), str.encode(seed))


def create_account_with_seed_trx(self, account, seed, lamports, space):
seed_str = str(seed, 'utf8')
logger.debug("createAccountWithSeedTrx base(%s) account(%s) seed(%s)", type(self.operator),account, seed_str)
logger.debug("createAccountWithSeedTrx base(%s) account(%s) seed(%s)", type(self.operator_pda_account),account, seed_str)
return TransactionInstruction(
keys=[
AccountMeta(pubkey=self.operator, is_signer=True, is_writable=True),
AccountMeta(pubkey=self.operator_pda_account, is_signer=True, is_writable=True),
AccountMeta(pubkey=account, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.operator, is_signer=True, is_writable=False),
AccountMeta(pubkey=self.operator_pda_account, is_signer=True, is_writable=False),
],
program_id=SYS_PROGRAM_ID,
data=create_account_with_seed_layout(self.operator, seed_str, lamports, space)
data=create_account_with_seed_layout(self.operator_pda_account, seed_str, lamports, space)
)


def make_create_eth_account_trx(self, eth_address, code_acc=None):
def make_create_eth_account_trx(self, eth_address: EthereumAddress, code_acc=None) -> Tuple[Transaction, PublicKey]:
solana_address, nonce = ether2program(eth_address)
token_acc_address = getTokenAddr(PublicKey(solana_address))
logger.debug(f'Create eth account: {eth_address}, sol account: {solana_address}, token_acc_address: {token_acc_address}, nonce: {nonce}')

base = self.operator
base = self.operator_pda_account
data = create_account_layout(0, 0, bytes(eth_address), nonce)
trx = Transaction()
if code_acc is None:
Expand Down Expand Up @@ -180,7 +181,7 @@ def createERC20TokenAccountTrx(self, token_info) -> Transaction:
program_id=EVM_LOADER_ID,
data=bytes.fromhex('0F'),
keys=[
AccountMeta(pubkey=self.operator, is_signer=True, is_writable=True),
AccountMeta(pubkey=self.operator_pda_account, is_signer=True, is_writable=True),
AccountMeta(pubkey=PublicKey(token_info["key"]), is_signer=False, is_writable=True),
AccountMeta(pubkey=PublicKey(token_info["owner"]), is_signer=False, is_writable=True),
AccountMeta(pubkey=PublicKey(token_info["contract"]), is_signer=False, is_writable=True),
Expand All @@ -195,22 +196,21 @@ def createERC20TokenAccountTrx(self, token_info) -> Transaction:


def make_transfer_instruction(self, associated_token_account: PublicKey) -> TransactionInstruction:
owner_associated_token_account = getTokenAddr(self.operator)
transfer_instruction = transfer2(Transfer2Params(
source=owner_associated_token_account,
owner=self.operator,
source=self.operator_associated_token_address,
owner=self.operator_pda_account,
dest=associated_token_account,
amount=NEW_USER_AIRDROP_AMOUNT * eth_utils.denoms.gwei,
decimals=9,
mint=ETH_TOKEN_MINT_ID,
program_id=TOKEN_PROGRAM_ID
))
logger.debug(f"Token transfer from token: {owner_associated_token_account}, owned by: {self.operator}, to token: "
logger.debug(f"Token transfer from token: {self.operator_associated_token_address}, owned by: {self.operator_pda_account}, to token: "
f"{associated_token_account}, owned by: {associated_token_account} , value: {NEW_USER_AIRDROP_AMOUNT}")
return transfer_instruction


def make_trx_with_create_and_airdrop (self, eth_account, code_acc=None) -> Transaction:
def make_trx_with_create_and_airdrop(self, eth_account, code_acc=None) -> Transaction:
trx = Transaction()
create_trx, associated_token_account = self.make_create_eth_account_trx(eth_account, code_acc)
trx.add(create_trx)
Expand All @@ -234,7 +234,7 @@ def make_resize_instruction(self, acc_desc, code_account_new, seed) -> Transacti
AccountMeta(pubkey=PublicKey("11111111111111111111111111111111"), is_signer=False, is_writable=False)
),
AccountMeta(pubkey=code_account_new, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.operator, is_signer=True, is_writable=False)
AccountMeta(pubkey=self.operator_pda_account, is_signer=True, is_writable=False)
],
)

Expand All @@ -245,7 +245,7 @@ def make_write_transaction(self, offset: int, data: bytes) -> Transaction:
data=write_holder_layout(self.perm_accs_id, offset, data),
keys=[
AccountMeta(pubkey=self.holder, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.operator, is_signer=True, is_writable=False),
AccountMeta(pubkey=self.operator_pda_account, is_signer=True, is_writable=False),
]
))

Expand All @@ -266,9 +266,9 @@ def make_05_call_instruction(self) -> TransactionInstruction:
data = bytearray.fromhex("05") + self.collateral_pool_index_buf + self.msg,
keys = [
AccountMeta(pubkey=SYSVAR_INSTRUCTION_PUBKEY, is_signer=False, is_writable=False),
AccountMeta(pubkey=self.operator, is_signer=True, is_writable=True),
AccountMeta(pubkey=self.operator_pda_account, is_signer=True, is_writable=True),
AccountMeta(pubkey=self.collateral_pool_address, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.operator_token, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.operator_associated_token_address, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.caller_token, is_signer=False, is_writable=True),
AccountMeta(pubkey=SYS_PROGRAM_ID, is_signer=False, is_writable=False),

Expand All @@ -291,9 +291,9 @@ def make_partial_call_instruction(self) -> TransactionInstruction:
AccountMeta(pubkey=self.storage, is_signer=False, is_writable=True),

AccountMeta(pubkey=SYSVAR_INSTRUCTION_PUBKEY, is_signer=False, is_writable=False),
AccountMeta(pubkey=self.operator, is_signer=True, is_writable=True),
AccountMeta(pubkey=self.operator_pda_account, is_signer=True, is_writable=True),
AccountMeta(pubkey=self.collateral_pool_address, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.operator_token, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.operator_associated_token_address, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.caller_token, is_signer=False, is_writable=True),
AccountMeta(pubkey=SYS_PROGRAM_ID, is_signer=False, is_writable=False),

Expand All @@ -319,9 +319,9 @@ def make_call_from_account_instruction(self) -> Transaction:
AccountMeta(pubkey=self.holder, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.storage, is_signer=False, is_writable=True),

AccountMeta(pubkey=self.operator, is_signer=True, is_writable=True),
AccountMeta(pubkey=self.operator_pda_account, is_signer=True, is_writable=True),
AccountMeta(pubkey=self.collateral_pool_address, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.operator_token, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.operator_associated_token_address, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.caller_token, is_signer=False, is_writable=True),
AccountMeta(pubkey=SYS_PROGRAM_ID, is_signer=False, is_writable=False),

Expand All @@ -343,9 +343,9 @@ def make_continue_instruction(self, steps, index=None) -> Transaction:
keys = [
AccountMeta(pubkey=self.storage, is_signer=False, is_writable=True),

AccountMeta(pubkey=self.operator, is_signer=True, is_writable=True),
AccountMeta(pubkey=self.operator_pda_account, is_signer=True, is_writable=True),
AccountMeta(pubkey=self.collateral_pool_address, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.operator_token, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.operator_associated_token_address, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.caller_token, is_signer=False, is_writable=True),
AccountMeta(pubkey=SYS_PROGRAM_ID, is_signer=False, is_writable=False),

Expand All @@ -362,8 +362,8 @@ def make_cancel_instruction(self) -> Transaction:
data = bytearray.fromhex("15") + self.eth_trx.nonce.to_bytes(8, 'little'),
keys = [
AccountMeta(pubkey=self.storage, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.operator, is_signer=True, is_writable=True),
AccountMeta(pubkey=self.operator_token, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.operator_pda_account, is_signer=True, is_writable=True),
AccountMeta(pubkey=self.operator_associated_token_address, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.caller_token, is_signer=False, is_writable=True),
AccountMeta(pubkey=INCINERATOR_PUBKEY, is_signer=False, is_writable=True),
AccountMeta(pubkey=SYS_PROGRAM_ID, is_signer=False, is_writable=False),
Expand Down
7 changes: 2 additions & 5 deletions proxy/common_neon/solana_interactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,10 @@ def confirm_transaction(self, tx_sig, confirmations=0):
status = resp['result']['value'][0]
if status and (status['confirmationStatus'] == 'finalized' or \
status['confirmationStatus'] == 'confirmed' and status['confirmations'] >= confirmations):
# logger.debug('Confirmed transaction:', resp)
return
time.sleep(CONFIRMATION_CHECK_DELAY)
elapsed_time += CONFIRMATION_CHECK_DELAY
#if not resp["result"]:
raise RuntimeError("could not confirm transaction: ", tx_sig)
#return resp


def collect_results(self, receipts, eth_trx=None, reason=None):
Expand All @@ -132,8 +129,8 @@ def collect_results(self, receipts, eth_trx=None, reason=None):
results.append(self.collect_result(rcpt, eth_trx, reason))
return results


def extract_measurements_from_receipt(self, receipt):
@staticmethod
def extract_measurements_from_receipt(receipt):
log_messages = receipt['result']['meta']['logMessages']
transaction = receipt['result']['transaction']
accounts = transaction['message']['accountKeys']
Expand Down
6 changes: 2 additions & 4 deletions proxy/common_neon/transaction_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ def create_account_list_by_emulate(self):
resize_instr = []
for acc_desc in output_json["accounts"]:
if acc_desc["new"] == False:

address = bytes.fromhex(acc_desc["address"][2:])
if acc_desc["code_size_current"] is not None and acc_desc["code_size"] is not None:
if acc_desc["code_size"] > acc_desc["code_size_current"]:
code_size = acc_desc["code_size"] + 2048
Expand Down Expand Up @@ -255,7 +253,7 @@ def create_account_list_by_emulate(self):
# add_keys_05.append(AccountMeta(pubkey=code_account, is_signer=False, is_writable=acc_desc["writable"]))
code_account_writable = acc_desc["writable"]

create_trx = self.instruction.make_trx_with_create_and_airdrop (address, code_account)
create_trx = self.instruction.make_trx_with_create_and_airdrop(address, code_account)
self.create_acc_trx.add(create_trx)

if address == to_address:
Expand Down Expand Up @@ -393,7 +391,7 @@ def call_continue_step_by_step(self):
logger.debug("Continue iterative step:")
result = self.call_continue_step()
signature = check_if_continue_returned(result)
if signature:
if signature is not None:
return signature
Copy link
Contributor

@rozhkovdmitrii rozhkovdmitrii Nov 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as return check_if_continue_returned(result)?

In other case you should check it like that:

if signature is not None:

and return None explicitly



Expand Down
11 changes: 1 addition & 10 deletions proxy/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,7 @@ def version(self):
raise

def read_elf_params(out_dict):
logger.debug('load for solana_url={} and evm_loader_id={}'.format(SOLANA_URL, EVM_LOADER_ID))
res = solana_cli().call('program', 'dump', EVM_LOADER_ID, './evm_loader.dump')
substr = "Wrote program to "
path = ""
for line in res.splitlines():
if line.startswith(substr):
path = line[len(substr):].strip()
if path == "":
raise Exception("cannot program dump for ", EVM_LOADER_ID)
for param in neon_cli().call("neon-elf-params", path).splitlines():
for param in neon_cli().call("neon-elf-params").splitlines():
if param.startswith('NEON_') and '=' in param:
v = param.split('=')
out_dict[v[0]] = v[1]
Expand Down
Loading