Example #1
0
    def start(self):

        log = self.app.log
        args = self.app.pargs

        abci_app = ABCIServer(app=EzoABCI())
        abci_app.run()
Example #2
0
def start():
    logger.info(BANNER)

    from abci import ABCIServer

    app = ABCIServer(app=App())
    app.run()
Example #3
0
def start():
    # Exchange object for event stream api
    logger.info('Starting BigchainDB')
    exchange = Exchange()
    # start the web api
    app_server = server.create_server(settings=bigchaindb.config['server'],
                                      log_config=bigchaindb.config['log'],
                                      bigchaindb_factory=BigchainDB)
    p_webapi = Process(name='bigchaindb_webapi',
                       target=app_server.run,
                       daemon=True)
    p_webapi.start()

    # start message
    logger.info(BANNER.format(bigchaindb.config['server']['bind']))

    # start websocket server
    p_websocket_server = Process(name='bigchaindb_ws',
                                 target=websocket_server.start,
                                 daemon=True,
                                 args=(exchange.get_subscriber_queue(
                                     EventTypes.BLOCK_VALID), ))
    p_websocket_server.start()

    # connect to tendermint event stream
    p_websocket_client = Process(name='bigchaindb_ws_to_tendermint',
                                 target=event_stream.start,
                                 daemon=True,
                                 args=(exchange.get_publisher_queue(), ))
    p_websocket_client.start()

    p_exchange = Process(name='bigchaindb_exchange',
                         target=exchange.run,
                         daemon=True)
    p_exchange.start()

    # We need to import this after spawning the web server
    # because import ABCIServer will monkeypatch all sockets
    # for gevent.
    from abci import ABCIServer

    setproctitle.setproctitle('bigchaindb')

    # Start the ABCIServer
    app = ABCIServer(app=App())
    app.run()
Example #4
0
def abci_server():
    from abci import ABCIServer
    from bigchaindb.tendermint.core import App
    from bigchaindb.utils import Process

    app = ABCIServer(app=App())
    abci_proxy = Process(name='ABCI', target=app.run)
    yield abci_proxy.start()
    abci_proxy.terminate()
Example #5
0
def start():
    # Exchange object for event stream api
    logger.info('Starting BigchainDB')
    exchange = Exchange()
    # start the web api
    app_server = server.create_server(
        settings=bigchaindb.config['server'],
        log_config=bigchaindb.config['log'],
        bigchaindb_factory=BigchainDB)
    p_webapi = Process(name='bigchaindb_webapi', target=app_server.run, daemon=True)
    p_webapi.start()

    # start message
    logger.info(BANNER.format(bigchaindb.config['server']['bind']))

    # start websocket server
    p_websocket_server = Process(name='bigchaindb_ws',
                                 target=websocket_server.start,
                                 daemon=True,
                                 args=(exchange.get_subscriber_queue(EventTypes.BLOCK_VALID),))
    p_websocket_server.start()

    # connect to tendermint event stream
    p_websocket_client = Process(name='bigchaindb_ws_to_tendermint',
                                 target=event_stream.start,
                                 daemon=True,
                                 args=(exchange.get_publisher_queue(),))
    p_websocket_client.start()

    p_exchange = Process(name='bigchaindb_exchange', target=exchange.run, daemon=True)
    p_exchange.start()

    # We need to import this after spawning the web server
    # because import ABCIServer will monkeypatch all sockets
    # for gevent.
    from abci import ABCIServer

    setproctitle.setproctitle('bigchaindb')

    # Start the ABCIServer
    app = ABCIServer(app=App())
    app.run()
Example #6
0
def start(args):

    # Exchange object for event stream api
    logger.info('Starting BigchainDB')
    exchange = Exchange()
    # start the web api
    app_server = server.create_server(settings=bigchaindb.config['server'],
                                      log_config=bigchaindb.config['log'],
                                      bigchaindb_factory=BigchainDB)
    p_webapi = Process(name='bigchaindb_webapi',
                       target=app_server.run,
                       daemon=True)
    p_webapi.start()

    logger.info(BANNER.format(bigchaindb.config['server']['bind']))

    # start websocket server
    p_websocket_server = Process(name='bigchaindb_ws',
                                 target=websocket_server.start,
                                 daemon=True,
                                 args=(exchange.get_subscriber_queue(
                                     EventTypes.BLOCK_VALID), ))
    p_websocket_server.start()

    p_exchange = Process(name='bigchaindb_exchange',
                         target=exchange.run,
                         daemon=True)
    p_exchange.start()

    # We need to import this after spawning the web server
    # because import ABCIServer will monkeypatch all sockets
    # for gevent.
    from abci import ABCIServer

    setproctitle.setproctitle('bigchaindb')

    # Start the ABCIServer
    if args.experimental_parallel_validation:
        app = ABCIServer(app=ParallelValidationApp(
            events_queue=exchange.get_publisher_queue()))
    else:
        app = ABCIServer(app=App(events_queue=exchange.get_publisher_queue()))
    app.run()
