Skip to content

Commit

Permalink
add aborted transaction processing and other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
HarukaMa committed Sep 11, 2024
1 parent b5387be commit 056beca
Show file tree
Hide file tree
Showing 7 changed files with 471 additions and 426 deletions.
2 changes: 1 addition & 1 deletion api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async def run():
port = int(os.environ.get("API_PORT", 8001))
config = uvicorn.Config(
"api:app", reload=True, log_level="info", host=host, port=port,
forwarded_allow_ips=["127.0.0.1", "::1", "10.0.4.1"]
forwarded_allow_ips=["127.0.0.1", "::1", "10.0.4.1", "10.0.5.1"]
)
logging.getLogger("uvicorn.access").handlers = []
server = UvicornServer(config=config)
Expand Down
7 changes: 5 additions & 2 deletions db/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,9 @@ async def get_unconfirmed_transaction_count(self) -> int:
async with self.pool.connection() as conn:
async with conn.cursor() as cur:
try:
await cur.execute("SELECT COUNT(*) FROM transaction WHERE confirmed_transaction_id IS NULL")
await cur.execute(
"SELECT COUNT(*) FROM transaction WHERE confirmed_transaction_id IS NULL AND aborted = FALSE"
)
res = await cur.fetchone()
if res is None:
raise RuntimeError("database inconsistent")
Expand All @@ -497,7 +499,8 @@ async def get_unconfirmed_transactions_range(self, start: int, end: int) -> list
async with conn.cursor() as cur:
try:
await cur.execute(
"SELECT transaction_id FROM transaction WHERE confirmed_transaction_id IS NULL "
"SELECT transaction_id FROM transaction "
"WHERE confirmed_transaction_id IS NULL AND aborted = FALSE "
"ORDER BY first_seen DESC LIMIT %s OFFSET %s",
(end - start, start)
)
Expand Down
854 changes: 436 additions & 418 deletions db/insert.py

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion db/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ async def migrate(self):
(1, self.migrate_1_add_block_validator_index),
(2, self.migrate_2_add_address_tag_and_validator_table),
(3, self.migrate_3_change_tag_validator_index_to_unique),
(4, self.migrate_4_create_transaction_aborted_flag),
]
async with self.pool.connection() as conn:
async with conn.cursor() as cur:
Expand Down Expand Up @@ -74,4 +75,8 @@ async def migrate_3_change_tag_validator_index_to_unique(conn: psycopg.AsyncConn
await conn.execute("create unique index address_tag_tag_index on address_tag (tag)")

await conn.execute("drop index validator_info_address_index")
await conn.execute("create unique index validator_info_address_index on validator_info (address)")
await conn.execute("create unique index validator_info_address_index on validator_info (address)")

@staticmethod
async def migrate_4_create_transaction_aborted_flag(conn: psycopg.AsyncConnection[DictRow], redis: Redis[str]):
await conn.execute("alter table transaction add column aborted boolean not null default false")
2 changes: 1 addition & 1 deletion node/testnet/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ class Testnet:
deployment_fee_multiplier = 1000
synthesis_fee_multiplier = 25

ans_registry = "aleo_name_service_registry_v1.aleo"
ans_registry = "aleo_name_service_registry.aleo"

restrictions_id = Field(7562506206353711030068167991213732850758501012603348777370400520506564970105)
23 changes: 21 additions & 2 deletions webapi/block_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,33 @@ async def block_route(request: Request):
all_validators: list[str] = []
for v in all_validators_raw:
all_validators.append(v["address"])

css: list[dict[str, Any]] = []
target_sum = 0
if coinbase_reward is not None:
solutions = await db.get_solution_by_height(height, 0, 100)
for solution in solutions:
css.append({
"address": solution["address"],
"counter": solution["counter"],
"target": solution["target"],
"reward": solution["reward"],
"solution_id": solution["solution_id"],
})
target_sum += solution["target"]
result = {
"block": block.json(),
"coinbase_reward": coinbase_reward,
"validators": validators,
"all_validators": all_validators,
"solutions": css,
}
result["resolved_addresses"] = await UIAddress.resolve_recursive_detached(result, db, {})
result["resolved_addresses"] = \
await UIAddress.resolve_recursive_detached(
result, db,
await UIAddress.resolve_recursive_detached(
result["solutions"], db, {}
)
)

return CJSONResponse(result)

Expand Down
2 changes: 1 addition & 1 deletion webapi/webapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def run():
port = int(os.environ.get("WEBAPI_PORT", 8002))
config = uvicorn.Config(
"webapi:app", reload=True, log_level="info", host=host, port=port,
forwarded_allow_ips=["127.0.0.1", "::1", "10.0.4.1"]
forwarded_allow_ips=["127.0.0.1", "::1", "10.0.4.1", "10.0.5.1"]
)
logging.getLogger("uvicorn.access").handlers = []
server = UvicornServer(config=config)
Expand Down

0 comments on commit 056beca

Please sign in to comment.