Skip to content

Upgrade add limit to how many time a dowstream can change the proxy t…#196

Open
Fi3 wants to merge 4 commits into
dmnd-pool:masterfrom
Fi3:AddSupportForMultipleUsers3
Open

Upgrade add limit to how many time a dowstream can change the proxy t…#196
Fi3 wants to merge 4 commits into
dmnd-pool:masterfrom
Fi3:AddSupportForMultipleUsers3

Conversation

@Fi3
Copy link
Copy Markdown
Contributor

@Fi3 Fi3 commented Mar 9, 2026

…oken.

Add a configurable limit for proxy token changes, with a default value of 1, so token rotation is controlled instead of being effectively unbounded.

Load the new setting from the existing configuration pipeline and keep the enforcement state in a shared translator-side tracker rather than inside each SV1 downstream object. This is important because the limit must apply across all downstream connections handled by the same proxy/upstream session, not restart from zero for every new downstream connection.

When a downstream sends mining.authorize with a password different from the current proxy token, increment the shared counter and update the shared token state only while the change is still within the configured limit. Once the counter reaches limit + 1, do not send the special SetCustomMiningJob message upstream and immediately close the offending downstream connection.

Also keep each downstream's local token view synchronized with the shared token state, preserve normal behavior for unchanged tokens and duplicate authorize calls, and add tests covering allowed token updates, unchanged authorize flows, and cross-downstream limit enforcement.

@Fi3 Fi3 force-pushed the AddSupportForMultipleUsers3 branch from ac4d007 to 85f2b95 Compare March 9, 2026 16:05
@Fi3 Fi3 force-pushed the AddSupportForMultipleUsers3 branch 2 times, most recently from a2f9de5 to f8b7d08 Compare March 24, 2026 12:06
fi3 added 4 commits April 25, 2026 10:35
…oken.

Add a configurable limit for proxy token changes, with a default value of 1,
so token rotation is controlled instead of being effectively unbounded.

Load the new setting from the existing configuration pipeline and keep the
enforcement state in a shared translator-side tracker rather than inside each
SV1 downstream object. This is important because the limit must apply across
all downstream connections handled by the same proxy/upstream session, not
restart from zero for every new downstream connection.

When a downstream sends `mining.authorize` with a password different from the
current proxy token, increment the shared counter and update the shared token
state only while the change is still within the configured limit. Once the
counter reaches `limit + 1`, do not send the special `SetCustomMiningJob`
message upstream and immediately close the offending downstream connection.

Also keep each downstream's local token view synchronized with the shared
token state, preserve normal behavior for unchanged tokens and duplicate
authorize calls, and add tests covering allowed token updates, unchanged
authorize flows, and cross-downstream limit enforcement.
@Fi3 Fi3 force-pushed the AddSupportForMultipleUsers3 branch from 5d732a8 to 4e491b9 Compare April 25, 2026 08:43
Copy link
Copy Markdown
Collaborator

@lorbax lorbax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a client is exposed with max_token_changes_per_connection != 0, then anyone can change the token for that downstream. Can this be used by a malicious third party to disconnect the miner connected to it? if so, max_token_changes_per_connection must be set to 0, but we can obtain a better result working on infra, for example by putting client and fpps proxy in the same vpc?

I did not test it yet, but apart from that, looking at the code the PR is coherent and fulfills its premises. I will test it asap

Comment thread src/lib.rs
mod shutdown;
mod translator;

pub use ingress::sv1_ingress::bind_downstream_listener;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you export it?

return AuthorizeTokenAction::KeepCurrent(self.current_token.clone());
}

self.change_count = self.change_count.saturating_add(1);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does increment need to be saturating? If the max_token_change_per_connection limit has been hit, just stop increment self.change_count

ProxyState::update_upstream_state(UpstreamType::TranslatorUpstream);
}
});
} else if self
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand the logic here.
As I understand, this code activates when a miner connects with an empty password field in mining.authorize. So, there is no token (i.e. token is empty).

  1. Why do we set the max_token_changes_per_connection to be 0?
  2. does this mean that user cannot change the token anymore?

}

#[derive(Debug)]
pub(super) struct TokenChangeTracker {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to expose only to (super)?

token
}
AuthorizeTokenAction::Disconnect => {
self.disconnect_requested.set(true);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was wandering if there is a better way to signal that the downstream has to be disconnected

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