Example #7
0
        logger.info("Transaction delivered succesfully")
        return ResponseDeliverTx(code=CodeTypeOk)

    def check_tx(self, tx):
        return ResponseCheckTx(code=CodeTypeOk)

    def commit(self):
        byte_length = max(ceil(self.state.size.bit_length() / 8), 1)
        app_hash = self.state.size.to_bytes(byte_length, byteorder='big')
        self.state.app_hash = app_hash
        self.state.height += 1
        self.state.save()
        return ResponseCommit(data=app_hash)

    def query(self, req):
        if req.prove:
            value = self.state.db.get(prefix_key(req.data))
            # todo: make Proof return index
            return ResponseQuery(code=CodeTypeOk, value=value)
        else:
            value = self.state.db.get(prefix_key(req.data))
            return ResponseQuery(code=CodeTypeOk, value=value)


if __name__ == '__main__':
    logger.info("Initalisation is complete. KV Store Application is ready")

    app = ABCIServer(app=KVStoreApplication())
    app.run()
Example #8
0
        if not self.__valid_input(tx):
            return Result.error(log='bad count')

        self.txCount += 1
        return Result.ok()

    def end_block(self, height):
        """Called at the end of processing. If this is a stateful application
        you can use the height from here to record the last_block_height"""
        self.last_block_height = height
        return ResponseEndBlock()

    def query(self, reqQuery):
        """Return the last tx count"""
        v = encode_number(self.txCount)
        rq = ResponseQuery(code=0,
                           key=b'count',
                           value=v,
                           height=self.last_block_height)
        return rq

    def commit(self):
        """Return the current encode state value to tendermint"""
        h = struct.pack('>Q', self.txCount)
        return Result.ok(data=h)


if __name__ == '__main__':
    app = ABCIServer(app=SimpleCounter())
    app.run()
Example #9
0
            return ResponseCheckTx(code=1)
        return ResponseCheckTx(code=CodeTypeOk)

    def deliver_tx(self, tx) -> ResponseDeliverTx:
        """Simply increment the state"""
        self.txCount += 1
        return ResponseDeliverTx(code=CodeTypeOk)

    def query(self, req) -> ResponseQuery:
        """Return the last tx count"""
        v = encode_number(self.txCount)
        return ResponseQuery(code=CodeTypeOk, value=v, height=self.last_block_height)

    def commit(self) -> ResponseCommit:
        """Return the current encode state value to tendermint"""
        hash = struct.pack('>Q', self.txCount)
        return ResponseCommit(data=hash)


if __name__ == '__main__':
    # Define argparse argument for changing proxy app port
    parser = argparse.ArgumentParser()
    parser.add_argument('-p', type=int, help='Proxy app port')
    args = parser.parse_args()
    # Create the app
    if args.p is None:
        app = ABCIServer(app=SimpleCounter())   # defaults to default port if -p not provided
    else:
        app = ABCIServer(app=SimpleCounter(), port=args.p)
    # Run it
    app.run()
Example #10
0
            return rq

    def begin_block(self, reqBeginBlock):
        """Called to process a block"""

        self.new_block_txs = []
        return ResponseBeginBlock()

    def end_block(self, height):
        """Called at the end of processing. If this is a stateful application
        you can use the height from here to record the last_block_height"""

        self.db.set_block_height(increment=True)
        if self.new_block_txs:  # Change app hash only if there any new txns
            self.db.set_block_app_hash(
                utils.get_merkle_root(self.new_block_txs))

        return ResponseEndBlock()

    def commit(self):
        """Return the current encode state value to tendermint"""

        h = self.db.get_block_app_hash().encode()

        return ResponseCommit(data=h)


if __name__ == '__main__':
    app = ABCIServer(app=SimpleCoin(), port=26658)
    app.run()
Example #11
0
 def run(self):
     """ Run the app in the py-abci server
     """
     server = ABCIServer(app=self)
     server.run()
Example #12
0

    # def reset_chains(self):
    #     """
    #     reset the state of the application.
    #     """
    #     self.bdomainschain = Blockchain()
    #     self.bobjectschain = Blockchain()
    #     self.bdomainstree = MerkleTools(hash_type="md5")
    #     self.bobjectstree = MerkleTools(hash_type="md5")
    #     self.db0domains = DB0()
    #     self.db0objects = DB0()
    #     self.users = {}
    #     self.groups = {}
    #     self.acls = {}
    #     self.acis = {}


    # def restore_state(self):
    #     """
    #     Apply the transactions from the chains the achieve the application state.
    #     """
    #     for tx in self.bdomainschain:
    #         self.handle_tx(tx)
    #     for tx in self.bobjectschain:
    #         self.handle_tx(tx)


if __name__ == '__main__':
    app = ABCIServer(app=SimpleRC())
    app.run()
