Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8d079ed
introduce logged_based
Dec 27, 2021
4b609b1
Get used with logged_group
Dec 29, 2021
a63d17d
Provide logged group on the rest of code base
Dec 29, 2021
4c3ffad
Merge remote-tracking branch 'origin/develop' into 422_introduce_logg…
Dec 29, 2021
b4eda35
Add Airdropper logged_group
Dec 29, 2021
8275f07
Spit and polish
Dec 29, 2021
b3ecaae
Spit and polish
Dec 29, 2021
c8d51ff
Spit and polish
Dec 29, 2021
e5854f4
Spit and polish
Dec 29, 2021
1c36d89
Spit and polish
Dec 29, 2021
bea6cfa
Spit and polish
Dec 29, 2021
465754e
Spit and polish
Dec 29, 2021
f7a055a
rollback proxy.py
Dec 29, 2021
c345177
spit and polish
Dec 29, 2021
ab79eb0
Remove log_level param from airdropper
Dec 29, 2021
76f914e
Spit and polish
Dec 29, 2021
c5cbdba
Fix indexer base init error
Dec 29, 2021
ee87cb7
Fix indexer base init error
Dec 29, 2021
1218d78
Reduce Airdropper level
Dec 30, 2021
523e44f
roll back get_measurements prefix
Dec 30, 2021
dcdf481
Get logged-groups package from different place
Dec 30, 2021
13242b0
install git to resolve python dependency
Dec 30, 2021
b32b936
Spit on Dockerfile and polish
Dec 30, 2021
35a51b7
Fix get_measurements errors parsig command
Dec 30, 2021
5372136
Merge remote-tracking branch 'origin/develop' into 422_introduce_logg…
Dec 30, 2021
125c56e
Polish after merge
Dec 30, 2021
3f759ac
Fix
Dec 30, 2021
3862077
fix
Dec 30, 2021
a7b1de2
fix
Dec 30, 2021
ed83fe6
Merge branch 'develop' into 422_introduce_logged_groups
Jan 10, 2022
440ba11
fix
Jan 10, 2022
7989afb
fix
Jan 10, 2022
ccdd299
spit and polish
Jan 10, 2022
0b81aca
fix errors
Jan 11, 2022
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
Get used with logged_group
  • Loading branch information
rozhkovdmitrii committed Dec 29, 2021
commit 4b609b1df5cf2f50c607749bda033b7e3fd5a2a8
7 changes: 4 additions & 3 deletions log_cfg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"format": null,
"format": "%(asctime)23s %(levelname)8s %(process)6d:%(threadName)-10s %(class)20s:%(class_id)-8s %(message)s",
"colored": true,
"groups": {
"Indexer": "DEBUG"
"logged_groups": {
"Indexer": "CRITICAL",
"Proxy": "DEBUG"
}
}
5 changes: 0 additions & 5 deletions proxy/common_neon/address.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import random

from eth_keys import keys as eth_keys
Expand All @@ -11,10 +10,6 @@
from ..environment import neon_cli, ETH_TOKEN_MINT_ID, EVM_LOADER_ID


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


class EthereumAddress:
def __init__(self, data, private=None):
if isinstance(data, str):
Expand Down
9 changes: 3 additions & 6 deletions proxy/common_neon/emulator_interactor.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import json
import logging
from logged_groups import logged_group

from .errors import EthereumError
from ..environment import neon_cli


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


def call_emulated(contract_id, caller_id, data=None, value=None):
@logged_group("Proxy")
def call_emulated(contract_id, caller_id, data=None, value=None, *, logger):
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)
result = json.loads(output)
Expand Down
11 changes: 5 additions & 6 deletions proxy/common_neon/neon_instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
from ..environment import EVM_LOADER_ID, ETH_TOKEN_MINT_ID , COLLATERAL_POOL_BASE, NEW_USER_AIRDROP_AMOUNT


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

from logged_groups import logged_group

