コード例 #1
0
ファイル: maintenance.go プロジェクト: mm3/Sia
// applyMissedStorageProof adds the outputs and diffs that result from a file
// contract expiring.
func (cs *State) applyMissedStorageProof(bn *blockNode, fcid types.FileContractID) {
	// Sanity checks.
	fc, exists := cs.fileContracts[fcid]
	if build.DEBUG {
		// Check that the file contract in question exists.
		if !exists {
			panic("misuse of applyMissedProof")
		}

		// Check that the file contract in question expires at bn.height.
		if fc.WindowEnd != bn.height {
			panic("applyMissedStorageProof being called at the wrong height")
		}
	}

	// Add all of the outputs in the missed proof outputs to the consensus set.
	for i, mpo := range fc.MissedProofOutputs {
		// Sanity check - output should not already exist.
		spid := fcid.StorageProofOutputID(types.ProofMissed, i)
		if build.DEBUG {
			_, exists := cs.delayedSiacoinOutputs[bn.height+types.MaturityDelay][spid]
			if exists {
				panic("missed proof output already exists in the delayed outputs set")
			}
			_, exists = cs.siacoinOutputs[spid]
			if exists {
				panic("missed proof output already exists in the siacoin outputs set")
			}
		}

		dscod := modules.DelayedSiacoinOutputDiff{
			Direction:      modules.DiffApply,
			ID:             spid,
			SiacoinOutput:  mpo,
			MaturityHeight: bn.height + types.MaturityDelay,
		}
		bn.delayedSiacoinOutputDiffs = append(bn.delayedSiacoinOutputDiffs, dscod)
		cs.commitDelayedSiacoinOutputDiff(dscod, modules.DiffApply)
	}

	// Remove the contract from the State and record the diff in the blockNode.
	delete(cs.fileContracts, fcid)
	bn.fileContractDiffs = append(bn.fileContractDiffs, modules.FileContractDiff{
		Direction:    modules.DiffRevert,
		ID:           fcid,
		FileContract: fc,
	})

	return
}
コード例 #2
0
ファイル: maintenance.go プロジェクト: kustomzone/Sia
// applyMissedStorageProof adds the outputs and diffs that result from a file
// contract expiring.
func (cs *ConsensusSet) applyTxMissedStorageProof(tx *bolt.Tx, pb *processedBlock, fcid types.FileContractID) error {
	// Sanity checks.
	fc, err := getFileContract(tx, fcid)
	if err != nil {
		return err
	}
	if build.DEBUG {
		// Check that the file contract in question expires at pb.Height.
		if fc.WindowEnd != pb.Height {
			panic(errStorageProofTiming)
		}
	}

	// Add all of the outputs in the missed proof outputs to the consensus set.
	for i, mpo := range fc.MissedProofOutputs {
		// Sanity check - output should not already exist.
		spoid := fcid.StorageProofOutputID(types.ProofMissed, uint64(i))
		if build.DEBUG {
			exists := isSiacoinOutput(tx, spoid)
			if exists {
				panic(errPayoutsAlreadyPaid)
			}
		}

		dscod := modules.DelayedSiacoinOutputDiff{
			Direction:      modules.DiffApply,
			ID:             spoid,
			SiacoinOutput:  mpo,
			MaturityHeight: pb.Height + types.MaturityDelay,
		}
		pb.DelayedSiacoinOutputDiffs = append(pb.DelayedSiacoinOutputDiffs, dscod)
		err = cs.commitTxDelayedSiacoinOutputDiff(tx, dscod, modules.DiffApply)
		if err != nil {
			return err
		}
	}

	// Remove the file contract from the consensus set and record the diff in
	// the blockNode.
	fcd := modules.FileContractDiff{
		Direction:    modules.DiffRevert,
		ID:           fcid,
		FileContract: fc,
	}
	pb.FileContractDiffs = append(pb.FileContractDiffs, fcd)
	return cs.commitTxFileContractDiff(tx, fcd, modules.DiffApply)
}
コード例 #3
0
ファイル: maintenance.go プロジェクト: cfromknecht/Sia
// applyMissedStorageProof adds the outputs and diffs that result from a file
// contract expiring.
func applyMissedStorageProof(tx *bolt.Tx, pb *processedBlock, fcid types.FileContractID) (dscods []modules.DelayedSiacoinOutputDiff, fcd modules.FileContractDiff) {
	// Sanity checks.
	fc, err := getFileContract(tx, fcid)
	if build.DEBUG && err != nil {
		panic(err)
	}
	if build.DEBUG {
		// Check that the file contract in question expires at pb.Height.
		if fc.WindowEnd != pb.Height {
			panic(errStorageProofTiming)
		}
	}

	// Add all of the outputs in the missed proof outputs to the consensus set.
	for i, mpo := range fc.MissedProofOutputs {
		// Sanity check - output should not already exist.
		spoid := fcid.StorageProofOutputID(types.ProofMissed, uint64(i))
		if build.DEBUG && isSiacoinOutput(tx, spoid) {
			panic(errPayoutsAlreadyPaid)
		}

		// Don't add the output if the value is zero.
		dscod := modules.DelayedSiacoinOutputDiff{
			Direction:      modules.DiffApply,
			ID:             spoid,
			SiacoinOutput:  mpo,
			MaturityHeight: pb.Height + types.MaturityDelay,
		}
		dscods = append(dscods, dscod)
	}

	// Remove the file contract from the consensus set and record the diff in
	// the blockNode.
	fcd = modules.FileContractDiff{
		Direction:    modules.DiffRevert,
		ID:           fcid,
		FileContract: fc,
	}
	return dscods, fcd
}