Search in sources :

Example 16 with ImportResult

use of org.aion.mcf.core.ImportResult in project aion by aionnetwork.

the class TaskImportBlocks method run.

@Override
public void run() {
    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    while (start.get()) {
        BlocksWrapper bw;
        try {
            bw = importedBlocks.take();
        } catch (InterruptedException ex) {
            return;
        }
        List<AionBlock> batch = bw.getBlocks();
        for (AionBlock b : batch) {
            if (importedBlockHashes.containsKey(ByteArrayWrapper.wrap(b.getHash()))) {
                continue;
            }
            long t1 = System.currentTimeMillis();
            ImportResult importResult = this.chain.tryToConnect(b);
            long t2 = System.currentTimeMillis();
            log.info("<import-status: node = {}, number = {}, txs = {}, result = {}, time elapsed = {} ms>", bw.getDisplayId(), b.getNumber(), b.getTransactionsList().size(), importResult, t2 - t1);
            switch(importResult) {
                case IMPORTED_BEST:
                    importedBlockHashes.put(ByteArrayWrapper.wrap(b.getHash()), null);
                    break;
                case IMPORTED_NOT_BEST:
                    importedBlockHashes.put(ByteArrayWrapper.wrap(b.getHash()), null);
                    break;
                case EXIST:
                    importedBlockHashes.put(ByteArrayWrapper.wrap(b.getHash()), null);
                    break;
                case NO_PARENT:
                    break;
                case INVALID_BLOCK:
                    break;
                default:
                    break;
            }
        }
        this.statis.update(this.chain.getBestBlock().getNumber());
    }
}
Also used : ImportResult(org.aion.mcf.core.ImportResult) AionBlock(org.aion.zero.impl.types.AionBlock)

Aggregations

ImportResult (org.aion.mcf.core.ImportResult)16 AionBlock (org.aion.zero.impl.types.AionBlock)14 Test (org.junit.Test)11 Address (org.aion.base.type.Address)5 BigInteger (java.math.BigInteger)4 ArrayList (java.util.ArrayList)4 AionTransaction (org.aion.zero.types.AionTransaction)4 IByteArrayKeyValueDatabase (org.aion.base.db.IByteArrayKeyValueDatabase)3 TrieImpl (org.aion.mcf.trie.TrieImpl)3 ByteArrayWrapper (org.aion.base.util.ByteArrayWrapper)2 ECKey (org.aion.crypto.ECKey)2 Ignore (org.junit.Ignore)2 Date (java.util.Date)1 IRepository (org.aion.base.db.IRepository)1 IEvent (org.aion.evtmgr.IEvent)1 EventBlock (org.aion.evtmgr.impl.evt.EventBlock)1 ChainConfiguration (org.aion.zero.impl.blockchain.ChainConfiguration)1 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)1