Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration from Raft to BFT test #4561

Merged
merged 4 commits into from
Jan 21, 2024
Merged

Conversation

MayRosenbaum
Copy link
Contributor

@MayRosenbaum MayRosenbaum commented Nov 30, 2023

Type of change

  • Test Improvement
  • Test update

Related Issue

#3773

Signed-off-by: Yacov Manevich <yacov.manevich@ibm.com>
@MayRosenbaum MayRosenbaum requested a review from a team as a code owner November 30, 2023 16:27
@MayRosenbaum MayRosenbaum force-pushed the migration branch 10 times, most recently from 58a7b1b to d27fd90 Compare December 4, 2023 08:33
@MayRosenbaum MayRosenbaum force-pushed the migration branch 2 times, most recently from 06ae680 to e2f1c5e Compare December 11, 2023 13:45
Copy link
Contributor

Choose a reason for hiding this comment

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

add a test case that emulates what happens when a raft chain receives the config block that changes from raft to BFT

orderer/consensus/etcdraft/util.go Outdated Show resolved Hide resolved
@@ -84,22 +86,32 @@ func MetadataHasDuplication(md *etcdraft.ConfigMetadata) error {
}

// MetadataFromConfigValue reads and translates configuration updates from config value into raft metadata
func MetadataFromConfigValue(configValue *common.ConfigValue) (*etcdraft.ConfigMetadata, error) {
func MetadataFromConfigValue(configValue *common.ConfigValue) (*etcdraft.ConfigMetadata, *orderer.ConsensusType, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

add a unit test

Comment on lines 1469 to 1470
c.logger.Panicf("illegal consensus type detected during consensus metadata validation: %s", newOrdererConfig.ConsensusType())
panic("illegal consensus type detected during consensus metadata validation")
Copy link
Contributor

Choose a reason for hiding this comment

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

why panic? return error

@MayRosenbaum MayRosenbaum force-pushed the migration branch 3 times, most recently from 0207578 to f2ad291 Compare December 11, 2023 19:00
@MayRosenbaum MayRosenbaum force-pushed the migration branch 9 times, most recently from fa0db9d to b3d82c2 Compare January 8, 2024 07:49
Signed-off-by: May Rosenbaum <mayro1595@gmail.com>
}

_, err := validateBFTMetadataOptions(1, updatedMetadata)
if updatedMetadata.XXX_unrecognized != nil || err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

what is this XXX field thing check? This is prorobuf implementation specific, isn't it?

Once we upgrade the protobuf version, we might not have this field anymore.

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's right, we can skip this check, err check is enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

True, the XXX fields are not required to preserve backwards compatibility going forward, so we better not use them.

Copy link
Contributor

Choose a reason for hiding this comment

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

verifying with validateBFTMetadataOptions should be enough, but see comment on verifying the consenters map as well.

c.logger.Infof("Detected migration to %s", consensusType.Type)
return nil
} else {
c.logger.Panicf("illegal consensus type detected: %s", consensusType.Type)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is post consensus. Do we have a validation check for this condition pre-consensus anywhere?

Copy link
Contributor

Choose a reason for hiding this comment

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

otherwise, you know what will happen once we reach this point ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have one more check in the maintenance filter.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, May is correct, we prevent it the maintenance filter.

}

_, err := validateBFTMetadataOptions(1, updatedMetadata)
if updatedMetadata.XXX_unrecognized != nil || err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

True, the XXX fields are not required to preserve backwards compatibility going forward, so we better not use them.

orderer/common/msgprocessor/maintenancefilter.go Outdated Show resolved Hide resolved
}

_, err := validateBFTMetadataOptions(1, updatedMetadata)
if updatedMetadata.XXX_unrecognized != nil || err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

verifying with validateBFTMetadataOptions should be enough, but see comment on verifying the consenters map as well.

block := FetchBlock(network, o1, 1, "testchannel")
Expect(block).NotTo(BeNil())

By("Change to maintenance mode")
Copy link
Contributor

Choose a reason for hiding this comment

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

before each step of the migration, add a numbered comment like:

// === Step 1: Config update, change to MAINTENANCE ===
By("1) ...")

as is done in the tests below. this helps keep track of what is going on in the logs.
be consistent about how these look.

orderer/common/msgprocessor/maintenancefilter.go Outdated Show resolved Hide resolved
Comment on lines 94 to 97
if consensusTypeValue.Type != "etcdraft" {
if consensusTypeValue.Type == "BFT" {
return nil, consensusTypeValue, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

In case it is not etcdraft just do return nil, consensusTypeValue, nil if it is not BFT, the chain will panic

orderer/consensus/etcdraft/util_test.go Show resolved Hide resolved
c.logger.Infof("Detected migration to %s", consensusType.Type)
return nil
} else {
c.logger.Panicf("illegal consensus type detected: %s", consensusType.Type)
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, May is correct, we prevent it the maintenance filter.

c.logger.Infof("Detected configuration change: consensusType is: %s, configMetadata is: %v", consensusType, configMetadata)

if consensusType == nil {
c.logger.Infof("ConsensusType is %v", consensusType)
Copy link
Contributor

Choose a reason for hiding this comment

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

"ConsensusType is nil"

does this ever happen?

Copy link
Contributor Author

@MayRosenbaum MayRosenbaum Jan 17, 2024

Choose a reason for hiding this comment

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

In the absence of this check, one of the chain tests fails.
Anyway, to be safe, it is better to check it

@MayRosenbaum MayRosenbaum force-pushed the migration branch 2 times, most recently from 1877849 to 29c35a4 Compare January 18, 2024 10:27
Signed-off-by: May Rosenbaum <mayro1595@gmail.com>
@yacovm
Copy link
Contributor

yacovm commented Jan 20, 2024

@tock-ibm what is left in your opinion so this can be merged?

return errors.Wrap(err, "failed to unmarshal BFT metadata configuration")
}

_, err := validateBFTMetadataOptions(1, updatedMetadata)
Copy link
Contributor

Choose a reason for hiding this comment

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

Either

  • remove the first return value, because it is not used here, and the id can be hard coded, or
  • move the function consensus/smartbft/configFromMetadataOptions to a package consensus/smartbft/util and make it public. This would break the import cycle. I prefer this option, this way we don't duplicate code.

@MayRosenbaum MayRosenbaum force-pushed the migration branch 2 times, most recently from 8c9a62f to a78393f Compare January 21, 2024 15:14
Signed-off-by: May Rosenbaum <mayro1595@gmail.com>
@tock-ibm tock-ibm merged commit 7054e88 into hyperledger:main Jan 21, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants