Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Ibft Height Manager #418

Merged
merged 23 commits into from
Dec 19, 2018
Merged

Ibft Height Manager #418

merged 23 commits into from
Dec 19, 2018

Conversation

rain-on
Copy link
Contributor

@rain-on rain-on commented Dec 13, 2018

The IbftHeightManager is responsible for all things 'meta-round'
related, such things as:

  • Handling RoundTimeout and starting a new round
  • Handling NewRound messages and starting a new round
  • Ensuring RoundChange messages are sent at the correct time with
    appropriate content.
  • Collating RoundChange messages and starting a new round using the
    best prepared certificate in the collection.

@rain-on rain-on added the blocked Blocked by other issues label Dec 16, 2018
tmohay added 4 commits December 17, 2018 21:10
The IbftHeightManager is responsible for all things 'meta-round'
related, such things as:
* Handling RoundTimeout and starting a new round
* Handling NewRound messages and starting a new round
* Ensuring RoundChange messages are sent at the correct time with
  appropriate content.
* Collating RoundChange messages and starting a new round using the
  best prepared certificate in the collection.
@rain-on rain-on removed the blocked Blocked by other issues label Dec 17, 2018

private void actionOrBufferMessage(
final SignedData<? extends Payload> msg,
final Action inRoundHandler,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be nicer to have stronger typing here for the inRoundHandler function reference so say something like Consumer<SignedData<T>> inRoundHandler where T is <T extends Payload>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will work, the goal here was to have the lambdas fully defined in the calling function - i.e. this function no longer actually needs the msg (other than for its RoundNumber) - as the supplied lambda already has the message contained within it.

Have replaced 'Action' with the inbuilt Runnable.

By having the lambda contain the message, this function is no longer templated, which is a secondary nicety.

}

if (newRoundMessageValidator.validateNewRoundMessage(msg)) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra whitespace line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


private void actionOrBufferMessage(
final SignedData<? extends Payload> msg,
final Runnable inRoundHandler,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't love Runnable as it's documented to be for actions run in a thread. I can't find a suitable alternative in java.util.function that matches the type signature. Do we know of anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue the docs are providing purpose without appreciating the concept of something which can be "done" - i.e. its a consumer without parameter, and its a supplier without a result.
Anyway - its been changed to a Biconsumer.

roundChangeCache
.entrySet()
.removeIf(entry -> isAnEarlierOrEqualRound(entry.getKey(), completedRoundIdentifier));
.removeIf(entry -> isAnEarlierRound(entry.getKey(), completedRoundIdentifier));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not part of your change, but can simplify with .keySet().removeIf(roundIdentifier-> isAnEarlierRound(roundIdentifier, ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

when(messageValidator.validateCommmitMessage(any())).thenReturn(true);
when(messageValidator.validatePrepareMessage(any())).thenReturn(true);

// when(finalState.getValidators()).thenReturn(validators);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

@@ -27,7 +27,7 @@ public IbftStateMachine(final IbftBlockCreatorFactory blockCreatorFactory) {
/**
* Attempt to consume the event and update the maintained state
*
* @param event the external action that has occurred
* @param event the external Action that has occurred
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got capitalised in an auto refactor from the Action type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

final Runnable inRoundHandler,
private <T extends Payload> void actionOrBufferMessage(
final SignedData<T> msg,
final Consumer<SignedData<T>> inRoundHandler,
final Consumer<RoundState> buffer) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with inRoundHandler accepting the message but the buffer lambda having the msg already inside it, feels mismatched. Need to make them both take msg or neither. I'm leaning towards both and making buffer be BiConsumer<RoundState, SignedData>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@rain-on rain-on merged commit cae7c90 into PegaSysEng:master Dec 19, 2018
@rain-on rain-on deleted the height_mgm branch January 16, 2019 21:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants