Skip to content

Commit

Permalink
Stop creating threshold records
Browse files Browse the repository at this point in the history
Signed-off-by: tinker-michaelj <[email protected]>
  • Loading branch information
tinker-michaelj committed Aug 27, 2020
1 parent 678420c commit 5d9c314
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.hederahashgraph.api.proto.java.TransactionRecord;
import com.swirlds.fcmap.FCMap;

import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
Expand Down Expand Up @@ -102,18 +103,15 @@ public void addNewRecords() {
var record = txnCtx.recordSoFar();

long cachingFeePaid = payForCaching(record);
long thresholdRecordFee = fees.computeStorageFee(record);
Set<AccountID> qualifiers = getThreshXQualifiers(thresholdRecordFee);
feeCharging.setFor(THRESHOLD_RECORD, thresholdRecordFee);
payForThresholdRecords(qualifiers);
if (feeCharging.numThresholdFeesCharged() > 0 || cachingFeePaid > 0L) {
if (cachingFeePaid > 0L) {
record = txnCtx.updatedRecordGiven(ledger.netTransfersInTxn());
}

lastCreatedRecord = record;

long now = txnCtx.consensusTime().getEpochSecond();
long submittingMember = txnCtx.submittingSwirldsMember();
Set<AccountID> qualifiers = new HashSet<>();
addNonThreshXQualifiers(record, qualifiers);
if (!qualifiers.isEmpty()) {
createHistorical(qualifiers, record, now, submittingMember);
Expand All @@ -140,40 +138,6 @@ public void reviewExistingRecords() {
expiries.resumeTrackingFrom(accounts.get());
}

private boolean qualifiesForRecord(AccountAmount adjustment, long recordFee) {
AccountID id = adjustment.getAccountID();
if (ledger.isPendingCreation(id)) {
return false;
}
long balance = ledger.getBalance(id);
if (balance < recordFee) {
return false;
}

long amount = adjustment.getAmount();
return checkIfAmountUnderThreshold(amount, id);
}

private boolean checkIfAmountUnderThreshold(long amount, AccountID id) {
if (amount < 0) {
return -1 * amount > ledger.fundsSentRecordThreshold(id);
} else {
return amount > ledger.fundsReceivedRecordThreshold(id);
}
}

private void payForThresholdRecords(Set<AccountID> ids) {
ids.forEach(id -> feeCharging.chargeParticipant(id, THRESHOLD_RECORD_FEE));
}

private Set<AccountID> getThreshXQualifiers(long recordFee) {
return ledger.netTransfersInTxn().getAccountAmountsList()
.stream()
.filter(aa -> qualifiesForRecord(aa, recordFee))
.map(AccountAmount::getAccountID)
.collect(toSet());
}

private void createHistorical(
Set<AccountID> ids,
TransactionRecord record,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,60 +304,6 @@ public void usesActivePayerForCachePayment() {
verify(ledger).doTransfer(sn, funding, cacheRecordFee);
}

@Test
public void addsRecordToQualifyingThresholdAccounts() {
setupForAdd();

// when:
subject.addNewRecords();

// then:
verify(exemptions).hasExemptPayer(txnCtx.accessor());
verify(fees).computeCachingFee(record);
verify(recordCache).setPostConsensus(
txnIdA,
finalRecord.getReceipt().getStatus(),
payerRecord);
verify(ledger).doTransfer(a, funding, aBalance);
// and:
verify(ledger, times(2)).netTransfersInTxn();
verify(txnCtx).recordSoFar();
verify(txnCtx).updatedRecordGiven(any());
verify(fees).computeStorageFee(record);
// and:
verify(ledger, times(2)).getBalance(a);
verify(ledger).getBalance(b);
verify(ledger).fundsReceivedRecordThreshold(b);
verify(ledger).getBalance(c);
verify(ledger).getBalance(d);
verify(ledger).fundsSentRecordThreshold(d);
// and:
verify(properties, times(1)).getAccountProperty("ledger.funding.account");
verify(ledger).doTransfer(b, funding, recordFee);
verify(ledger, never()).doTransfer(c, funding, recordFee);
verify(ledger).doTransfer(d, funding, recordFee);
// and:
verify(properties, never()).getIntProperty("ledger.records.ttl");
verify(txnCtx, times(1)).consensusTime();
// and:
verify(creator).createExpiringHistoricalRecord(b, finalRecord, now.getEpochSecond(), submittingMember);
verify(creator).createExpiringHistoricalRecord(c, finalRecord, now.getEpochSecond(), submittingMember);
verify(creator).createExpiringHistoricalRecord(d, finalRecord, now.getEpochSecond(), submittingMember);
verify(creator, never()).createExpiringHistoricalRecord(
asAccount(contract), finalRecord, now.getEpochSecond(), submittingMember);
verify(ledger, never()).addRecord(b, jFinalRecord);
verify(expirations, never()).offer(new EarliestRecordExpiry(expiry, b));
verify(ledger, never()).addRecord(c, jFinalRecord);
verify(expirations, never()).offer(new EarliestRecordExpiry(expiry, c));
verify(ledger, never()).addRecord(d, jFinalRecord);
verify(expirations, never()).offer(new EarliestRecordExpiry(expiry, d));
verify(ledger, never()).addRecord(asAccount(contract), jFinalRecord);
// and:
assertEquals(finalRecord, subject.lastCreatedRecord().get());
// and:
verify(creator).createExpiringPayerRecord(effPayer, finalRecord, nows, submittingMember);
}

@Test
public void managesReviewCorrectly() {
setupForReview();
Expand Down

0 comments on commit 5d9c314

Please sign in to comment.