use of org.aion.txpool.common.AccountState in project aion by aionnetwork.
the class TxPoolA0 method remove.
@Override
public synchronized List<TX> remove(Map<Address, BigInteger> accNonce) {
List<ByteArrayWrapper> bwList = new ArrayList<>();
for (Map.Entry<Address, BigInteger> en1 : accNonce.entrySet()) {
AccountState as = this.getAccView(en1.getKey());
Iterator<Map.Entry<BigInteger, AbstractMap.SimpleEntry<ByteArrayWrapper, BigInteger>>> it = as.getMap().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<BigInteger, AbstractMap.SimpleEntry<ByteArrayWrapper, BigInteger>> en = it.next();
if (en1.getValue().compareTo(en.getKey()) > 0) {
bwList.add(en.getValue().getKey());
it.remove();
} else {
break;
}
}
Set<BigInteger> fee = Collections.synchronizedSet(new HashSet<>());
if (this.getPoolStateView(en1.getKey()) != null) {
this.getPoolStateView(en1.getKey()).parallelStream().forEach(ps -> fee.add(ps.getFee()));
}
fee.parallelStream().forEach(bi -> {
if (this.getFeeView().get(bi) != null) {
this.getFeeView().get(bi).entrySet().removeIf(byteArrayWrapperTxDependListEntry -> byteArrayWrapperTxDependListEntry.getValue().getAddress().equals(en1.getKey()));
if (this.getFeeView().get(bi).isEmpty()) {
this.getFeeView().remove(bi);
}
}
});
as.setDirty();
}
List<TX> removedTxl = Collections.synchronizedList(new ArrayList<>());
bwList.parallelStream().forEach(bw -> {
if (this.getMainMap().get(bw) != null) {
ITransaction tx = this.getMainMap().get(bw).getTx().clone();
removedTxl.add((TX) tx);
long timestamp = tx.getTimeStampBI().longValue() / multiplyM;
synchronized (this.getTimeView().get(timestamp)) {
if (this.getTimeView().get(timestamp) == null) {
LOG.error("Txpool.remove can't find the timestamp in the map [{}]", tx.toString());
return;
}
this.getTimeView().get(timestamp).remove(bw);
if (this.getTimeView().get(timestamp).isEmpty()) {
this.getTimeView().remove(timestamp);
}
}
this.getMainMap().remove(bw);
}
});
this.updateAccPoolState();
this.updateFeeMap();
if (LOG.isInfoEnabled()) {
LOG.info("TxPoolA0.remove {} TX", removedTxl.size());
}
return removedTxl;
}
use of org.aion.txpool.common.AccountState in project aion by aionnetwork.
the class TxPoolA0 method remove.
@Override
@Deprecated
public synchronized List<TX> remove(List<TX> txs) {
List<TX> removedTxl = Collections.synchronizedList(new ArrayList<>());
Set<Address> checkedAddress = Collections.synchronizedSet(new HashSet<>());
for (TX tx : txs) {
ByteArrayWrapper bw = ByteArrayWrapper.wrap(tx.getHash());
if (this.getMainMap().remove(bw) == null) {
continue;
}
// noinspection unchecked
removedTxl.add((TX) tx.clone());
if (LOG.isTraceEnabled()) {
LOG.trace("TxPoolA0.remove:[{}] nonce:[{}]", ByteUtils.toHexString(tx.getHash()), tx.getNonceBI().toString());
}
long timestamp = tx.getTimeStampBI().longValue() / multiplyM;
if (this.getTimeView().get(timestamp).remove(bw)) {
if (this.getTimeView().get(timestamp).isEmpty()) {
this.getTimeView().remove(timestamp);
}
}
// remove the all transactions belong to the given address in the feeView
Address address = tx.getFrom();
Set<BigInteger> fee = Collections.synchronizedSet(new HashSet<>());
if (!checkedAddress.contains(address)) {
this.getPoolStateView(tx.getFrom()).parallelStream().forEach(ps -> fee.add(ps.getFee()));
fee.parallelStream().forEach(bi -> {
this.getFeeView().get(bi).entrySet().removeIf(byteArrayWrapperTxDependListEntry -> byteArrayWrapperTxDependListEntry.getValue().getAddress().equals(address));
if (this.getFeeView().get(bi).isEmpty()) {
this.getFeeView().remove(bi);
}
});
checkedAddress.add(address);
}
AccountState as = this.getAccView(tx.getFrom());
as.getMap().remove(tx.getNonceBI());
as.setDirty();
}
this.updateAccPoolState();
this.updateFeeMap();
if (LOG.isInfoEnabled()) {
LOG.info("TxPoolA0.remove TX remove [{}] removed [{}]", txs.size(), removedTxl.size());
}
return removedTxl;
}
Aggregations