obligatory_accounts = [
AccountMeta(pubkey=EVM_LOADER_ID, is_signer=False, is_writable=False),
Expand Down Expand Up @@ -83,6 +81,7 @@ def make_keccak_instruction_data(check_instruction_index, msg_len, data_start):
return data


@logged_group("Proxy")
class NeonInstruction:
def __init__(self, operator):
self.operator_account = operator
Expand Down Expand Up @@ -121,7 +120,7 @@ def create_collateral_pool_address(collateral_pool_index):

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),account, seed_str)
self.debug("createAccountWithSeedTrx base(%s) account(%s) seed(%s)", type(self.operator_account),account, seed_str)
return TransactionInstruction(
keys=[
AccountMeta(pubkey=self.operator_account, is_signer=True, is_writable=True),
Expand All @@ -136,7 +135,7 @@ def create_account_with_seed_trx(self, account, seed, lamports, space):
def make_create_eth_account_trx(self, eth_address: EthereumAddress, code_acc=None) -> Tuple[Transaction, PublicKey]:
pda_account, nonce = ether2program(eth_address)
neon_token_account = getTokenAddr(PublicKey(pda_account))
logger.debug(f'Create eth account: {eth_address}, sol account: {pda_account}, neon_token_account: {neon_token_account}, nonce: {nonce}')
self.debug(f'Create eth account: {eth_address}, sol account: {pda_account}, neon_token_account: {neon_token_account}, nonce: {nonce}')

base = self.operator_account
data = create_account_layout(0, 0, bytes(eth_address), nonce)
Expand Down Expand Up @@ -203,7 +202,7 @@ def make_transfer_instruction(self, associated_token_account: PublicKey) -> Tran
mint=ETH_TOKEN_MINT_ID,
program_id=TOKEN_PROGRAM_ID
))
logger.debug(f"Token transfer from token: {self.operator_neon_address}, owned by: {self.operator_account}, to token: "
self.debug(f"Token transfer from token: {self.operator_neon_address}, owned by: {self.operator_account}, to token: "
f"{associated_token_account}, owned by: {associated_token_account} , value: {NEW_USER_AIRDROP_AMOUNT}")
return transfer_instruction

Expand Down
75 changes: 36 additions & 39 deletions proxy/common_neon/transaction_sender.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import logging
import math
import os
import rlp
Expand All @@ -11,6 +10,7 @@
from solana.rpc.api import SendTransactionError
from solana.sysvar import *
from solana.transaction import AccountMeta, Transaction
from logged_groups import logged_group

from ..core.acceptor.pool import new_acc_id_glob, acc_list_glob

Expand All @@ -25,10 +25,7 @@
from ..plugin.eth_proto import Trx as EthTrx


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


@logged_group("Proxy")
class TransactionSender:
def __init__(self, solana_interactor: SolanaInteractor, eth_trx: EthTrx, steps: int) -> None:
self.sender = solana_interactor
Expand All @@ -50,16 +47,16 @@ def execute(self):
call_from_holder = True
else:
try:
logger.debug("Try single trx call")
self.debug("Try single trx call")
return noniterative_executor.call_signed_noniterative()
except Exception as err:
logger.debug(str(err))
self.debug(str(err))
errStr = str(err)
if "Program failed to complete" in errStr or "Computational budget exceeded" in errStr:
logger.debug("Program exceeded instructions")
self.debug("Program exceeded instructions")
call_iterative = True
elif str(err).startswith("transaction too large:"):
logger.debug("Transaction too large, call call_signed_with_holder_acc():")
self.debug("Transaction too large, call call_signed_with_holder_acc():")
call_from_holder = True
else:
raise
Expand All @@ -71,9 +68,9 @@ def execute(self):
try:
return iterative_executor.call_signed_iterative_combined()
except Exception as err:
logger.debug(str(err))
self.debug(str(err))
if str(err).startswith("transaction too large:"):
logger.debug("Transaction too large, call call_signed_with_holder_acc():")
self.debug("Transaction too large, call call_signed_with_holder_acc():")
call_from_holder = True
else:
raise
Expand Down Expand Up @@ -107,7 +104,7 @@ def init_perm_accs(self):
self.perm_accs_id = new_acc_id_glob.value
new_acc_id_glob.value += 1

logger.debug("LOCK RESOURCES {}".format(self.perm_accs_id))
self.debug("LOCK RESOURCES {}".format(self.perm_accs_id))

acc_id_bytes = self.perm_accs_id.to_bytes((self.perm_accs_id.bit_length() + 7) // 8, 'big')

Expand All @@ -123,13 +120,13 @@ def init_perm_accs(self):
sizes=[STORAGE_SIZE, STORAGE_SIZE]
)
except Exception as err:
logger.warn("Account is locked err({}) id({}) owner({})".format(str(err), self.perm_accs_id, self.sender.get_operator_key()))
self.warn("Account is locked err({}) id({}) owner({})".format(str(err), self.perm_accs_id, self.sender.get_operator_key()))
else:
break


def free_perm_accs(self):
logger.debug("FREE RESOURCES {}".format(self.perm_accs_id))
self.debug("FREE RESOURCES {}".format(self.perm_accs_id))
with new_acc_id_glob.get_lock():
acc_list_glob.append(self.perm_accs_id)

Expand All @@ -139,7 +136,7 @@ def create_account_with_seed(self, seed, storage_size):

if self.sender.get_sol_balance(account) == 0:
minimum_balance = self.sender.get_rent_exempt_balance_for_size(storage_size)
logger.debug("Minimum balance required for account {}".format(minimum_balance))
self.debug("Minimum balance required for account {}".format(minimum_balance))

trx = Transaction()
trx.add(self.instruction.create_account_with_seed_trx(account, seed, minimum_balance, storage_size))
Expand All @@ -160,7 +157,7 @@ def create_multiple_accounts_with_seed(self, seeds, sizes):

account_info = self.sender.get_account_info(account)
if account_info is None:
logger.debug("Minimum balance required for account {}".format(minimum_balance))
self.debug("Minimum balance required for account {}".format(minimum_balance))

trx.add(self.instruction.create_account_with_seed_trx(account, seed, minimum_balance, storage_size))
else:
Expand Down Expand Up @@ -190,11 +187,11 @@ def create_account_list_by_emulate(self):
to_address_arg = self.eth_trx.toAddress.hex()
to_address = self.eth_trx.toAddress

logger.debug("send_addr: %s", self.eth_trx.sender())
logger.debug("dest_addr: %s", to_address.hex())
self.debug("send_addr: %s", self.eth_trx.sender())
self.debug("dest_addr: %s", to_address.hex())

output_json = call_emulated(to_address_arg, sender_ether.hex(), self.eth_trx.callData.hex(), hex(self.eth_trx.value))
logger.debug("emulator returns: %s", json.dumps(output_json, indent=3))
self.debug("emulator returns: %s", json.dumps(output_json, indent=3))

# resize storage account
resize_instr = []
Expand All @@ -206,30 +203,30 @@ def create_account_list_by_emulate(self):
seed = b58encode(ACCOUNT_SEED_VERSION + os.urandom(20))
code_account_new = accountWithSeed(self.sender.get_operator_key(), seed)

logger.debug("creating new code_account with increased size %s", code_account_new)
self.debug("creating new code_account with increased size %s", code_account_new)
self.create_account_with_seed(seed, code_size)
logger.debug("resized account is created %s", code_account_new)
self.debug("resized account is created %s", code_account_new)

resize_instr.append(self.instruction.make_resize_instruction(acc_desc, code_account_new, seed))
# replace code_account
acc_desc["contract"] = code_account_new

for instr in resize_instr:
logger.debug("code and storage migration, account %s from %s to %s", instr.keys[0].pubkey, instr.keys[1].pubkey, instr.keys[2].pubkey)
self.debug("code and storage migration, account %s from %s to %s", instr.keys[0].pubkey, instr.keys[1].pubkey, instr.keys[2].pubkey)

tx = Transaction().add(instr)
success = False
count = 0

while count < 2:
logger.debug("attemt: %d", count)
self.debug("attemt: %d", count)

self.sender.send_transaction(tx, eth_trx=self.eth_trx, reason='resize_storage_account')
info = self.sender._getAccountData(instr.keys[0].pubkey, ACCOUNT_INFO_LAYOUT.sizeof())
info_data = AccountInfo.frombytes(info)
if info_data.code_account == instr.keys[2].pubkey:
success = True
logger.debug("successful code and storage migration, %s", instr.keys[0].pubkey)
self.debug("successful code and storage migration, %s", instr.keys[0].pubkey)
break
# wait for unlock account
time.sleep(1)
Expand All @@ -244,11 +241,11 @@ def create_account_list_by_emulate(self):
code_account = None
code_account_writable = False
if acc_desc["new"]:
logger.debug("Create solana accounts for %s: %s %s", acc_desc["address"], acc_desc["account"], acc_desc["contract"])
self.debug("Create solana accounts for %s: %s %s", acc_desc["address"], acc_desc["account"], acc_desc["contract"])
if acc_desc["code_size"]:
seed = b58encode(ACCOUNT_SEED_VERSION+address)
code_account = accountWithSeed(self.sender.get_operator_key(), seed)
logger.debug(" with code account %s", code_account)
self.debug(" with code account %s", code_account)
code_size = acc_desc["code_size"] + 2048
code_account_balance = self.sender.get_rent_exempt_balance_for_size(code_size)
self.create_acc_trx.add(self.instruction.create_account_with_seed_trx(code_account, seed, code_account_balance, code_size))
Expand Down Expand Up @@ -358,7 +355,7 @@ def create_accounts_for_trx(self):
length = len(self.create_acc_trx.instructions)
if length == 0:
return
logger.debug(f"Create account for trx: {length}")
self.debug(f"Create account for trx: {length}")
precall_txs = Transaction()
precall_txs.add(self.create_acc_trx)
result = self.sender.send_measured_transaction(precall_txs, self.eth_trx, 'CreateAccountsForTrx')
Expand All @@ -368,7 +365,7 @@ def create_accounts_for_trx(self):


def write_trx_to_holder_account(self):
logger.debug('write_trx_to_holder_account')
self.debug('write_trx_to_holder_account')
msg = self.eth_trx.signature() + len(self.eth_trx.unsigned_msg()).to_bytes(8, byteorder="little") + self.eth_trx.unsigned_msg()

offset = 0
Expand All @@ -385,12 +382,12 @@ def write_trx_to_holder_account(self):
for trx in trxs:
receipts[self.sender.send_transaction_unconfirmed(trx)] = trx

logger.debug("receipts %s", receipts)
self.debug("receipts %s", receipts)
for rcpt, trx in receipts.items():
try:
self.sender.collect_result(rcpt, eth_trx=self.eth_trx, reason='WriteHolder')
except Exception as err:
logger.debug("collect_result exception: {}".format(str(err)))
self.debug("collect_result exception: {}".format(str(err)))
else:
trxs.remove(trx)

Expand All @@ -400,7 +397,7 @@ def call_continue(self):
try:
return_result = self.call_continue_bucked()
except Exception as err:
logger.debug("call_continue_bucked_combined exception: {}".format(str(err)))
self.debug("call_continue_bucked_combined exception: {}".format(str(err)))
if str(err).startswith("transaction too large:"):
raise

Expand All @@ -414,15 +411,15 @@ def call_continue_iterative(self):
try:
return self.call_continue_step_by_step()
except Exception as err:
logger.error("call_continue_step_by_step exception:")
logger.debug(str(err))
self.error("call_continue_step_by_step exception:")
self.debug(str(err))

return self.call_cancel()


def call_continue_step_by_step(self):
while True:
logger.debug("Continue iterative step:")
self.debug("Continue iterative step:")
result = self.call_continue_step()
signature = check_if_continue_returned(result)
if signature is not None:
Expand All @@ -434,7 +431,7 @@ def call_continue_step(self):
while step_count > 0:
trx = self.make_combined_trx(step_count, 0)

logger.debug("Step count {}".format(step_count))
self.debug("Step count {}".format(step_count))
try:
result = self.sender.send_measured_transaction(trx, self.eth_trx, self.instruction_type)
return result
Expand All @@ -449,20 +446,20 @@ def call_continue_step(self):
def call_cancel(self):
trx = self.instruction.make_cancel_transaction()

logger.debug("Cancel")
self.debug("Cancel")
result = self.sender.send_measured_transaction(trx, self.eth_trx, 'CancelWithNonce')
return result['result']['transaction']['signatures'][0]


def call_continue_bucked(self):
logger.debug("Send bucked combined: %s", self.instruction_type)
self.debug("Send bucked combined: %s", self.instruction_type)
receipts = []
for index in range(math.ceil(self.steps_emulated/self.steps) + self.addition_count()):
try:
trx = self.make_combined_trx(self.steps, index)
receipts.append(self.sender.send_transaction_unconfirmed(trx))
except Exception as err:
logger.debug(str(err))
self.debug(str(err))
if len(receipts) > 0:
break
else:
Expand Down Expand Up @@ -496,7 +493,7 @@ def make_combined_trx(self, steps, index):


def collect_bucked_results(self, receipts, reason):
logger.debug(f"Collected bucked results: {receipts}")
self.debug(f"Collected bucked results: {receipts}")
result_list = self.sender.collect_results(receipts, eth_trx=self.eth_trx, reason=reason)
for result in result_list:
self.sender.get_measurements(result)
Expand Down
Loading