This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
[PIE-1580] Metrics for smart contract permissioning actions #1492
Merged
Errorific
merged 11 commits into
PegaSysEng:master
from
Errorific:feature/PIE-1580.Permissioning_metrics
May 26, 2019
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
915b5d5
Wired the metrics system through
Errorific 6d3e984
node smart contract metrics
Errorific 9a7f7ff
New functionality needs the metrics system
Errorific e1f7fb0
metrics test for node smart contract permissioning
Errorific 81ae096
Tests for the node permissioning
Errorific 455c1fb
Transaction smart contract metrics tests
Errorific a57be76
spotless
Errorific 17e22ba
Trying to make errorprone comfortable
Errorific 8a429f5
lets ignore the casting
Errorific c2ef587
Javadoc fixes
Errorific c157d15
Merge branch 'master' into feature/PIE-1580.Permissioning_metrics
Errorific File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,9 @@ | |
import tech.pegasys.pantheon.ethereum.transaction.CallParameter; | ||
import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulator; | ||
import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulatorResult; | ||
import tech.pegasys.pantheon.metrics.Counter; | ||
import tech.pegasys.pantheon.metrics.MetricCategory; | ||
import tech.pegasys.pantheon.metrics.MetricsSystem; | ||
import tech.pegasys.pantheon.util.bytes.BytesValue; | ||
import tech.pegasys.pantheon.util.bytes.BytesValues; | ||
|
||
|
@@ -41,6 +44,9 @@ public class TransactionSmartContractPermissioningController | |
"transactionAllowed(address,address,uint256,uint256,uint256,bytes)"; | ||
// hashed function signature for connection allowed call | ||
private static final BytesValue FUNCTION_SIGNATURE_HASH = hashSignature(FUNCTION_SIGNATURE); | ||
private final Counter checkCounterPermitted; | ||
private final Counter checkCounter; | ||
private final Counter checkCounterUnpermitted; | ||
|
||
// The first 4 bytes of the hash of the full textual signature of the function is used in | ||
// contract calls to determine the function being called | ||
|
@@ -61,11 +67,30 @@ private static BytesValue hashSignature(final String signature) { | |
* | ||
* @param contractAddress The address at which the permissioning smart contract resides | ||
* @param transactionSimulator A transaction simulator with attached blockchain and world state | ||
* @param metricsSystem The metrics provider that is to be reported to | ||
*/ | ||
public TransactionSmartContractPermissioningController( | ||
final Address contractAddress, final TransactionSimulator transactionSimulator) { | ||
final Address contractAddress, | ||
final TransactionSimulator transactionSimulator, | ||
final MetricsSystem metricsSystem) { | ||
this.contractAddress = contractAddress; | ||
this.transactionSimulator = transactionSimulator; | ||
|
||
this.checkCounter = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing about the total checks counter. |
||
metricsSystem.createCounter( | ||
MetricCategory.PERMISSIONING, | ||
"transaction_smart_contract_check_count", | ||
"Number of times the transaction smart contract permissioning provider has been checked"); | ||
this.checkCounterPermitted = | ||
metricsSystem.createCounter( | ||
MetricCategory.PERMISSIONING, | ||
"transaction_smart_contract_check_count_permitted", | ||
"Number of times the transaction smart contract permissioning provider has been checked and returned permitted"); | ||
this.checkCounterUnpermitted = | ||
metricsSystem.createCounter( | ||
MetricCategory.PERMISSIONING, | ||
"transaction_smart_contract_check_count_unpermitted", | ||
"Number of times the transaction smart contract permissioning provider has been checked and returned unpermitted"); | ||
} | ||
|
||
/** | ||
|
@@ -76,6 +101,7 @@ public TransactionSmartContractPermissioningController( | |
*/ | ||
@Override | ||
public boolean isPermitted(final Transaction transaction) { | ||
this.checkCounter.inc(); | ||
final BytesValue payload = createPayload(transaction); | ||
final CallParameter callParams = | ||
new CallParameter(null, contractAddress, -1, null, null, payload); | ||
|
@@ -103,7 +129,13 @@ public boolean isPermitted(final Transaction transaction) { | |
} | ||
} | ||
|
||
return result.map(r -> checkTransactionResult(r.getOutput())).orElse(false); | ||
if (result.map(r -> checkTransactionResult(r.getOutput())).orElse(false)) { | ||
this.checkCounterPermitted.inc(); | ||
return true; | ||
} else { | ||
this.checkCounterUnpermitted.inc(); | ||
return false; | ||
} | ||
} | ||
|
||
// Checks the returned bytes from the permissioning contract call to see if it's a value we | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have the counter for permitted and unpermitted, do we really need the total counter or can we just infer from the other two metrics?
I'm not aware of the impact of the metrics in system resources so maybe we are better playing safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an outcome where the permissioning check crashes (no contract, bad transaction etc) which increments the total counter but not the other 2. I'm assuming the metrics are no heavier than adding log lines so I decided to be distinct about all the things we might be checking.