Skip to content

Commit 2b70a45

Browse files
Merge branch 'develop' into 583-introduce-full-test-suite
2 parents d95ba7a + 2f3d590 commit 2b70a45

File tree

10 files changed

+243
-177
lines changed

10 files changed

+243
-177
lines changed

proxy/common_neon/address.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,26 @@
77
from solana.publickey import PublicKey
88
from typing import NamedTuple
99

10+
1011
class EthereumAddress:
11-
def __init__(self, data, private=None):
12+
def __init__(self, data, private: eth_keys.PrivateKey = None):
1213
if isinstance(data, str):
1314
data = bytes(bytearray.fromhex(data[2:]))
1415
self.data = data
1516
self.private = private
1617

1718
@staticmethod
18-
def random():
19+
def random() -> EthereumAddress:
1920
letters = '0123456789abcdef'
2021
data = bytearray.fromhex(''.join([random.choice(letters) for k in range(64)]))
2122
pk = eth_keys.PrivateKey(data)
2223
return EthereumAddress(pk.public_key.to_canonical_address(), pk)
2324

25+
@staticmethod
26+
def from_private_key(pk_data: bytes) -> EthereumAddress:
27+
pk = eth_keys.PrivateKey(pk_data)
28+
return EthereumAddress(pk.public_key.to_canonical_address(), pk)
29+
2430
def __str__(self):
2531
return '0x'+self.data.hex()
2632

@@ -70,7 +76,7 @@ def frombytes(data) -> AccountInfoLayout:
7076

