Search in sources :

Example 6 with Transaction

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

the class InventoryFilterTest method test.

@Test
public void test() throws IOException {
    BloomFilter<byte[]> filter = BloomFilter.create(Funnels.byteArrayFunnel(), 1000000, 0.00001);
    List<String> list = new ArrayList<>();
    Set<NulsDigestData> set = new HashSet<>();
    ArrayList<Transaction> txList = new ArrayList<>();
    for (int i = 0; i < 1000000; i++) {
        Transaction tx = new TransferTransaction();
        tx.setTime(i);
        tx.setRemark("sdfsdfsdfsdfsdfsdfaaadsfasdfsadfsdfasdfasdfasdfasdfasdfsadfaaaaaaaaaaaaaaaaaaaaaabsdsadfsadfsdfsdfsdfsdfsdfsdfsdfaaadsfasdfsadfsdfasdfasdfasdfasdfasdfsadfaaaaaaaaaaaaaaaaaaaaaabsdsadfsadfsdfsdfsdfsdfsdfsdfsdfaa".getBytes());
        tx.setHash(NulsDigestData.calcDigestData(tx.serializeForHash()));
        txList.add(tx);
    }
    for (int i = 0; i < 2; i++) {
        Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                for (Transaction tx : txList) {
                    NulsDigestData hash = tx.getHash();
                    if (!filter.mightContain(hash.getDigestBytes())) {
                        filter.put(hash.getDigestBytes());
                        set.add(hash);
                        int num = count.incrementAndGet();
                        if (num % 1000 == 0) {
                            System.out.println("count::::::" + num);
                        }
                    }
                }
                list.add("done");
            }
        });
        t.start();
    }
    while (list.size() < 5) {
        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    System.out.println("count====" + count.get());
    System.out.println("real-size====" + set.size());
}
Also used : ArrayList(java.util.ArrayList) Transaction(io.nuls.kernel.model.Transaction) TransferTransaction(io.nuls.protocol.model.tx.TransferTransaction) NulsDigestData(io.nuls.kernel.model.NulsDigestData) TransferTransaction(io.nuls.protocol.model.tx.TransferTransaction) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with Transaction

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

the class TransactionCacheStorageServiceTest method test.

@Test
public void test() {
    Transaction tx = null;
    long time = System.currentTimeMillis();
    for (int i = 0; i < 1000000; i++) {
        tx = new TransactionPoTest(1);
        tx.setTime(i);
        tx.setRemark("asldfjsaldfjsldjfoijioj222fsdafasdfasdfasdfasdfasdfasdfsadfsa".getBytes());
        boolean success = service.putTx(tx);
        assert (success);
    }
    System.out.println("新增耗时:" + (System.currentTimeMillis() - time) + " ms");
    time = System.currentTimeMillis();
    int count = 0;
    while ((tx = service.pollTx()) != null) {
        count++;
    }
    System.out.println(count);
    System.out.println("出队耗时:" + (System.currentTimeMillis() - time) + " ms");
    assert (count == 1000000);
}
Also used : Transaction(io.nuls.kernel.model.Transaction) Test(org.junit.Test)

Example 8 with Transaction

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

the class CreateAgentTxProcessor method conflictDetect.

@Override
public ValidateResult conflictDetect(List<Transaction> txList) {
    // 冲突检测,检测委托人和打包人是否重复
    if (null == txList || txList.isEmpty()) {
        return ValidateResult.getSuccessResult();
    }
    Set<String> addressSet = new HashSet<>();
    List<Agent> agentList = PocConsensusContext.getChainManager().getMasterChain().getChain().getAgentList();
    for (Agent agent : agentList) {
        if (agent.getDelHeight() > 0) {
            continue;
        }
        if (agent.getBlockHeight() == txList.get(0).getBlockHeight()) {
            continue;
        }
        addressSet.add(agent.getAgentAddressStr());
        addressSet.add(agent.getPackingAddressStr());
    }
    for (Transaction transaction : txList) {
        if (transaction.getType() == ConsensusConstant.TX_TYPE_REGISTER_AGENT) {
            CreateAgentTransaction createAgentTransaction = (CreateAgentTransaction) transaction;
            Agent agent = createAgentTransaction.getTxData();
            if (!addressSet.add(agent.getPackingAddressStr()) || !addressSet.add(agent.getAgentAddressStr())) {
                return (ValidateResult) ValidateResult.getFailedResult(getClass().getName(), PocConsensusErrorCode.AGENT_EXIST).setData(transaction);
            }
        } else if (transaction.getType() == ConsensusConstant.TX_TYPE_RED_PUNISH) {
            RedPunishTransaction redPunishTransaction = (RedPunishTransaction) transaction;
            RedPunishData redPunishData = redPunishTransaction.getTxData();
            String address = AddressTool.getStringAddressByBytes(redPunishData.getAddress());
            if (!addressSet.add(address)) {
                return (ValidateResult) ValidateResult.getFailedResult(getClass().getName(), PocConsensusErrorCode.LACK_OF_CREDIT).setData(transaction);
            }
        }
    }
    return ValidateResult.getSuccessResult();
}
Also used : Agent(io.nuls.consensus.poc.protocol.entity.Agent) CreateAgentTransaction(io.nuls.consensus.poc.protocol.tx.CreateAgentTransaction) RedPunishTransaction(io.nuls.consensus.poc.protocol.tx.RedPunishTransaction) Transaction(io.nuls.kernel.model.Transaction) RedPunishTransaction(io.nuls.consensus.poc.protocol.tx.RedPunishTransaction) RedPunishData(io.nuls.consensus.poc.protocol.entity.RedPunishData) ValidateResult(io.nuls.kernel.validate.ValidateResult) CreateAgentTransaction(io.nuls.consensus.poc.protocol.tx.CreateAgentTransaction) HashSet(java.util.HashSet)

Example 9 with Transaction

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

the class TransactionManager method putTx.

public static final void putTx(Class<? extends Transaction> txClass, Class<? extends TransactionProcessor> txProcessorClass) {
    if (null != txProcessorClass) {
        TX_SERVICE_MAP.put(txClass, txProcessorClass);
    }
    try {
        Transaction tx = txClass.newInstance();
        TYPE_TX_MAP.put(tx.getType(), txClass);
    } catch (InstantiationException e) {
        Log.error(e);
    } catch (IllegalAccessException e) {
        Log.error(e);
    }
}
Also used : Transaction(io.nuls.kernel.model.Transaction)

Example 10 with Transaction

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

the class TransactionManager method getInstance.

public static Transaction getInstance(NulsByteBuffer byteBuffer) throws Exception {
    int txType = byteBuffer.readUint16();
    byteBuffer.setCursor(byteBuffer.getCursor() - SerializeUtils.sizeOfUint16());
    Class<? extends Transaction> txClass = TYPE_TX_MAP.get(txType);
    if (null == txClass) {
        throw new NulsRuntimeException(KernelErrorCode.DATA_NOT_FOUND);
    }
    Transaction tx = byteBuffer.readNulsData(txClass.newInstance());
    return tx;
}
Also used : Transaction(io.nuls.kernel.model.Transaction) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException)

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