Esempio n. 1
0
    def handle_block(self, block):
        # verify banks signature
        public_key = bank_public_key(self.next_id)
        public_key.verify(block.signature, block.blockmessage)

        # Verify every transaction
        # copy utxo set to validate on the fly
        temp_utxo = deepcopy(self.utxo_set)
        for tx in block.txns:
            self.validate_tx(tx, temp_utxo)
            # After each TX update the temporary utxo set
            for tx_out in tx.tx_outs:
                temp_utxo[tx_out.outpoint] = tx_out
            for tx_in in tx.tx_ins:
                del temp_utxo[tx_in.outpoint]

        # After all tx are valid, update real utxo set
        for tx in block.txns:
            self.update_utxo_set(tx, True)

        # Update (clean) mempool HOMEWORK
        logger.info("Mempool before cleanup: " + str(len(self.mempool)))
        self.mempool = [
            tx for tx in self.mempool
            if tx.id not in [btx.id for btx in block.txns]
        ]
        logger.info("Mempool after cleanup: " + str(len(self.mempool)))
        # update self.blocks
        self.blocks.append(block)

        # schedule next block
        self.schedule_next_block()
Esempio n. 2
0
    def handle_block(self, block):
        public_key = bank_public_key(self.next_id())
        public_key.verify(block.signature, block.message())

        for tx in block.txns:
            self.validate_tx(tx)

        for tx in block.txns:
            self.update_utxo_set(tx)

        self.blocks.append(block)

        self.schedule_next_block()
Esempio n. 3
0
    def handle_block(self, block):

        # verify bank sig if heigt > 0
        if len(self.blocks) > 0:
            public_key = bank_public_key(self.next_id)
            public_key.verify(block.signature, block.message)
        # verify all tx
        for tx in block.txns:
            self.validate(tx)
        # update utxo set
        for tx in block.txns:
            self.update_utxo_set(tx)
        # clean mempool
        # TODO
        # update self.blocks
        self.blocks.append(block)
        # schedule next block
        self.schedule_next_block()
Esempio n. 4
0
    def handle_block(self, block):
        #Verify bank signature if height > 0
        if len(self.blocks) > 0:
            public_key = bank_public_key(self.next_id)
            public_key.verify(block.signature, block.message)

        #Verify every transaction
        for tx in block.txns:
            self.validate_tx(tx)

        # Update update self.utxo_set
        for tx in block.txns:
            self.update_utxo_set(tx)

        # Update self.blocks
        self.blocks.append(block)
        #Schedule next block
        self.schedule_next_block()
Esempio n. 5
0
    def handle_block(self, block):
        # Genesis block has no signature
        if len(self.blocks) > 0:
            public_key = bank_public_key(self.next_id)
            public_key.verify(block.signature, block.message)

        # Check the transactions are valid
        for tx in block.txns:
            self.validate_tx(tx)

        # If they're all good, update self.blocks and self.utxo_set
        for tx in block.txns:
            self.update_utxo_set(tx)

        # Add the block and increment the id of bank who will report next block
        self.blocks.append(block)

        # Schedule submisison of next block
        self.schedule_next_block()
Esempio n. 6
0
    def handle_block(self, block):
        # verify bank signature
        public_key = bank_public_key(self.next_id)
        public_key.verify(block.signature, block.message)

        # Verify every transaction
        for tx in block.txns:
            self.validate_tx(tx)

        # Update self.utxo_set
        for tx in block.txns:
            self.update_utxo_set(tx)

        # Clean self.mempool HOMEWORK

        # Update self.blocks
        self.blocks.append(block)

        # Schedule next block
        self.schedule_next_block()