7177
cont = ACCOUNT_INFO_LAYOUT.parse(data)
7278
return AccountInfoLayout(
73-
ether=cont.ether,
79+
ether=cont.ether,
7480
balance=int.from_bytes(cont.balance, "little"),
7581
trx_count=int.from_bytes(cont.trx_count, "little"),
7682
code_account=PublicKey(cont.code_account)

proxy/common_neon/neon_instruction.py

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
from solana._layouts.system_instructions import SYSTEM_INSTRUCTIONS_LAYOUT, InstructionType
55
from solana.publickey import PublicKey
66
from solana.system_program import SYS_PROGRAM_ID
7-
from solana.sysvar import SYSVAR_RENT_PUBKEY
7+
from solana.sysvar import SYSVAR_RENT_PUBKEY
88
from solana.transaction import AccountMeta, TransactionInstruction, Transaction
99
from spl.token.constants import TOKEN_PROGRAM_ID
10-
from typing import Tuple, Optional
1110
from logged_groups import logged_group
1211

1312
from .address import accountWithSeed, ether2program, EthereumAddress
@@ -24,7 +23,7 @@
2423
def create_account_with_seed_layout(base, seed, lamports, space):
2524
return SYSTEM_INSTRUCTIONS_LAYOUT.build(
2625
dict(
27-
instruction_type = InstructionType.CREATE_ACCOUNT_WITH_SEED,
26+
instruction_type=InstructionType.CREATE_ACCOUNT_WITH_SEED,
2827
args=dict(
2928
base=bytes(base),
3029
seed=dict(length=len(seed), chars=seed),
@@ -44,15 +43,15 @@ def create_account_layout(ether, nonce):
4443

4544

4645
def write_holder_layout(nonce, offset, data):
47-
return (bytes.fromhex('12')+
48-
nonce.to_bytes(8, byteorder='little')+
49-
offset.to_bytes(4, byteorder='little')+
50-
len(data).to_bytes(8, byteorder='little')+
46+
return (bytes.fromhex('12') +
47+
nonce.to_bytes(8, byteorder='little') +
48+
offset.to_bytes(4, byteorder='little') +
49+
len(data).to_bytes(8, byteorder='little') +
5150
data)
5251

5352

5453
def make_keccak_instruction_data(check_instruction_index, msg_len, data_start):
55-
if check_instruction_index > 255 and check_instruction_index < 0:
54+
if check_instruction_index > 255 or check_instruction_index < 0:
5655
raise Exception("Invalid index for instruction - {}".format(check_instruction_index))
5756

5857
check_count = 1
@@ -76,9 +75,20 @@ def make_keccak_instruction_data(check_instruction_index, msg_len, data_start):
7675

7776
@logged_group("neon.Proxy")
7877
class NeonInstruction:
79-
def __init__(self, operator: PublicKey, operator_ether: Optional[EthereumAddress] = None):
78+
def __init__(self, operator: PublicKey):
8079
self.operator_account = operator
81-
self.operator_neon_address = ether2program(operator_ether)[0] if operator_ether else None
80+
self.operator_neon_address = None
81+
self.eth_accounts = []
82+
self.eth_trx = None
83+
self.msg = None
84+
self.collateral_pool_index_buf = None
85+
self.collateral_pool_address = None
86+
self.storage = None
87+
self.holder = None
88+
self.perm_accs_id = None
89+
90+
def init_operator_ether(self, operator_ether: EthereumAddress):
91+
self.operator_neon_address = ether2program(operator_ether)[0]
8292

8393
def init_eth_trx(self, eth_trx, eth_accounts):
8494
self.eth_accounts = eth_accounts
@@ -171,9 +181,9 @@ def createERC20TokenAccountTrx(self, token_info) -> Transaction:
171181

172182
def make_resize_instruction(self, account, code_account_old, code_account_new, seed) -> TransactionInstruction:
173183
return TransactionInstruction(
174-
program_id = EVM_LOADER_ID,
175-
data = bytearray.fromhex("11") + bytes(seed), # 17- ResizeStorageAccount
176-
keys = [
184+
program_id=EVM_LOADER_ID,
185+
data=bytearray.fromhex("11") + bytes(seed), # 17- ResizeStorageAccount
186+
keys=[
177187
AccountMeta(pubkey=PublicKey(account), is_signer=False, is_writable=True),
178188
(
179189
AccountMeta(pubkey=code_account_old, is_signer=False, is_writable=True)
@@ -195,7 +205,8 @@ def make_write_transaction(self, offset: int, data: bytes) -> Transaction:
195205
]
196206
))
197207

198-
def make_keccak_instruction(self, check_instruction_index, msg_len, data_start) -> TransactionInstruction:
208+
@staticmethod
209+
def make_keccak_instruction(check_instruction_index, msg_len, data_start) -> TransactionInstruction:
199210
return TransactionInstruction(
200211
program_id=KECCAK_PROGRAM,
201212
data=make_keccak_instruction_data(check_instruction_index, msg_len, data_start),
@@ -206,9 +217,9 @@ def make_keccak_instruction(self, check_instruction_index, msg_len, data_start)
206217

207218
def make_05_call_instruction(self) -> TransactionInstruction:
208219
return TransactionInstruction(
209-
program_id = EVM_LOADER_ID,
210-
data = bytearray.fromhex("05") + self.collateral_pool_index_buf + self.msg,
211-
keys = [
220+
program_id=EVM_LOADER_ID,
221+
data=bytearray.fromhex("05") + self.collateral_pool_index_buf + self.msg,
222+
keys=[
212223
AccountMeta(pubkey=SYSVAR_INSTRUCTION_PUBKEY, is_signer=False, is_writable=False),
213224
AccountMeta(pubkey=self.operator_account, is_signer=True, is_writable=True),
214225
AccountMeta(pubkey=self.collateral_pool_address, is_signer=False, is_writable=True),
@@ -224,17 +235,16 @@ def make_noniterative_call_transaction(self, length_before: int = 0) -> Transact
224235
trx.add(self.make_05_call_instruction())
225236
return trx
226237

227-
def make_cancel_transaction(self, cancel_keys = None) -> Transaction:
228-
append_keys = []
238+
def make_cancel_transaction(self, cancel_keys=None) -> Transaction:
229239
if cancel_keys:
230240
append_keys = cancel_keys
231241
else:
232242
append_keys = self.eth_accounts
233243
append_keys += obligatory_accounts
234244
return Transaction().add(TransactionInstruction(
235-
program_id = EVM_LOADER_ID,
236-
data = bytearray.fromhex("15") + self.eth_trx.nonce.to_bytes(8, 'little'),
237-
keys = [
245+
program_id=EVM_LOADER_ID,
246+
data=bytearray.fromhex("15") + self.eth_trx.nonce.to_bytes(8, 'little'),
247+
keys=[
238248
AccountMeta(pubkey=self.storage, is_signer=False, is_writable=True),
239249
AccountMeta(pubkey=self.operator_account, is_signer=True, is_writable=True),
240250
AccountMeta(pubkey=INCINERATOR_PUBKEY, is_signer=False, is_writable=True),
@@ -244,9 +254,9 @@ def make_cancel_transaction(self, cancel_keys = None) -> Transaction:
244254
def make_partial_call_or_continue_instruction(self, steps=0) -> TransactionInstruction:
245255
data = bytearray.fromhex("0D") + self.collateral_pool_index_buf + steps.to_bytes(8, byteorder="little") + self.msg
246256
return TransactionInstruction(
247-
program_id = EVM_LOADER_ID,
248-
data = data,
249-
keys = [
257+
program_id=EVM_LOADER_ID,
258+
data=data,
259+
keys=[
250260
AccountMeta(pubkey=self.storage, is_signer=False, is_writable=True),
251261

252262
AccountMeta(pubkey=SYSVAR_INSTRUCTION_PUBKEY, is_signer=False, is_writable=False),
@@ -269,9 +279,9 @@ def make_partial_call_or_continue_from_account_data(self, steps, index=0) -> Tra
269279
if index:
270280
data = data + index.to_bytes(8, byteorder="little")
271281
return Transaction().add(TransactionInstruction(
272-
program_id = EVM_LOADER_ID,
273-
data = data,
274-
keys = [
282+
program_id=EVM_LOADER_ID,
283+
data=data,
284+
keys=[
275285
AccountMeta(pubkey=self.holder, is_signer=False, is_writable=True),
276286
AccountMeta(pubkey=self.storage, is_signer=False, is_writable=True),
277287

proxy/common_neon/solana_interactor.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def _send_rpc_batch_request(self, method: str, params_list: List[Any]) -> List[R
118118
full_request_data.append(request)
119119

120120
# Protection from big payload
121-
if len(request_data) == 30 or len(full_request_data) == len(params_list):
121+
if len(request_data) >= 25 or len(full_request_data) == len(params_list):
122122
raw_response = self._make_request(request_data)
123123
response_data = cast(List[RPCResponse], raw_response.json())
124124

@@ -587,12 +587,6 @@ def _on_post_send(self):
587587
elif len(self._budget_exceeded_list):
588588
raise RuntimeError(COMPUTATION_BUDGET_EXCEEDED)
589589

590-
# There is no more retries to send transactions
591-
if self._retry_idx >= RETRY_ON_FAIL:
592-
if not self._is_canceled:
593-
self._cancel()
594-
return
595-
596590
if len(self._blocked_account_list):
597591
time.sleep(0.4) # one block time
598592

0 commit comments

Comments
 (0)