Skip to content

Commit

Permalink
Merge pull request #7 from raventrov/platon-0.1.0
Browse files Browse the repository at this point in the history
remove some comment which wrote in chinese
  • Loading branch information
benbaley authored Dec 17, 2018
2 parents 50ad9ac + e224799 commit 93ca04d
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 228 deletions.
1 change: 0 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,6 @@ func SetDashboardConfig(ctx *cli.Context, cfg *dashboard.Config) {
// RegisterEthService adds an Ethereum client to the stack.
func RegisterEthService(stack *node.Node, cfg *eth.Config) {
var err error
// 注册即为定义构造函数的实现方式
if cfg.SyncMode == downloader.LightSync {
err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
return les.New(ctx, cfg)
Expand Down
3 changes: 0 additions & 3 deletions common/compiler/solidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

// 对solc的一个包装啦啦啦啦
// Package compiler wraps the Solidity compiler executable (solc).
package compiler

Expand Down Expand Up @@ -69,7 +68,6 @@ type solcOutput struct {
Version string
}

// 构建命令参数
func (s *Solidity) makeArgs() []string {
p := []string{
"--combined-json", "bin,abi,userdoc,devdoc",
Expand All @@ -93,7 +91,6 @@ func SolidityVersion(solc string) (*Solidity, error) {
if err != nil {
return nil, err
}
// 正则表达式取匹配部分
matches := versionRegexp.FindStringSubmatch(out.String())
if len(matches) != 4 {
return nil, fmt.Errorf("can't parse solc version %q", out.String())
Expand Down
2 changes: 1 addition & 1 deletion common/compiler/solidity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestCompileError(t *testing.T) {

func TestSolidityVersion(t *testing.T) {
solidity, err := SolidityVersion("solc")
t.Log("哈哈哈哈,这是单元测试")
t.Log("Hahahaha, this is unit test")
if err != nil {
t.Log("error throws.", err)
} else {
Expand Down
2 changes: 1 addition & 1 deletion consensus/cbft/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type API struct {
cbft *Cbft
}

// 获取出块人地址
// Get the block address of producer.
func (api *API) GetProducer(number *rpc.BlockNumber) (common.Address, error) {
// Retrieve the requested block number (or current if none requested)
var header *types.Header
Expand Down
4 changes: 2 additions & 2 deletions consensus/cbft/cbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ func (cbft *Cbft) signReceiver(sig *cbfttypes.BlockSignature) error {

cbft.saveBlock(sig.Hash, ext)
} else if ext.isStored {
//收到已经确认块的签名,直接扔掉
// Receive the signature of the confirmed block and throw it away directly.
log.Debug("received a highestConfirmed block's signature, just discard it")
return nil
}
Expand Down Expand Up @@ -952,7 +952,7 @@ func (b *Cbft) Prepare(chain consensus.ChainReader, header *types.Header) error
cbft.lock.RLock()
defer cbft.lock.RUnlock()

//检查父区块
// Check the parent block
if cbft.highestLogical.block == nil || header.ParentHash != cbft.highestLogical.block.Hash() || header.Number.Uint64()-1 != cbft.highestLogical.block.NumberU64() {
return consensus.ErrUnknownAncestor
}
Expand Down
22 changes: 11 additions & 11 deletions consensus/cbft/consensus_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewCache(blockChain *core.BlockChain) *Cache {
return cache
}

// 从缓存map中读取Receipt集合
// Read the Receipt collection from the cache map.
func (c *Cache) ReadReceipts(blockHash common.Hash) []*types.Receipt {
c.receiptsMu.RLock()
defer c.receiptsMu.RUnlock()
Expand All @@ -51,7 +51,7 @@ func (c *Cache) ReadReceipts(blockHash common.Hash) []*types.Receipt {
return nil
}

// 从缓存map中读取StateDB实例
// Read the StateDB instance from the cache map.
func (c *Cache) ReadStateDB(stateRoot common.Hash) *state.StateDB {
c.stateDBMu.RLock()
defer c.stateDBMu.RUnlock()
Expand All @@ -61,7 +61,7 @@ func (c *Cache) ReadStateDB(stateRoot common.Hash) *state.StateDB {
return nil
}

// 将Receipt写入缓存
// Write Receipt to the cache.
func (c *Cache) WriteReceipts(blockHash common.Hash, receipts []*types.Receipt, blockNum uint64) {
c.receiptsMu.Lock()
defer c.receiptsMu.Unlock()
Expand All @@ -73,7 +73,7 @@ func (c *Cache) WriteReceipts(blockHash common.Hash, receipts []*types.Receipt,
}
}

// 将StateDB实例写入缓存
// Write StateDB instance to the cache.
func (c *Cache) WriteStateDB(stateRoot common.Hash, stateDB *state.StateDB, blockNum uint64) {
c.stateDBMu.Lock()
defer c.stateDBMu.Unlock()
Expand All @@ -82,7 +82,7 @@ func (c *Cache) WriteStateDB(stateRoot common.Hash, stateDB *state.StateDB, bloc
}
}

// 从缓存map中读取Receipt集合
// Read the Receipt collection from the cache map.
func (c *Cache) clearReceipts(blockHash common.Hash) {
c.receiptsMu.Lock()
defer c.receiptsMu.Unlock()
Expand All @@ -99,7 +99,7 @@ func (c *Cache) clearReceipts(blockHash common.Hash) {
}
}

// 从缓存map中读取StateDB实例
// Read the statedb instance from the cache map.
func (c *Cache) clearStateDB(stateRoot common.Hash) {
c.stateDBMu.Lock()
defer c.stateDBMu.Unlock()
Expand All @@ -116,22 +116,22 @@ func (c *Cache) clearStateDB(stateRoot common.Hash) {
}
}

// 获取相应block的StateDB实例
// Get the StateDB instance of the corresponding block.
func (c *Cache) MakeStateDB(block *types.Block) (*state.StateDB, error) {
// 基于stateRoot从blockchain中创建StateDB实例
// Create a StateDB instance from the blockchain based on stateRoot.
if state, err := c.chain.StateAt(block.Root()); err == nil && state != nil {
return state, nil
}
// 读取并拷贝缓存中StateDB实例
log.Info("读取并拷贝缓存中StateDB实例", "stateRoot", block.Root())
// Read and copy the stateDB instance in the cache.
log.Info("~ Read and copy the stateDB instance in the cache.", "stateRoot", block.Root())
if state := c.ReadStateDB(block.Root()); state != nil {
return state.Copy(), nil
} else {
return nil, errMakeStateDB
}
}

// 获取相应block的StateDB实例
// Get the StateDB instance of the corresponding block.
func (c *Cache) ClearCache(block *types.Block) {
c.clearReceipts(block.Hash())
c.clearStateDB(block.Root())
Expand Down
20 changes: 11 additions & 9 deletions consensus/cbft/dpos.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ type dpos struct {
primaryNodeList []discover.NodeID
chain *core.BlockChain
lastCycleBlockNum uint64
startTimeOfEpoch int64 // 一轮共识开始时间,通常是上一轮共识结束时最后一个区块的出块时间;如果是第一轮,则从1970.1.1.0.0.0.0开始。单位:秒
startTimeOfEpoch int64 // A round of consensus start time is usually the block time
// of the last block at the end of the last round of consensus;
// if it is the first round, it starts from 1970.1.1.0.0.0.0. Unit: second

}

Expand All @@ -25,8 +27,8 @@ func newDpos(initialNodes []discover.NodeID) *dpos {
return dpos
}

// Determine whether the current node is a consensus node.
func (d *dpos) IsPrimary(addr common.Address) bool {
// 判断当前节点是否是共识节点
for _, node := range d.primaryNodeList {
pub, err := node.Pubkey()
if err != nil || pub == nil {
Expand All @@ -48,21 +50,21 @@ func (d *dpos) NodeIndex(nodeID discover.NodeID) int64 {
}

func (d *dpos) LastCycleBlockNum() uint64 {
// 获取最后一轮共识结束时的区块高度
// Get the block height at the end of the final round of consensus.
return d.lastCycleBlockNum
}

func (d *dpos) SetLastCycleBlockNum(blockNumber uint64) {
// 设置最后一轮共识结束时的区块高度
// Set the block height at the end of the last round of consensus
d.lastCycleBlockNum = blockNumber
}

// 返回当前共识节点地址列表
// Returns the current consensus node address list.
/*func (b *dpos) ConsensusNodes() []discover.Node {
return b.primaryNodeList
}
*/
// 判断某个节点是否本轮或上一轮选举共识节点
// Determine whether a node is the current or previous round of election consensus nodes.
/*func (b *dpos) CheckConsensusNode(id discover.NodeID) bool {
nodes := b.ConsensusNodes()
for _, node := range nodes {
Expand All @@ -73,7 +75,7 @@ func (d *dpos) SetLastCycleBlockNum(blockNumber uint64) {
return false
}*/

// 判断当前节点是否本轮或上一轮选举共识节点
// Determine whether the current node is the current or previous round of election consensus nodes.
/*func (b *dpos) IsConsensusNode() (bool, error) {
return true, nil
}
Expand All @@ -84,7 +86,7 @@ func (d *dpos) StartTimeOfEpoch() int64 {
}

func (d *dpos) SetStartTimeOfEpoch(startTimeOfEpoch int64) {
// 设置最后一轮共识结束时的出块时间
// Set the block time at the end of the last round of consensus.
d.startTimeOfEpoch = startTimeOfEpoch
log.Info("设置最后一轮共识结束时的出块时间", "startTimeOfEpoch", startTimeOfEpoch)
log.Info("~ Set the block time at the end of the last round of consensus.", "startTimeOfEpoch", startTimeOfEpoch)
}
16 changes: 8 additions & 8 deletions consensus/cbft/rotating.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (

type rotating struct {
dpos *dpos
rotaList []common.Address // 本轮循环出块节点顺序列表
startTime int64 // 本轮循环开始时间戳,单位毫秒
endTime int64 // 本轮循环结束时间戳,单位毫秒
timeInterval int64 // 每个节点出块时间,单位毫秒
rotaList []common.Address // This round of cyclic block node order list
startTime int64 // The current cycle start timestamp, in milliseconds
endTime int64 // The current cycle end timestamp, in milliseconds
timeInterval int64 // Block time per unit, in milliseconds
}

func newRotating(dpos *dpos, timeInterval int64) *rotating {
Expand All @@ -21,13 +21,13 @@ func newRotating(dpos *dpos, timeInterval int64) *rotating {
}

func sort() {
// 新一轮共识的排序函数
// xor(上一轮的最后区块hash + 节点公钥地址)
// New round of consensus sorting function
// xor(Last block last block hash + node public key address)
}

func (r *rotating) IsRotating(common.Address) bool {
// 判断当前节点是否轮值出块
// 根据共识排序以及时间窗口
// Determine whether the current node is out of order
// Sort by consensus and time window
return false
}

Expand Down
11 changes: 6 additions & 5 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ type PoW interface {
type Bft interface {
Engine

// 返回当前共识节点地址列表
// Returns the current consensus node address list.
ConsensusNodes() ([]discover.NodeID, error)

// 返回当前节点是否轮值出块
// Returns whether the current node is out of the block.
ShouldSeal() (bool, error)

//收到新的区块签名
//需要验证签名是否时nodeID签名的
// Received a new block signature
// Need to verify if the signature is signed by nodeID
OnBlockSignature(chain ChainReader, nodeID discover.NodeID, sig *cbfttypes.BlockSignature) error

// Process the BFT signatures
Expand All @@ -140,7 +140,8 @@ type Bft interface {

IsConsensusNode() (bool, error)

//目前最高的合理块,本节点出块时,需要基于最高合理块来生成区块。
// At present, the highest reasonable block, when the node is out of the block,
// it needs to generate the block based on the highest reasonable block.
HighestLogicalBlock() *types.Block

SetPrivateKey(privateKey *ecdsa.PrivateKey)
Expand Down
4 changes: 2 additions & 2 deletions core/cbfttypes/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

// Block's Signature info
type BlockSignature struct {
SignHash common.Hash //签名hash,header[0:32]
Hash common.Hash //块hash,header[:]
SignHash common.Hash // signature hash,header[0:32]
Hash common.Hash // block hash,header[:]
Number *big.Int
Signature *common.BlockConfirmSign
}
Expand Down
4 changes: 0 additions & 4 deletions core/chain_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,19 @@ import (
"github.com/PlatONnetwork/PlatON-Go/log"
)

// 定义了处理区块链片段的方法,并把处理结果写入数据库
// ChainIndexerBackend defines the methods needed to process chain segments in
// the background and write the segment results into the database. These can be
// used to create filter blooms or CHTs.
type ChainIndexerBackend interface {

// 用来初始化一个新的区块链片段,可能会终止任何没有完成的操作
// Reset initiates the processing of a new chain segment, potentially terminating
// any partially completed operations (in case of a reorg).
Reset(ctx context.Context, section uint64, prevHead common.Hash) error

// 对区块链片段中的下一个区块头进行处理。 调用者将确保区块头的连续顺序
// Process crunches through the next header in the chain segment. The caller
// will ensure a sequential order of headers.
Process(ctx context.Context, header *types.Header) error

// 完成区块链片段的元数据并将其存储到数据库中
// Commit finalizes the section metadata and stores it into the database.
Commit() error
}
Expand Down
Loading

0 comments on commit 93ca04d

Please sign in to comment.