Skip to content
Merged
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
#291 move perm accs to transaction sender
  • Loading branch information
otselnik committed Nov 16, 2021
commit 143913b5c4bec6c61ba9af309d1cf4096c9f7536
173 changes: 84 additions & 89 deletions proxy/plugin/solana_rest_api_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,47 +138,6 @@ def __new__(cls):
cls.instance.operator_cost = SQLCost()
return cls.instance

class PermanentAccounts:
def __init__(self, client, signer):
while True:
with new_acc_id_glob.get_lock():
try:
self.acc_id = acc_list_glob.pop(0)
except IndexError:
self.acc_id = new_acc_id_glob.value
new_acc_id_glob.value += 1

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

self.operator = signer.public_key()
self.operator_token = getTokenAddr(self.operator)

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

storage_seed = keccak_256(b"storage" + acc_id_bytes).hexdigest()[:32]
storage_seed = bytes(storage_seed, 'utf8')

holder_seed = keccak_256(b"holder" + acc_id_bytes).hexdigest()[:32]
holder_seed = bytes(holder_seed, 'utf8')

try:
self.storage, self.holder = create_multiple_accounts_with_seed(
client,
funding=signer,
base=signer,
seeds=[storage_seed, holder_seed],
sizes=[STORAGE_SIZE, STORAGE_SIZE]
)
except Exception as err:
logger.warn("Account is locked err({}) id({}) owner({})".format(str(err), self.acc_id, signer.public_key()))
else:
break

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


class AccountInfo(NamedTuple):
ether: eth_keys.PublicKey
Expand Down Expand Up @@ -276,50 +235,6 @@ def create_collateral_pool_address(collateral_pool_index):
return accountWithSeed(PublicKey(COLLATERAL_POOL_BASE), str.encode(seed), PublicKey(evm_loader_id))


def create_account_with_seed(client, funding, base, seed, storage_size, eth_trx=None):
account = accountWithSeed(base.public_key(), seed, PublicKey(evm_loader_id))

if client.get_balance(account, commitment=Confirmed)['result']['value'] == 0:
minimum_balance = client.get_minimum_balance_for_rent_exemption(storage_size, commitment=Confirmed)["result"]
logger.debug("Minimum balance required for account {}".format(minimum_balance))

trx = Transaction()
trx.add(createAccountWithSeedTrx(funding.public_key(), base.public_key(), seed, minimum_balance, storage_size, PublicKey(evm_loader_id)))
send_transaction(client, trx, funding, eth_trx=eth_trx, reason='createAccountWithSeed')

return account


def create_multiple_accounts_with_seed(client, funding, base, seeds, sizes):
accounts = []
trx = Transaction()

for seed, storage_size in zip(seeds, sizes):
account = accountWithSeed(base.public_key(), seed, PublicKey(evm_loader_id))
accounts.append(account)

minimum_balance = client.get_minimum_balance_for_rent_exemption(storage_size, commitment=Confirmed)["result"]

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

trx.add(createAccountWithSeedTrx(funding.public_key(), base.public_key(), seed, minimum_balance, storage_size, PublicKey(evm_loader_id)))
else:
(tag, lamports, owner) = account_info
if lamports < minimum_balance:
raise Exception("insufficient balance")
if PublicKey(owner) != PublicKey(evm_loader_id):
raise Exception("wrong owner")
if tag != EMPTY_STORAGE_TAG:
raise Exception("not empty")

if len(trx.instructions) > 0:
send_transaction(client, trx, funding)

return accounts


def make_keccak_instruction_data(check_instruction_index, msg_len, data_start):
if check_instruction_index > 255 and check_instruction_index < 0:
raise Exception("Invalid index for instruction - {}".format(check_instruction_index))
Expand Down Expand Up @@ -610,6 +525,86 @@ def __init__(self, signer, client, eth_trx, steps) -> None:
self.collateral_pool_address = create_collateral_pool_address(collateral_pool_index)


def init_perm_accs(self):
while True:
with new_acc_id_glob.get_lock():
try:
self.perm_accs_id = acc_list_glob.pop(0)
except IndexError:
self.perm_accs_id = new_acc_id_glob.value
new_acc_id_glob.value += 1

logger.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')

storage_seed = keccak_256(b"storage" + acc_id_bytes).hexdigest()[:32]
storage_seed = bytes(storage_seed, 'utf8')

holder_seed = keccak_256(b"holder" + acc_id_bytes).hexdigest()[:32]
holder_seed = bytes(holder_seed, 'utf8')

try:
self.storage, self.holder = self.create_multiple_accounts_with_seed(
seeds=[storage_seed, holder_seed],
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.signer.public_key()))
else:
break


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


def create_account_with_seed(self, seed, storage_size):
account = accountWithSeed(self.signer.public_key(), seed, PublicKey(evm_loader_id))

if self.client.get_balance(account, commitment=Confirmed)['result']['value'] == 0:
minimum_balance = self.client.get_minimum_balance_for_rent_exemption(storage_size, commitment=Confirmed)["result"]
logger.debug("Minimum balance required for account {}".format(minimum_balance))

trx = Transaction()
trx.add(createAccountWithSeedTrx(self.signer.public_key(), self.signer.public_key(), seed, minimum_balance, storage_size, PublicKey(evm_loader_id)))
send_transaction(self.client, trx, self.signer, eth_trx=self.eth_trx, reason='createAccountWithSeed')

return account


def create_multiple_accounts_with_seed(self, seeds, sizes):
accounts = []
trx = Transaction()

for seed, storage_size in zip(seeds, sizes):
account = accountWithSeed(self.signer.public_key(), seed, PublicKey(evm_loader_id))
accounts.append(account)

minimum_balance = self.client.get_minimum_balance_for_rent_exemption(storage_size, commitment=Confirmed)["result"]

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

trx.add(createAccountWithSeedTrx(self.signer.public_key(), self.signer.public_key(), seed, minimum_balance, storage_size, PublicKey(evm_loader_id)))
else:
(tag, lamports, owner) = account_info
if lamports < minimum_balance:
raise Exception("insufficient balance")
if PublicKey(owner) != PublicKey(evm_loader_id):
raise Exception("wrong owner")
if tag != EMPTY_STORAGE_TAG:
raise Exception("not empty")

if len(trx.instructions) > 0:
send_transaction(self.client, trx, self.signer, eth_trx=self.eth_trx, reason='createAccountWithSeed')

return accounts


def execute(self):
self.create_account_list_by_emulate()

Expand All @@ -634,7 +629,7 @@ def execute(self):
else:
raise

self.perm_accs = PermanentAccounts(self.client, self.signer)
self.init_perm_accs()
try:
if call_iterative:
try:
Expand All @@ -650,7 +645,7 @@ def execute(self):
if call_from_holder:
return self.call_signed_with_holder_acc()
finally:
del self.perm_accs
self.free_perm_accs()


def create_account_list_by_emulate(self):
Expand Down Expand Up @@ -681,7 +676,7 @@ def create_account_list_by_emulate(self):
code_account_new = accountWithSeed(self.signer.public_key(), seed, PublicKey(evm_loader_id))

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

resize_instr.append(TransactionInstruction(
Expand Down Expand Up @@ -880,7 +875,7 @@ def write_trx_to_holder_account(self):
trx = Transaction()
# logger.debug("sender_sol %s %s %s", sender_sol, holder, acc.public_key())
trx.add(TransactionInstruction(program_id=evm_loader_id,
data=write_holder_layout(self.perm_accs.acc_id, offset, part),
data=write_holder_layout(self.perm_accs_id, offset, part),
keys=[
AccountMeta(pubkey=self.perm_accs.holder, is_signer=False, is_writable=True),
AccountMeta(pubkey=self.signer.public_key(), is_signer=True, is_writable=False),
Expand Down