Skip to content

Commit

Permalink
integrating PlatformTxnRecord with ServicesState
Browse files Browse the repository at this point in the history
Signed-off-by: abhishek-hedera <[email protected]>
  • Loading branch information
abhishek-hedera committed May 28, 2021
1 parent 2596ae3 commit 467b037
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
34 changes: 17 additions & 17 deletions hedera-node/src/main/java/com/hedera/services/ServicesState.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import com.hedera.services.state.submerkle.ExchangeRates;
import com.hedera.services.state.submerkle.SequenceNumber;
import com.hedera.services.stream.RecordsRunningHashLeaf;
import com.hedera.services.utils.PlatformTxnAccessor;
import com.hedera.services.utils.PlatformTxnRecord;
import com.hederahashgraph.api.proto.java.AccountID;
import com.swirlds.blob.BinaryObjectStore;
import com.swirlds.common.AddressBook;
Expand Down Expand Up @@ -115,20 +115,23 @@ static class ChildIndices {
}

ServicesContext ctx;
private PlatformTxnAccessor txnAccessor;
private PlatformTxnRecord platformTxnRecord;

public ServicesState() {
platformTxnRecord = new PlatformTxnRecord(15L);
}

public ServicesState(List<MerkleNode> children) {
super(ChildIndices.NUM_0140_CHILDREN);
platformTxnRecord = new PlatformTxnRecord(15L);
addDeserializedChildren(children, MERKLE_VERSION);
}

public ServicesState(ServicesContext ctx, NodeId nodeId, List<MerkleNode> children) {
this(children);
this.ctx = ctx;
this.nodeId = nodeId;
platformTxnRecord = new PlatformTxnRecord(15L);
if (ctx != null) {
ctx.update(this);
}
Expand Down Expand Up @@ -295,14 +298,6 @@ private void initializeContext(final ServicesContext ctx) {
}
}

private void setPlatformTxnAccessor(Transaction platformTxn){
try {
txnAccessor = new PlatformTxnAccessor(platformTxn);
} catch (InvalidProtocolBufferException e) {
log.warn("expandSignatures called with non-gRPC txn!", e);
}
}

@Override
public AddressBook getAddressBookCopy() {
return addressBook().copy();
Expand All @@ -317,22 +312,27 @@ public synchronized void handleTransaction(
com.swirlds.common.Transaction transaction
) {
if (isConsensus) {
ctx.logic().incorporateConsensusTxn(transaction, txnAccessor, consensusTime, submittingMember);
ctx.logic().incorporateConsensusTxn(transaction,
platformTxnRecord.getPlatformTxnAccessor(transaction),
consensusTime,
submittingMember);
}
}

@Override
public void expandSignatures(Transaction platformTxn) {
try {
setPlatformTxnAccessor(platformTxn);
if (txnAccessor == null)
return;

platformTxnRecord.addTransaction(platformTxn);
var accessor = platformTxnRecord.getPlatformTxnAccessor(platformTxn);
expandIn(
txnAccessor,
accessor,
ctx.lookupRetryingKeyOrder(),
new ScopedSigBytesProvider(txnAccessor),
new ScopedSigBytesProvider(accessor),
ctx.sigFactoryCreator()::createScopedFactory);
} catch (InvalidProtocolBufferException e) {
log.warn("expandSignatures called with non-gRPC txn!", e);
} catch (NullPointerException e) {
log.warn("The platformTxn was null!", e);
} catch (Exception race) {
log.warn("Unexpected problem, signatures will be verified synchronously in handleTransaction!", race);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public PlatformTxnAccessor getPlatformTxnAccessor(Transaction platformTxn){

}

public void addTransaction(Transaction transaction) throws InvalidProtocolBufferException {
public void addTransaction(Transaction transaction) throws InvalidProtocolBufferException, NullPointerException {
PlatformTxnAccessor accessor = new PlatformTxnAccessor(transaction);
cache.put(transaction, accessor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import com.hedera.services.stream.RecordsRunningHashLeaf;
import com.hedera.services.throttling.FunctionalityThrottling;
import com.hedera.services.txns.ProcessLogic;
import com.hedera.services.utils.PlatformTxnAccessor;
import com.hedera.services.utils.SystemExits;
import com.hedera.test.extensions.LogCaptor;
import com.hedera.test.extensions.LogCaptureExtension;
Expand Down Expand Up @@ -133,7 +132,6 @@ class ServicesStateTest {
BinaryObjectStore blobStore;
Instant now = Instant.now();
Transaction platformTxn;
PlatformTxnAccessor txnAccessor;
Address address;
AddressBook book;
AddressBook bookCopy;
Expand Down Expand Up @@ -195,7 +193,6 @@ private void setup() {
out = mock(SerializableDataOutputStream.class);
in = mock(SerializableDataInputStream.class);
platformTxn = mock(Transaction.class);
txnAccessor = mock(PlatformTxnAccessor.class);

address = mock(Address.class);
given(address.getMemo()).willReturn("0.0.3");
Expand Down Expand Up @@ -437,6 +434,16 @@ public void catchesProtobufParseException() {
assertDoesNotThrow(() -> subject.expandSignatures(platformTxn));
}

@Test
public void catchesNullPointerExceptionInExpandSigs() {
// expect
assertDoesNotThrow(() -> subject.expandSignatures(null));

// then:
assertThat(logCaptor.warnLogs(),
contains(Matchers.startsWith("The platformTxn was null!")));
}

@Test
public void invokesMigrationsAsApropos() {
// setup:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void addTransactionWillThrowExceptionOnInvalidTxn() {

// when
assertThrows(InvalidProtocolBufferException.class, () -> subject.addTransaction(transactionA));
assertThrows(NullPointerException.class, () -> subject.addTransaction(null));
}

@Test
Expand Down

0 comments on commit 467b037

Please sign in to comment.