use of org.aion.txpool.common.TxDependList in project aion by aionnetwork.
the class TxPoolA0 method snapshot.
public synchronized List<TX> snapshot() {
List<TX> rtn = new ArrayList<>();
sortTxn();
removeTimeoutTxn();
int cnt_txSz = 0;
long cnt_nrg = 0;
Set<ByteArrayWrapper> snapshotSet = new HashSet<>();
for (Entry<BigInteger, Map<ByteArrayWrapper, TxDependList<ByteArrayWrapper>>> e : this.getFeeView().entrySet()) {
if (LOG.isTraceEnabled()) {
LOG.trace("snapshot fee[{}]", e.getKey().toString());
}
Map<ByteArrayWrapper, TxDependList<ByteArrayWrapper>> tpl = e.getValue();
for (Entry<ByteArrayWrapper, TxDependList<ByteArrayWrapper>> pair : tpl.entrySet()) {
// Check the small nonce tx must been picked before put the high nonce tx
ByteArrayWrapper dependTx = pair.getValue().getDependTx();
if (dependTx == null || snapshotSet.contains(dependTx)) {
boolean firstTx = true;
for (ByteArrayWrapper bw : pair.getValue().getTxList()) {
ITransaction itx = this.getMainMap().get(bw).getTx();
cnt_txSz += itx.getEncoded().length;
cnt_nrg += itx.getNrgConsume();
if (LOG.isTraceEnabled()) {
LOG.trace("from:[{}] nonce:[{}] txSize: txSize[{}] nrgConsume[{}]", itx.getFrom().toString(), new BigInteger(1, itx.getNonce()).toString(), itx.getEncoded().length, itx.getNrgConsume());
}
if (cnt_txSz < blkSizeLimit && cnt_nrg < blkNrgLimit.get()) {
try {
rtn.add((TX) itx.clone());
if (firstTx) {
snapshotSet.add(bw);
firstTx = false;
}
} catch (Exception ex) {
ex.printStackTrace();
if (LOG.isErrorEnabled()) {
LOG.error("TxPoolA0.snapshot exception[{}], return [{}] TX", ex.toString(), rtn.size());
}
return rtn;
}
} else {
if (LOG.isWarnEnabled()) {
LOG.warn("Reach blockLimit: txSize[{}], nrgConsume[{}], tx#[{}]", cnt_txSz, cnt_nrg, rtn.size());
}
return rtn;
}
}
}
}
}
if (LOG.isInfoEnabled()) {
LOG.info("TxPoolA0.snapshot return [{}] TX, poolSize[{}]", rtn.size(), getMainMap().size());
}
return rtn;
}
Aggregations