-
Notifications
You must be signed in to change notification settings - Fork 20
#295 iterative execution #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
90a4e56
143913b
16c9bff
f2c0303
57f3b53
3369f67
af721bb
e512bb8
8dc5e29
8dce2a5
cef8f21
1bf8383
9672438
2d42b73
ac2755c
3519c61
bf313a2
3093fcc
e3c4e33
9b57e53
ccffcf4
4d685db
6f63338
4546926
7befc6b
b5010f8
5ebf76a
b464b1e
79088c6
52173a0
4fe15e9
607e74e
d9f762a
842ec7d
78de121
47cf219
0eebc1f
cec7a38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -373,3 +373,56 @@ def make_cancel_instruction(self) -> Transaction: | |
| AccountMeta(pubkey=SYSVAR_INSTRUCTION_PUBKEY, is_signer=False, is_writable=False), | ||
| ] + obligatory_accounts | ||
| )) | ||
|
|
||
|
|
||
| def make_partial_call_or_continue_instruction(self, steps: int = 0) -> TransactionInstruction: | ||
| data = bytearray.fromhex("0D") + self.collateral_pool_index_buf + steps.to_bytes(8, byteorder="little") + self.msg | ||
vasiliy-zaznobin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return TransactionInstruction( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it better if it would be separated on two parts. The part that is passed in - is too long instraction =
...
return instruction
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This remark could be connected to the previous definition as well |
||
| program_id = EVM_LOADER_ID, | ||
| data = data, | ||
| keys = [ | ||
| 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.collateral_pool_address, is_signer=False, is_writable=True), | ||
| AccountMeta(pubkey=self.operator_token, 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), | ||
|
|
||
| ] + self.eth_accounts + [ | ||
|
|
||
| AccountMeta(pubkey=SYSVAR_INSTRUCTION_PUBKEY, is_signer=False, is_writable=False), | ||
| ] + obligatory_accounts | ||
| ) | ||
|
|
||
|
|
||
| def make_partial_call_or_continue_transaction(self, steps: int = 0, length_before: int = 0) -> Transaction: | ||
| trx = Transaction() | ||
| trx.add(self.make_keccak_instruction(length_before + 1, len(self.eth_trx.unsigned_msg()), 13)) | ||
| trx.add(self.make_partial_call_or_continue_instruction(steps)) | ||
| return trx | ||
|
|
||
|
|
||
| def make_partial_call_or_continue_from_account_data(self, steps, index=None) -> Transaction: | ||
| data = bytearray.fromhex("0E") + self.collateral_pool_index_buf + steps.to_bytes(8, byteorder='little') | ||
| if index: | ||
| data = data + index.to_bytes(8, byteorder="little") | ||
| return TransactionInstruction( | ||
| program_id = EVM_LOADER_ID, | ||
| data = data, | ||
| keys = [ | ||
| 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.collateral_pool_address, is_signer=False, is_writable=True), | ||
| AccountMeta(pubkey=self.operator_token, 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), | ||
|
|
||
| ] + self.eth_accounts + [ | ||
|
|
||
| AccountMeta(pubkey=SYSVAR_INSTRUCTION_PUBKEY, is_signer=False, is_writable=False), | ||
| ] + obligatory_accounts | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| import re | ||
| import time | ||
|
|
||
| from solana.rpc.api import Client as SolanaClient | ||
| from solana.rpc.commitment import Confirmed | ||
| from solana.rpc.types import TxOpts | ||
|
|
||
|
|
@@ -17,7 +18,7 @@ | |
|
|
||
|
|
||
| class SolanaInteractor: | ||
| def __init__(self, signer, client) -> None: | ||
| def __init__(self, signer, client: SolanaClient) -> None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. signer needs its own annotation as well |
||
| self.signer = signer | ||
| self.client = client | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,14 +20,19 @@ | |
| from .layouts import ACCOUNT_INFO_LAYOUT | ||
| from .neon_instruction import NeonInstruction | ||
| from .solana_interactor import SolanaInteractor, check_if_continue_returned, check_if_program_exceeded_instructions | ||
| from ..environment import EVM_LOADER_ID | ||
| from ..environment import EVM_LOADER_ID, USE_COMBINED_START_CONTINUE | ||
| from ..plugin.eth_proto import Trx as EthTrx | ||
|
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
| logger.setLevel(logging.DEBUG) | ||
|
|
||
|
|
||
| CONTINUE_REGULAR = 'ContinueV02' | ||
|
||
| CONTINUE_COMBINED = 'PartialCallOrContinueFromRawEthereumTX' | ||
| CONTINUE_HOLDER_COMB = 'ExecuteTrxFromAccountDataIterativeOrContinue' | ||
|
|
||
|
|
||
| class TransactionSender: | ||
| def __init__(self, solana_interactor: SolanaInteractor, eth_trx: EthTrx, steps: int) -> None: | ||
| self.sender = solana_interactor | ||
|
|
@@ -348,13 +353,13 @@ def call_signed_iterative(self): | |
| call_txs = self.instruction.make_iterative_call_transaction() | ||
| self.sender.send_measured_transaction(call_txs, self.eth_trx, 'PartialCallFromRawEthereumTXv02') | ||
|
|
||
| return self.call_continue() | ||
| return self.call_continue(CONTINUE_REGULAR) | ||
|
|
||
|
|
||
| def call_signed_iterative_combined(self): | ||
| self.create_accounts_for_trx_if_needed() | ||
|
|
||
| return self.call_continue_combined() | ||
| return self.call_continue(CONTINUE_COMBINED) | ||
|
|
||
|
|
||
| def call_signed_with_holder_acc(self): | ||
|
|
@@ -365,13 +370,13 @@ def call_signed_with_holder_acc(self): | |
| call_txs = self.instruction.make_call_from_account_instruction() | ||
| self.sender.send_measured_transaction(call_txs, self.eth_trx, 'ExecuteTrxFromAccountDataIterativeV02') | ||
|
|
||
| return self.call_continue() | ||
| return self.call_continue(CONTINUE_REGULAR) | ||
|
|
||
| def call_signed_with_holder_combined(self): | ||
| self.write_trx_to_holder_account() | ||
| self.create_accounts_for_trx_if_needed() | ||
|
|
||
| return self.call_continue_with_holder_combined() | ||
| return self.call_continue(CONTINUE_HOLDER_COMB) | ||
|
|
||
|
|
||
| def create_accounts_for_trx_if_needed(self): | ||
|
||
|
|
@@ -399,7 +404,21 @@ def write_trx_to_holder_account(self): | |
| self.sender.collect_results(receipts, eth_trx=self.eth_trx, reason='WriteHolder') | ||
|
|
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. single blank line in python classes separates methods
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need just some issue for styling. Not here |
||
| def call_continue(self): | ||
| def call_continue(self, instruction_type): | ||
| return_result = None | ||
| try: | ||
| return_result = self.call_continue_bucked(instruction_type) | ||
| except Exception as err: | ||
| logger.debug("call_continue_bucked_combined exception:") | ||
|
||
| logger.debug(str(err)) | ||
|
|
||
| if return_result is not None: | ||
| return return_result | ||
|
|
||
| return self.call_continue_iterative() | ||
|
|
||
|
|
||
| def call_continue_iterative(self): | ||
| try: | ||
| return self.call_continue_step_by_step() | ||
| except Exception as err: | ||
|
|
@@ -441,3 +460,53 @@ def call_cancel(self): | |
| logger.debug("Cancel") | ||
| result = self.sender.send_measured_transaction(trx, self.eth_trx, 'CancelWithNonce') | ||
| return result['result']['transaction']['signatures'][0] | ||
|
|
||
|
|
||
| def call_continue_bucked(self, instruction_type): | ||
|
||
| logger.debug("Send bucked combined:") | ||
| steps = self.steps | ||
|
|
||
| addition_count = 0 | ||
|
||
| if instruction_type == CONTINUE_COMBINED: | ||
| addition_count = 2 | ||
| elif instruction_type == CONTINUE_HOLDER_COMB: | ||
| addition_count = 1 | ||
|
|
||
| receipts = [] | ||
| for index in range(math.ceil(self.steps_emulated/steps) + addition_count): | ||
| try: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is too heave, you can isolate some logically independent parts |
||
|
|
||
| if instruction_type == CONTINUE_REGULAR: | ||
| trx = self.instruction.make_continue_instruction(steps, index) | ||
| elif instruction_type == CONTINUE_COMBINED: | ||
| trx = self.instruction.make_partial_call_or_continue_transaction(steps - index) | ||
| elif instruction_type == CONTINUE_HOLDER_COMB: | ||
| trx = self.instruction.make_partial_call_or_continue_from_account_data(steps, index) | ||
| else: | ||
| raise Exception("Unknown contionue type: {}".format(instruction_type)) | ||
|
|
||
| result = self.sender.send_transaction_unconfirmed(trx) | ||
| receipts.append(result) | ||
| except Exception as err: | ||
| logger.debug(str(err)) | ||
|
||
| if str(err).startswith("Transaction simulation failed: Error processing Instruction 0: custom program error: 0x1"): | ||
|
||
| pass | ||
| elif str(err).startswith("Transaction simulation failed: Error processing Instruction 0: custom program error: 0x4"): | ||
|
||
| pass | ||
| elif check_if_program_exceeded_instructions(err.result): | ||
| steps = int(steps * 90 / 100) | ||
| else: | ||
| raise | ||
|
|
||
| return self.collect_bucked_results(receipts, instruction_type) | ||
|
|
||
|
|
||
| def collect_bucked_results(self, receipts, reason): | ||
| logger.debug("Collect bucked results:") | ||
|
||
| logger.debug("receipts %s", 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) | ||
| signature = check_if_continue_returned(result) | ||
| if signature: | ||
| return signature | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotations