fix: use current UTC timestamp for genesis blocks and fix lambda closure bugs
Some checks failed
Blockchain Synchronization Verification / sync-verification (push) Failing after 3s
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Successful in 2s
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Successful in 3s
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Successful in 2s
Cross-Node Transaction Testing / transaction-test (push) Successful in 3s
Deploy to Testnet / deploy-testnet (push) Successful in 1m12s
Integration Tests / test-service-integration (push) Successful in 1m23s
Multi-Chain Island Architecture Tests / test-multi-chain-island (push) Successful in 2s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 3s
Multi-Node Stress Testing / stress-test (push) Successful in 3s
Node Failover Simulation / failover-test (push) Successful in 3s
P2P Network Verification / p2p-verification (push) Successful in 2s
Python Tests / test-python (push) Failing after 45s
Security Scanning / security-scan (push) Successful in 23s
Cross-Chain Functionality Tests / aggregate-results (push) Successful in 2s
Some checks failed
Blockchain Synchronization Verification / sync-verification (push) Failing after 3s
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Successful in 2s
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Successful in 3s
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Successful in 2s
Cross-Node Transaction Testing / transaction-test (push) Successful in 3s
Deploy to Testnet / deploy-testnet (push) Successful in 1m12s
Integration Tests / test-service-integration (push) Successful in 1m23s
Multi-Chain Island Architecture Tests / test-multi-chain-island (push) Successful in 2s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 3s
Multi-Node Stress Testing / stress-test (push) Successful in 3s
Node Failover Simulation / failover-test (push) Successful in 3s
P2P Network Verification / p2p-verification (push) Successful in 2s
Python Tests / test-python (push) Failing after 45s
Security Scanning / security-scan (push) Successful in 23s
Cross-Chain Functionality Tests / aggregate-results (push) Successful in 2s
- Changed genesis block timestamp from hardcoded 2025-01-01 to datetime.now(timezone.utc) - Fixes unified_genesis.py, poa.py genesis creation, and fallback genesis timestamp - Fixed lambda closure bugs in session_factory by capturing chain_id with default parameter - Removed localhost:8006 from default bootstrap peers (hub nodes create own genesis) - Updated comments to reflect genesis timestamp change from deterministic to current time
This commit is contained in:
@@ -123,7 +123,7 @@ def create_genesis_wallet(password: str = None, chain_id: str = "ait-mainnet") -
|
||||
def create_genesis_block(chain_id: str, proposer: str, timestamp: datetime = None) -> Dict[str, Any]:
|
||||
"""Create genesis block"""
|
||||
if not timestamp:
|
||||
timestamp = datetime.fromisoformat("2025-01-01 00:00:00")
|
||||
timestamp = datetime.now(timezone.utc)
|
||||
|
||||
parent_hash = "0x00"
|
||||
genesis_hash = compute_block_hash(0, parent_hash, timestamp, chain_id)
|
||||
|
||||
@@ -111,8 +111,7 @@ class PoAProposer:
|
||||
|
||||
def _fetch_chain_head(self) -> Optional[Block]:
|
||||
"""Fetch the current chain head block from the database."""
|
||||
from ..database import session_scope
|
||||
with session_scope(self._config.chain_id) as session:
|
||||
with self._session_factory() as session:
|
||||
return session.exec(
|
||||
select(Block).where(Block.chain_id == self._config.chain_id).order_by(Block.height.desc()).limit(1)
|
||||
).first()
|
||||
@@ -442,7 +441,7 @@ class PoAProposer:
|
||||
|
||||
if genesis_hash and genesis_state_root:
|
||||
# Create genesis block with RPC-provided data
|
||||
timestamp = datetime(2025, 1, 1, 0, 0, 0)
|
||||
timestamp = datetime.now(timezone.utc)
|
||||
genesis = Block(
|
||||
chain_id=self._config.chain_id,
|
||||
height=0,
|
||||
@@ -473,8 +472,8 @@ class PoAProposer:
|
||||
# Fall back to local genesis block creation
|
||||
self._logger.info(f"Creating genesis block locally for chain {self._config.chain_id}")
|
||||
|
||||
# Use a deterministic genesis timestamp so all nodes agree on the genesis block hash
|
||||
timestamp = datetime(2025, 1, 1, 0, 0, 0)
|
||||
# Use current timestamp for genesis block
|
||||
timestamp = datetime.now(timezone.utc)
|
||||
block_hash = self._compute_block_hash(0, "0x00", timestamp)
|
||||
|
||||
# Check if block with this hash already exists (duplicate check)
|
||||
@@ -607,7 +606,7 @@ class PoAProposer:
|
||||
peer_url = peer_url.replace("http://", "")
|
||||
peer_url = f"http://{peer_url}"
|
||||
trusted_peers.append(peer_url)
|
||||
trusted_peers.append("http://localhost:8006")
|
||||
# Don't add localhost as default bootstrap peer - hub nodes should create their own genesis
|
||||
|
||||
self._logger.info(f"Attempting RPC bootstrap for genesis block from peers: {trusted_peers}")
|
||||
|
||||
@@ -647,7 +646,7 @@ class PoAProposer:
|
||||
peer_url = peer_url.replace("http://", "")
|
||||
peer_url = f"http://{peer_url}"
|
||||
trusted_peers.append(peer_url)
|
||||
trusted_peers.append("http://localhost:8006")
|
||||
# Don't add localhost as default bootstrap peer - hub nodes should create their own genesis
|
||||
|
||||
self._logger.info(f"Attempting RPC bootstrap from peers: {trusted_peers}")
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ class BlockchainNode:
|
||||
|
||||
async def _ensure_genesis_for_chains(self) -> None:
|
||||
for chain_id in self._supported_chains():
|
||||
proposer = PoAProposer(config=self._proposer_config(chain_id), session_factory=lambda: session_scope(chain_id))
|
||||
proposer = PoAProposer(config=self._proposer_config(chain_id), session_factory=lambda cid=chain_id: session_scope(cid))
|
||||
await proposer._ensure_genesis_block()
|
||||
|
||||
async def _setup_gossip_subscribers(self) -> None:
|
||||
@@ -192,7 +192,7 @@ class BlockchainNode:
|
||||
import json
|
||||
block_data = json.loads(block_data)
|
||||
logger.info(f"Importing block for chain {chain_id_param}: {block_data.get('height')}")
|
||||
sync = ChainSync(session_factory=lambda: session_scope(chain_id_param), chain_id=chain_id_param)
|
||||
sync = ChainSync(session_factory=lambda cid=chain_id_param: session_scope(cid), chain_id=chain_id_param)
|
||||
res = sync.import_block(block_data, transactions=block_data.get("transactions"))
|
||||
logger.info(f"Import result: accepted={res.accepted}, reason={res.reason}")
|
||||
|
||||
@@ -322,7 +322,7 @@ class BlockchainNode:
|
||||
if chain_id in self._proposers:
|
||||
continue
|
||||
|
||||
proposer = PoAProposer(config=self._proposer_config(chain_id), session_factory=lambda: session_scope(chain_id))
|
||||
proposer = PoAProposer(config=self._proposer_config(chain_id), session_factory=lambda cid=chain_id: session_scope(cid))
|
||||
self._proposers[chain_id] = proposer
|
||||
asyncio.create_task(proposer.start())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user