hiero-ledger / hiero-ledger/hiero-consensus-node

Improve SwirldState.java javadocs

Open
#5,538 3 comments 0 reactions 0 assignees View on GitHub
Platform Tech Debt Reduced
Dominant language
Java
Stars
406
Forks
226
Avg merge
3d 4h
Merged PRs (30d)
210

Description

Proposed new javadocs for methods in `SwirldsState.java`. @lbaird before I merge this, let's have a quick chat to make sure these look good.

```
/**
* Provides the application an opportunity to perform operations on transactions in an event prior to handling.
* Called against a given {@link Event} only once, globally (not once per state instance). This method may modify
* the {@link Transaction}s in the event, but such modification is not necessary.
*


* No ordering guarantees are given for this method.
* The only guarantee is that for all events that reach consensus,
* this method will eventually be called as long as the node does not crash.
*


    *

  • * This method is usually invoked on an event before it reaches consensus,
    * but that is not a hard guarantee.
    *

  • *

  • * This method may be called after {@link #handleConsensusRound(Round, SwirldDualState)} has been called on that
    * event's round (although such behavior is expected to be uncommon).
    *

      *

    • * If it is desired that pre-handle always come before handle for a given event, then the application should
      * implement its own ordering mechanism that causes handle to wait until pre-handle has completed.
      *

    • *

    *

  • *

  • * The order that events may be passed to this method may be different from their eventual consensus order.
    *

  • *

  • * It is possible for this method to be called on an event, but for that
    * event never to reach consensus (thus becoming stale).
    *

  • *

  • * For events that become stale, this method may be called on some nodes but not others.
    *

  • *

*
*


* This method is always invoked on an immutable state. Which immutable state copy
* is not guaranteed, although it will always be a recent copy.
*
* @param event the event to perform pre-handling on
* @see #handleConsensusRound(Round, SwirldDualState)
*/
default void preHandle(final Event event) {
// Override if needed
}

/**
* Handle transactions in a round apply them to the state.
* This method is always called on the mutable state, i.e. the most recent copy.
*


* After this method returns, all side effects of the transactions in this round must be written to the state.
* It is not ok to asynchronously modify the state after this method returns.
*


* All modifications to the state in this method must be deterministic. That is, the state that results
* from applying this method must be guaranteed to always have the same cryptographic merkle hash.
*


* This method is called on all rounds in sequential order. This method is not called for round N+1 until round
* N has been fully handled. Between each call of this method, the state will be fast copied. Each copy of the
* state will only have this method called on it once.
*


* With the exception of the {@link #init(Platform, SwirldDualState, InitTrigger, SoftwareVersion)} method
* and serialization migration hooks, it is NEVER ok to modify the state except in this method.
*
* @param round the round to be handled and applied to this state
* @param swirldDualState the dual state for this round
*/
void handleConsensusRound(final Round round, final SwirldDualState swirldDualState);
```

Contributor guide

Open the contributing guide

Research direction

Open SwirldsState.java and review the proposed Javadocs for preHandle(Event) and handleConsensusRound(Round, SwirldDualState). Confirm the documented ordering, mutability, determinism, and lifecycle guarantees with the maintainer; done means the accepted Javadocs are applied to both methods.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.