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());
}
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);
}
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();
}
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);
}
}
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;
}
Aggregations