예제 #1
0
def main(argv):
    conf = {
        "count": 200,
        "seed": 1,
        "blkfile": None,
    }
    cmdline = util.CmdLine(argv, conf)
    cmdline.usage = lambda: \
        """Usage: python -m Abe.mixup [-h] [--config=FILE] [--CONFIGVAR=VALUE]...

Load blocks out of order.

  --help                    Show this help message and exit.
  --config FILE             Read options from FILE.
  --count NUMBER            Load COUNT blocks.
  --blkfile FILE            Load the first COUNT blocks from FILE.
  --seed NUMBER             Random seed (not implemented; 0=file order).

All configuration variables may be given as command arguments."""

    store, argv = cmdline.init()
    if store is None:
        return 0
    args = store.args

    if args.blkfile is None:
        raise ValueError("--blkfile is required.")

    ds = BCDataStream.BCDataStream()
    file = open(args.blkfile, "rb")
    ds.map_file(file, 0)
    file.close()
    mixup_blocks(store, ds, int(args.count), None, int(args.seed or 0))
    return 0
예제 #2
0
def main(argv):
    cmdline = util.CmdLine(argv)
    cmdline.usage = lambda: \
        """Usage: python -m Abe.admin [-h] [--config=FILE] COMMAND...

Options:

  --help                    Show this help message and exit.
  --config FILE             Abe configuration file.

Commands:

  delete-chain-blocks NAME  Delete all blocks in the specified chain
                            from the database.

  delete-chain-transactions NAME  Delete all blocks and transactions in
                            the specified chain.

  delete-tx TX_ID           Delete the specified transaction.
  delete-tx TX_HASH

  link-txin                 Link transaction inputs to previous outputs.

  rewind-datadir DIRNAME    Reset the pointer to force a rescan of
                            blockfiles in DIRNAME."""

    store, argv = cmdline.init()
    if store is None:
        return 0

    while len(argv) != 0:
        command = argv.pop(0)
        if command == 'delete-chain-blocks':
            delete_chain_blocks(store, argv.pop(0))
        elif command == 'delete-chain-transactions':
            delete_chain_transactions(store, argv.pop(0))
        elif command == 'delete-tx':
            delete_tx(store, argv.pop(0))
        elif command == 'rewind-datadir':
            rewind_datadir(store, argv.pop(0))
        elif command == 'link-txin':
            link_txin(store)
        else:
            raise ValueError("Unknown command: " + command)

    return 0
예제 #3
0
def main(argv):
    cmdline = util.CmdLine(argv)
    cmdline.usage = lambda: \
        "Usage: verify.py --dbtype=MODULE --connect-args=ARGS"

    store, argv = cmdline.init()
    if store is None:
        return 0

    logger = logging.getLogger("verify")
    checked, bad = 0, 0
    for (chain_id, ) in store.selectall("""
        SELECT chain_id FROM chain"""):
        logger.info("checking chain %d", chain_id)
        checked1, bad1 = verify_tx_merkle_hashes(store, logger, chain_id)
        checked += checked1
        bad += bad1
    logger.info("All chains: %d Merkle trees, %d bad", checked, bad)
    return bad and 1
예제 #4
0
def main(argv):
    cmdline = util.CmdLine(argv)
    cmdline.usage = lambda: \
        """Usage: python -m Abe.reconfigure [-h] [--config=FILE] [--CONFIGVAR=VALUE]...

Apply configuration changes to an existing Abe database, if possible.

  --help                    Show this help message and exit.
  --config FILE             Read options from FILE.
  --use-firstbits {true|false}
                            Turn Firstbits support on or off.
  --keep-scriptsig false    Remove input validation scripts from the database.

All configuration variables may be given as command arguments."""

    store, argv = cmdline.init()
    if store is None:
        return 0

    firstbits.reconfigure(store, args)
    keep_scriptsig_reconfigure(store, args)
    return 0
