From b36b7792aec3a85b9e5fd03c0798d97c7eb445a1 Mon Sep 17 00:00:00 2001 From: Jeremy Anderson Date: Thu, 16 Apr 2020 00:05:15 -0600 Subject: [PATCH] Use correct varint value (#54) Explanation of this code provided by blondefrogs: The transactions in a block are places in a vector. To serialize a vector, we need to be able to read its contents, so it serializes the size of the vector first but we don't know the size, so it uses a variable called a varint. A varint is trying to serialize the size in as little bits as possible. If the size is below 0xfc, it will just serialize the size Otherwise, if the size is above 0xfc, it will serialize a 0xfd first, then the size. Basically, before this fix, the stratum would submit an invalidly coded block to the node if there were between 127 - 253 transactions in the block. --- lib/blockTemplate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/blockTemplate.js b/lib/blockTemplate.js index 8224b15..4be3c60 100644 --- a/lib/blockTemplate.js +++ b/lib/blockTemplate.js @@ -189,7 +189,7 @@ var BlockTemplate = module.exports = function BlockTemplate( txCount = "0" + txCount; } - if (this.txCount <= 0x7f){ + if (this.txCount <= 0xfc){ var varInt = new Buffer(txCount, 'hex'); } else if (this.txCount <= 0x7fff) { if (txCount.length == 2) {