forked from jhoenicke/mempool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmempool-sql.pl
More file actions
60 lines (56 loc) · 1.89 KB
/
Copy pathmempool-sql.pl
File metadata and controls
60 lines (56 loc) · 1.89 KB
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
58
59
60
#!/usr/bin/perl
use List::Util qw[min max];
my $SQLITE="sqlite3";
my $MYSQL="mysql";
my $MEMPOOLLOG="mempool.log";
my $MYSQLMEMPOOLDB="btc_mempool";
my @feelimit=(0.0001,1,2,3,4,5,6,7,8,10,12,14,17,20,25,30,40,50,60,70,80,100,120,140,170,200,250,300,400,500,600,700,800,1000,1200,1400,1700,2000,2500,3000,4000,5000,6000,7000,8000,10000,2100000000000000);
my @total=();
my @count=();
my @fees=();
my $time = time();
for ($i = 0; $i< @feelimit - 1; $i++) {
$total[$i] = 0;
$count[$i] = 0;
$fees[$i] = 0;
}
my $found = 0;
while(<>) {
/"size": (\d+)/ and $size = $1;
/"ancestorsize": (\d+)/ and $asize = $1;
/"descendantsize": (\d+)/ and $dsize = $1;
/"fee": (\d*\.\d+)/ and $fee = int($1*1e8 + .5);
/"ancestorfees": (\d+)/ and $afees = $1;
/"descendantfees": (\d+)/ and $dfees = $1;
if (/},/) {
$afpb = $afees / $asize; # ancestor fee (includes current)
$fpb = $fee / $size; # current fee
$dfpb = $dfees / $dsize; # descendant fee (includes current)
# total average fee for mining all ancestors and descendants.
$tfpb = ($afees + $dfees - $fee) / ($asize + $dsize - $size);
# the "min"s ensure we take the fee level of ancestors in account
# if and only if they pay less (like a miner would do).
# the "max" ensures we take the descendants into account for CPFP.
$feeperbyte = max(min($dfpb, $tfpb), min($fpb, $afpb));
for ($i = 0; $i< @feelimit-1; $i++) {
if ($feeperbyte >= $feelimit[$i] && $feeperbyte < $feelimit[$i+1]) {
$total[$i] += $size;
$count[$i]++;
$fees[$i] += $fee;
}
}
$found = 1;
}
}
if ($found) {
my $cnt = join(",", @count);
my $size = join(",", @total);
my $fee = join(",", @fees);
open(LOG, ">>$MEMPOOLLOG");
print LOG "[$time,[$cnt],[$size],[$fee]],\n";
close(LOG);
open(SQL, "|$MYSQL $MYSQLMEMPOOLDB");
$line = "INSERT INTO mempool VALUES($time,$cnt,$size,$fee);\n";
print SQL $line;
close SQL;
}