Skip to content

Commit 3a55da0

Browse files
author
Jason Yellick
committed
Define a static TestChainID
As multichain support comes online, the randomly generated chainID in the static bootstrapper causes problems. This is because the clients must know the chainID ahead of time before submitting transactions. This has also caused problems for SBFT testing as multiple processes must agree on the system chain ID. This changeset defines a static TestChainID for static bootstrapping and fixes the assorted sample clients to utilize this TestChainID. Change-Id: I73457faea4b29fc6f8f62a196f419fcc66cb36ed Signed-off-by: Jason Yellick <[email protected]>
1 parent 6b58537 commit 3a55da0

File tree

6 files changed

+41
-14
lines changed

6 files changed

+41
-14
lines changed

orderer/common/bootstrap/static/static.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@ limitations under the License.
1717
package static
1818

1919
import (
20-
"fmt"
21-
22-
"github.com/hyperledger/fabric/core/crypto/primitives"
2320
"github.com/hyperledger/fabric/orderer/common/bootstrap"
2421
"github.com/hyperledger/fabric/orderer/common/cauthdsl"
2522
"github.com/hyperledger/fabric/orderer/common/configtx"
2623
"github.com/hyperledger/fabric/orderer/common/util"
2724
cb "github.com/hyperledger/fabric/protos/common"
2825
)
2926

27+
var TestChainID = []byte("**TEST_CHAINID**")
28+
3029
const msgVersion = int32(1)
3130

3231
type bootstrapper struct {
@@ -35,11 +34,7 @@ type bootstrapper struct {
3534

3635
// New returns a new static bootstrap helper.
3736
func New() bootstrap.Helper {
38-
chainID, err := primitives.GetRandomBytes(16)
39-
if err != nil {
40-
panic(fmt.Errorf("Cannot generate random chain ID: %s", err))
41-
}
42-
return &bootstrapper{chainID}
37+
return &bootstrapper{chainID: TestChainID}
4338
}
4439

4540
// GenesisBlock returns the genesis block to be used for bootstrapping

orderer/sample_clients/bd_counter/broadcast.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import (
2121
"io"
2222
"strconv"
2323

24-
"github.com/golang/protobuf/proto"
24+
"github.com/hyperledger/fabric/orderer/common/bootstrap/static"
2525
cb "github.com/hyperledger/fabric/protos/common"
2626
ab "github.com/hyperledger/fabric/protos/orderer"
27+
28+
"github.com/golang/protobuf/proto"
2729
context "golang.org/x/net/context"
2830
)
2931

@@ -49,7 +51,14 @@ func (c *clientImpl) broadcast() {
4951
logger.Info("Client shutting down")
5052
return
5153
case tokenChan <- struct{}{}:
52-
payload, err := proto.Marshal(&cb.Payload{Data: []byte(strconv.Itoa(count))})
54+
payload, err := proto.Marshal(&cb.Payload{
55+
Header: &cb.Header{
56+
ChainHeader: &cb.ChainHeader{
57+
ChainID: static.TestChainID,
58+
},
59+
},
60+
Data: []byte(strconv.Itoa(count)),
61+
})
5362
if err != nil {
5463
panic(err)
5564
}

orderer/sample_clients/bd_counter/deliver.go

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"io"
2222
"log"
2323

24+
"github.com/hyperledger/fabric/orderer/common/bootstrap/static"
2425
ab "github.com/hyperledger/fabric/protos/orderer"
2526
context "golang.org/x/net/context"
2627
)
@@ -30,6 +31,7 @@ func (c *clientImpl) deliver() {
3031
Type: &ab.DeliverUpdate_Seek{
3132
Seek: &ab.SeekInfo{
3233
WindowSize: uint64(c.config.window),
34+
ChainID: static.TestChainID,
3335
},
3436
},
3537
}

orderer/sample_clients/broadcast_timestamp/client.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"time"
2222

2323
"github.com/golang/protobuf/proto"
24+
"github.com/hyperledger/fabric/orderer/common/bootstrap/static"
2425
"github.com/hyperledger/fabric/orderer/config"
2526
cb "github.com/hyperledger/fabric/protos/common"
2627
ab "github.com/hyperledger/fabric/protos/orderer"
@@ -38,7 +39,14 @@ func newBroadcastClient(client ab.AtomicBroadcast_BroadcastClient) *broadcastCli
3839
}
3940

4041
func (s *broadcastClient) broadcast(transaction []byte) error {
41-
payload, err := proto.Marshal(&cb.Payload{Data: transaction})
42+
payload, err := proto.Marshal(&cb.Payload{
43+
Header: &cb.Header{
44+
ChainHeader: &cb.ChainHeader{
45+
ChainID: static.TestChainID,
46+
},
47+
},
48+
Data: transaction,
49+
})
4250
if err != nil {
4351
panic(err)
4452
}

orderer/sample_clients/deliver_stdout/client.go

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package main
1919
import (
2020
"fmt"
2121

22+
"github.com/hyperledger/fabric/orderer/common/bootstrap/static"
2223
"github.com/hyperledger/fabric/orderer/config"
2324
cb "github.com/hyperledger/fabric/protos/common"
2425
ab "github.com/hyperledger/fabric/protos/orderer"
@@ -42,6 +43,7 @@ func (r *deliverClient) seekOldest() error {
4243
Seek: &ab.SeekInfo{
4344
Start: ab.SeekInfo_OLDEST,
4445
WindowSize: r.windowSize,
46+
ChainID: static.TestChainID,
4547
},
4648
},
4749
})
@@ -53,6 +55,7 @@ func (r *deliverClient) seekNewest() error {
5355
Seek: &ab.SeekInfo{
5456
Start: ab.SeekInfo_NEWEST,
5557
WindowSize: r.windowSize,
58+
ChainID: static.TestChainID,
5659
},
5760
},
5861
})
@@ -65,6 +68,7 @@ func (r *deliverClient) seek(blockNumber uint64) error {
6568
Start: ab.SeekInfo_SPECIFIED,
6669
SpecifiedNumber: blockNumber,
6770
WindowSize: r.windowSize,
71+
ChainID: static.TestChainID,
6872
},
6973
},
7074
})

