From c8d3092208f73ee991a123052a71b7dbf7fffc27 Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Mon, 3 Sep 2018 10:01:40 +0800 Subject: core: Add a new structure `Position` and move `ShardID`, `ChainID` and `Height` from `Block` (#89) --- core/consensus.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'core/consensus.go') diff --git a/core/consensus.go b/core/consensus.go index 4d1a386..2618b54 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -122,7 +122,7 @@ func NewConsensus( func (con *Consensus) Run() { go con.processMsg(con.network.ReceiveChan()) - chainID := uint64(0) + chainID := uint32(0) hashes := make(common.Hashes, 0, len(con.gov.GetValidatorSet())) for vID := range con.gov.GetValidatorSet() { hashes = append(hashes, vID.Hash) @@ -130,14 +130,16 @@ func (con *Consensus) Run() { sort.Sort(hashes) for i, hash := range hashes { if hash == con.ID.Hash { - chainID = uint64(i) + chainID = uint32(i) break } } genesisBlock := &types.Block{ ProposerID: con.ID, - ChainID: chainID, + Position: types.Position{ + ChainID: chainID, + }, } if err := con.PrepareGenesisBlock(genesisBlock, time.Now().UTC()); err != nil { fmt.Println(err) @@ -156,7 +158,9 @@ ProposingBlockLoop: } block := &types.Block{ ProposerID: con.ID, - ChainID: chainID, + Position: types.Position{ + ChainID: chainID, + }, } if err := con.PrepareBlock(block, time.Now().UTC()); err != nil { fmt.Println(err) @@ -321,7 +325,7 @@ func (con *Consensus) PrepareBlock(b *types.Block, con.rbModule.prepareBlock(b) b.Timestamps[b.ProposerID] = proposeTime - b.Payloads = con.app.PreparePayloads(b.ShardID, b.ChainID, b.Height) + b.Payloads = con.app.PreparePayloads(b.Position) b.Hash, err = hashBlock(b) if err != nil { return @@ -343,7 +347,7 @@ func (con *Consensus) PrepareGenesisBlock(b *types.Block, err = ErrGenesisBlockNotEmpty return } - b.Height = 0 + b.Position.Height = 0 b.ParentHash = common.Hash{} b.Acks = make(map[common.Hash]struct{}) b.Timestamps = make(map[types.ValidatorID]time.Time) -- cgit v1.2.3