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

FAB-15817 Prefer last config in signatures metadata field #363

Merged
merged 1 commit into from
Jan 7, 2020

Conversation

wlahti
Copy link
Contributor

@wlahti wlahti commented Dec 4, 2019

This commit updates the orderer and peer to prefer retrieving the
last config from the SIGNATURES field and fallback to retrieving
it from the LAST_CONFIG field.

Signed-off-by: Will Lahti wtlahti@us.ibm.com

@wlahti
Copy link
Contributor Author

wlahti commented Dec 4, 2019

/ci-run

@github-actions
Copy link

github-actions bot commented Dec 4, 2019

AZP build triggered!

@lindluni
Copy link
Contributor

lindluni commented Dec 5, 2019

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@lindluni
Copy link
Contributor

lindluni commented Dec 5, 2019

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@wlahti wlahti force-pushed the FAB-15817 branch 2 times, most recently from adaecf1 to 8457066 Compare December 6, 2019 17:10
@wlahti
Copy link
Contributor Author

wlahti commented Dec 6, 2019

/ci-run

@github-actions
Copy link

github-actions bot commented Dec 6, 2019

AZP build triggered!

@wlahti
Copy link
Contributor Author

wlahti commented Dec 6, 2019

/ci-run

@github-actions
Copy link

github-actions bot commented Dec 6, 2019

AZP build triggered!

@wlahti
Copy link
Contributor Author

wlahti commented Dec 6, 2019

/ci-run

@github-actions
Copy link

github-actions bot commented Dec 6, 2019

AZP build triggered!

@wlahti
Copy link
Contributor Author

wlahti commented Dec 6, 2019

/ci-run

@github-actions
Copy link

github-actions bot commented Dec 6, 2019

AZP build triggered!

@wlahti
Copy link
Contributor Author

wlahti commented Dec 6, 2019

/ci-run

@github-actions
Copy link

github-actions bot commented Dec 6, 2019

AZP build already running!

@wlahti
Copy link
Contributor Author

wlahti commented Dec 9, 2019

/ci-run

@github-actions
Copy link

github-actions bot commented Dec 9, 2019

AZP build triggered!

Copy link
Contributor

@jyellick jyellick left a comment

Choose a reason for hiding this comment

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

We need to make sure that:

a) Old clients can still use new blockchains (ie, continue to populate the old metadata position)
b) New clients can still parse old blockchains (ie, fall-back to the old metadata position if the new one is empty)
c) New clients prefer the new metadata location (the old location is not signed)

common/genesis/genesis.go Show resolved Hide resolved
@@ -74,6 +78,11 @@ func CreateNextBlock(rl Reader, messages []*cb.Envelope) *cb.Block {
block := protoutil.NewBlock(nextBlockNumber, previousBlockHash)
block.Header.DataHash = protoutil.BlockDataHash(data)
block.Data = data
block.Metadata.Metadata[cb.BlockMetadataIndex_SIGNATURES] = protoutil.MarshalOrPanic(&cb.Metadata{
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious why we're populating this metadata field here now, when we didn't use to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's due to the LastConfig now being nested inside the OrdererBlockMetadata instead of as its own separate value. Without setting this here, certain tests panic with a nil pointer when attempting to retrieve the index of a nil LastConfig (in regstrar_test.go's testLastConfigBlockNumber function). It's possibly the case that these tests weren't really testing that the last config was set correctly and merely relied on the default value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then I think we need to fix those tests. The CreateNextBlock function has no business setting this metadata. In fact, it can't set it correctly, because it doesn't know whether this block is a config block (in which case, the last config should be this block number.) As implemented above, all blocks would point to block 0 as the last config, as there is no case where the value is updated.

orderer/common/cluster/replication.go Show resolved Hide resolved
orderer/common/multichannel/blockwriter.go Outdated Show resolved Hide resolved
@wlahti wlahti changed the title FAB-15817 Transition to last config index in signatures field FAB-15817 Prefer last config in signatures metadata field Dec 10, 2019
Copy link
Contributor

@jyellick jyellick left a comment

Choose a reason for hiding this comment

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

I'd make sure to do a quick audit that in the tests you have not removed checks that the old field value be set, and that the fallback scenarios are appropriately tested.

@@ -74,6 +78,11 @@ func CreateNextBlock(rl Reader, messages []*cb.Envelope) *cb.Block {
block := protoutil.NewBlock(nextBlockNumber, previousBlockHash)
block.Header.DataHash = protoutil.BlockDataHash(data)
block.Data = data
block.Metadata.Metadata[cb.BlockMetadataIndex_SIGNATURES] = protoutil.MarshalOrPanic(&cb.Metadata{
Copy link
Contributor

Choose a reason for hiding this comment

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

Then I think we need to fix those tests. The CreateNextBlock function has no business setting this metadata. In fact, it can't set it correctly, because it doesn't know whether this block is a config block (in which case, the last config should be this block number.) As implemented above, all blocks would point to block 0 as the last config, as there is no case where the value is updated.

orderer/common/cluster/replication.go Show resolved Hide resolved
@@ -652,7 +652,7 @@ func LastConfigBlock(block *common.Block, blockRetriever BlockRetriever) (*commo
if blockRetriever == nil {
return nil, errors.New("nil blockRetriever")
}
if block.Metadata == nil || len(block.Metadata.Metadata) <= int(common.BlockMetadataIndex_LAST_CONFIG) {
if block.Metadata == nil || len(block.Metadata.Metadata) <= int(common.BlockMetadataIndex_SIGNATURES) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Either this check is not helping us, or we could have a similar out of bounds reference here.

orderer/common/multichannel/registrar_test.go Show resolved Hide resolved
orderer/common/server/main_test.go Show resolved Hide resolved
protoutil/blockutils.go Show resolved Hide resolved
@wlahti wlahti force-pushed the FAB-15817 branch 2 times, most recently from 9d52978 to fd5feee Compare December 11, 2019 16:44
@@ -130,7 +138,7 @@ func GetMetadataFromBlockOrPanic(block *cb.Block, index cb.BlockMetadataIndex) *
func GetConsenterMetadataFromBlock(block *cb.Block) (*cb.Metadata, error) {
m, err := GetMetadataFromBlock(block, cb.BlockMetadataIndex_SIGNATURES)
if err != nil {
return nil, errors.Wrapf(err, "failed to retrieve metadata at index: %d", cb.BlockMetadataIndex_SIGNATURES)
return nil, errors.Wrap(err, "failed to retrieve metadata")
Copy link
Contributor

Choose a reason for hiding this comment

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

If you're changing this, let's do a WithMessage instead of a Wrap, no need to have two stacks attached.

Copy link
Contributor

@jyellick jyellick left a comment

Choose a reason for hiding this comment

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

Looks pretty good to me, just a couple very minor things.

protoutil/blockutils.go Show resolved Hide resolved
@wlahti
Copy link
Contributor Author

wlahti commented Dec 18, 2019

/ci-run

@github-actions
Copy link

AZP build triggered!

This commit updates the orderer and peer to prefer retrieving the
last config from the SIGNATURES field and fallback to retrieving
it from the LAST_CONFIG field.

Signed-off-by: Will Lahti <wtlahti@us.ibm.com>
@jyellick jyellick merged commit f26c2b4 into hyperledger:master Jan 7, 2020
@wlahti wlahti deleted the FAB-15817 branch March 25, 2020 18:18
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.

5 participants