Conversation
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| CodeStyle | 2 minor |
| Complexity | 3 medium |
🟢 Metrics 0 complexity · 32 duplication
Metric Results Complexity 0 Duplication 32
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
f9aa0cc to
e0bd6d8
Compare
a386e55 to
a14186e
Compare
ivannov
left a comment
There was a problem hiding this comment.
Looks to me that this PR captures whatever it is expected to capture.
I give my official unofficial +1, but I would leave other folks confirm
Nana-EC
left a comment
There was a problem hiding this comment.
Good start, did a first pass with some suggestions and questions.
Will need a second pass.
@jsync-swirlds and @AlfredoG87 should review next week
| startOfBlockStateRootHash); | ||
| } | ||
| } catch (final IllegalStateException e) { | ||
| LOGGER.log(WARNING, "Block [{0}] has malformed proof structure: %s".formatted(e.getMessage()), e); |
There was a problem hiding this comment.
Looks like you're missing logic to insert the block number into the log.
Also probably don't need both message and the exception itself
There was a problem hiding this comment.
This structure doesn't work correctly; the following should be better.
| LOGGER.log(WARNING, "Block [{0}] has malformed proof structure: %s".formatted(e.getMessage()), e); | |
| LOGGER.log(WARNING, "Block %d has malformed proof structure".formatted(blockNumber), e); |
There was a problem hiding this comment.
All of the new plugin was a straight up copy of the existing one. As things will change very drastically with the next PR, all of these will be addressed.
| MISSING_MANDATORY_FIELD, | ||
| /// This type indicates that the session was cancelled | ||
| CANCELLED, | ||
| /// This type indicates that an unknow error occurred |
There was a problem hiding this comment.
| /// This type indicates that an unknow error occurred | |
| /// This type indicates that an unknown error occurred |
There was a problem hiding this comment.
Thanks, I'll fix in the follow up.
| /// This type indicates that the block is missing a mandatory item | ||
| MISSING_MANDATORY_ITEM, | ||
| /// This type indicates that the block is missing a mandatory field (null) | ||
| MISSING_MANDATORY_FIELD, |
There was a problem hiding this comment.
Q: Is this a field within a proto message?
There was a problem hiding this comment.
Yes, if a message is missing a mandatory field (no value provided).
| @Loggable @ConfigProperty(defaultValue = "10") int allBlocksHasherPersistenceInterval, | ||
| @Loggable @ConfigProperty(defaultValue = "/opt/hiero/block-node/verification/tss-parameters.bin") Path tssParametersFilePath) {} | ||
| @Loggable @ConfigProperty(defaultValue = "/opt/hiero/block-node/verification/rootHashOfAllPreviousBlocks.bin") Path allBlocksHasherFilePath, | ||
| @Loggable @ConfigProperty(defaultValue = "false") boolean allBlocksHasherEnabled, |
There was a problem hiding this comment.
Q: is this the logic to not use the history of block hashes tree in the block verification or is this just the calculation of the tree?
There was a problem hiding this comment.
So, with the next PR for the new plugin, where we will drastically rework things, the all blocks hasher will simply no longer be a part of the verification process. As far as the enable/disable configuration, currently if enabled, we will attempt to initialize it and if successful, we will use for verification process. In the next PR, we can either remove it, or it will simply mean "try to initialize it and use it only to store new hashes, but will no longer be part of the verification process".
| public static final byte[] ZERO_BLOCK_HASH = EMPTY_TREE_HASH; | ||
| /// Expected size of a block hash in bytes. | ||
| public static final int BLOCK_HASH_LENGTH = ZERO_BLOCK_HASH.length; | ||
| /// The initial value of the [#persistenceThresholdCounter], while this value is |
There was a problem hiding this comment.
Q: Do you mean where it's -1 persistence of the of allBlocksHash is disabled?
There was a problem hiding this comment.
If we have successfully initialized the hasher, meaning it is enabled and working, on start we set this to 0. The sentinel value is used so that if -1, no persistence will be attempted.
This can and should probably change when we completely move the all blocks hasher out of verification.
| public static final int BLOCK_HASH_LENGTH = ZERO_BLOCK_HASH.length; | ||
| /// The initial value of the [#persistenceThresholdCounter], while this value is | ||
| /// present, persistence is inactive. This is during init, on start go to 0 as default value. | ||
| private static final int UNINITIALIZED_PERSISTENCE_THRESHOLD = -1; |
There was a problem hiding this comment.
I don't see this getting set to 0 or anything else.
Also when used it checks if the counter is greater that it.
The counter that is compared to it also only checks for > meaning you only need one increment, so the threshold is always 1.
Is that the intention?
Also is this variable needed if there's also a variable for whether it's enabled? Is there ever a case where it's enabled but persistence is disabled? If not then just use the config value
There was a problem hiding this comment.
The value is changed on start() if we are available.
Here is how the counter is used:
On each successful addition of a new hash, the counter is incremented assuming the all blocks hasher is available. If the threshold is passed, then we roll it back and persist. Subsequent calls continue to increment the counter until the threshold is passed and we repeat the process. The reason for the counter is that we want to configure an interval for persistence to avoid excessive disk usage.
Note that with upcoming PR, there will be only a single place where these updates will happen, so we will not worry about things racing. And in the future when the all blocks hasher is completely removed from verification plugin, we will simply have to report the newest hash and forget about the rest, from the perspective of the verification plugin that is.
And finally, to answer your last question, no, there are no cases where the all blocks hasher is enabled and persistence disable. There are cases where the all blocks hasher is enabled, but unavailable for any given reason.
| return BlockUnparsed.PROTOBUF.parse( | ||
| rawData.toReadableSequentialData(), false, false, Codec.DEFAULT_MAX_DEPTH, MAX_BLOCK_SIZE_BYTES); | ||
| } catch (final ParseException e) { | ||
| } catch (final RuntimeException | ParseException e) { |
There was a problem hiding this comment.
Hmm, this swallows a more concerning error no? Currently if the block can't be parsed we swallow and log, but Runtime would catch more severe considerations.
Any culprits that you're trying to catch right now?
Might be a larger problem but if such an issue occurs should we be trying to clean up so that the BN can backfill it?
There was a problem hiding this comment.
So, the thing is that we have defined the block accessor to return null if something happens during reading. There was a fairly recent change that made the same additions to implementations, but not here. I've made this addition so that we do not end up in a situation where we throw while trying to get an accessor. The caller will receive null if the block is not available or something happened when trying to read it.
| public void appendLatestHashToAllPreviousBlocksStreamingHasher( | ||
| @NonNull final byte[] blockHashBytes, final long blockNumber) { | ||
| if (isAvailable()) { | ||
| // @todo(2461) use blockNumber |
There was a problem hiding this comment.
yeah, unclear of why blockNumber isn't the only approach used here.
The the counter comparisons seem like proxies. I might need to circle back to this
There was a problem hiding this comment.
This will be much improved once we move out the whole all blocks hasher out of verification. For now, (with an upcoming PR) the all blocks hasher will be extracted from the verification process and there will be a single point (thread) that will update this when appropriate. The counter is there to introduce an interval for persistence.
| // Must have at least 3 (signed block siblings) and remainder must be groups of 4 (gap blocks) | ||
| if (totalSiblings < 3 || (totalSiblings - 3) % 4 != 0) { | ||
| LOGGER.log( | ||
| WARNING, | ||
| "Block {0} state proof sibling count {1} is invalid (need >= 3, remainder must be multiple of 4)", | ||
| blockNumber, | ||
| totalSiblings); | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Actually, the groups of 4 part might not be true.
We can check >= 3, but probably shouldn't check past that, because there are different ways to structure things past the first 3.
There was a problem hiding this comment.
Interesting, thanks for the note. This is a straight up copy of existing logic. Once we have a follow up of this PR, we will be able to decouple hashing logic from proof verification logic and we can, piece by piece address these.
* Move the `AllPreviousBlocksRootHashHasherSnapshot` to internal protos * All blocks hasher general cleanup and hardening * Configuration property for optional hashing from history * Remove time-based `AllPreviousBlocksRootHashHasherSnapshot` persistence and make it block based (configurable) * Consolidate verification additions from #2535 and #2666 Signed-off-by: Atanas Atanasov <a.v.atanasov98@gmail.com>
a14186e to
29ca1a8
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #2704 +/- ##
============================================
+ Coverage 81.46% 81.54% +0.07%
- Complexity 1508 1510 +2
============================================
Files 141 141
Lines 7154 7157 +3
Branches 756 756
============================================
+ Hits 5828 5836 +8
+ Misses 1018 1013 -5
Partials 308 308
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
AllPreviousBlocksRootHashHasherSnapshotto internal protosAllPreviousBlocksRootHashHasherSnapshotpersistence and make it block based (configurable)Reviewer Notes
Related Issue(s)
Closes #2461