Skip to content

Commit 587387f

Browse files
author
Kostas Christidis
committed
Revert [FAB-3493] Fix LAST_CONFIG on new channels
This reverts commit 150d17e. A simpler fix is introduced in a follow-up changeset. Change-Id: I5c63edbf3064b4f637f71becf6ac57a6f5d8d1d3 Signed-off-by: Kostas Christidis <kostas@christidis.io>
1 parent 0fe5cb2 commit 587387f

File tree

15 files changed

+100
-175
lines changed

15 files changed

+100
-175
lines changed

common/configtx/manager.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,24 +175,15 @@ func (cm *configManager) proposeConfigUpdate(configtx *cb.Envelope) (*cb.ConfigE
175175

176176
func (cm *configManager) prepareApply(configEnv *cb.ConfigEnvelope) (map[string]comparable, *configResult, error) {
177177
if configEnv == nil {
178-
return nil, nil, fmt.Errorf("attempted to apply config with nil envelope")
178+
return nil, nil, fmt.Errorf("Attempted to apply config with nil envelope")
179179
}
180180

181181
if configEnv.Config == nil {
182-
return nil, nil, fmt.Errorf("config cannot be nil")
182+
return nil, nil, fmt.Errorf("Config cannot be nil")
183183
}
184184

185-
var expectedSequence uint64
186-
if configEnv.Config.NewChannel {
187-
expectedSequence = FixNewChannelConfig(configEnv).Config.Sequence
188-
if configEnv.Config.Sequence != expectedSequence {
189-
return nil, nil, fmt.Errorf("should prepare to update to %d (new channel) got %d instead", expectedSequence, configEnv.Config.Sequence)
190-
}
191-
} else {
192-
expectedSequence = cm.current.sequence + 1
193-
if configEnv.Config.Sequence != expectedSequence {
194-
return nil, nil, fmt.Errorf("expected sequence %d (config at: %d), cannot prepare to update to %d", expectedSequence, cm.current.sequence, configEnv.Config.Sequence)
195-
}
185+
if configEnv.Config.Sequence != cm.current.sequence+1 {
186+
return nil, nil, fmt.Errorf("Config at sequence %d, cannot prepare to update to %d", cm.current.sequence, configEnv.Config.Sequence)
196187
}
197188

198189
configUpdateEnv, err := envelopeToConfigUpdate(configEnv.LastUpdate)
@@ -207,11 +198,11 @@ func (cm *configManager) prepareApply(configEnv *cb.ConfigEnvelope) (map[string]
207198

208199
channelGroup, err := configMapToConfig(configMap)
209200
if err != nil {
210-
return nil, nil, fmt.Errorf("could not turn configMap back to channelGroup: %s", err)
201+
return nil, nil, fmt.Errorf("Could not turn configMap back to channelGroup: %s", err)
211202
}
212203

213204
if !reflect.DeepEqual(channelGroup, configEnv.Config.ChannelGroup) {
214-
return nil, nil, fmt.Errorf("configEnvelope LastUpdate did not produce the supplied config result")
205+
return nil, nil, fmt.Errorf("ConfigEnvelope LastUpdate did not produce the supplied config result")
215206
}
216207

217208
result, err := cm.processConfig(channelGroup)

common/configtx/util.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,3 @@ func UnmarshalConfigEnvelopeOrPanic(data []byte) *cb.ConfigEnvelope {
9797
}
9898
return result
9999
}
100-
101-
// FixNewChannelConfig is to be applied on messages of type ConfigEnvelope that
102-
// are used to create a new channel. It returns a ConfigEnvelope whose
103-
// Config.Sequence and Config.NewChannel fields are set so that the config
104-
// manager of the new channel starts at the right sequence number.
105-
func FixNewChannelConfig(configEnv *cb.ConfigEnvelope) *cb.ConfigEnvelope {
106-
properSequence := uint64(0)
107-
if configEnv.Config.Sequence != properSequence {
108-
logger.Debugf("Received a new channel config env whose sequence is incorrectly set to %d, setting to %d instead",
109-
configEnv.Config.Sequence, properSequence)
110-
}
111-
configEnv.Config.Sequence = properSequence
112-
configEnv.Config.NewChannel = true
113-
return configEnv
114-
}

common/configtx/util_test.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ package configtx
1919
import (
2020
"math/rand"
2121
"testing"
22-
23-
cb "github.com/hyperledger/fabric/protos/common"
24-
25-
"github.com/stretchr/testify/assert"
2622
)
2723

2824
// TestValidchainID checks that the constraints on chain IDs are enforced properly
@@ -63,20 +59,6 @@ func TestValidChainID(t *testing.T) {
6359
})
6460
}
6561

66-
// TestFixNewChannelConfig checks that returned config envelope has its Sequence
67-
// and NewChannel fields set appropriately.
68-
func TestFixNewChannelConfig(t *testing.T) {
69-
expectedSequenceValue := uint64(0)
70-
expectedNewChannelValue := true
71-
72-
sampleConfigEnvelope := &cb.ConfigEnvelope{Config: &cb.Config{Sequence: uint64(rand.Uint32())}}
73-
returnedConfigEnvelope := FixNewChannelConfig(sampleConfigEnvelope)
74-
75-
assert.Equal(t, expectedSequenceValue, returnedConfigEnvelope.Config.Sequence, "Sequence should be zero %d", expectedSequenceValue)
76-
assert.NotNil(t, returnedConfigEnvelope.Config.NewChannel, "NewChannel field should be set")
77-
assert.Equal(t, expectedNewChannelValue, returnedConfigEnvelope.Config.NewChannel, "NewChannel field should be set to %t", expectedNewChannelValue)
78-
}
79-
8062
// Helper functions
8163

8264
func randomAlphaString(size int) string {

common/mocks/configtx/configtx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ type Manager struct {
177177
// ProposeConfigUpdateError is returned as the error value for ProposeConfigUpdate
178178
ProposeConfigUpdateError error
179179

180-
// ProposeConfigUpdateVal returns as the value for ProposeConfigUpdate
180+
// ProposeConfigUpdateVal is returns as the value for ProposeConfigUpdate
181181
ProposeConfigUpdateVal *cb.ConfigEnvelope
182182

183183
// ConfigEnvelopeVal is returned as the value for ConfigEnvelope()

orderer/common/broadcast/broadcast.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func (bh *handlerImpl) Handle(srv ab.AtomicBroadcast_BroadcastServer) error {
162162
}
163163

164164
if logger.IsEnabledFor(logging.DEBUG) {
165-
logger.Debugf("Broadcast has successfully enqueued message of type %s for chain %s", cb.HeaderType_name[chdr.Type], chdr.ChannelId)
165+
logger.Debugf("Broadcast has successfully enqueued message of type %d for chain %s", chdr.Type, chdr.ChannelId)
166166
}
167167

168168
err = srv.Send(&ab.BroadcastResponse{Status: cb.Status_SUCCESS})

orderer/configupdate/configupdate.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ package configupdate
2323
import (
2424
"fmt"
2525

26-
"github.com/hyperledger/fabric/common/configtx"
2726
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
2827
"github.com/hyperledger/fabric/common/crypto"
2928
cb "github.com/hyperledger/fabric/protos/common"
@@ -142,7 +141,7 @@ func (p *Processor) newChannelConfig(channelID string, envConfigUpdate *cb.Envel
142141
return nil, err
143142
}
144143

145-
newChannelEnvConfig, err := utils.CreateSignedEnvelope(cb.HeaderType_CONFIG, channelID, p.signer, configtx.FixNewChannelConfig(newChannelConfigEnv), msgVersion, epoch)
144+
newChannelEnvConfig, err := utils.CreateSignedEnvelope(cb.HeaderType_CONFIG, channelID, p.signer, newChannelConfigEnv, msgVersion, epoch)
146145
if err != nil {
147146
return nil, err
148147
}

orderer/configupdate/configupdate_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ func (msm *mockSupportManager) GetChain(chainID string) (Support, bool) {
5858
func (msm *mockSupportManager) NewChannelConfig(env *cb.Envelope) (configtxapi.Manager, error) {
5959
return &mockconfigtx.Manager{
6060
ProposeConfigUpdateVal: &cb.ConfigEnvelope{
61-
Config: &cb.Config{
62-
Sequence: 0,
63-
},
6461
LastUpdate: env,
6562
},
6663
}, nil

orderer/multichain/chainsupport.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ func (cs *chainSupport) addLastConfigSignature(block *cb.Block) {
231231
}
232232

233233
lastConfigValue := utils.MarshalOrPanic(&cb.LastConfig{Index: cs.lastConfig})
234-
logger.Debugf("[channel: %s] About to write block, setting its LAST_CONFIG to %d", cs.ChainID(), cs.lastConfig)
235234

236235
lastConfigSignature.Signature = utils.SignOrPanic(cs.signer, util.ConcatenateBytes(lastConfigValue, lastConfigSignature.SignatureHeader, block.Header.Bytes()))
237236

@@ -258,8 +257,6 @@ func (cs *chainSupport) WriteBlock(block *cb.Block, committers []filter.Committe
258257
if err != nil {
259258
logger.Panicf("[channel: %s] Could not append block: %s", cs.ChainID(), err)
260259
}
261-
262-
logger.Debugf("[channel: %s] Wrote block %d", cs.ChainID(), block.GetHeader().Number)
263260
return block
264261
}
265262

orderer/multichain/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func (ml *multiLedger) NewChannelConfig(envConfigUpdate *cb.Envelope) (configtxa
290290
channelGroup.Groups[config.ApplicationGroupKey] = applicationGroup
291291
channelGroup.Values[config.ConsortiumKey] = config.TemplateConsortium(consortium.Name).Values[config.ConsortiumKey]
292292

293-
templateConfig, _ := utils.CreateSignedEnvelope(cb.HeaderType_CONFIG, configUpdate.ChannelId, ml.signer, &cb.ConfigEnvelope{
293+
templateConfig, err := utils.CreateSignedEnvelope(cb.HeaderType_CONFIG, configUpdate.ChannelId, ml.signer, &cb.ConfigEnvelope{
294294
Config: &cb.Config{
295295
ChannelGroup: channelGroup,
296296
},

orderer/multichain/manager_test.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"testing"
2222
"time"
2323

24-
"github.com/golang/protobuf/proto"
2524
"github.com/hyperledger/fabric/common/configtx"
2625
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
2726
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
@@ -254,7 +253,7 @@ func TestNewChain(t *testing.T) {
254253
configEnv, err := cm.ProposeConfigUpdate(envConfigUpdate)
255254
assert.NoError(t, err, "Proposing initial update")
256255

257-
ingressTx, err := utils.CreateSignedEnvelope(cb.HeaderType_CONFIG, newChainID, mockCrypto(), configtx.FixNewChannelConfig(configEnv), msgVersion, epoch)
256+
ingressTx, err := utils.CreateSignedEnvelope(cb.HeaderType_CONFIG, newChainID, mockCrypto(), configEnv, msgVersion, epoch)
258257
assert.NoError(t, err, "Creating ingresstx")
259258

260259
wrapped := wrapConfigTx(ingressTx)
@@ -316,16 +315,6 @@ func TestNewChain(t *testing.T) {
316315
if status != cb.Status_SUCCESS {
317316
t.Fatalf("Could not retrieve block on new chain")
318317
}
319-
320-
// Inspect LAST_CONFIG value
321-
metadataItem := &cb.Metadata{}
322-
err := proto.Unmarshal(block.Metadata.Metadata[cb.BlockMetadataIndex_LAST_CONFIG], metadataItem)
323-
assert.NoError(t, err, "Block should carry LAST_CONFIG metadata item")
324-
lastConfig := &cb.LastConfig{}
325-
err = proto.Unmarshal(metadataItem.Value, lastConfig)
326-
assert.NoError(t, err, "LAST_CONFIG metadata item should carry last config value")
327-
assert.Equal(t, uint64(0), lastConfig.Index, "LAST_CONFIG value should point to genesis block")
328-
329318
for i := 0; i < int(conf.Orderer.BatchSize.MaxMessageCount); i++ {
330319
if !reflect.DeepEqual(utils.ExtractEnvelopeOrPanic(block, i), messages[i]) {
331320
t.Errorf("Block contents wrong at index %d in new chain", i)

0 commit comments

Comments
 (0)