> For the complete documentation index, see [llms.txt](https://agzs.gitbook.io/geth-pbft-book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://agzs.gitbook.io/geth-pbft-book/chapter4-development-notes/chapter4-development-notes/zhiguo-notes.md).

# Section4.2.1 zhiguo's notes

## Summary:

1. clique.go and pbft.go are merged into one file pbft.go
2. Struct PBFT is defined, containing a ProtocolManager
3. Seal() in pbft.go is revised to work with pbft-core.go
4. util/events.go are copied from fabric/util
5. some parts related to batch in pbft-core.go and pbft.go have been commented.

## 11/10

### 19. innerBroadcast is changed to sending messages to commChan:

```
instance.commChan <- &types.PbftMessage{Payload: &types.PbftMessage_Commit{Commit: commit}}
```

replace the following code

```
instance.innerBroadcast(&Message{&Message_Commit{commit}})
```

## 07/10

### 17. two channels are used for communication:

* commChan: PBFT algorithm --> ProtocolManager. PrePrepare, Prepare, Commit messages
* ResultChan: inside PBFT algorithm, inform engine that consensus is achieved after receiving enough Commit messages.

  Note: cannot use Protocolmanager in PBFT directly because import cycle problem.

### 18. Message format problem

Modify the file generated by protobuf, but do not use protobuf. Use RLP of ethereum for message transmission.

## 01/10

### 14. util.go of fabric contains a hash function, which is used for hashing Request and RequestBatch.

it uses hash function sha3 from core/util/utils.go (ComputeCryptoHash).

### 15. RequestBatch --> Candidate Block. reqBatchStore --> blockStore

msgCert? certStore

### 16. ChainConfig() ---> add one more parameter as one more engine is added.

## 30/09

### 13. pset: prepared or not for a node; qset: prepared or not for a node

## 28/09

### 12. protobuf install:

<https://tleyden.github.io/blog/2014/12/02/getting-started-with-go-and-protocol-buffers/>

Ubuntu 14.04

If you want to use an older version (v2.5), simply do:

`$ apt-get install protobuf-compiler`

Otherwise if you want the latest version (v2.6):

```
$ apt-get install build-essential
$ wget https://protobuf.googlecode.com/svn/rc/protobuf-2.6.0.tar.gz
$ tar xvfz protobuf-2.6.0.tar.gz
$ cd protobuf-2.6.0
$ ./configure && make install
```

OSX

```
$ brew install protobuf
```

## 27/09

### 11. 消息类别定义Message\_CONSENSUS定义在photos目录下的fabric.pb.go文件中，由proton编译而成，

其源文件为fabric.proto

### 10. golang protobuffer reference

A practical guide to protocol buffers (Protobuf) in Go (Golang)

<http://www.minaandrawos.com/2014/05/27/practical-guide-protocol-buffers-protobuf-go-golang/#SourceCode>

In fabric PBFT, messages are defined using protocolbuffer, check this reference, and also the following one:

<https://stackoverflow.com/questions/40025602/how-to-use-predifined-protobuf-type-i-e-google-protobuf-timestamp-proto-wit>

## 26/09

#### 9. Message format revision:

1\) Request in fabric\_pbft contain one tx, while we use a block for negotiate consensus.

* do not use request type
* use pre\_prepare type in messages.proto to hold the candidate block

### 8. Some unknown things:

1\) watermarks, checkpoints (both clique and pbft have it) 2) Cert and CertStore do not contain any certs. 3) timer mechanisms---broadcast timer, viewchange timer, softstartTimer, startTimer etc.

### 7. in pbft-core.go add ProtocolManager, but vscode cannot find its definition. Method to resolve it:

`~/go/bin/godef -debug -f pbft-core.go eth.ProtocolManager`

find which package is not installed, then install it using gage:

`go get gopkg.in/fatih/set.v0`

## 22/09

### 6. timer mechanism:

timer is created by timerFactory, and it is associated with the Manager of obcBatch, so from obcBatch, one can control all timers.

### 5. we do not need batch, because we process candidate block with PBFT algorithm

each node sign the block with its key, just like Clique?

### 4. checkpoint, state related codes should be commented all

## 21/09

### 1. in ethereum, no need to execute txs or contracts

A candidate block is Finalized and then mined, then is inserted to the blockchain; InsertChain -> State\_Processor.Process() -> ApplyMessage(), update state root etc.

### 2. in pbft, each transaction/contract is executed after consensus (need to call chaincode.ApplyTransaction)

No need to execute/rollback etc. anymore.
