github.com/NebulousLabs/Sia@v1.3.7/modules/consensus/fork_helpers_test.go (about)

     1  package consensus
     2  
     3  import (
     4  	"github.com/coreos/bbolt"
     5  )
     6  
     7  // dbBacktrackToCurrentPath is a convenience function to call
     8  // backtrackToCurrentPath without a bolt.Tx.
     9  func (cs *ConsensusSet) dbBacktrackToCurrentPath(pb *processedBlock) (pbs []*processedBlock) {
    10  	_ = cs.db.Update(func(tx *bolt.Tx) error {
    11  		pbs = backtrackToCurrentPath(tx, pb)
    12  		return nil
    13  	})
    14  	return pbs
    15  }
    16  
    17  // dbRevertToNode is a convenience function to call revertToBlock without a
    18  // bolt.Tx.
    19  func (cs *ConsensusSet) dbRevertToNode(pb *processedBlock) (pbs []*processedBlock) {
    20  	_ = cs.db.Update(func(tx *bolt.Tx) error {
    21  		pbs = cs.revertToBlock(tx, pb)
    22  		return nil
    23  	})
    24  	return pbs
    25  }
    26  
    27  // dbForkBlockchain is a convenience function to call forkBlockchain without a
    28  // bolt.Tx.
    29  func (cs *ConsensusSet) dbForkBlockchain(pb *processedBlock) (revertedBlocks, appliedBlocks []*processedBlock, err error) {
    30  	updateErr := cs.db.Update(func(tx *bolt.Tx) error {
    31  		revertedBlocks, appliedBlocks, err = cs.forkBlockchain(tx, pb)
    32  		return nil
    33  	})
    34  	if updateErr != nil {
    35  		panic(updateErr)
    36  	}
    37  	return revertedBlocks, appliedBlocks, err
    38  }