Files changed
Commits
Branches
100ms render time
Unified
Split
src/consensus.rs
+42 -8
@@ -120,15 +120,28 @@ impl ConsensusEngine {}
| 120 | |
| 121 | /// Initialize the consensus mechanism for the shard network. |
| 122 | /// This now supports async shard synchronization. |
| 123 | - pub fn sync_shard(id: u32) -> Result<(), Error> { |
| 123 | + pub async fn sync_shard(id: u32, priority: u8) -> Result<(), Error> { |
| 124 | let shard = self.get_shard(id)?; |
| 125 | |
| 126 | + // Calculate timeout based on priority level |
| 127 | + let timeout = duration_from_priority(priority); |
| 128 | + let deadline = Instant::now() + timeout; |
| 126 | |
| 127 | - self.broadcast_state(&shard).await?; |
| 129 | + loop { |
| 130 | + if Instant::now() > deadline { |
| 131 | + return Err(Error::Timeout); |
| 132 | + } |
| 133 | + if let Ok(state) = broadcast_state(&shard).await { |
| 134 | + return Ok(state); |
| 135 | + } |
| 136 | + sleep(Duration::from_millis(50)).await; |
| 137 | + } |
sarah_ops
· 1 hour ago
Nice addition of the timeout loop. Should we add jitter to the sleep duration to prevent thundering herd issues when priority=0?
@@ -145,7 +158,12 @@ impl ConsensusEngine {}
| 145 | } |
| 146 | |
| 147 | - fn validate_block(&self, block: &Block) -> bool { |
| 148 | + async fn validate_block(&self, block: &Block) -> Result<bool, ValidationError> { |
| 148 | let sig = block.signature; |
| 149 | |
| 150 | + // Verify against distributed validator set |
| 151 | + let validators = self.get_validators(block.epoch).await?; |
| 152 | + if !verify_multi_sig(sig, &validators) { |
| 153 | + return Err(ValidationError::InvalidSig); |
| 154 | + } |
alex.kim
· 55 mins ago
@sarah_ops Good catch. Added jitter in the next patch on this branch. The sleep is now randomized between 30ms and 70ms.