Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
0ec2268
Introduce proxy/db_scheme.py
vasiliy-zaznobin Feb 18, 2022
43d1b28
Merge remote-tracking branch 'origin/develop' into 368-Move_SQL_schem…
vasiliy-zaznobin Feb 18, 2022
075273e
Debug
vasiliy-zaznobin Feb 18, 2022
768bf09
Introduce run-db-creation.sh
vasiliy-zaznobin Feb 21, 2022
09bf1ac
Use entrypoint: proxy/run-db-creation.sh
vasiliy-zaznobin Feb 21, 2022
f2cac17
Add dbcreation.log
vasiliy-zaznobin Feb 21, 2022
d8ecf1b
Debug
vasiliy-zaznobin Feb 21, 2022
68a7841
Debug
vasiliy-zaznobin Feb 21, 2022
d34c8f7
Merge remote-tracking branch 'origin/develop' into 368-Move_SQL_schem…
vasiliy-zaznobin Feb 21, 2022
6a47f6b
Add dbcreation.log
vasiliy-zaznobin Feb 21, 2022
2058f0a
Use from ..proxy
vasiliy-zaznobin Feb 21, 2022
295568e
Debug
vasiliy-zaznobin Feb 21, 2022
8a7047f
Debug
vasiliy-zaznobin Feb 21, 2022
3cf914e
Introduce dbcreation_mode to run proxy
vasiliy-zaznobin Feb 21, 2022
550c46e
Change paths
vasiliy-zaznobin Feb 21, 2022
f22a780
Will run in dbcreation mode with SOLANA_URL and EVM_LOADER
vasiliy-zaznobin Feb 21, 2022
e6c0e43
Debug
vasiliy-zaznobin Feb 21, 2022
acf7bce
Debug
vasiliy-zaznobin Feb 21, 2022
eaf23d2
Debug
vasiliy-zaznobin Feb 21, 2022
5a0306b
SOLANA_URL: http://solana:8899
vasiliy-zaznobin Feb 21, 2022
27c0e68
Add logged_groups
vasiliy-zaznobin Feb 21, 2022
0ac19fa
Debug
vasiliy-zaznobin Feb 21, 2022
33515b4
Log schema
vasiliy-zaznobin Feb 21, 2022
f1c2c50
Use psql
vasiliy-zaznobin Feb 21, 2022
8865af4
Add postgresql-client-common in the docker image
vasiliy-zaznobin Feb 21, 2022
1eb1bf9
Add postgresql-client in the docker image
vasiliy-zaznobin Feb 21, 2022
cf47fad
Set network_mode: container:postgres
vasiliy-zaznobin Feb 21, 2022
7b9167c
Remove networks
vasiliy-zaznobin Feb 21, 2022
9355411
Use network_mode: service:postgres
vasiliy-zaznobin Feb 21, 2022
505b3eb
Remove hostname
vasiliy-zaznobin Feb 21, 2022
11fa1bc
Remove hostname
vasiliy-zaznobin Feb 21, 2022
6d9c6ca
ports:
vasiliy-zaznobin Feb 21, 2022
b9c2f7a
networks:
vasiliy-zaznobin Feb 21, 2022
1586797
Add ports:
vasiliy-zaznobin Feb 21, 2022
31b8048
Add networks:
vasiliy-zaznobin Feb 21, 2022
d9154eb
Try to use links: - postgres
vasiliy-zaznobin Feb 21, 2022
b66b803
Use export PGPASSWORD=${POSTGRES_PASSWORD} to set the password for psql
vasiliy-zaznobin Feb 21, 2022
a12fe00
Use run_dbcreation()
vasiliy-zaznobin Feb 21, 2022
7803d3c
Merge remote-tracking branch 'origin/develop' into 368-Move_SQL_schem…
vasiliy-zaznobin Feb 21, 2022
0360208
Merge remote-tracking branch 'origin/develop' into 368-Move_SQL_schem…
vasiliy-zaznobin Feb 23, 2022
94f733a
Correction after the prev merge
vasiliy-zaznobin Feb 23, 2022
92d0201
Correction after the prev merge
vasiliy-zaznobin Feb 23, 2022
ea0dbdc
Lowercase in function names
vasiliy-zaznobin Feb 23, 2022
d02bfee
Refactor to introduce scheme.sql
vasiliy-zaznobin Feb 24, 2022
df19f2d
Debug
vasiliy-zaznobin Feb 24, 2022
6a38f0c
Debug
vasiliy-zaznobin Feb 24, 2022
c94126b
Debug
vasiliy-zaznobin Feb 24, 2022
6bf4cfc
Add table airdrop_scheduled
vasiliy-zaznobin Feb 24, 2022
7560704
Revert some changes
vasiliy-zaznobin Feb 24, 2022
5ab70f3
Fixed: psql:proxy/db/scheme.sql:73: ERROR: syntax error at or near "{"
vasiliy-zaznobin Feb 24, 2022
f6d17d2
Use run_indexer(solana_url)
vasiliy-zaznobin Feb 24, 2022
bb07118
Merge remote-tracking branch 'origin/develop' into 368-Move_SQL_schem…
vasiliy-zaznobin Feb 24, 2022
db54d3b
Use run_airdropper with 7 args
vasiliy-zaznobin Feb 24, 2022
ffab8cd
Remove creation.py
vasiliy-zaznobin Feb 24, 2022
3881bac
Remove creation.py
vasiliy-zaznobin Feb 24, 2022
e5f8f64
Remove dbcreation_mode
vasiliy-zaznobin Feb 25, 2022
37ebf6a
Merge branch 'develop' into 368-Move_SQL_schema_to_distinct_file
rozhkovdmitrii Mar 11, 2022
4832f03
check it
rozhkovdmitrii Mar 11, 2022
46e1c2b
check it
rozhkovdmitrii Mar 11, 2022
f5891cb
Catch "Operator has NO resources!" exception
rozhkovdmitrii Mar 11, 2022
b5811da
Catch "Operator has NO resources!" exception
rozhkovdmitrii Mar 11, 2022
06ae9df
Get rid of create_table in sql_dict.py
rozhkovdmitrii Mar 12, 2022
d05f9d1
Get rid of stuff from sql_dict
rozhkovdmitrii Mar 12, 2022
4ec9a14
Get rid of crating table stuff from TrxReceiptsStorage
rozhkovdmitrii Mar 12, 2022
b092d3d
Roll back NEON_ERC20_MAX_AMOUNT
rozhkovdmitrii Mar 12, 2022
8dd8800
Spit and polish
rozhkovdmitrii Mar 12, 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
Next Next commit
Introduce proxy/db_scheme.py
  • Loading branch information
vasiliy-zaznobin committed Feb 18, 2022
commit 0ec226827ed96e3bcf285dbb88566195ecd5712a
17 changes: 3 additions & 14 deletions proxy/common_neon/costs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base58

from ..db_scheme import CREATE_TABLE_OPERATOR_COST
from ..environment import EVM_LOADER_ID
from ..indexer.utils import BaseDB

Expand All @@ -9,20 +10,8 @@ def __init__(self):
BaseDB.__init__(self)

def _create_table_sql(self) -> str:
self._table_name = 'OPERATOR_COST'
return f"""
CREATE TABLE IF NOT EXISTS {self._table_name} (
id SERIAL PRIMARY KEY,
hash char(64),
cost bigint,
used_gas bigint,
sender char(40),
to_address char(40) ,
sig char(100),
status varchar(100),
reason varchar(100)
);
"""
(sql, self._table_name) = CREATE_TABLE_OPERATOR_COST()
return sql

def insert(self, hash, cost, used_gas, sender, to_address, sig, status, reason):
with self._conn.cursor() as cur:
Expand Down
170 changes: 170 additions & 0 deletions proxy/db_scheme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
from typing import Tuple


def CREATE_TABLE_OPERATOR_COST() -> Tuple[str, str]:
TABLE_NAME_OPERATOR_COST = 'OPERATOR_COST'
return f"""
CREATE TABLE IF NOT EXISTS {TABLE_NAME_OPERATOR_COST} (
id SERIAL PRIMARY KEY,
hash char(64),
cost bigint,
used_gas bigint,
sender char(40),
to_address char(40) ,
sig char(100),
status varchar(100),
reason varchar(100)
);
""", TABLE_NAME_OPERATOR_COST


