mmnode-blocks-info: minor fixes, cleanups
This commit is contained in:
parent
374bb21bcd
commit
5d1c392131
4 changed files with 32 additions and 17 deletions
|
|
@ -146,24 +146,25 @@ class BlocksInfo:
|
|||
break
|
||||
yield ls + self.fields[name].fs + rs
|
||||
|
||||
def parse_cmd_args():
|
||||
def parse_cmd_args(): # => (block_list, first, last, step)
|
||||
if not cmd_args:
|
||||
return (None,self.tip,self.tip)
|
||||
return (None,self.tip,self.tip,None)
|
||||
elif len(cmd_args) == 1:
|
||||
r = self.parse_rangespec(cmd_args[0])
|
||||
return (
|
||||
list(range(r.first,r.last+1,r.step)) if r.step else None,
|
||||
r.first,
|
||||
r.last
|
||||
r.last,
|
||||
r.step
|
||||
)
|
||||
else:
|
||||
return ([self.conv_blkspec(a) for a in cmd_args],None,None)
|
||||
return ([self.conv_blkspec(a) for a in cmd_args],None,None,None)
|
||||
|
||||
self.rpc = rpc
|
||||
self.opt = opt
|
||||
self.tip = rpc.blockcount
|
||||
|
||||
self.block_list,self.first,self.last = parse_cmd_args()
|
||||
self.block_list,self.first,self.last,self.step = parse_cmd_args()
|
||||
|
||||
fnames = get_fields() if opt.fields else self.dfl_fields
|
||||
|
||||
|
|
@ -288,7 +289,7 @@ class BlocksInfo:
|
|||
|
||||
return self.range_data(first,last,from_tip,nblocks,step)
|
||||
|
||||
async def run(self):
|
||||
async def process_blocks(self):
|
||||
|
||||
c = self.rpc
|
||||
heights = self.block_list or range(self.first,self.last+1)
|
||||
|
|
@ -311,10 +312,11 @@ class BlocksInfo:
|
|||
if self.block_list:
|
||||
await init(n)
|
||||
ret = await self.process_block(heights[n],hashes[n],self.hdrs[n])
|
||||
if opt.stats_only:
|
||||
continue
|
||||
else:
|
||||
Msg(self.fs.format(*ret))
|
||||
if not self.opt.stats_only:
|
||||
self.output_block(ret,n)
|
||||
|
||||
def output_block(self,data,n):
|
||||
Msg(self.fs.format(*data))
|
||||
|
||||
async def process_block(self,height,H,hdr):
|
||||
class local_vars: pass
|
||||
|
|
@ -375,7 +377,7 @@ class BlocksInfo:
|
|||
Msg(self.fs.format(*hdr1))
|
||||
Msg(self.fs.format(*hdr2))
|
||||
|
||||
def print_stats(self,name):
|
||||
def process_stats(self,name):
|
||||
return getattr(self,f'print_{name}_stats')()
|
||||
|
||||
async def print_range_stats(self):
|
||||
|
|
@ -419,19 +421,27 @@ class BlocksInfo:
|
|||
if rel > bdi_avg_blks:
|
||||
rel_hdr = await c.call('getblockheader',await c.call('getblockhash',self.tip-rel))
|
||||
bdi = ( tip_hdr['time'] - rel_hdr['time'] ) / rel
|
||||
bdi_disp = bdi
|
||||
else:
|
||||
bdi_adj = float(tip_hdr['difficulty'] / bdi_avg_hdr['difficulty'])
|
||||
bdi = bdi_avg * ( (bdi_adj * (bdi_avg_blks-rel)) + rel ) / bdi_avg_blks
|
||||
bdi_disp = bdi_avg
|
||||
|
||||
rem = 2016 - rel
|
||||
Msg_r(fmt(f"""
|
||||
Current height: {self.tip}
|
||||
Next diff adjust: {self.tip+rem} (in {rem} block{suf(rem)} [{self.t_fmt((rem)*bdi_avg)}])
|
||||
BDI (cur period): {bdi/60:.2f} min
|
||||
BDI (cur period): {bdi_disp/60:.2f} min
|
||||
Cur difficulty: {tip_hdr['difficulty']:.2e}
|
||||
Est. diff adjust: {((600 / bdi) - 1) * 100:+.2f}%
|
||||
"""))
|
||||
|
||||
def process_stats_pre(self,i):
|
||||
if not (self.opt.stats_only and i == 0):
|
||||
Msg('')
|
||||
|
||||
def finalize_output(self): pass
|
||||
|
||||
# 'getblockstats' RPC raises exception on Genesis Block, so provide our own stats:
|
||||
genesis_stats = {
|
||||
'avgfee': 0,
|
||||
|
|
|
|||
|
|
@ -118,23 +118,25 @@ cmd_args = opts.init(opts_data)
|
|||
async def main():
|
||||
|
||||
from mmgen.protocol import init_proto_from_opts
|
||||
from mmgen.rpc import rpc_init
|
||||
|
||||
proto = init_proto_from_opts()
|
||||
|
||||
from mmgen.rpc import rpc_init
|
||||
m = BlocksInfo( cmd_args, opt, await rpc_init(proto) )
|
||||
|
||||
if not opt.no_header:
|
||||
m.print_header()
|
||||
|
||||
await m.run()
|
||||
await m.process_blocks()
|
||||
|
||||
if m.last and m.stats:
|
||||
for i,stat in enumerate(m.stats):
|
||||
if stat == 'diff': # Display diff stats by default only if user-requested range ends with chain tip
|
||||
if not opt.stats and m.last != m.tip:
|
||||
continue
|
||||
if not (opt.stats_only and i == 0):
|
||||
Msg('')
|
||||
await m.print_stats(stat)
|
||||
m.process_stats_pre(i)
|
||||
await m.process_stats(stat)
|
||||
|
||||
m.finalize_output()
|
||||
|
||||
run_session(main())
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -28,6 +28,8 @@ class my_install_data(install_data):
|
|||
os.chmod(os.path.join(sdir,f),0o644)
|
||||
install_data.run(self)
|
||||
|
||||
os.umask(0o0022)
|
||||
|
||||
setup(
|
||||
name = 'mmgen-node-tools',
|
||||
description = 'Optional tools for the MMGen wallet system',
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ class dummyRPC:
|
|||
|
||||
class dummyOpt:
|
||||
fields = None
|
||||
stats = None
|
||||
miner_info = None
|
||||
|
||||
class unit_tests:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue