blockTransactons
mainChainIndex
txStatus
- voteResult
-)
-
-var (
- blockStoreKey = []byte{blockStore}
- blockHashesPrefix = []byte{blockHashes, colon}
- blockHeaderPrefix = []byte{blockHeader, colon}
- blockTransactonsPrefix = []byte{blockTransactons, colon}
- mainChainIndexPrefix = []byte{mainChainIndex, colon}
- txStatusPrefix = []byte{txStatus, colon}
- voteResultPrefix = []byte{voteResult, colon}
+ consensusResult
)
func loadBlockStoreStateJSON(db dbm.DB) *protocol.BlockStoreState {
- bytes := db.Get(blockStoreKey)
+ bytes := db.Get([]byte{blockStore})
if bytes == nil {
return nil
}
func calcMainChainIndexPrefix(height uint64) []byte {
buf := [8]byte{}
binary.BigEndian.PutUint64(buf[:], height)
- return append(mainChainIndexPrefix, buf[:]...)
+ return append([]byte{mainChainIndex, colon}, buf[:]...)
}
func calcBlockHashesPrefix(height uint64) []byte {
buf := [8]byte{}
binary.BigEndian.PutUint64(buf[:], height)
- return append(blockHashesPrefix, buf[:]...)
+ return append([]byte{blockHashes, colon}, buf[:]...)
}
func calcBlockHeaderKey(hash *bc.Hash) []byte {
- return append(blockHeaderPrefix, hash.Bytes()...)
+ return append([]byte{blockHeader, colon}, hash.Bytes()...)
}
func calcBlockTransactionsKey(hash *bc.Hash) []byte {
- return append(blockTransactonsPrefix, hash.Bytes()...)
+ return append([]byte{blockTransactons, colon}, hash.Bytes()...)
}
func calcTxStatusKey(hash *bc.Hash) []byte {
- return append(txStatusPrefix, hash.Bytes()...)
+ return append([]byte{txStatus, colon}, hash.Bytes()...)
}
-func calcVoteResultKey(seq uint64) []byte {
+func calcConsensusResultKey(seq uint64) []byte {
buf := [8]byte{}
binary.BigEndian.PutUint64(buf[:], seq)
- return append(voteResultPrefix, buf[:]...)
+ return append([]byte{consensusResult, colon}, buf[:]...)
}
// GetBlockHeader return the block header by given hash
return hash, nil
}
-// GetVoteResult return the vote result by given sequence
-func GetVoteResult(db dbm.DB, seq uint64) (*state.VoteResult, error) {
- data := db.Get(calcVoteResultKey(seq))
+// GetConsensusResult return the vote result by given sequence
+func GetConsensusResult(db dbm.DB, seq uint64) (*state.ConsensusResult, error) {
+ data := db.Get(calcConsensusResultKey(seq))
if data == nil {
- return nil, protocol.ErrNotFoundVoteResult
+ return nil, protocol.ErrNotFoundConsensusResult
}
- voteResult := new(state.VoteResult)
- if err := json.Unmarshal(data, voteResult); err != nil {
+ consensusResult := new(state.ConsensusResult)
+ if err := json.Unmarshal(data, consensusResult); err != nil {
return nil, errors.Wrap(err, "unmarshaling vote result")
}
- return voteResult, nil
+ return consensusResult, nil
}
// NewStore creates and returns a new Store object.
return GetMainChainHash(db, height)
}
- fillVoteResultFn := func(seq uint64) (*state.VoteResult, error) {
- return GetVoteResult(db, seq)
+ fillConsensusResultFn := func(seq uint64) (*state.ConsensusResult, error) {
+ return GetConsensusResult(db, seq)
}
- cache := newCache(fillBlockHeaderFn, fillBlockTxsFn, fillBlockHashesFn, fillMainChainHashFn, fillVoteResultFn)
+ cache := newCache(fillBlockHeaderFn, fillBlockTxsFn, fillBlockHashesFn, fillMainChainHashFn, fillConsensusResultFn)
return &Store{
db: db,
cache: cache,
return getUtxo(s.db, hash)
}
-// GetVoteResult retrive the voting result in specified vote sequence
-func (s *Store) GetVoteResult(seq uint64) (*state.VoteResult, error) {
- return s.cache.lookupVoteResult(seq)
+// GetConsensusResult retrive the voting result in specified vote sequence
+func (s *Store) GetConsensusResult(seq uint64) (*state.ConsensusResult, error) {
+ return s.cache.lookupConsensusResult(seq)
}
// SaveBlock persists a new block in the protocol.
}
// SaveChainStatus save the core's newest status && delete old status
-func (s *Store) SaveChainStatus(blockHeader, irrBlockHeader *types.BlockHeader, mainBlockHeaders []*types.BlockHeader, view *state.UtxoViewpoint, voteResults []*state.VoteResult) error {
+func (s *Store) SaveChainStatus(blockHeader, irrBlockHeader *types.BlockHeader, mainBlockHeaders []*types.BlockHeader, view *state.UtxoViewpoint, consensusResults []*state.ConsensusResult) error {
batch := s.db.NewBatch()
if err := saveUtxoView(batch, view); err != nil {
return err
}
- for _, vote := range voteResults {
- bytes, err := json.Marshal(vote)
+ for _, result := range consensusResults {
+ bytes, err := json.Marshal(result)
if err != nil {
return err
}
- batch.Set(calcVoteResultKey(vote.Seq), bytes)
- s.cache.removeVoteResult(vote)
+ batch.Set(calcConsensusResultKey(result.Seq), bytes)
+ s.cache.removeConsensusResult(result)
}
blockHash := blockHeader.Hash()
if err != nil {
return err
}
- batch.Set(blockStoreKey, bytes)
+ batch.Set([]byte{blockStore}, bytes)
// save main chain blockHeaders
for _, bh := range mainBlockHeaders {