From 28b2ff02304ac8af8a045c26eef46b401ef78d58 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sat, 3 May 2014 22:37:08 +0000 Subject: [PATCH] blkmk_get_mdata: Accept can_roll_ntime as an argument --- README | 14 ++++++++++---- blkmaker.c | 4 ++-- blkmaker.h | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README b/README index d5820a2..1f6f5bf 100644 --- a/README +++ b/README @@ -10,7 +10,13 @@ Note that you must assign blkmk_sha256_impl to a function pointer: bool mysha256(void *hash_out, const void *data, size_t datasz) hash_out must be able to overlap with data! -Also note that you should NOT roll ntime for data retrieved; while it will -probably work, there is no guarantee it won't fall outside the maxtime limits -for the blocktemplate. It is usually best to simply get more data as often -as it is needed. +Also note that you should NOT roll ntime for data retrieved without explicitly +checking that it falls within the template's limitations (mintime, maxtime, +mintimeoff, and maxtimeoff); read the BIP 23 specification in detail to +understand how they work. It is usually best to simply get more data as often +as it is needed. For blkmk_get_mdata, you may specify that you intend to roll +the ntime header exactly once per second past usetime - it will then set +*out_expires such that the expiration occurs before you roll beyond any ntime +limits. If you are rolling ntime at any rate other than once per second, you +should NOT specify can_roll_ntime to blkmk_get_mdata, and must check that your +usage falls within the explicit template limits yourself. diff --git a/blkmaker.c b/blkmaker.c index cf8bebe..13810f7 100644 --- a/blkmaker.c +++ b/blkmaker.c @@ -345,7 +345,7 @@ size_t blkmk_get_data(blktemplate_t *tmpl, void *buf, size_t bufsz, time_t useti return 76; } -bool blkmk_get_mdata(blktemplate_t * const tmpl, void * const buf, const size_t bufsz, const time_t usetime, int16_t * const out_expire, void * const _out_cbtxn, size_t * const out_cbtxnsz, size_t * const cbextranonceoffset, int * const out_branchcount, void * const _out_branches, size_t extranoncesz) +bool blkmk_get_mdata(blktemplate_t * const tmpl, void * const buf, const size_t bufsz, const time_t usetime, int16_t * const out_expire, void * const _out_cbtxn, size_t * const out_cbtxnsz, size_t * const cbextranonceoffset, int * const out_branchcount, void * const _out_branches, size_t extranoncesz, const bool can_roll_ntime) { if (!(true && blkmk_time_left(tmpl, usetime) @@ -378,7 +378,7 @@ bool blkmk_get_mdata(blktemplate_t * const tmpl, void * const buf, const size_t return false; } - blkmk_set_times(tmpl, &cbuf[68], usetime, out_expire, true); + blkmk_set_times(tmpl, &cbuf[68], usetime, out_expire, can_roll_ntime); memcpy(&cbuf[72], &tmpl->diffbits, 4); *out_branchcount = tmpl->_mrklbranchcount; diff --git a/blkmaker.h b/blkmaker.h index 2cdb5c2..460aee3 100644 --- a/blkmaker.h +++ b/blkmaker.h @@ -19,7 +19,7 @@ extern ssize_t blkmk_append_coinbase_safe(blktemplate_t *, const void *append, s extern ssize_t blkmk_append_coinbase_safe2(blktemplate_t *, const void *append, size_t appendsz, int extranoncesz, bool merkle_only); extern bool _blkmk_extranonce(blktemplate_t *tmpl, void *vout, unsigned int workid, size_t *offs); extern size_t blkmk_get_data(blktemplate_t *, void *buf, size_t bufsz, time_t usetime, int16_t *out_expire, unsigned int *out_dataid); -extern bool blkmk_get_mdata(blktemplate_t *, void *buf, size_t bufsz, time_t usetime, int16_t *out_expire, void *out_cbtxn, size_t *out_cbtxnsz, size_t *cbextranonceoffset, int *out_branchcount, void *out_branches, size_t extranoncesz); +extern bool blkmk_get_mdata(blktemplate_t *, void *buf, size_t bufsz, time_t usetime, int16_t *out_expire, void *out_cbtxn, size_t *out_cbtxnsz, size_t *cbextranonceoffset, int *out_branchcount, void *out_branches, size_t extranoncesz, bool can_roll_ntime); extern blktime_diff_t blkmk_time_left(const blktemplate_t *, time_t nowtime); extern unsigned long blkmk_work_left(const blktemplate_t *); #define BLKMK_UNLIMITED_WORK_COUNT ULONG_MAX