// createDSCOBucket creates a bucket for the delayed siacoin outputs at the // input height. func createDSCOBucket(tx *bolt.Tx, bh types.BlockHeight) { bucketID := append(prefixDSCO, encoding.Marshal(bh)...) _, err := tx.CreateBucket(bucketID) if build.DEBUG && err != nil { panic(err) } }
// createConsensusObjects initialzes the consensus portions of the database. func (cs *ConsensusSet) createConsensusDB(tx *bolt.Tx) error { // Enumerate and create the database buckets. buckets := [][]byte{ BlockHeight, BlockMap, BlockPath, Consistency, SiacoinOutputs, FileContracts, SiafundOutputs, SiafundPool, } for _, bucket := range buckets { _, err := tx.CreateBucket(bucket) if err != nil { return err } } // Set the block height to -1, so the genesis block is at height 0. blockHeight := tx.Bucket(BlockHeight) underflow := types.BlockHeight(0) err := blockHeight.Put(BlockHeight, encoding.Marshal(underflow-1)) if err != nil { return err } // Set the siafund pool to 0. setSiafundPool(tx, types.NewCurrency64(0)) // Update the siafund output diffs map for the genesis block on disk. This // needs to happen between the database being opened/initilized and the // consensus set hash being calculated for _, sfod := range cs.blockRoot.SiafundOutputDiffs { commitSiafundOutputDiff(tx, sfod, modules.DiffApply) } // Add the miner payout from the genesis block to the delayed siacoin // outputs - unspendable, as the unlock hash is blank. createDSCOBucket(tx, types.MaturityDelay) addDSCO(tx, types.MaturityDelay, cs.blockRoot.Block.MinerPayoutID(0), types.SiacoinOutput{ Value: types.CalculateCoinbase(0), UnlockHash: types.UnlockHash{}, }) // Add the genesis block to the block strucutres - checksum must be taken // after pushing the genesis block into the path. pushPath(tx, cs.blockRoot.Block.ID()) if build.DEBUG { cs.blockRoot.ConsensusChecksum = consensusChecksum(tx) } addBlockMap(tx, &cs.blockRoot) return nil }
// resetDB deletes all consensus related persistence from the transaction pool. func (tp *TransactionPool) resetDB(tx *bolt.Tx) error { err := tx.DeleteBucket(bucketConfirmedTransactions) if err != nil { return err } err = tp.putRecentConsensusChange(tx, modules.ConsensusChangeBeginning) if err != nil { return err } _, err = tx.CreateBucket(bucketConfirmedTransactions) return err }
// createChangeLog assumes that no change log exists and creates a new one. func (cs *ConsensusSet) createChangeLog(tx *bolt.Tx) error { // Create the changelog bucket. cl, err := tx.CreateBucket(ChangeLog) if err != nil { return err } // Add the genesis block as the first entry of the change log. ge := cs.genesisEntry() geid := ge.ID() cn := changeNode{ Entry: ge, Next: modules.ConsensusChangeID{}, } err = cl.Put(geid[:], encoding.Marshal(cn)) if err != nil { return err } err = cl.Put(ChangeLogTailID, geid[:]) if err != nil { return err } return nil }