Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 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
e3c4e33
#295 fix state
otselnik Nov 24, 2021
9b57e53
#291 iterative combined
otselnik Nov 25, 2021
ccffcf4
#295 do not get measurments
otselnik Nov 25, 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
4546926
Merge branch '291_proxy_refactoring' into 295_iterative_execution
otselnik Nov 25, 2021
7befc6b
#295 turn combined instructions ON
otselnik Nov 29, 2021
b5010f8
#295 make neon_instructions return transasactions
otselnik Nov 29, 2021
5ebf76a
Merge remote-tracking branch 'origin/develop' into 291_proxy_refactoring
otselnik Dec 2, 2021
b464b1e
#291 merge fix
otselnik Dec 2, 2021
79088c6
#295 get rid of `USE_COMBINED_START_CONTINUE`
otselnik Dec 2, 2021
52173a0
Merge branch '291_proxy_refactoring' into 295_iterative_execution
otselnik Dec 2, 2021
4fe15e9
#295 requested fixes
otselnik Dec 2, 2021
607e74e
Merge remote-tracking branch 'origin/develop' into 295_iterative_exec…
otselnik Dec 2, 2021
d9f762a
#295 call_continue_bucked refactoring
otselnik Dec 2, 2021
842ec7d
#295 fix
otselnik Dec 3, 2021
78de121
#295 leave only combined iterative transactions
otselnik Dec 3, 2021
47cf219
#295 move constants into class
otselnik Dec 3, 2021
0eebc1f
#295 refactoring
otselnik Dec 3, 2021
cec7a38
Merge remote-tracking branch 'origin/develop' into 295_iterative_exec…
otselnik Dec 6, 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
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'origin/develop' into 291_proxy_refactoring
  • Loading branch information
otselnik committed Nov 23, 2021
commit 57f3b534f5021d9e171088c86c6f701a740309b4
14 changes: 9 additions & 5 deletions proxy/common_neon/costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ def __new__(cls):
return cls.instance


def update_transaction_cost(receipt, eth_trx, reason=None, extra_sol_trx=False, ):
def update_transaction_cost(receipt, eth_trx, extra_sol_trx=False, reason=None):
cost = receipt['result']['meta']['preBalances'][0] - receipt['result']['meta']['postBalances'][0]

hash = eth_trx.hash_signed().hex()
sender = eth_trx.sender()
to_address = eth_trx.toAddress.hex() if eth_trx.toAddress else "None"
if eth_trx:
hash = eth_trx.hash_signed().hex()
sender = eth_trx.sender()
to_address = eth_trx.toAddress.hex() if eth_trx.toAddress else "None"
else:
hash = None
sender = None
to_address = None

sig = receipt['result']['transaction']['signatures'][0]
used_gas=None
Expand Down
13 changes: 1 addition & 12 deletions proxy/common_neon/emulator_interactor.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import json
import logging
from proxy.environment import neon_cli
from .errors import EthereumError


logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


class EthereumError(Exception):
def __init__(self, code, message, data=None):
self.code = code
self.message = message
self.data = data

def getError(self):
error = {'code': self.code, 'message': self.message}
if self.data: error['data'] = self.data
return error


def call_emulated(contract_id, caller_id, data=None, value=None):
output = emulator(contract_id, caller_id, data, value)
logger.debug("call_emulated %s %s %s %s return %s", contract_id, caller_id, data, value, output)
Expand Down
11 changes: 11 additions & 0 deletions proxy/common_neon/errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
from enum import Enum


class EthereumError(Exception):
def __init__(self, code, message, data=None):
self.code = code
self.message = message
self.data = data

def getError(self):
error = {'code': self.code, 'message': self.message}
if self.data: error['data'] = self.data
return error

class SolanaErrors(Enum):
AccountNotFound = "Invalid param: could not find account"

Expand Down
70 changes: 48 additions & 22 deletions proxy/common_neon/neon_instruction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import struct
import eth_utils
from construct import Bytes, Int8ul, Int64ul
from construct import Struct as cStruct
from solana._layouts.system_instructions import SYSTEM_INSTRUCTIONS_LAYOUT, InstructionType
Expand All @@ -8,9 +9,10 @@
from solana.sysvar import SYSVAR_CLOCK_PUBKEY, SYSVAR_RENT_PUBKEY
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 sha3 import keccak_256

