Skip to content

tProxy: aggregated-mode channel_id collision can overwrite the AGGREGATED_CHANNEL_ID upstream channel #622

Description

@GitGab19

Suggested Fix

diff --git a/miner-apps/translator/src/lib/sv2/channel_manager/mod.rs b/miner-apps/translator/src/lib/sv2/channel_manager/mod.rs
--- a/miner-apps/translator/src/lib/sv2/channel_manager/mod.rs
+++ b/miner-apps/translator/src/lib/sv2/channel_manager/mod.rs
@@ -879,10 +879,17 @@ impl ChannelManager {
                 // Find max channel ID, excluding AGGREGATED_CHANNEL_ID
                 // (u32::MAX) which would cause overflow when adding 1
                 let channel_id = self
                     .extended_channels
                     .iter()
                     .filter(|x| *x.key() != AGGREGATED_CHANNEL_ID)
                     .fold(0, |acc, x| std::cmp::max(acc, *x.key()));
                 let next_channel_id = channel_id + 1;
+                if next_channel_id == AGGREGATED_CHANNEL_ID {
+                    error!("Refusing to allocate reserved aggregated channel ID to downstream");
+                    return Err(TproxyError::fallback(
+                        TproxyErrorKind::OpenMiningChannelError,
+                    ));
+                }
+
                 let success_extranonce_prefix: Vec<u8> = new_extranonce_prefix.as_bytes().to_vec();
                 let new_downstream_extended_channel = ExtendedChannel::new(
                     next_channel_id,

Note

I'm not sure we should trigger fallback in this case, probably it's better to just disconnect the client which is asking for this new channel.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Todo 📝
    Status
    Todo 📝

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions