mempool: mem usage estimation.
This commit is contained in:
parent
9c8d4d185f
commit
d17ba07475
@ -1493,7 +1493,7 @@ Mempool.prototype._removeSpenders = function _removeSpenders(entry) {
|
||||
|
||||
Mempool.prototype.memUsage = function memUsage(tx) {
|
||||
var mem = 0;
|
||||
var i, input, output;
|
||||
var i, j, input, output, coin, op;
|
||||
|
||||
mem += 264; // tx
|
||||
mem += 80; // _hash
|
||||
@ -1507,13 +1507,19 @@ Mempool.prototype.memUsage = function memUsage(tx) {
|
||||
mem += 144; // input
|
||||
|
||||
if (input.coin) {
|
||||
coin = input.coin;
|
||||
mem += 144; // coin
|
||||
mem += 88; // coin hash
|
||||
mem += 40; // script
|
||||
mem += 80; // script raw buffer
|
||||
mem += 32; // script code array
|
||||
mem += input.coin.script.code.length * 40; // opcodes
|
||||
mem += 80; // add a code buffer (assume p2pkh)
|
||||
mem += coin.script.code.length * 40; // opcodes
|
||||
|
||||
for (j = 0; j < coin.script.code.length; j++) {
|
||||
op = coin.script.code[j];
|
||||
if (op.data)
|
||||
mem += 80; // op buffers
|
||||
}
|
||||
}
|
||||
|
||||
mem += 104; // prevout
|
||||
@ -1523,7 +1529,12 @@ Mempool.prototype.memUsage = function memUsage(tx) {
|
||||
mem += 80; // script raw buffer
|
||||
mem += 32; // script code array
|
||||
mem += input.script.code.length * 40; // opcodes
|
||||
mem += 160; // add two code buffers (assume p2pkh)
|
||||
|
||||
for (j = 0; j < input.script.code.length; j++) {
|
||||
op = input.script.code[j];
|
||||
if (op.data)
|
||||
mem += 80; // op buffers
|
||||
}
|
||||
|
||||
mem += 96; // witness
|
||||
mem += 32; // witness items
|
||||
@ -1534,22 +1545,22 @@ Mempool.prototype.memUsage = function memUsage(tx) {
|
||||
|
||||
for (i = 0; i < tx.outputs.length; i++) {
|
||||
output = tx.outputs[i];
|
||||
|
||||
mem += 120; // output
|
||||
mem += 40; // script
|
||||
mem += 80; // script raw buffer
|
||||
mem += 32; // script code array
|
||||
mem += output.script.code.length * 40; // opcodes
|
||||
mem += 80; // add a code buffer (assume p2pkh)
|
||||
|
||||
for (j = 0; j < output.script.code.length; j++) {
|
||||
op = output.script.code[j];
|
||||
if (op.data)
|
||||
mem += 80; // op buffers
|
||||
}
|
||||
}
|
||||
|
||||
mem += 176; // mempool entry
|
||||
|
||||
// Note: normally we could add 176 (88 * 2)
|
||||
// bytes for the spent and tx hash table
|
||||
// entries, but v8 seems to store these
|
||||
// strings off the heap, so it shouldn't
|
||||
// be too much of a problem.
|
||||
|
||||
return mem;
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user