Skip to content

Commit

Permalink
stratum: allow to limit txs per block
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot committed Feb 18, 2018
1 parent 033d50c commit 236650d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
24 changes: 21 additions & 3 deletions stratum/coind_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,20 @@ YAAMP_JOB_TEMPLATE *coind_create_template(YAAMP_COIND *coind)
txids.push_back("");

templ->has_segwit_txs = false;
// to force/test
// templ->has_segwit_txs = coind->usesegwit = (coind->usesegwit || g_stratum_segwit);

templ->has_filtered_txs = false;
templ->filtered_txs_fee = 0;

for(int i = 0; i < json_tx->u.array.length; i++)
{
const char *p = json_get_string(json_tx->u.array.values[i], "hash");
char hash_be[256] = { 0 };

if (templ->has_filtered_txs) {
templ->filtered_txs_fee += json_get_int(json_tx->u.array.values[i], "fee");
continue;
}

string_be(p, hash_be);
txhashes.push_back(hash_be);

Expand All @@ -396,7 +404,6 @@ YAAMP_JOB_TEMPLATE *coind_create_template(YAAMP_COIND *coind)
string_be(txid, txid_be);
txids.push_back(txid_be);
if (strcmp(hash_be, txid_be)) {
//debuglog("%s segwit tx found, height %d\n", coind->symbol, templ->height);
templ->has_segwit_txs = true; // if not, its useless to generate a segwit block, bigger
}
} else {
Expand All @@ -405,6 +412,17 @@ YAAMP_JOB_TEMPLATE *coind_create_template(YAAMP_COIND *coind)

const char *d = json_get_string(json_tx->u.array.values[i], "data");
templ->txdata.push_back(d);

// if wanted, we can limit the count of txs to include
if (g_limit_txs_per_block && i >= g_limit_txs_per_block-2) {
debuglog("limiting block to %d first txs (of %d)\n", g_limit_txs_per_block, json_tx->u.array.length);
templ->has_filtered_txs = true;
}
}

if (templ->has_filtered_txs) {
// coinbasevalue is a total with all tx fees, need to reduce it if some are skipped
templ->value -= templ->filtered_txs_fee;
}

templ->txmerkles[0] = '\0';
Expand Down
3 changes: 3 additions & 0 deletions stratum/job.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ struct YAAMP_JOB_TEMPLATE

bool has_segwit_txs;

bool has_filtered_txs;
int filtered_txs_fee;

int auxs_size;
YAAMP_COIND_AUX *auxs[MAX_AUXS];
};
Expand Down
5 changes: 5 additions & 0 deletions stratum/stratum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ int g_stratum_max_cons = 5000;
bool g_stratum_reconnect;
bool g_stratum_renting;
bool g_stratum_segwit = false;

int g_limit_txs_per_block = 0;

bool g_autoexchange = true;

uint64_t g_max_shares = 0;
Expand Down Expand Up @@ -236,6 +239,8 @@ int main(int argc, char **argv)
g_stratum_reconnect = iniparser_getint(ini, "STRATUM:reconnect", true);
g_stratum_renting = iniparser_getint(ini, "STRATUM:renting", true);

g_limit_txs_per_block = iniparser_getint(ini, "STRATUM:max_txs_per_block", 0);

iniparser_freedict(ini);

g_current_algo = stratum_find_algo(g_stratum_algo);
Expand Down
1 change: 1 addition & 0 deletions stratum/stratum.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ extern int g_stratum_max_ttf;
extern bool g_stratum_reconnect;
extern bool g_stratum_renting;
extern bool g_stratum_segwit;
extern int g_limit_txs_per_block;

extern uint64_t g_max_shares;
extern uint64_t g_shares_counter;
Expand Down

0 comments on commit 236650d

Please sign in to comment.