from proxy.environment import evm_loader_id as EVM_LOADER_ID, ETH_TOKEN_MINT_ID , COLLATERAL_POOL_BASE
from proxy.environment import evm_loader_id as EVM_LOADER_ID, ETH_TOKEN_MINT_ID , COLLATERAL_POOL_BASE, NEW_USER_AIRDROP_AMOUNT
from .constants import SYSVAR_INSTRUCTION_PUBKEY, INCINERATOR_PUBKEY, KECCAK_PROGRAM, COLLATERALL_POOL_MAX
from .address import accountWithSeed, ether2program, getTokenAddr

Expand Down Expand Up @@ -148,25 +150,21 @@ def create_account_with_seed_trx(self, seed, lamports, space):
)


def createEtherAccountTrx(self, ether, code_acc=None):
if isinstance(ether, str):
if ether.startswith('0x'): ether = ether[2:]
else: ether = ether.hex()
(sol, nonce) = ether2program(ether)
associated_token = getTokenAddr(PublicKey(sol))
logger.debug('createEtherAccount: {} {} => {}'.format(ether, nonce, sol))
logger.debug('associatedTokenAccount: {}'.format(associated_token))
def make_create_eth_account_trx(self, eth_address, code_acc=None):
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
data=create_account_layout(0, 0, bytes.fromhex(ether), nonce)
data = create_account_layout(0, 0, bytes(eth_address), nonce)
trx = Transaction()
if code_acc is None:
trx.add(TransactionInstruction(
program_id=EVM_LOADER_ID,
data=data,
keys=[
AccountMeta(pubkey=base, is_signer=True, is_writable=True),
AccountMeta(pubkey=PublicKey(sol), is_signer=False, is_writable=True),
AccountMeta(pubkey=associated_token, is_signer=False, is_writable=True),
AccountMeta(pubkey=PublicKey(solana_address), is_signer=False, is_writable=True),
AccountMeta(pubkey=token_acc_address, is_signer=False, is_writable=True),
AccountMeta(pubkey=SYS_PROGRAM_ID, is_signer=False, is_writable=False),
AccountMeta(pubkey=ETH_TOKEN_MINT_ID, is_signer=False, is_writable=False),
AccountMeta(pubkey=TOKEN_PROGRAM_ID, is_signer=False, is_writable=False),
Expand All @@ -179,19 +177,19 @@ def createEtherAccountTrx(self, ether, code_acc=None):
data=data,
keys=[
AccountMeta(pubkey=base, is_signer=True, is_writable=True),
AccountMeta(pubkey=PublicKey(sol), is_signer=False, is_writable=True),
AccountMeta(pubkey=associated_token, is_signer=False, is_writable=True),
AccountMeta(pubkey=PublicKey(solana_address), is_signer=False, is_writable=True),
AccountMeta(pubkey=token_acc_address, is_signer=False, is_writable=True),
AccountMeta(pubkey=PublicKey(code_acc), is_signer=False, is_writable=True),
AccountMeta(pubkey=SYS_PROGRAM_ID, is_signer=False, is_writable=False),
AccountMeta(pubkey=ETH_TOKEN_MINT_ID, is_signer=False, is_writable=False),
AccountMeta(pubkey=TOKEN_PROGRAM_ID, is_signer=False, is_writable=False),
AccountMeta(pubkey=ASSOCIATED_TOKEN_PROGRAM_ID, is_signer=False, is_writable=False),
AccountMeta(pubkey=SYSVAR_RENT_PUBKEY, is_signer=False, is_writable=False),
]))
return (trx, sol, associated_token)
return trx, token_acc_address


def createERC20TokenAccountTrx(self, token_info):
def createERC20TokenAccountTrx(self, token_info) -> Transaction:
trx = Transaction()
trx.add(TransactionInstruction(
program_id=EVM_LOADER_ID,
Expand All @@ -211,7 +209,35 @@ def createERC20TokenAccountTrx(self, token_info):
return trx


def make_write_transaction(self, offset: int, data: bytes):
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,
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: "
f"{associated_token_account}, owned by: {associated_token_account} , value: {NEW_USER_AIRDROP_AMOUNT}")
return transfer_instruction


def 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)
if NEW_USER_AIRDROP_AMOUNT <= 0:
return trx
transfer_instruction = self.make_transfer_instruction(associated_token_account)
trx.add(transfer_instruction)

return trx


def make_write_transaction(self, offset: int, data: bytes) -> Transaction:
return Transaction().add(TransactionInstruction(
program_id=EVM_LOADER_ID,
data=write_holder_layout(self.perm_accs_id, offset, data),
Expand All @@ -222,7 +248,7 @@ def make_write_transaction(self, offset: int, data: bytes):
))


def make_keccak_instruction(self, check_instruction_index, msg_len, data_start):
def make_keccak_instruction(self, check_instruction_index, msg_len, data_start) -> TransactionInstruction:
return TransactionInstruction(
program_id=KECCAK_PROGRAM,
data=make_keccak_instruction_data(check_instruction_index, msg_len, data_start),
Expand All @@ -232,7 +258,7 @@ def make_keccak_instruction(self, check_instruction_index, msg_len, data_start):
)


def make_05_call_instruction(self):
def make_05_call_instruction(self) -> TransactionInstruction:
return TransactionInstruction(
program_id = EVM_LOADER_ID,
data = bytearray.fromhex("05") + self.collateral_pool_index_buf + self.msg,
Expand All @@ -255,7 +281,7 @@ def make_noniterative_call_transaction(self, length_before: int = 0) -> Transact
return trx


def make_partial_call_instruction(self):
def make_partial_call_instruction(self) -> TransactionInstruction:
return TransactionInstruction(
program_id = EVM_LOADER_ID,
data = bytearray.fromhex("13") + self.collateral_pool_index_buf + int(0).to_bytes(8, byteorder="little") + self.msg,
Expand Down Expand Up @@ -304,7 +330,7 @@ def make_call_from_account_instruction(self) -> Transaction:
))


def make_continue_instruction(self, steps, index=None):
def make_continue_instruction(self, steps, index=None) -> Transaction:
data = bytearray.fromhex("14") + self.collateral_pool_index_buf + steps.to_bytes(8, byteorder="little")
if index:
data = data + index.to_bytes(8, byteorder="little")
Expand All @@ -328,7 +354,7 @@ def make_continue_instruction(self, steps, index=None):
))