def CREATE_TABLE_NEON_ACCOUNTS() -> Tuple[str, str]:
TABLE_NAME_NEON_ACCOUNTS = 'neon_accounts'
return f"""
CREATE TABLE IF NOT EXISTS {TABLE_NAME_NEON_ACCOUNTS} (
neon_account CHAR(42),
pda_account VARCHAR(50),
code_account VARCHAR(50),
slot BIGINT,
code TEXT,

UNIQUE(pda_account, code_account)
);
""", TABLE_NAME_NEON_ACCOUNTS


def CREATE_TABLE_FAILED_AIRDROP_ATTEMPTS() -> Tuple[str, str]:
TABLE_NAME_FAILED_AIRDROP_ATTEMPTS = 'failed_airdrop_attempts'
return f"""
CREATE TABLE IF NOT EXISTS {TABLE_NAME_FAILED_AIRDROP_ATTEMPTS} (
attempt_time BIGINT,
eth_address TEXT,
reason TEXT
);
CREATE INDEX IF NOT EXISTS failed_attempt_time_idx ON {TABLE_NAME_FAILED_AIRDROP_ATTEMPTS} (attempt_time);
""", TABLE_NAME_FAILED_AIRDROP_ATTEMPTS


def CREATE_TABLE_AIRDROP_READY() -> Tuple[str, str]:
TABLE_NAME_AIRDROP_READY = 'airdrop_ready'
return f"""
CREATE TABLE IF NOT EXISTS {TABLE_NAME_AIRDROP_READY} (
eth_address TEXT UNIQUE,
scheduled_ts BIGINT,
finished_ts BIGINT,
duration INTEGER,
amount_galans INTEGER
);
""", TABLE_NAME_AIRDROP_READY


def CREATE_TABLE_SOLANA_BLOCK() -> Tuple[str, str]:
TABLE_NAME_SOLANA_BLOCK = 'solana_block'
return f"""
CREATE TABLE IF NOT EXISTS {TABLE_NAME_SOLANA_BLOCK}_heights (
slot BIGINT,
height BIGINT,

UNIQUE(slot),
UNIQUE(height)
);
CREATE TABLE IF NOT EXISTS {TABLE_NAME_SOLANA_BLOCK}_hashes (
slot BIGINT,
hash CHAR(66),

parent_hash CHAR(66),
blocktime BIGINT,
signatures BYTEA,

UNIQUE(slot),
UNIQUE(hash)
);
""", TABLE_NAME_SOLANA_BLOCK


def CREATE_TABLE_NEON_TRANSACTION_LOGS() -> Tuple[str, str]:
TABLE_NAME_NEON_TRANSACTION_LOGS = 'neon_transaction_logs'
return f"""
CREATE TABLE IF NOT EXISTS {TABLE_NAME_NEON_TRANSACTION_LOGS} (
address CHAR(42),
blockHash CHAR(66),
blockNumber BIGINT,

transactionHash CHAR(66),
transactionLogIndex INT,
topic TEXT,

json TEXT,

UNIQUE(blockNumber, transactionHash, transactionLogIndex)
);
CREATE INDEX IF NOT EXISTS {TABLE_NAME_NEON_TRANSACTION_LOGS}_block_hash ON {TABLE_NAME_NEON_TRANSACTION_LOGS}(blockHash);
CREATE INDEX IF NOT EXISTS {TABLE_NAME_NEON_TRANSACTION_LOGS}_address ON {TABLE_NAME_NEON_TRANSACTION_LOGS}(address);
CREATE INDEX IF NOT EXISTS {TABLE_NAME_NEON_TRANSACTION_LOGS}_topic ON {TABLE_NAME_NEON_TRANSACTION_LOGS}(topic);
""", TABLE_NAME_NEON_TRANSACTION_LOGS


def CREATE_TABLE_SOLANA_NEON_TRANSACTIONS() -> Tuple[str, str]:
TABLE_NAME_SOLANA_NEON_TRANSACTIONS = 'solana_neon_transactions'
return f"""
CREATE TABLE IF NOT EXISTS {TABLE_NAME_SOLANA_NEON_TRANSACTIONS} (
sol_sign CHAR(88),
neon_sign CHAR(66),
slot BIGINT,
idx INT,

UNIQUE(sol_sign, neon_sign, idx),
UNIQUE(neon_sign, sol_sign, idx)
);
""", TABLE_NAME_SOLANA_NEON_TRANSACTIONS


def CREATE_TABLE_NEON_TRANSACTIONS() -> Tuple[str, str]:
TABLE_NAME_NEON_TRANSACTIONS = 'neon_transactions'
return f"""
CREATE TABLE IF NOT EXISTS {TABLE_NAME_NEON_TRANSACTIONS} (
neon_sign CHAR(66),
from_addr CHAR(42),
sol_sign CHAR(88),
slot BIGINT,
block_height BIGINT,
block_hash CHAR(66),
idx INT,

nonce VARCHAR,
gas_price VARCHAR,
gas_limit VARCHAR,
value VARCHAR,
gas_used VARCHAR,

to_addr CHAR(42),
contract CHAR(42),

status CHAR(3),

return_value TEXT,

v TEXT,
r TEXT,
s TEXT,

calldata TEXT,
logs BYTEA,

UNIQUE(neon_sign),
UNIQUE(sol_sign, idx)
);
""", TABLE_NAME_NEON_TRANSACTIONS


def CREATE_TABLE_TRANSACTION_RECEIPTS(table_name='transaction_receipts') -> Tuple[str, str]:
return f"""
CREATE TABLE IF NOT EXISTS {table_name} (
slot BIGINT,
signature VARCHAR(88),
trx BYTEA,
PRIMARY KEY (slot, signature)
);
""", table_name


14 changes: 3 additions & 11 deletions proxy/indexer/accounts_db.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ..db_scheme import CREATE_TABLE_NEON_ACCOUNTS
from ..indexer.utils import BaseDB, DBQuery
from ..common_neon.utils import str_fmt_object

Expand All @@ -19,17 +20,8 @@ def __init__(self):
BaseDB.__init__(self)

def _create_table_sql(self) -> str:
self._table_name = 'neon_accounts'
return f"""
CREATE TABLE IF NOT EXISTS {self._table_name} (
neon_account CHAR(42),
pda_account VARCHAR(50),
code_account VARCHAR(50),
slot BIGINT,
code TEXT,

UNIQUE(pda_account, code_account)
);"""
(sql, self._table_name) = CREATE_TABLE_NEON_ACCOUNTS()
return sql

def set_acc_by_request(self, neon_account: str, pda_account: str, code_account: str, code: str):
with self._conn.cursor() as cursor:
Expand Down
25 changes: 6 additions & 19 deletions proxy/indexer/airdropper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from decimal import Decimal
import os
from logged_groups import logged_group

from ..db_scheme import CREATE_TABLE_FAILED_AIRDROP_ATTEMPTS, CREATE_TABLE_AIRDROP_READY
from ..environment import NEON_PRICE_USD

try:
Expand All @@ -28,15 +30,8 @@ def __init__(self) -> None:
BaseDB.__init__(self)

def _create_table_sql(self) -> str:
self._table_name = 'failed_airdrop_attempts'
return f'''
CREATE TABLE IF NOT EXISTS {self._table_name} (
attempt_time BIGINT,
eth_address TEXT,
reason TEXT
);
CREATE INDEX IF NOT EXISTS failed_attempt_time_idx ON {self._table_name} (attempt_time);
'''
(sql, self._table_name) = CREATE_TABLE_FAILED_AIRDROP_ATTEMPTS()
return sql

def airdrop_failed(self, eth_address, reason):
with self._conn.cursor() as cur:
Expand All @@ -51,16 +46,8 @@ def __init__(self):
BaseDB.__init__(self)

def _create_table_sql(self) -> str:
self._table_name = 'airdrop_ready'
return f'''
CREATE TABLE IF NOT EXISTS {self._table_name} (
eth_address TEXT UNIQUE,
scheduled_ts BIGINT,
finished_ts BIGINT,
duration INTEGER,
amount_galans INTEGER
)
'''
(sql, self._table_name) = CREATE_TABLE_AIRDROP_READY()
return sql

def register_airdrop(self, eth_address: str, airdrop_info: dict):
finished = int(datetime.now().timestamp())
Expand Down
25 changes: 4 additions & 21 deletions proxy/indexer/blocks_db.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import psycopg2
import psycopg2.extras

from ..db_scheme import CREATE_TABLE_SOLANA_BLOCK
from ..indexer.utils import BaseDB, DBQuery
from ..common_neon.utils import SolanaBlockInfo

Expand All @@ -10,27 +12,8 @@ def __init__(self):
self._full_column_lst = ('slot', 'hash', 'parent_hash', 'blocktime', 'signatures')

def _create_table_sql(self) -> str:
self._table_name = 'solana_block'
return f"""
CREATE TABLE IF NOT EXISTS {self._table_name}_heights (
slot BIGINT,
height BIGINT,

UNIQUE(slot),
UNIQUE(height)
);
CREATE TABLE IF NOT EXISTS {self._table_name}_hashes (
slot BIGINT,
hash CHAR(66),

parent_hash CHAR(66),
blocktime BIGINT,
signatures BYTEA,

UNIQUE(slot),
UNIQUE(hash)
);
"""
(sql, self._table_name) = CREATE_TABLE_SOLANA_BLOCK()
return sql

def _fetch_block(self, slot, q: DBQuery) -> SolanaBlockInfo:
e = self._build_expression(q)
Expand Down
23 changes: 4 additions & 19 deletions proxy/indexer/logs_db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json

from ..db_scheme import CREATE_TABLE_NEON_TRANSACTION_LOGS
from ..indexer.utils import BaseDB


Expand All @@ -7,25 +9,8 @@ def __init__(self):
BaseDB.__init__(self)

def _create_table_sql(self) -> str:
self._table_name = 'neon_transaction_logs'
return f"""
CREATE TABLE IF NOT EXISTS {self._table_name} (
address CHAR(42),
blockHash CHAR(66),
blockNumber BIGINT,

transactionHash CHAR(66),
transactionLogIndex INT,
topic TEXT,

json TEXT,

UNIQUE(blockNumber, transactionHash, transactionLogIndex)
);
CREATE INDEX IF NOT EXISTS {self._table_name}_block_hash ON {self._table_name}(blockHash);
CREATE INDEX IF NOT EXISTS {self._table_name}_address ON {self._table_name}(address);
CREATE INDEX IF NOT EXISTS {self._table_name}_topic ON {self._table_name}(topic);
"""
(sql, self._table_name) = CREATE_TABLE_NEON_TRANSACTION_LOGS()
return sql

def push_logs(self, logs, block):
rows = []
Expand Down
Loading