code: func (b *BlockChain) calcNextBlockVersion(prevNode *blockNode) (int32, error) {
  	// Set the appropriate bits for each actively defined rule deployment
  	// that is either in the process of being voted on, or locked in for the
  	// activation at the next threshold window change.
  	expectedVersion := uint32(vbTopBits)
  	for id := 0; id < len(b.chainParams.Deployments); id++ {
  		deployment := &b.chainParams.Deployments[id]
  		cache := &b.deploymentCaches[id]
  		checker := deploymentChecker{deployment: deployment, chain: b}
  		state, err := b.thresholdState(prevNode, checker, cache)
  		if err != nil {
  			return 0, err
  		}
  		if state == ThresholdStarted || state == ThresholdLockedIn {
  			expectedVersion |= uint32(1) << deployment.BitNumber
  		}
  	}
  	return int32(expectedVersion), nil
  }
docs: // calcNextBlockVersion calculates the expected version of the block after the
  // passed previous block node based on the state of started and locked in
  // rule change deployments.
  //
  // This function differs from the exported CalcNextBlockVersion in that the
  // exported version uses the current best chain as the previous block node
  // while this function accepts any block node.
  //
  // This function MUST be called with the chain state lock held (for writes).