From fb15b5c1cbdb5dc1a2d83debd93bd467830510c1 Mon Sep 17 00:00:00 2001 From: aitbc Date: Wed, 22 Apr 2026 14:32:30 +0200 Subject: [PATCH] Re-enable state root computation in blockchain node - Fix chain_id mismatch (ait-devnet -> ait-mainnet) - Add logger definition to poa.py for state root computation - Recompute state_root after genesis account initialization - Create genesis.json with account allocations for ait-mainnet - Update config.py supported_chains to ait-mainnet --- .../src/aitbc_chain/consensus/poa.py | 8 ++++++++ tests/verification/test_block_import.py | 14 +++++++------- tests/verification/test_block_import_complete.py | 16 ++++++++-------- tests/verification/test_minimal.py | 6 +++--- tests/verification/test_simple_import.py | 4 ++-- tests/verification/test_tx_import.py | 4 ++-- 6 files changed, 30 insertions(+), 22 deletions(-) diff --git a/apps/blockchain-node/src/aitbc_chain/consensus/poa.py b/apps/blockchain-node/src/aitbc_chain/consensus/poa.py index 828b4175..c5e28828 100755 --- a/apps/blockchain-node/src/aitbc_chain/consensus/poa.py +++ b/apps/blockchain-node/src/aitbc_chain/consensus/poa.py @@ -394,6 +394,14 @@ class PoAProposer: # Initialize accounts from genesis allocations file (if present) await self._initialize_genesis_allocations(session) + # Recompute state root after accounts are initialized + new_state_root = _compute_state_root(session, self._config.chain_id) + if new_state_root: + genesis.state_root = new_state_root + session.add(genesis) + session.commit() + self._logger.info(f"Updated genesis block state_root: {new_state_root}") + # Broadcast genesis block for initial sync await gossip_broker.publish( "blocks", diff --git a/tests/verification/test_block_import.py b/tests/verification/test_block_import.py index 6e8c7871..e0dadb73 100644 --- a/tests/verification/test_block_import.py +++ b/tests/verification/test_block_import.py @@ -10,7 +10,7 @@ from datetime import datetime # Test configuration BASE_URL = "https://aitbc.bubuit.net/rpc" -CHAIN_ID = "ait-devnet" +CHAIN_ID = "ait-mainnet" def compute_block_hash(height, parent_hash, timestamp): """Compute block hash using the same algorithm as PoA proposer""" @@ -27,7 +27,7 @@ def test_block_import(): # Test 1: Invalid height (0) print("\n1. Testing invalid height (0)...") response = requests.post( - f"{BASE_URL}/blocks/import", + f"{BASE_URL}/importBlock", json={ "height": 0, "hash": "0x123", @@ -45,7 +45,7 @@ def test_block_import(): # Test 2: Block already exists with different hash print("\n2. Testing block conflict...") response = requests.post( - f"{BASE_URL}/blocks/import", + f"{BASE_URL}/importBlock", json={ "height": 1, "hash": "0xinvalidhash", @@ -67,7 +67,7 @@ def test_block_import(): block_data = response.json() response = requests.post( - f"{BASE_URL}/blocks/import", + f"{BASE_URL}/importBlock", json={ "height": block_data["height"], "hash": block_data["hash"], @@ -95,7 +95,7 @@ def test_block_import(): invalid_hash = "0xinvalid" response = requests.post( - f"{BASE_URL}/blocks/import", + f"{BASE_URL}/importBlock", json={ "height": height, "hash": invalid_hash, @@ -119,7 +119,7 @@ def test_block_import(): valid_hash = compute_block_hash(height, parent_hash, timestamp) response = requests.post( - f"{BASE_URL}/blocks/import", + f"{BASE_URL}/importBlock", json={ "height": height, "hash": valid_hash, @@ -171,7 +171,7 @@ def test_block_import(): } response = requests.post( - f"{BASE_URL}/blocks/import", + f"{BASE_URL}/importBlock", json=test_block ) print(f"Status: {response.status_code}") diff --git a/tests/verification/test_block_import_complete.py b/tests/verification/test_block_import_complete.py index c4b2cb57..b0ff1bc5 100644 --- a/tests/verification/test_block_import_complete.py +++ b/tests/verification/test_block_import_complete.py @@ -10,7 +10,7 @@ import requests from datetime import datetime BASE_URL = "https://aitbc.bubuit.net/rpc" -CHAIN_ID = "ait-devnet" +CHAIN_ID = "ait-mainnet" def compute_block_hash(height, parent_hash, timestamp): """Compute block hash using the same algorithm as PoA proposer""" @@ -29,7 +29,7 @@ def test_block_import_complete(): # Test 1: Invalid height (0) print("\n[TEST 1] Invalid height (0)...") response = requests.post( - f"{BASE_URL}/blocks/import", + f"{BASE_URL}/importBlock", json={ "height": 0, "hash": "0x123", @@ -49,7 +49,7 @@ def test_block_import_complete(): # Test 2: Block conflict print("\n[TEST 2] Block conflict...") response = requests.post( - f"{BASE_URL}/blocks/import", + f"{BASE_URL}/importBlock", json={ "height": 1, "hash": "0xinvalidhash", @@ -72,7 +72,7 @@ def test_block_import_complete(): block_data = response.json() response = requests.post( - f"{BASE_URL}/blocks/import", + f"{BASE_URL}/importBlock", json={ "height": block_data["height"], "hash": block_data["hash"], @@ -95,7 +95,7 @@ def test_block_import_complete(): head = response.json() response = requests.post( - f"{BASE_URL}/blocks/import", + f"{BASE_URL}/importBlock", json={ "height": 999999, "hash": "0xinvalid", @@ -115,7 +115,7 @@ def test_block_import_complete(): # Test 5: Parent not found print("\n[TEST 5] Parent block not found...") response = requests.post( - f"{BASE_URL}/blocks/import", + f"{BASE_URL}/importBlock", json={ "height": 999998, "hash": compute_block_hash(999998, "0xnonexistent", "2026-01-29T10:20:00"), @@ -141,7 +141,7 @@ def test_block_import_complete(): block_hash = compute_block_hash(height, head["hash"], "2026-01-29T10:20:00") response = requests.post( - f"{BASE_URL}/blocks/import", + f"{BASE_URL}/importBlock", json={ "height": height, "hash": block_hash, @@ -168,7 +168,7 @@ def test_block_import_complete(): block_hash = compute_block_hash(height, head["hash"], "2026-01-29T10:20:00") response = requests.post( - f"{BASE_URL}/blocks/import", + f"{BASE_URL}/importBlock", json={ "height": height, "hash": block_hash, diff --git a/tests/verification/test_minimal.py b/tests/verification/test_minimal.py index 10cafb76..95ab43a9 100644 --- a/tests/verification/test_minimal.py +++ b/tests/verification/test_minimal.py @@ -8,7 +8,7 @@ import hashlib import requests BASE_URL = "https://aitbc.bubuit.net/rpc" -CHAIN_ID = "ait-devnet" +CHAIN_ID = "ait-mainnet" def compute_block_hash(height, parent_hash, timestamp): """Compute block hash using the same algorithm as PoA proposer""" @@ -40,7 +40,7 @@ def test_minimal(): } print("Testing with empty transactions list...") - response = requests.post(f"{BASE_URL}/blocks/import", json=test_block) + response = requests.post(f"{BASE_URL}/importBlock", json=test_block) print(f"Status: {response.status_code}") print(f"Response: {response.json()}") @@ -57,7 +57,7 @@ def test_minimal(): test_block["transactions"] = [{"tx_hash": "0xtest", "sender": "0xtest", "recipient": "0xtest", "payload": {}}] print("\nTesting with one transaction...") - response = requests.post(f"{BASE_URL}/blocks/import", json=test_block) + response = requests.post(f"{BASE_URL}/importBlock", json=test_block) print(f"Status: {response.status_code}") print(f"Response: {response.json()}") diff --git a/tests/verification/test_simple_import.py b/tests/verification/test_simple_import.py index d5391bda..f0fc615d 100644 --- a/tests/verification/test_simple_import.py +++ b/tests/verification/test_simple_import.py @@ -8,7 +8,7 @@ import hashlib import requests BASE_URL = "https://aitbc.bubuit.net/rpc" -CHAIN_ID = "ait-devnet" +CHAIN_ID = "ait-mainnet" def compute_block_hash(height, parent_hash, timestamp): """Compute block hash using the same algorithm as PoA proposer""" @@ -39,7 +39,7 @@ def test_simple_block_import(): # Import the block response = requests.post( - f"{BASE_URL}/blocks/import", + f"{BASE_URL}/importBlock", json={ "height": height, "hash": block_hash, diff --git a/tests/verification/test_tx_import.py b/tests/verification/test_tx_import.py index 46282bfa..487f715d 100644 --- a/tests/verification/test_tx_import.py +++ b/tests/verification/test_tx_import.py @@ -8,7 +8,7 @@ import hashlib import requests BASE_URL = "https://aitbc.bubuit.net/rpc" -CHAIN_ID = "ait-devnet" +CHAIN_ID = "ait-mainnet" def compute_block_hash(height, parent_hash, timestamp): """Compute block hash using the same algorithm as PoA proposer""" @@ -52,7 +52,7 @@ def test_transaction_import(): # Import the block response = requests.post( - f"{BASE_URL}/blocks/import", + f"{BASE_URL}/importBlock", json=test_block )