예제 #5
0
def main(argv):
    cmdline = util.CmdLine(argv)
    cmdline.usage = lambda: \
        """Usage: verify.py --dbtype=MODULE --connect-args=ARGS [checks]

  Check database consistency

  Chain selection:
    --chain LIST    Comma-separated list of chains to check (Default: all)

  Checks:
    --check-all     Check everything (overrides all other check options)
    --merkle-roots  Check merkle root hashes against block's transaction
    --block-stats   Check block statistics computed from prev blocks and
                    transactions

  Options (can be combined):
    --verbose       Print all errors found (default)
    --quiet         Print only progress info and error summary
    --silent        Print nothing; no feedback beside return code
    --min-height N  Check only blocks starting at height N
    --max-height N  Stop checking blocks above height N
    --blkstats LIST Comma-separated list of block statistics to check
                    Default: all valid values:
                      """ + ','.join(BLOCK_STATS_LIST) + """
    --repair        Attempt to repair the database (not all checks support
                    repair)

  Warning: Some checks rely on previous blocks to have valid information.
   Testing from a specific height does not guarantee the previous blocks are
   valid and while the computed data may be relatively valid the whole thing
   could still be totally off.

  The checks can generate a lot of output in the default mode (--verbose). To
  limit output to progress messages and results use the --quiet option.
"""

    store, argv = cmdline.init()
    if store is None:
        return 0

    logger = logging.getLogger("verify")
    # Override any defined loggers from abe's config
    logging.root.handlers = []
    logging.basicConfig(stream=sys.stdout, level=logging.INFO,
                        format="%(asctime)s: %(name)s: %(message)s")

    chk = AbeVerify(store, logger)

    try:
        opts, args = getopt.getopt(argv, "", [
            'chain=',
            'check-all',
            'merkle-roots',
            'block-stats',
            'verbose',
            'quiet',
            'silent',
            'min-height=',
            'max-height=',
            'blkstats=',
            'repair',
        ])
    except getopt.GetoptError as e:
        print e.msg, "\n\n", cmdline.usage()
        return 1

    chains = None
    err = 0
    for opt, arg in opts:
        if opt == '--chain':
            chains = arg.split(',')
        if opt == '--check-all':
            chk.ckmerkle, chk.ckstats = True, True
        if opt == '--merkle-roots':
            chk.ckmerkle = True
        if opt == '--block-stats':
            chk.ckstats = True
        if opt == '--verbose':
            logger.setLevel('INFO')
        if opt == '--quiet':
            logger.setLevel('WARNING')
        if opt == '--silent':
            logger.setLevel('ERROR')
        if opt == '--min-height':
            chk.block_min = int(arg)
        if opt == '--max-height':
            chk.block_max = int(arg)
        if opt == '--blkstats':
            chk.blkstats = arg.split(',')
        if opt == '--repair':
            chk.repair = True

    if args:
        print "Extra argument: %s!\n\n" % args[0], cmdline.usage()
        return 1

    if True not in (chk.ckmerkle, chk.ckstats):
        print "No checks selected!\n\n", cmdline.usage()
        return 1


    for chain_id, in store.selectall("""
        SELECT chain_id FROM chain ORDER BY chain_id DESC"""):
        chain = store.chains_by.id[chain_id]
        if chains is not None:
            if chain.name not in chains:
                continue
            chains.remove(chain.name)

        logger.warning("Checking %s chain (id %d) at height %d",
                chain.name, chain_id, (chk.block_min if chk.block_min else 0))

        try:
            chk.verify_blockchain(chain_id, chain)
        except KeyboardInterrupt:
            # Prevents some DB warnings warnings
            store.close()
            raise

        endmsg="Chain %s: %d blocks checked"
        endparams = (max(chk.mchecked, chk.schecked),)
        err += max(chk.mbad, chk.sbad)
        if chk.ckmerkle and chk.mbad:
            endmsg += ", %d bad merkle tree hashes"
            endparams += (chk.mbad,)
        if chk.ckstats and chk.sbad:
            endmsg += ", %d bad blocks stats"
            endparams += (chk.sbad,)
        if len(endparams) == 1:
            endmsg += ", no error found"
        logger.warning(endmsg, chain.name, *endparams)

    if chains:
        err += 1
        logger.warning("%d chain%s not found: %s",
            len(chains),
            ("s" if len(chains) > 1 else ""),
            ', '.join(chains),
        )
    return err and 1