Skip to content

Commit

Permalink
Make scheduled txn records queryable from ScheduleCreate payer acco…
Browse files Browse the repository at this point in the history
…unt (#9610)

Signed-off-by: Michael Tinker <[email protected]>
  • Loading branch information
tinker-michaelj authored Nov 1, 2023
1 parent aaba1db commit fbab206
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,16 @@ private void save(

private void save(
final ExpirableTxnRecord baseRecord,
final AccountID effPayer,
AccountID effPayer,
final TransactionID txnId,
final long submittingMember,
final long consensusSecond) {
if (txnId.getScheduled() && txnCtx.isPayerSigKnownActive()) {
// Give the record of executing this scheduled transaction to the ScheduleCreate payer account,
// since the override payer account (if any) is not trivial to derive from just the record; and
// the record is all the information we will have when purging it at expiry
effPayer = txnId.getAccountID();
}
final var expiringRecord = creator.saveExpiringRecord(effPayer, baseRecord, consensusSecond, submittingMember);
recordCache.setPostConsensus(txnId, baseRecord.getEnumStatus(), expiringRecord);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ACCOUNT_ID;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_CHUNK_NUMBER;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_NFT_ID;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_PAYER_SIGNATURE;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.MAX_CHILD_RECORDS_EXCEEDED;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.REVERTED_SUCCESS;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS;
Expand Down Expand Up @@ -397,11 +398,61 @@ void systemTransactionNotAvailableUnlessTopLevelIsNonNull() {

@Test
void systemTransactionIdsClearScheduledAndIncrementNonce() {
final var scheduledTopLevelId = txnIdA.toBuilder().setScheduled(true).build();
final var scheduleCreatePayer =
AccountID.newBuilder().setAccountNum(666_777_888L).build();
final var scheduledTopLevelId = TransactionID.newBuilder()
.setAccountID(scheduleCreatePayer)
.setScheduled(true)
.build();
final var scheduledFinalRecordBuilder = ExpirableTxnRecord.newBuilder()
.setTxnId(TxnId.fromGrpc(scheduledTopLevelId))
.setHbarAdjustments(initialTransfers)
.setMemo("This is different!")
.setReceipt(TxnReceipt.newBuilder().setStatus(SUCCESS.name()).build());
final var scheduledFinalRecord = scheduledFinalRecordBuilder.build();
givenTopLevelContextWith(scheduledTopLevelId);
given(txnCtx.recordSoFar()).willReturn(jFinalRecord);
given(creator.saveExpiringRecord(effPayer, finalRecord.build(), nows, submittingMember))
.willReturn(payerRecord);
given(txnCtx.recordSoFar()).willReturn(scheduledFinalRecordBuilder);
given(txnCtx.isPayerSigKnownActive()).willReturn(true);
given(creator.saveExpiringRecord(scheduleCreatePayer, scheduledFinalRecord, nows, submittingMember))
.willReturn(scheduledFinalRecord);
final var mockTxn = Transaction.getDefaultInstance();
given(accessor.getSignedTxnWrapper()).willReturn(mockTxn);

// when:
subject.saveExpirableTransactionRecords();

// then:
final var firstExpectedId = TxnId.fromGrpc(
scheduledTopLevelId.toBuilder().clearScheduled().setNonce(1).build());
final var secondExpectedId = TxnId.fromGrpc(
scheduledTopLevelId.toBuilder().clearScheduled().setNonce(2).build());
assertFalse(subject.nextSystemTransactionIdIsUnknown());
assertEquals(firstExpectedId, subject.computeNextSystemTransactionId());
assertEquals(secondExpectedId, subject.computeNextSystemTransactionId());
}

@Test
void scheduledInvalidPayerSigStillGoesToNodeAccount() {
final var scheduleCreatePayer =
AccountID.newBuilder().setAccountNum(666_777_888L).build();
final var scheduledTopLevelId = TransactionID.newBuilder()
.setAccountID(scheduleCreatePayer)
.setScheduled(true)
.build();
final var scheduledFinalRecordBuilder = ExpirableTxnRecord.newBuilder()
.setTxnId(TxnId.fromGrpc(scheduledTopLevelId))
.setHbarAdjustments(initialTransfers)
.setMemo("This is different!")
.setReceipt(TxnReceipt.newBuilder()
.setStatus(INVALID_PAYER_SIGNATURE.name())
.build());
final var scheduledFinalRecord = scheduledFinalRecordBuilder.build();
givenTopLevelContextWith(scheduledTopLevelId);
final var nodeAccountId = AccountID.newBuilder().setAccountNum(8L).build();
given(txnCtx.effectivePayer()).willReturn(nodeAccountId);
given(txnCtx.recordSoFar()).willReturn(scheduledFinalRecordBuilder);
given(creator.saveExpiringRecord(nodeAccountId, scheduledFinalRecord, nows, submittingMember))
.willReturn(scheduledFinalRecord);
final var mockTxn = Transaction.getDefaultInstance();
given(accessor.getSignedTxnWrapper()).willReturn(mockTxn);

Expand Down

0 comments on commit fbab206

Please sign in to comment.