use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.
the class TransactionStore method put.
public boolean put(INFO tx) {
byte[] txHash = tx.getReceipt().getTransaction().getHash();
List<INFO> existingInfos = null;
synchronized (lastSavedTxHash) {
if (lastSavedTxHash.put(new ByteArrayWrapper(txHash), object) != null || !lastSavedTxHash.isFull()) {
existingInfos = get(txHash);
}
}
if (existingInfos == null) {
existingInfos = new ArrayList<>();
} else {
for (AbstractTxInfo<TXR, TX> info : existingInfos) {
if (FastByteComparisons.equal(info.getBlockHash(), tx.getBlockHash())) {
return false;
}
}
}
existingInfos.add(tx);
put(txHash, existingInfos);
return true;
}
use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.
the class AbstractDatabaseWithCache method put.
@Override
public void put(byte[] k, byte[] v) {
AbstractDB.check(k);
// acquire write lock
lock.writeLock().lock();
try {
check();
ByteArrayWrapper key = ByteArrayWrapper.wrap(k);
this.loadingCache.put(key, Optional.ofNullable(v));
// keeping track of dirty data
this.dirtyEntries.put(key, v);
if (enableAutoCommit) {
flushInternal();
}
} finally {
// releasing write lock
lock.writeLock().unlock();
}
}
use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.
the class ApiWeb3Aion method eth_getTransactionReceipt.
public Object eth_getTransactionReceipt(String _txHash) {
byte[] txHash = TypeConverter.StringHexToByteArray(_txHash);
TxRecpt r = getTransactionReceipt(txHash);
// if we can't find the receipt on the mainchain, try looking for it in pending receipts cache
if (r == null) {
AionTxReceipt pendingReceipt = pendingReceipts.get(new ByteArrayWrapper(txHash));
r = new TxRecpt(pendingReceipt, null, null, null, true);
}
if (r == null)
return null;
return r.toJson();
}
use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.
the class ApiAion0 method pendingTxUpdate.
protected void pendingTxUpdate(ITxReceipt _txRcpt, EventTx.STATE _state) {
ByteArrayWrapper txHashW = new ByteArrayWrapper(((AionTxReceipt) _txRcpt).getTransaction().getHash());
if (LOG.isDebugEnabled()) {
LOG.debug("ApiAionA0.onPendingTransactionUpdate - txHash: [{}], state: [{}]", txHashW.toString(), _state.getValue());
}
if (getMsgIdMapping().get(txHashW) != null) {
if (pendingStatus.remainingCapacity() == 0) {
pendingStatus.poll();
LOG.warn("ApiAionA0.onPendingTransactionUpdate - txPend ingStatus queue full, drop the first message.");
}
if (LOG.isDebugEnabled()) {
LOG.debug("ApiAionA0.onPendingTransactionUpdate - the pending Tx state : [{}]", _state.getValue());
}
pendingStatus.add(new TxPendingStatus(txHashW, getMsgIdMapping().get(txHashW).getValue(), getMsgIdMapping().get(txHashW).getKey(), _state.getValue(), ByteArrayWrapper.wrap(((AionTxReceipt) _txRcpt).getExecutionResult() == null ? ByteUtil.EMPTY_BYTE_ARRAY : ((AionTxReceipt) _txRcpt).getExecutionResult())));
if (_state.isPending()) {
pendingReceipts.put(txHashW, ((AionTxReceipt) _txRcpt));
} else {
pendingReceipts.remove(txHashW);
getMsgIdMapping().remove(txHashW);
}
} else {
if (txWait.remainingCapacity() == 0) {
txWait.poll();
if (LOG.isDebugEnabled()) {
LOG.debug("ApiAionA0.onPendingTransactionUpdate - txWait queue full, drop the first message.");
}
}
// waiting origin Api call status been callback
try {
txWait.put(new TxWaitingMappingUpdate(txHashW, _state.getValue(), ((AionTxReceipt) _txRcpt)));
} catch (InterruptedException e) {
LOG.error("ApiAionA0.onPendingTransactionUpdate txWait.put exception", e.getMessage());
}
}
}
use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.
the class AbstractTxPool method updateAccPoolState.
protected void updateAccPoolState() {
// iterate tx by account
List<Address> clearAddr = new ArrayList<>();
for (Entry<Address, AccountState> e : this.accountView.entrySet()) {
AccountState as = e.getValue();
if (as.isDirty()) {
if (as.getMap().isEmpty()) {
this.poolStateView.remove(e.getKey());
clearAddr.add(e.getKey());
} else {
// checking AccountState given by account
List<PoolState> psl = this.poolStateView.get(e.getKey());
if (psl == null) {
psl = new LinkedList<>();
}
List<PoolState> newPoolState = new LinkedList<>();
// Checking new tx has been include into old pools.
BigInteger txNonceStart = as.getFirstNonce();
if (txNonceStart != null) {
if (LOG.isTraceEnabled()) {
LOG.trace("AbstractTxPool.updateAccPoolState fn [{}]", txNonceStart.toString());
}
for (PoolState ps : psl) {
// check the previous txn status in the old PoolState
if (isClean(ps, as) && ps.firstNonce.equals(txNonceStart) && ps.combo == SEQUENTAILTXNCOUNT_MAX) {
ps.resetInFeePool();
newPoolState.add(ps);
if (LOG.isTraceEnabled()) {
LOG.trace("AbstractTxPool.updateAccPoolState add fn [{}]", ps.firstNonce.toString());
}
txNonceStart = txNonceStart.add(BigInteger.valueOf(SEQUENTAILTXNCOUNT_MAX));
} else {
// remove old poolState in the feeMap
Map<ByteArrayWrapper, TxDependList<ByteArrayWrapper>> txDp = this.feeView.get(ps.getFee());
if (txDp != null) {
if (e.getValue().getMap().get(ps.firstNonce) != null) {
txDp.remove(e.getValue().getMap().get(ps.firstNonce).getKey());
}
if (LOG.isTraceEnabled()) {
LOG.trace("AbstractTxPool.updateAccPoolState remove fn [{}]", ps.firstNonce.toString());
}
if (txDp.isEmpty()) {
this.feeView.remove(ps.getFee());
}
}
}
}
}
int cnt = 0;
BigInteger fee = BigInteger.ZERO;
BigInteger totalFee = BigInteger.ZERO;
for (Entry<BigInteger, SimpleEntry<ByteArrayWrapper, BigInteger>> en : as.getMap().entrySet()) {
if (LOG.isTraceEnabled()) {
LOG.trace("AbstractTxPool.updateAccPoolState mapsize[{}] nonce:[{}] cnt[{}] txNonceStart[{}]", as.getMap().size(), en.getKey().toString(), cnt, txNonceStart.toString());
}
if (en.getKey().equals(txNonceStart != null ? txNonceStart.add(BigInteger.valueOf(cnt)) : null)) {
if (en.getValue().getValue().compareTo(fee) > -1) {
fee = en.getValue().getValue();
totalFee = totalFee.add(fee);
if (++cnt == SEQUENTAILTXNCOUNT_MAX) {
if (LOG.isTraceEnabled()) {
LOG.trace("AbstractTxPool.updateAccPoolState case1 - nonce:[{}] totalFee:[{}] cnt:[{}]", txNonceStart, totalFee.toString(), cnt);
}
newPoolState.add(new PoolState(txNonceStart, totalFee.divide(BigInteger.valueOf(cnt)), cnt));
txNonceStart = en.getKey().add(BigInteger.ONE);
totalFee = BigInteger.ZERO;
fee = BigInteger.ZERO;
cnt = 0;
}
} else {
if (LOG.isTraceEnabled()) {
LOG.trace("AbstractTxPool.updateAccPoolState case2 - nonce:[{}] totalFee:[{}] cnt:[{}]", txNonceStart, totalFee.toString(), cnt);
}
newPoolState.add(new PoolState(txNonceStart, totalFee.divide(BigInteger.valueOf(cnt)), cnt));
// next PoolState
txNonceStart = en.getKey();
fee = en.getValue().getValue();
totalFee = fee;
cnt = 1;
}
}
}
if (totalFee.signum() == 1) {
if (LOG.isTraceEnabled()) {
LOG.trace("AbstractTxPool.updateAccPoolState case3 - nonce:[{}] totalFee:[{}] cnt:[{}] bw:[{}]", txNonceStart, totalFee.toString(), cnt, e.getKey().toString());
}
newPoolState.add(new PoolState(txNonceStart, totalFee.divide(BigInteger.valueOf(cnt)), cnt));
}
this.poolStateView.put(e.getKey(), newPoolState);
if (LOG.isTraceEnabled()) {
this.poolStateView.forEach((k, v) -> v.forEach(l -> {
LOG.trace("AbstractTxPool.updateAccPoolState - the first nonce of the poolState list:[{}]", l.firstNonce);
}));
}
as.sorted();
}
}
}
if (!clearAddr.isEmpty()) {
clearAddr.forEach(addr -> {
this.accountView.remove(addr);
this.bestNonce.remove(addr);
});
}
}
Aggregations