orderer/sample_clients/single_tx_client/single_tx_client.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ import (
2020
"fmt"
2121
"time"
2222

23-
"github.com/golang/protobuf/proto"
23+
"github.com/hyperledger/fabric/orderer/common/bootstrap/static"
2424
cb "github.com/hyperledger/fabric/protos/common"
2525
ab "github.com/hyperledger/fabric/protos/orderer"
26+
27+
"github.com/golang/protobuf/proto"
2628
"github.com/op/go-logging"
2729
"golang.org/x/net/context"
2830
"google.golang.org/grpc"
@@ -96,7 +98,7 @@ func updateReceiver(resultch chan byte, errorch chan error, client ab.AtomicBroa
9698
errorch <- fmt.Errorf("Failed to get Deliver stream: %s", err)
9799
return
98100
}
99-
dstream.Send(&ab.DeliverUpdate{Type: &ab.DeliverUpdate_Seek{Seek: &ab.SeekInfo{Start: ab.SeekInfo_NEWEST, WindowSize: 10}}})
101+
dstream.Send(&ab.DeliverUpdate{Type: &ab.DeliverUpdate_Seek{Seek: &ab.SeekInfo{Start: ab.SeekInfo_NEWEST, WindowSize: 10, ChainID: static.TestChainID}}})
100102
logger.Info("{Update Receiver} Listening to ledger updates.")
101103
for i := 0; i < 2; i++ {
102104
m, inerr := dstream.Recv()
@@ -129,7 +131,14 @@ func broadcastSender(resultch chan byte, errorch chan error, client ab.AtomicBro
129131
return
130132
}
131133
bs := []byte{0, 1, 2, 3}
132-
pl := &cb.Payload{Data: bs}
134+
pl := &cb.Payload{
135+
Header: &cb.Header{
136+
ChainHeader: &cb.ChainHeader{
137+
ChainID: static.TestChainID,
138+
},
139+
},
140+
Data: bs,
141+
}
133142
mpl, err := proto.Marshal(pl)
134143
if err != nil {
135144
panic("Failed to marshal payload.")

0 commit comments

Comments
 (0)