diff --git a/src/stratifier.c b/src/stratifier.c index 20c4f4a5..8800b73e 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -180,6 +180,7 @@ struct user_instance { double dsps1440; double dsps10080; tv_t last_share; + time_t auth_time; }; /* Combined data from workers with the same workername */ @@ -1981,6 +1982,8 @@ static int send_recv_auth(stratum_instance_t *client) json_get_string(&secondaryuserid, val, "secondaryuserid"); json_get_int(&worker->mindiff, val, "difficultydefault"); client->suggest_diff = worker->mindiff; + if (!user_instance->auth_time) + user_instance->auth_time = time(NULL); } if (secondaryuserid && (!safecmp(response, "ok.authorise") || !safecmp(response, "ok.addrauth"))) { @@ -2082,7 +2085,13 @@ static json_t *parse_authorise(stratum_instance_t *client, json_t *params_val, j if (CKP_STANDALONE(ckp)) ret = true; else { - *errnum = send_recv_auth(client); + /* Preauth workers for the first 10 minutes after the user is + * first authorised by ckdb to avoid floods of worker auths. + * *errnum is implied zero already so ret will be set true */ + if (user_instance->auth_time && time(NULL) - user_instance->auth_time < 600) + queue_delayed_auth(client); + else + *errnum = send_recv_auth(client); if (!*errnum) ret = true; else if (*errnum < 0 && user_instance->secondaryuserid) {