Skip to content

Commit

Permalink
Define a static TestChainID
Browse files Browse the repository at this point in the history
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 <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Nov 22, 2016
1 parent 6b58537 commit 3a55da0
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 14 deletions.
11 changes: 3 additions & 8 deletions orderer/common/bootstrap/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ limitations under the License.
package static

import (
"fmt"

"github.com/hyperledger/fabric/core/crypto/primitives"
"github.com/hyperledger/fabric/orderer/common/bootstrap"
"github.com/hyperledger/fabric/orderer/common/cauthdsl"
"github.com/hyperledger/fabric/orderer/common/configtx"
"github.com/hyperledger/fabric/orderer/common/util"
cb "github.com/hyperledger/fabric/protos/common"
)

var TestChainID = []byte("**TEST_CHAINID**")

const msgVersion = int32(1)

type bootstrapper struct {
Expand All @@ -35,11 +34,7 @@ type bootstrapper struct {

// New returns a new static bootstrap helper.
func New() bootstrap.Helper {
chainID, err := primitives.GetRandomBytes(16)
if err != nil {
panic(fmt.Errorf("Cannot generate random chain ID: %s", err))
}
return &bootstrapper{chainID}
return &bootstrapper{chainID: TestChainID}
}

// GenesisBlock returns the genesis block to be used for bootstrapping
Expand Down
13 changes: 11 additions & 2 deletions orderer/sample_clients/bd_counter/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import (
"io"
"strconv"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/orderer/common/bootstrap/static"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"

"github.com/golang/protobuf/proto"
context "golang.org/x/net/context"
)

Expand All @@ -49,7 +51,14 @@ func (c *clientImpl) broadcast() {
logger.Info("Client shutting down")
return
case tokenChan <- struct{}{}:
payload, err := proto.Marshal(&cb.Payload{Data: []byte(strconv.Itoa(count))})
payload, err := proto.Marshal(&cb.Payload{
Header: &cb.Header{
ChainHeader: &cb.ChainHeader{
ChainID: static.TestChainID,
},
},
Data: []byte(strconv.Itoa(count)),
})
if err != nil {
panic(err)
}
Expand Down
2 changes: 2 additions & 0 deletions orderer/sample_clients/bd_counter/deliver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io"
"log"

"github.com/hyperledger/fabric/orderer/common/bootstrap/static"
ab "github.com/hyperledger/fabric/protos/orderer"
context "golang.org/x/net/context"
)
Expand All @@ -30,6 +31,7 @@ func (c *clientImpl) deliver() {
Type: &ab.DeliverUpdate_Seek{
Seek: &ab.SeekInfo{
WindowSize: uint64(c.config.window),
ChainID: static.TestChainID,
},
},
}
Expand Down
10 changes: 9 additions & 1 deletion orderer/sample_clients/broadcast_timestamp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/orderer/common/bootstrap/static"
"github.com/hyperledger/fabric/orderer/config"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"
Expand All @@ -38,7 +39,14 @@ func newBroadcastClient(client ab.AtomicBroadcast_BroadcastClient) *broadcastCli
}

func (s *broadcastClient) broadcast(transaction []byte) error {
payload, err := proto.Marshal(&cb.Payload{Data: transaction})
payload, err := proto.Marshal(&cb.Payload{
Header: &cb.Header{
ChainHeader: &cb.ChainHeader{
ChainID: static.TestChainID,
},
},
Data: transaction,
})
if err != nil {
panic(err)
}
Expand Down
4 changes: 4 additions & 0 deletions orderer/sample_clients/deliver_stdout/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"fmt"

"github.com/hyperledger/fabric/orderer/common/bootstrap/static"
"github.com/hyperledger/fabric/orderer/config"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"
Expand All @@ -42,6 +43,7 @@ func (r *deliverClient) seekOldest() error {
Seek: &ab.SeekInfo{
Start: ab.SeekInfo_OLDEST,
WindowSize: r.windowSize,
ChainID: static.TestChainID,
},
},
})
Expand All @@ -53,6 +55,7 @@ func (r *deliverClient) seekNewest() error {
Seek: &ab.SeekInfo{
Start: ab.SeekInfo_NEWEST,
WindowSize: r.windowSize,
ChainID: static.TestChainID,
},
},
})
Expand All @@ -65,6 +68,7 @@ func (r *deliverClient) seek(blockNumber uint64) error {
Start: ab.SeekInfo_SPECIFIED,
SpecifiedNumber: blockNumber,
WindowSize: r.windowSize,
ChainID: static.TestChainID,
},
},
})
Expand Down
15 changes: 12 additions & 3 deletions orderer/sample_clients/single_tx_client/single_tx_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import (
"fmt"
"time"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/orderer/common/bootstrap/static"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"

"github.com/golang/protobuf/proto"
"github.com/op/go-logging"
"golang.org/x/net/context"
"google.golang.org/grpc"
Expand Down Expand Up @@ -96,7 +98,7 @@ func updateReceiver(resultch chan byte, errorch chan error, client ab.AtomicBroa
errorch <- fmt.Errorf("Failed to get Deliver stream: %s", err)
return
}
dstream.Send(&ab.DeliverUpdate{Type: &ab.DeliverUpdate_Seek{Seek: &ab.SeekInfo{Start: ab.SeekInfo_NEWEST, WindowSize: 10}}})
dstream.Send(&ab.DeliverUpdate{Type: &ab.DeliverUpdate_Seek{Seek: &ab.SeekInfo{Start: ab.SeekInfo_NEWEST, WindowSize: 10, ChainID: static.TestChainID}}})
logger.Info("{Update Receiver} Listening to ledger updates.")
for i := 0; i < 2; i++ {
m, inerr := dstream.Recv()
Expand Down Expand Up @@ -129,7 +131,14 @@ func broadcastSender(resultch chan byte, errorch chan error, client ab.AtomicBro
return
}
bs := []byte{0, 1, 2, 3}
pl := &cb.Payload{Data: bs}
pl := &cb.Payload{
Header: &cb.Header{
ChainHeader: &cb.ChainHeader{
ChainID: static.TestChainID,
},
},
Data: bs,
}
mpl, err := proto.Marshal(pl)
if err != nil {
panic("Failed to marshal payload.")
Expand Down

0 comments on commit 3a55da0

Please sign in to comment.