github.com/insight-chain/inb-go@v1.1.3-0.20191221022159-da049980ae38/consensus/vdpos/snapContext.go (about) 1 // Copyright 2019 The inb-go Authors 2 // This file is part of the inb-go library. 3 // 4 // The inb-go library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software MiningReward, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The inb-go library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the inb-go library. If not, see <http://www.gnu.org/licenses/>. 16 17 // Package vdpos implements the delegated-proof-of-stake consensus engine. 18 package vdpos 19 20 import ( 21 "github.com/insight-chain/inb-go/common" 22 "github.com/insight-chain/inb-go/core/state" 23 "github.com/insight-chain/inb-go/core/types" 24 "github.com/insight-chain/inb-go/params" 25 "math/big" 26 ) 27 28 type SnapContext struct { 29 config *params.VdposConfig 30 statedb *state.StateDB 31 Number uint64 32 ParentHash common.Hash 33 TimeStamp int64 34 VdposContext *types.VdposContext 35 SignersPool []common.Address 36 } 37 38 // get last block number meet the confirm condition 39 func (s *SnapContext) getLastConfirmedBlockNumber() *big.Int { 40 i := s.Number 41 for ; i > s.Number-s.config.SignerBlocks*(s.config.MaxSignerCount*2/3+1); i-- { 42 } 43 return big.NewInt(int64(i)) 44 }