Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
e496b27
VERSION = (0, 4, 0)
vasiliy-zaznobin Nov 16, 2021
fe41d64
EVM_LOADER_REVISION:=v0.4.0
vasiliy-zaznobin Nov 16, 2021
5467c50
EVM_LOADER_REVISION:=stable
vasiliy-zaznobin Nov 16, 2021
3c6f4bc
289 implement eth get storage at (#298)
ivandzen Nov 18, 2021
6e1864e
#256 create and airdrop eth account (#259)
rozhkovdmitrii Nov 18, 2021
4880060
#305 Remove extra args from ether2program (#309)
rozhkovdmitrii Nov 19, 2021
531a9e2
Change default logDB postgress pass (#317)
rozhkovdmitrii Nov 23, 2021
6f3cf9a
#311 Create account and airdrop on gas estimation if it's preset
rozhkovdmitrii Nov 24, 2021
452a86d
neonbals/neon-evm#371 Update STORAGE_ACCOUNT_INFO_LAYOUT (#315)
sinev-valentine Nov 24, 2021
08ebfbc
319 add neon cli version handler (#325)
vasiliy-zaznobin Nov 24, 2021
fb01a4e
fix storage account check (#327)
sinev-valentine Nov 24, 2021
ed83d90
#320 add neon proxy version handler (#323)
vasiliy-zaznobin Nov 25, 2021
dea01f4
313 concurrent execution of solana program dump (#314)
ivandzen Nov 25, 2021
024bf02
fix scripts (#329)
ivandzen Nov 25, 2021
cf9112d
#318 JSON_RPC "params" field may be omitted (#322)
mich-master Nov 26, 2021
fa9e43e
#336 indexer refactoring (#340)
ivandzen Dec 2, 2021
c7ef793
#333 fix indexer errors (#334)
otselnik Dec 2, 2021
e74e568
#291 Proxy refactoring (#324)
otselnik Dec 2, 2021
d5a5015
#337 сreate base airdropper service (#343)
ivandzen Dec 3, 2021
50bc6ba
#337 fix running airdropper (#347)
ivandzen Dec 6, 2021
a619b66
#351 fix canceller droping running transactions (#352)
otselnik Dec 6, 2021
d2f8817
349 improve neon proxy logging to filter a request and the correspond…
vasiliy-zaznobin Dec 6, 2021
5d6dab2
#349 Fix using log sending solana transaction (#353)
vasiliy-zaznobin Dec 6, 2021
4045e90
#295 iterative execution (#332)
otselnik Dec 6, 2021
521696f
#354 Check result for errors (#355)
otselnik Dec 7, 2021
fff455e
#360 pass transaction too large upper (#361)
otselnik Dec 7, 2021
e15d847
Merge remote-tracking branch 'origin/develop'
vasiliy-zaznobin Dec 7, 2021
2416591
NEON_PROXY_PKG_VERSION = '0.5.0'
vasiliy-zaznobin Dec 7, 2021
168e428
VERSION = (0, 4, 0)
vasiliy-zaznobin Nov 16, 2021
3125645
EVM_LOADER_REVISION:=v0.4.0
vasiliy-zaznobin Nov 16, 2021
07f175d
EVM_LOADER_REVISION:=stable
vasiliy-zaznobin Nov 16, 2021
0bbb26b
289 implement eth get storage at (#298)
ivandzen Nov 18, 2021
7841b07
#256 create and airdrop eth account (#259)
rozhkovdmitrii Nov 18, 2021
ce05c81
#305 Remove extra args from ether2program (#309)
rozhkovdmitrii Nov 19, 2021
6ca860a
Change default logDB postgress pass (#317)
rozhkovdmitrii Nov 23, 2021
b3b322f
#311 Create account and airdrop on gas estimation if it's preset
rozhkovdmitrii Nov 24, 2021
c860ed0
neonbals/neon-evm#371 Update STORAGE_ACCOUNT_INFO_LAYOUT (#315)
sinev-valentine Nov 24, 2021
9bb3f89
319 add neon cli version handler (#325)
vasiliy-zaznobin Nov 24, 2021
081bc75
fix storage account check (#327)
sinev-valentine Nov 24, 2021
7845ca9
#320 add neon proxy version handler (#323)
vasiliy-zaznobin Nov 25, 2021
f299c57
313 concurrent execution of solana program dump (#314)
ivandzen Nov 25, 2021
0a5dc2d
fix scripts (#329)
ivandzen Nov 25, 2021
7964cad
#318 JSON_RPC "params" field may be omitted (#322)
mich-master Nov 26, 2021
01df8a4
#336 indexer refactoring (#340)
ivandzen Dec 2, 2021
d9a8e51
#333 fix indexer errors (#334)
otselnik Dec 2, 2021
f4b178c
#291 Proxy refactoring (#324)
otselnik Dec 2, 2021
5ced809
#337 сreate base airdropper service (#343)
ivandzen Dec 3, 2021
ae7b392
#337 fix running airdropper (#347)
ivandzen Dec 6, 2021
9feca6a
#351 fix canceller droping running transactions (#352)
otselnik Dec 6, 2021
2f0a0df
349 improve neon proxy logging to filter a request and the correspond…
vasiliy-zaznobin Dec 6, 2021
3b36864
#349 Fix using log sending solana transaction (#353)
vasiliy-zaznobin Dec 6, 2021
6bb8509
#295 iterative execution (#332)
otselnik Dec 6, 2021
56044ea
#354 Check result for errors (#355)
otselnik Dec 7, 2021
0bad34c
#360 pass transaction too large upper (#361)
otselnik Dec 7, 2021
9e8344c
NEON_PROXY_PKG_VERSION = '0.5.0'
vasiliy-zaznobin Dec 7, 2021
981c178
Merge remote-tracking branch 'origin/develop->master_0.5.0' into deve…
vasiliy-zaznobin Dec 7, 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 Proxy refactoring (#324)
* #291 extract transaction sender class

* #291 move perm accs to transaction sender

* #291 fix state

* #291 fix errors

* #291 merge fixes

* #291 refactoring

* #291 move EXTRA_GAS to environment

* #291 capitalize CONFIRMATION_CHECK_DELAY

* #291 sort imports

* #291 relative paths

* #291 Should be fixed in #326

* #291 testing chnages

* fix storage account check

* #291 rename `trx_with_create_and_airdrop` -> `make_trx_with_create_and_airdrop`

* #291 pull request fixes

* #291 merge fix

* #291 rename operator and associated token accounts

Co-authored-by: sinev-valentine <[email protected]>
  • Loading branch information
otselnik and sinev-valentine authored Dec 2, 2021
commit e74e5687ac05b6139b4f7622caccd999bbb93e6a
2 changes: 1 addition & 1 deletion .buildkite/steps/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -euo pipefail

REVISION=$(git rev-parse HEAD)

set ${SOLANA_REVISION:=v1.7.9-resources}
set ${SOLANA_REVISION:=v1.7.9-testnet}
set ${EVM_LOADER_REVISION:=latest}

# Refreshing neonlabsorg/solana:latest image is required to run .buildkite/steps/build-image.sh locally
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG SOLANA_REVISION=v1.7.9-resources
ARG SOLANA_REVISION=v1.7.9-testnet
ARG EVM_LOADER_REVISION=latest

FROM neonlabsorg/solana:${SOLANA_REVISION} AS cli
Expand Down
70 changes: 70 additions & 0 deletions proxy/common_neon/address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import logging
import random

from eth_keys import keys as eth_keys
from hashlib import sha256
from solana.publickey import PublicKey
from spl.token.instructions import get_associated_token_address
from typing import NamedTuple

from .layouts import ACCOUNT_INFO_LAYOUT
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):
data = bytes(bytearray.fromhex(data[2:]))
self.data = data
self.private = private

@staticmethod
def random():
letters = '0123456789abcdef'
data = bytearray.fromhex(''.join([random.choice(letters) for k in range(64)]))
pk = eth_keys.PrivateKey(data)
return EthereumAddress(pk.public_key.to_canonical_address(), pk)

def __str__(self):
return '0x'+self.data.hex()

def __repr__(self):
return self.__str__()

def __bytes__(self): return self.data


def accountWithSeed(base, seed):
result = PublicKey(sha256(bytes(base) + bytes(seed) + bytes(PublicKey(EVM_LOADER_ID))).digest())
return result


def ether2program(ether):
if isinstance(ether, str):
pass
elif isinstance(ether, EthereumAddress):
ether = str(ether)
else:
ether = ether.hex()
output = neon_cli().call("create-program-address", ether)
items = output.rstrip().split(' ')
return items[0], int(items[1])


def getTokenAddr(account):
return get_associated_token_address(PublicKey(account), ETH_TOKEN_MINT_ID)


class AccountInfo(NamedTuple):
ether: eth_keys.PublicKey
trx_count: int
code_account: PublicKey

@staticmethod
def frombytes(data):
cont = ACCOUNT_INFO_LAYOUT.parse(data)
return AccountInfo(cont.ether, cont.trx_count, PublicKey(cont.code_account))
12 changes: 12 additions & 0 deletions proxy/common_neon/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
KECCAK_PROGRAM = "KeccakSecp256k11111111111111111111111111111"
INCINERATOR_PUBKEY = "1nc1nerator11111111111111111111111111111111"
SYSVAR_INSTRUCTION_PUBKEY = "Sysvar1nstructions1111111111111111111111111"

STORAGE_SIZE = 128*1024

ACCOUNT_SEED_VERSION=b'\1'

COLLATERALL_POOL_MAX=10

EMPTY_STORAGE_TAG=0
FINALIZED_STORAGE_TAG=5
93 changes: 93 additions & 0 deletions proxy/common_neon/costs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import base58
import psycopg2

from ..environment import EVM_LOADER_ID
from ..indexer.sql_dict import POSTGRES_USER, POSTGRES_HOST, POSTGRES_DB, POSTGRES_PASSWORD

class SQLCost():
def __init__(self):

self.conn = psycopg2.connect(
dbname=POSTGRES_DB,
user=POSTGRES_USER,
password=POSTGRES_PASSWORD,
host=POSTGRES_HOST
)

self.conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
cur = self.conn.cursor()
cur.execute('''
CREATE TABLE IF NOT EXISTS OPERATOR_COST
(
hash char(64),
cost bigint,
used_gas bigint,
sender char(40),
to_address char(40) ,
sig char(100),
status varchar(100),
reason varchar(100)
)'''
)

def close(self):
self.conn.close()

def insert(self, hash, cost, used_gas, sender, to_address, sig, status, reason):
cur = self.conn.cursor()
cur.execute('''
INSERT INTO OPERATOR_COST (hash, cost, used_gas, sender, to_address, sig, status, reason)
VALUES (%s,%s,%s,%s,%s,%s,%s,%s)
''',
(hash, cost, used_gas, sender, to_address, sig, status, reason)
)


class CostSingleton(object):
def __new__(cls):
if not hasattr(cls, 'instance'):
cls.instance = super(CostSingleton, cls).__new__(cls)
cls.instance.operator_cost = SQLCost()
return cls.instance


def update_transaction_cost(receipt, eth_trx, extra_sol_trx=False, reason=None):
cost = receipt['result']['meta']['preBalances'][0] - receipt['result']['meta']['postBalances'][0]
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

tx_info = receipt['result']
accounts = tx_info["transaction"]["message"]["accountKeys"]
evm_loader_instructions = []

for idx, instruction in enumerate(tx_info["transaction"]["message"]["instructions"]):
if accounts[instruction["programIdIndex"]] == EVM_LOADER_ID:
evm_loader_instructions.append(idx)

for inner in (tx_info['meta']['innerInstructions']):
if inner["index"] in evm_loader_instructions:
for event in inner['instructions']:
if accounts[event['programIdIndex']] == EVM_LOADER_ID:
used_gas = base58.b58decode(event['data'])[2:10]
used_gas = int().from_bytes(used_gas, "little")

table = CostSingleton().operator_cost
table.insert(
hash,
cost,
used_gas if used_gas else 0,
sender,
to_address,
sig,
'extra' if extra_sol_trx else 'ok',
reason if reason else ''
)
34 changes: 34 additions & 0 deletions proxy/common_neon/emulator_interactor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import json
import logging

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):
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)
exit_status = result['exit_status']
if exit_status == 'revert':
result_value = result['result']
if len(result_value) < 8 or result_value[:8] != '08c379a0':
raise EthereumError(code=3, message='execution reverted')

offset = int(result_value[8:8+64], 16)
length = int(result_value[8+64:8+64+64], 16)
message = str(bytes.fromhex(result_value[8+offset*2+64:8+offset*2+64+length*2]), 'utf8')
raise EthereumError(code=3, message='execution reverted: '+message, data='0x'+result_value)
if result["exit_status"] != "succeed":
raise Exception("evm emulator error ", result)
return result


def emulator(contract, sender, data, value):
data = data or "none"
value = value or ""
return neon_cli().call("emulate", sender, contract, data, value)
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
39 changes: 39 additions & 0 deletions proxy/common_neon/layouts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

from construct import Bytes, Int8ul, Int64ul
from construct import Struct

STORAGE_ACCOUNT_INFO_LAYOUT = Struct(
# "tag" / Int8ul,
"caller" / Bytes(20),
"nonce" / Int64ul,
"gas_limit" / Int64ul,
"gas_price" / Int64ul,
"slot" / Int64ul,
"operator" / Bytes(32),
"accounts_len" / Int64ul,
"executor_data_size" / Int64ul,
"evm_data_size" / Int64ul,
"gas_used_and_paid" / Int64ul,
"number_of_payments" / Int64ul,
"sign" / Bytes(65),
)

ACCOUNT_INFO_LAYOUT = Struct(
"type" / Int8ul,
"ether" / Bytes(20),
"nonce" / Int8ul,
"trx_count" / Bytes(8),
"code_account" / Bytes(32),
"is_rw_blocked" / Int8ul,
"rw_blocked_acc" / Bytes(32),
"eth_token_account" / Bytes(32),
"ro_blocked_cnt" / Int8ul,
)


CREATE_ACCOUNT_LAYOUT = Struct(
"lamports" / Int64ul,
"space" / Int64ul,
"ether" / Bytes(20),
"nonce" / Int8ul
)
Loading