def make_cancel_instruction(self):
def make_cancel_instruction(self) -> Transaction:
return Transaction().add(TransactionInstruction(
program_id = EVM_LOADER_ID,
data = bytearray.fromhex("15") + self.eth_trx.nonce.to_bytes(8, 'little'),
Expand Down
24 changes: 12 additions & 12 deletions proxy/plugin/solana_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,36 @@
:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
"""
from typing import List, Tuple, Optional
import copy
import json
import unittest
import eth_utils
import rlp
import solana
import os
import logging
from typing import List, Tuple, Optional
from solana.account import Account as sol_Account
from ..common.utils import socket_connection, text_, build_http_response
from ..common.utils import build_http_response
from ..http.codes import httpStatusCodes
from ..http.parser import HttpParser
from ..http.websocket import WebsocketFrame
from ..http.server import HttpWebServerBasePlugin, httpProtocolTypes
from .eth_proto import Trx as EthTrx
from solana.rpc.api import Client as SolanaClient
from solana.rpc.api import Client as SolanaClient, SendTransactionError as SolanaTrxError
import base58
import traceback
import threading
from .solana_rest_api_tools import getTokens, getAccountInfo, \
call_signed, neon_config_load
from solana.rpc.commitment import Commitment, Confirmed
from .solana_rest_api_tools import getAccountInfo, \
call_signed, neon_config_load, get_token_balance_or_airdrop
from solana.rpc.commitment import Confirmed
from web3 import Web3
import logging
from ..core.acceptor.pool import proxy_id_glob
import os
from proxy.core.acceptor.pool import proxy_id_glob
from proxy.indexer.utils import get_trx_results, LogDB
from proxy.indexer.sql_dict import SQLDict
from proxy.environment import evm_loader_id, solana_cli, solana_url, MINIMAL_GAS_PRICE
from proxy.common_neon.emulator_interactor import EthereumError, call_emulated
from proxy.environment import neon_cli, solana_cli, solana_url, MINIMAL_GAS_PRICE
from proxy.common_neon.emulator_interactor import call_emulated
from proxy.common_neon.address import EthereumAddress
from proxy.common_neon.errors import EthereumError

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.