Encode height using integer varint format.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
diff --git a/cgminer.c b/cgminer.c
index af26d86..a34c8ba 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -2286,11 +2286,13 @@ static bool gbt_solo_decode(struct pool *pool, json_t *res_val)
memset(pool->scriptsig_base, 0, 42);
pool->scriptsig_base[ofs++] = 49; // Template is 49 bytes
- /* Put block height at start of template */
- pool->scriptsig_base[ofs++] = 0xff; // Always encode the height as u64
- u64 = (uint64_t *)&pool->scriptsig_base[ofs];
- *u64 = htole64(height); // Encode height as LE64
- ofs += 8; // size of uint64_t
+ /* Put block height at start of template. Pad to 9 == size of int64_t */
+ len = ser_number(pool->scriptsig_base + ofs, height);
+ ofs += len;
+ len = 9 - len - 1;
+ if (len)
+ pool->scriptsig_base[ofs++] = len;
+ ofs += len;
/* Followed by flags */
pool->scriptsig_base[ofs++] = 7; // Flags length should be 7
diff --git a/util.c b/util.c
index 2349a3b..b87ff2e 100644
--- a/util.c
+++ b/util.c
@@ -719,14 +719,14 @@ void address_to_pubkeyhash(unsigned char *pkh, const char *addr)
}
/* For encoding nHeight into coinbase */
-int ser_number(unsigned char *s, uint32_t val)
+int ser_number(unsigned char *s, int64_t val)
{
int i = 1;
s[0] = i;
while (val > 127) {
- s[0] = ++i;
s[i] = val % 256;
+ s[0] = ++i;
val /= 256;
}
s[++i] = val;
diff --git a/util.h b/util.h
index 9365e46..9b5d334 100644
--- a/util.h
+++ b/util.h
@@ -108,7 +108,7 @@ enum dev_reason;
struct cgpu_info;
void b58tobin(unsigned char *b58bin, const char *b58);
void address_to_pubkeyhash(unsigned char *pkh, const char *addr);
-int ser_number(unsigned char *s, uint32_t val);
+int ser_number(unsigned char *s, int64_t val);
unsigned char *ser_string(char *s, int *slen);
int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);
void thr_info_cancel(struct thr_info *thr);