Search in sources :

Example 31 with Transaction

use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.

the class NulsProtocolProcess method clearIncompatibleTx.

public void clearIncompatibleTx() {
    TransactionQueueStorageService tqs = NulsContext.getServiceBean(TransactionQueueStorageService.class);
    while (tqs.pollTx() != null) {
    }
    TransactionCacheStorageService tcs = NulsContext.getServiceBean(TransactionCacheStorageService.class);
    Transaction tx = null;
    while ((tx = tcs.pollTx()) != null) {
        tcs.removeTx(tx.getHash());
    }
    TxMemoryPool.getInstance().clear();
}
Also used : Transaction(io.nuls.kernel.model.Transaction) TransactionQueueStorageService(io.nuls.consensus.poc.storage.service.TransactionQueueStorageService) TransactionCacheStorageService(io.nuls.consensus.poc.storage.service.TransactionCacheStorageService)

Example 32 with Transaction

use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.

the class TransactionServiceImpl method conflictDetect.

/**
 * 冲突检测,检测如果传入的交易列表中有相冲突的交易,则返回失败,写明失败原因及所有的应该舍弃的交易列表
 * <p>
 * Conflict detection, which detects conflicting transactions in the incoming transaction list, returns failure,
 * indicating the cause of failure and all the list of trades that should be discarded.
 *
 * @param txList 需要检查的交易列表/A list of transactions to be checked.
 * @return 操作结果:成功则返回successResult,失败时,data中返回丢弃列表,msg中返回冲突原因
 * Operation result: success returns successResult. When failure, data returns the discard list, and MSG returns the cause of conflict.
 */
@Override
public ValidateResult conflictDetect(List<Transaction> txList) {
    if (null == txList || txList.isEmpty()) {
        return ValidateResult.getSuccessResult();
    }
    // ValidateResult result = ledgerService.verifyDoubleSpend(txList);
    // if (result.isFailed()) {
    // return result;
    // }
    List<Transaction> newTxList = new ArrayList<>();
    for (Transaction tx : txList) {
        if (tx.getType() == ProtocolConstant.TX_TYPE_COINBASE || tx.getType() == ProtocolConstant.TX_TYPE_TRANSFER) {
            continue;
        }
        newTxList.add(tx);
    }
    List<TransactionProcessor> processorList = TransactionManager.getAllProcessorList();
    ValidateResult result = ValidateResult.getSuccessResult();
    for (TransactionProcessor processor : processorList) {
        result = processor.conflictDetect(newTxList);
        if (result.isFailed()) {
            break;
        }
    }
    return result;
}
Also used : Transaction(io.nuls.kernel.model.Transaction) TransactionProcessor(io.nuls.kernel.processor.TransactionProcessor) ValidateResult(io.nuls.kernel.validate.ValidateResult) ArrayList(java.util.ArrayList)

Example 33 with Transaction

use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.

the class InventoryFilterTest method test1.

@Test
public void test1() {
    BloomFilter<byte[]> filter = BloomFilter.create(Funnels.byteArrayFunnel(), 1000000, 0.00001);
    ArrayList<Transaction> txList = new ArrayList<>();
    for (int i = 1000000; i < 2000000; i++) {
        Transaction tx = new TransferTransaction();
        tx.setTime(i);
        tx.setRemark("sdfsdfsdfsdfsdfsdfaaadsfasdfsadfsdfasdfasdfasdfasdfasdfsadfaaaaaaaaaaaaaaaaaaaaaabsdsadfsadfsdfsdfsdfsdfsdfsdfsdfaaadsfasdfsadfsdfasdfasdfasdfasdfasdfsadfaaaaaaaaaaaaaaaaaaaaaabsdsadfsadfsdfsdfsdfsdfsdfsdfsdfaa".getBytes());
        txList.add(tx);
    }
    System.out.println("start....");
    long start = System.currentTimeMillis();
    for (Transaction tx : txList) {
        NulsDigestData hash = tx.getHash();
        if (!filter.mightContain(hash.getDigestBytes())) {
            filter.put(hash.getDigestBytes());
            int num = count.incrementAndGet();
            if (num % 100 == 0) {
                System.out.println("count::::::" + num);
            }
        }
    }
    System.out.println("use time::" + (System.currentTimeMillis() - start));
    System.out.println(count.get());
}
Also used : Transaction(io.nuls.kernel.model.Transaction) TransferTransaction(io.nuls.protocol.model.tx.TransferTransaction) ArrayList(java.util.ArrayList) NulsDigestData(io.nuls.kernel.model.NulsDigestData) TransferTransaction(io.nuls.protocol.model.tx.TransferTransaction) Test(org.junit.Test)

Example 34 with Transaction

use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.

the class SmallBlock method parse.

@Override
public void parse(NulsByteBuffer byteBuffer) throws NulsException {
    this.header = byteBuffer.readNulsData(new BlockHeader());
    this.txHashList = new ArrayList<>();
    long hashListSize = byteBuffer.readVarInt();
    for (int i = 0; i < hashListSize; i++) {
        this.txHashList.add(byteBuffer.readHash());
    }
    this.subTxList = new ArrayList<>();
    long subTxListSize = byteBuffer.readVarInt();
    for (int i = 0; i < subTxListSize; i++) {
        Transaction tx = byteBuffer.readTransaction();
        tx.setBlockHeight(header.getHeight());
        this.subTxList.add(tx);
    }
}
Also used : Transaction(io.nuls.kernel.model.Transaction) BlockHeader(io.nuls.kernel.model.BlockHeader)

Example 35 with Transaction

use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.

the class SmallBlock method serializeToStream.

@Override
protected void serializeToStream(NulsOutputStreamBuffer stream) throws IOException {
    stream.writeNulsData(header);
    stream.writeVarInt(txHashList.size());
    for (NulsDigestData hash : txHashList) {
        stream.writeNulsData(hash);
    }
    stream.writeVarInt(subTxList.size());
    for (Transaction tx : subTxList) {
        stream.writeNulsData(tx);
    }
}
Also used : Transaction(io.nuls.kernel.model.Transaction) NulsDigestData(io.nuls.kernel.model.NulsDigestData)

Aggregations

Transaction (io.nuls.kernel.model.Transaction)38 NulsDigestData (io.nuls.kernel.model.NulsDigestData)12 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)8 NulsException (io.nuls.kernel.exception.NulsException)7 ValidateResult (io.nuls.kernel.validate.ValidateResult)7 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 Result (io.nuls.kernel.model.Result)4 TransferTransaction (io.nuls.protocol.model.tx.TransferTransaction)4 CreateAgentTransaction (io.nuls.consensus.poc.protocol.tx.CreateAgentTransaction)3 RedPunishTransaction (io.nuls.consensus.poc.protocol.tx.RedPunishTransaction)3 NulsByteBuffer (io.nuls.kernel.utils.NulsByteBuffer)3 UnconfirmedTxPo (io.nuls.account.ledger.storage.po.UnconfirmedTxPo)2 StopAgentTransaction (io.nuls.consensus.poc.protocol.tx.StopAgentTransaction)2 AgentPo (io.nuls.consensus.poc.storage.po.AgentPo)2 Coin (io.nuls.kernel.model.Coin)2 TransactionProcessor (io.nuls.kernel.processor.TransactionProcessor)2 Alias (io.nuls.account.model.Alias)1