Example #13
0
    def deliver_tx(self, tx: bytes) -> ResponseDeliverTx:
        message = decode(tx)
        self.state, resp = self.handlers[type(message.data)].deliver_tx(self.state, message)
        return resp

    def query(self, req) -> ResponseQuery:
        message = sign_message(RawMessage(self.public_key, self.state, self.sequence), self.private_key)
        res = encode_for_wire(message)
        self.sequence += 1
        return ResponseQuery(code=CodeTypeOk, value=res, height=self.state.last_block_height)

    def end_block(self, req) -> ResponseEndBlock:
        self.state, resp = self.end_block_handler.end_block(self.state, req)
        return resp

    def commit(self) -> ResponseCommit:
        return ResponseCommit(data=state_hash(self.state))


if __name__ == '__main__':
    tp = TenderPotato(
        [
            NewPlayerHandler(),
            TossPotatoHandler(),
        ],
        FixedBlowUp(100),
    )
    app = ABCIServer(app=tp)
    app.run()
Example #14
0
        self.state.app_hash = app_hash
        self.state.height += 1
        self.state.save()
        return ResponseCommit(data=app_hash)

    def query(self, req):
        output = dict()
        param = req.data.split(b',')
        varId = param[0].split(b':')[1]
        varSpk = param[1].split(b':')[1]
        varRpk = param[2].split(b':')[1]
        srchStr = "id:" + varId.decode('ascii') + ","
        srchStr = srchStr + "senderpk:" + (varSpk.decode('ascii'),
                                           ".*")[varSpk == b''] + ","
        srchStr = srchStr + "receiverpk:" + (varRpk.decode('ascii'),
                                             ".*")[varRpk == b'']
        for key, val in self.state.db.snapshot().items():
            x = re.search(srchStr, key.decode('ascii'))
            if not x is None:
                value = self.state.db.get(key)
                output[key] = value
        return ResponseQuery(code=CodeTypeOk,
                             value=str(output).encode('ascii'))


if __name__ == '__main__':
    logger.info("Initalisation is complete. KV Store Application is ready")

    app = ABCIServer(app=KVStoreApplication(), port=46658)
    app.run()
Example #15
0
                        help='Path to dataset')
    parser.add_argument('-device', type=str, default="CPU", help='Device')
    parser.add_argument('-config', type=str, default=None, help='config')
    args = parser.parse_args()

    if args.config is None:
        exit("No config.ini found.")

    con = Configer(args.config)

    os.environ["DATASET"] = con.trainer.get_dataset()

    # newsender = sender(log, url_="http://node0:26657")
    newsender = sender(log, url_=con.bcfl.get_sender())
    # newdb = moddb("ipfs")
    newdb = moddb(con.bcfl.get_db())

    newagg = aggregator(log, con, newdb, newsender)
    # newtrain = trainer(log, args.dataset, newdb, newsender, devices=args.device)
    newtrain = trainer(log, con, newdb, newsender)

    newcontroller = State_controller(log, newtrain, newagg,
                                     con.agg.get_threshold())

    # Create the app
    # app = ABCIServer(app=SimpleBCFL(newcontroller), port=args.p)
    app = ABCIServer(app=SimpleBCFL(newcontroller),
                     port=con.bcfl.get_app_port())
    # Run it
    app.run()
Example #16
0
            try:
                self.f1 = open(path1, 'a')
                self.f2 = open(path2, 'a')
            except:
                path1 = './time.txt'
                path2 = './num.txt'
                self.f1 = open(path1, 'a')
                self.f2 = open(path2, 'a')
                print("change path to current directory")
            self.f1.write(format(int(time.time()*1000)))
            self.f1.write('\n')
            self.f1.flush()
            self.f2.write(format(self.txIndex))
            self.f2.write('\n')
            self.f2.flush()
            
        #ret = [self.txIndex]
        self.txIndex = 0
        return ResponseCommit()#data=bytes(ret))


if __name__ == '__main__':
    if len(sys.argv) == 2:
        port = sys.argv[1]#26658
    else:
        port = 26658
    if len(sys.argv) == 2:
        port = int(sys.argv[1])
    app = ABCIServer(port=port, app=PlasmaCash())
    app.run()
Example #17
0
            )

            return rq

    def begin_block(self, reqBeginBlock):
        """Called to process a block"""

        self.new_block_txs = []
        return ResponseBeginBlock()

    def end_block(self, height):
        """Called at the end of processing. If this is a stateful application
        you can use the height from here to record the last_block_height"""

        self.db.set_block_height(increment=True)
        if self.new_block_txs:  # Change app hash only if there any new txns
            self.db.set_block_app_hash(utils.get_merkle_root(self.new_block_txs))

        return ResponseEndBlock()

    def commit(self):
        """Return the current encode state value to tendermint"""

        h = self.db.get_block_app_hash().encode()

        return Result.ok(data=h)

if __name__ == '__main__':
    app = ABCIServer(app=SimpleCoin())
    app.run()