FIX: lcp context at finalize

This commit is contained in:
denis k 2018-08-24 18:36:03 +10:00
parent b2bb4c8ccf
commit cc457a78cf

View file

@ -356,7 +356,7 @@ func AccumulateRewards(config *params.ChainConfig, state *state.StateDB, header
} }
func (d *LCP) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, func (d *LCP) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction,
uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) { uncles []*types.Header, receipts []*types.Receipt, lcpContext *types.LCPContext) (*types.Block, error) {
// Accumulate block rewards and commit the final state root // Accumulate block rewards and commit the final state root
AccumulateRewards(chain.Config(), state, header, uncles) AccumulateRewards(chain.Config(), state, header, uncles)
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number)) header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
@ -364,7 +364,7 @@ func (d *LCP) Finalize(chain consensus.ChainReader, header *types.Header, state
parent := chain.GetHeaderByHash(header.ParentHash) parent := chain.GetHeaderByHash(header.ParentHash)
epochContext := &EpochContext{ epochContext := &EpochContext{
statedb: state, statedb: state,
Context: LCPContext, Context: lcpContext,
TimeStamp: header.Time.Int64(), TimeStamp: header.Time.Int64(),
} }
if timeOfFirstBlock == 0 { if timeOfFirstBlock == 0 {
@ -379,8 +379,8 @@ func (d *LCP) Finalize(chain consensus.ChainReader, header *types.Header, state
} }
//update mint count trie //update mint count trie
updateMintCnt(parent.Time.Int64(), header.Time.Int64(), header.Validator, LCPContext) updateMintCnt(parent.Time.Int64(), header.Time.Int64(), header.Validator, lcpContext)
header.LCPContext = LCPContext.ToProto() header.LCPContext = lcpContext.ToProto()
return types.NewBlock(header, txs, uncles, receipts), nil return types.NewBlock(header, txs, uncles, receipts), nil
} }
@ -497,8 +497,8 @@ func NextSlot(now int64) int64 {
} }
// update counts in MintCntTrie for the miner of newBlock // update counts in MintCntTrie for the miner of newBlock
func updateMintCnt(parentBlockTime, currentBlockTime int64, validator common.Address, dposContext *types.LCPContext) { func updateMintCnt(parentBlockTime, currentBlockTime int64, validator common.Address, lcpContext *types.LCPContext) {
currentMintCntTrie := dposContext.MintCntTrie() currentMintCntTrie := lcpContext.MintCntTrie()
currentEpoch := parentBlockTime / epochInterval currentEpoch := parentBlockTime / epochInterval
currentEpochBytes := make([]byte, 8) currentEpochBytes := make([]byte, 8)
binary.BigEndian.PutUint64(currentEpochBytes, uint64(currentEpoch)) binary.BigEndian.PutUint64(currentEpochBytes, uint64(currentEpoch))
@ -524,5 +524,5 @@ func updateMintCnt(parentBlockTime, currentBlockTime int64, validator common.Add
newEpochBytes := make([]byte, 8) newEpochBytes := make([]byte, 8)
binary.BigEndian.PutUint64(newEpochBytes, uint64(newEpoch)) binary.BigEndian.PutUint64(newEpochBytes, uint64(newEpoch))
binary.BigEndian.PutUint64(newCntBytes, uint64(cnt)) binary.BigEndian.PutUint64(newCntBytes, uint64(cnt))
dposContext.MintCntTrie().TryUpdate(append(newEpochBytes, validator.Bytes()...), newCntBytes) lcpContext.MintCntTrie().TryUpdate(append(newEpochBytes, validator.Bytes()...), newCntBytes)
} }