Skip to content

Commit

Permalink
try to add tx tracing for observer (#219)
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Yuan <[email protected]>
  • Loading branch information
SamYuan1990 authored Nov 6, 2021
1 parent 93679ae commit 20faec6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 23 additions & 1 deletion pkg/infra/observer/commitObserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,31 @@ func (o *CommitObserver) Start() {
if r == nil {
panic("Received nil message, but expect a valid block instead. You could look into your peer logs for more info")
}
tx := len(r.GetBlock().Data.Data)
block := r.GetBlock()
tx := len(block.Data.Data)
n += tx
fmt.Printf("From Orderer Time %8.2fs\tBlock %6d\t Tx %6d\n", time.Since(o.Now).Seconds(), n, tx)
for _, data := range block.Data.Data {
txID := ""
env, err := protoutil.GetEnvelopeFromBlock(data)
if err != nil {
continue
}
payload, err := protoutil.UnmarshalPayload(env.Payload)
if err != nil {
continue
}
chdr, err := protoutil.UnmarshalChannelHeader(payload.Header.ChannelHeader)
if err != nil {
continue
}
if common.HeaderType(chdr.Type) == common.HeaderType_ENDORSER_TRANSACTION {
txID = chdr.TxId
}
if txID != "" {
basic.LogEvent(o.logger, string(txID), "BlockFromOrderer")
}
}
if o.n > 0 {
if n >= o.n {
close(o.finishCh)
Expand Down
3 changes: 3 additions & 0 deletions pkg/infra/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ func (o *Observer) Start(errorCh chan error, blockCh chan<- *AddressedBlock, now
}

fb := r.Type.(*peer.DeliverResponse_FilteredBlock)
for _, b := range fb.FilteredBlock.FilteredTransactions {
basic.LogEvent(o.logger, b.Txid, "CommitAtPeer")
}
o.logger.Debugf("receivedTime %8.2fs\tBlock %6d\tTx %6d\t Address %s\n", time.Since(now).Seconds(), fb.FilteredBlock.Number, len(fb.FilteredBlock.FilteredTransactions), o.Address)

blockCh <- &AddressedBlock{fb.FilteredBlock, o.index, time.Since(now)}
Expand Down

0 comments on commit 20faec6

Please sign in to comment.