Skip to content

Commit

Permalink
[FAB-6987]Fix single_tx_client panic error
Browse files Browse the repository at this point in the history
Likley due to the fact that it has not
really been maintained, the
single_tx_client panicked because
the proper message structures were
not being send to the orderer.

Once this was fixed, it led to
a type mismatch error due to the
way the deliver channel is set up.

Rather than muck around with this, I
simply got the client working such that
it gets the latest block from the orderer
and then also gets the block for the tx it
submits as well.

Change-Id: Ie05ac79a2d940e2b30b1d8935bb2feeea527518b
Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
  • Loading branch information
mastersingh24 committed Nov 26, 2017
1 parent b19580a commit dc8d323
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions orderer/sample_clients/single_tx_client/single_tx_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"fmt"
"math"
"time"

"github.com/hyperledger/fabric/common/configtx/tool/provisional"
Expand All @@ -42,7 +43,7 @@ var NEEDED_SENT = 1
func main() {
logger.Info("Creating an Atomic Broadcast GRPC connection.")
timeout := 4 * time.Second
clientconn, err := grpc.Dial(":7101", grpc.WithBlock(), grpc.WithTimeout(timeout), grpc.WithInsecure())
clientconn, err := grpc.Dial(":7050", grpc.WithBlock(), grpc.WithTimeout(timeout), grpc.WithInsecure())
if err != nil {
logger.Errorf("Failed to connect to GRPC: %s", err)
return
Expand Down Expand Up @@ -108,32 +109,37 @@ func updateReceiver(resultch chan byte, errorch chan error, client ab.AtomicBroa
SignatureHeader: utils.MarshalOrPanic(&cb.SignatureHeader{}),
},
Data: utils.MarshalOrPanic(&ab.SeekInfo{
Start: &ab.SeekPosition{Type: &ab.SeekPosition_Newest{}},
Stop: &ab.SeekPosition{Type: &ab.SeekPosition_Newest{}},
Start: &ab.SeekPosition{Type: &ab.SeekPosition_Newest{
Newest: &ab.SeekNewest{}}},
Stop: &ab.SeekPosition{Type: &ab.SeekPosition_Specified{Specified: &ab.SeekSpecified{Number: math.MaxUint64}}},
Behavior: ab.SeekInfo_BLOCK_UNTIL_READY,
}),
}),
})

logger.Info("{Update Receiver} Listening to ledger updates.")
for i := 0; i < 2; i++ {
for i := 0; i < 3; i++ {
m, inerr := dstream.Recv()
if inerr != nil {
errorch <- fmt.Errorf("Failed to receive consensus: %s", inerr)
return
}
b := m.Type.(*ab.DeliverResponse_Block)
logger.Info("{Update Receiver} Received a ledger update.")
for i, tx := range b.Block.Data.Data {
pl := &cb.Payload{}
e := &cb.Envelope{}
merr1 := proto.Unmarshal(tx, e)
merr2 := proto.Unmarshal(e.Payload, pl)
if merr1 == nil && merr2 == nil {
logger.Infof("{Update Receiver} %d - %v", i+1, pl.Data)
switch b := m.Type.(type) {
case *ab.DeliverResponse_Status:
fmt.Println("Got status ", b)
case *ab.DeliverResponse_Block:
logger.Info("{Update Receiver} Received a ledger update.")
for i, tx := range b.Block.Data.Data {
pl := &cb.Payload{}
e := &cb.Envelope{}
merr1 := proto.Unmarshal(tx, e)
merr2 := proto.Unmarshal(e.Payload, pl)
if merr1 == nil && merr2 == nil {
logger.Infof("{Update Receiver} %d - %v", i+1, pl.Data)
}
}
resultch <- UPDATE
}
resultch <- UPDATE
}
logger.Info("{Update Receiver} Exiting...")
}
Expand Down

0 comments on commit dc8d323

Please sign in to comment.