Skip to content

Fix node scaling, smart contract scaling, and propagation system issues#7

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-8d70730b-7772-4fb5-a499-9db4c4b06c97
Draft

Fix node scaling, smart contract scaling, and propagation system issues#7
Copilot wants to merge 3 commits intomainfrom
copilot/fix-8d70730b-7772-4fb5-a499-9db4c4b06c97

Conversation

Copy link

Copilot AI commented Sep 28, 2025

This PR addresses critical issues with node scaling, smart contract execution scaling, and network propagation that were affecting the reliability and performance of the Stellaris blockchain network.

Issues Fixed

Node Identity and Connection Problems

The handshake system was not properly verifying node identities, leading to unreliable peer connections. The HandshakeManager was using placeholder verification instead of cryptographic validation:

# Before: Placeholder verification
def _verify_node_id_matches_pubkey(self, node_id: str, pubkey: str) -> bool:
    return True  # Always returned True!

# After: Proper cryptographic verification
def _verify_node_id_matches_pubkey(self, node_id: str, pubkey: str) -> bool:
    pubkey_bytes = bytes.fromhex(pubkey)
    computed_node_id = hashlib.sha256(pubkey_bytes).hexdigest()
    return node_id == computed_node_id

Smart Contract Scaling Bottlenecks

The VM scaler was creating unnecessary dependencies between smart contract transactions, forcing sequential execution when parallel execution was safe:

# Before: Over-conservative dependency analysis
if task.transaction.contract_address == transaction.contract_address:
    dependencies.add(task_id)  # Always created dependency for same contract

# After: Granular state conflict detection
if (self._is_state_modifying_call(task.transaction) and 
    self._is_state_modifying_call(transaction) and
    self._may_conflict_state(task.transaction, transaction)):
    dependencies.add(task_id)  # Only when actual conflict possible

Node Selection and Load Balancing

The node selection algorithm was primitive and could lead to poor load distribution:

# Before: Simple load ratio scoring
score = load_ratio * 10 + time_penalty

# After: Comprehensive weighted scoring
score = (load_ratio * 40 +           # Load factor (40% weight)
        time_penalty * 30 +          # Speed factor (30% weight)  
        (1 - success_rate) * 30 +    # Reliability factor (30% weight)
        random.uniform(0, 0.1))      # Random factor to avoid clustering

Memory Leaks in Cache Management

The cache systems were growing unbounded, causing memory issues in long-running nodes:

# Added cache size limits and cleanup
max_cache_size = 1000
if len(self.execution_cache) > max_cache_size:
    sorted_cache = sorted(self.execution_cache.items(), key=lambda x: x[1][1])
    self.execution_cache = dict(sorted_cache[-max_cache_size:])

Key Improvements

Enhanced NodeInterface: Added proper node_id tracking, handshake completion status, and helper methods for common operations like get_nodes(), get_block(), and get_blocks().

Improved Propagation Logic: The propagation system now attempts proper handshake to get authentic node_id, with graceful fallback to URL-based identification when handshake fails.

Optimized Dependency Analysis: Smart contract transactions are now analyzed for actual state conflicts rather than assuming all transactions to the same contract must be serialized.

Better Health Monitoring: Added node recovery tracking, stalled execution detection, and automatic reset mechanisms for improved reliability.

Memory Management: Implemented cache size limits, automatic cleanup of expired entries, and removal of old completed tasks to prevent memory leaks.

Testing

All changes have been thoroughly tested with comprehensive integration tests covering:

  • Node identity generation and verification
  • Peer management and propagation selection
  • Smart contract dependency analysis and execution
  • Load balancing and node selection algorithms
  • Cache management and memory optimization

The improvements maintain full backward compatibility while significantly enhancing performance, reliability, and scalability of the Stellaris network.

Original prompt

Fix the node scaling / connecting and make sure that smartcontracts scale properly. Make sure propagation and node identity works


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits September 28, 2025 19:36
Co-authored-by: connor33341 <107011324+connor33341@users.noreply.github.com>
…ting

Co-authored-by: connor33341 <107011324+connor33341@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix the node scaling / connecting and make sure that smartcontracts scale properly. Make sure propagation and node identity works Fix node scaling, smart contract scaling, and propagation system issues Sep 28, 2025
Copilot AI requested a review from connor33341 September 28, 2025 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants