Commit 835dbac1 authored by Marc Lester Tan's avatar Marc Lester Tan Committed by Luke Champine

Added ./sync and ./types to lint packages (#2786)

* Added ./sync and ./types to lint packages

* Update Makefile
parent 6092e269
......@@ -60,9 +60,10 @@ vet: release-std
# will always run on some packages for a while.
lintpkgs = ./build ./cmd/siac ./cmd/siad ./compatibility ./crypto ./encoding ./modules ./modules/consensus ./modules/explorer \
./modules/gateway ./modules/host ./modules/miner ./modules/host/contractmanager ./modules/renter ./modules/renter/contractor ./modules/renter/hostdb \
./modules/renter/hostdb/hosttree ./modules/renter/proto ./modules/wallet ./modules/transactionpool ./node ./node/api ./node/api/server ./persist \
./siatest ./siatest/consensus ./siatest/renter
./modules/gateway ./modules/host ./modules/miner ./modules/host/contractmanager ./modules/renter \
./modules/renter/contractor ./modules/renter/hostdb ./modules/renter/hostdb/hosttree ./modules/renter/proto \
./modules/wallet ./modules/transactionpool ./node ./node/api ./node/api/server ./persist ./siatest ./sync ./types \
lint:
golint -min_confidence=1.0 -set_exit_status $(lintpkgs)
......
......@@ -32,9 +32,7 @@ type (
Transactions []Transaction `json:"transactions"`
}
// A BlockHeader, when encoded, is an 80-byte constant size field
// containing enough information to do headers-first block downloading.
// Hashing the header results in the block ID.
// A BlockHeader contains the data that, when hashed, produces the Block's ID.
BlockHeader struct {
ParentID BlockID `json:"parentid"`
Nonce BlockNonce `json:"nonce"`
......@@ -42,9 +40,16 @@ type (
MerkleRoot crypto.Hash `json:"merkleroot"`
}
// BlockHeight is the number of blocks that exist after the genesis block.
BlockHeight uint64
BlockID crypto.Hash
BlockNonce [8]byte
// A BlockID is the hash of a BlockHeader. A BlockID uniquely
// identifies a Block, and indicates the amount of work performed
// to mine that Block. The more leading zeros in the BlockID, the
// more work was performed.
BlockID crypto.Hash
// The BlockNonce is a "scratch space" that miners can freely alter to produce
// a BlockID that satisfies a given Target.
BlockNonce [8]byte
)
// CalculateCoinbase calculates the coinbase for a given height. The coinbase
......
......@@ -13,42 +13,115 @@ import (
)
var (
BlockFrequency BlockHeight
BlockSizeLimit = uint64(2e6)
// BlockFrequency is the desired number of seconds that
// should elapse, on average, between successive Blocks.
BlockFrequency BlockHeight
// BlockSizeLimit is the maximum size of a binary-encoded Block
// that is permitted by the consensus rules.
BlockSizeLimit = uint64(2e6)
// ExtremeFutureThreshold is a temporal limit beyond which Blocks are
// discarded by the consensus rules. When incoming Blocks are processed, their
// Timestamp is allowed to exceed the processor's current time by a small amount.
// But if the Timestamp is further into the future than ExtremeFutureThreshold,
// the Block is immediately discarded.
ExtremeFutureThreshold Timestamp
FutureThreshold Timestamp
GenesisBlock Block
// FutureThreshold is a temporal limit beyond which Blocks are
// discarded by the consensus rules. When incoming Blocks are processed, their
// Timestamp is allowed to exceed the processor's current time by no more than
// FutureThreshold. If the excess duration is larger than FutureThreshold, but
// smaller than ExtremeFutureThreshold, the Block may be held in memory until
// the Block's Timestamp exceeds the current time by less than FutureThreshold.
FutureThreshold Timestamp
// GenesisBlock is the first block of the block chain
GenesisBlock Block
// The GenesisID is used in many places. Calculating it once saves lots of
// GenesisID is used in many places. Calculating it once saves lots of
// redundant computation.
GenesisID BlockID
// GenesisSiafundAllocation is the set of SiafundOutputs created in the Genesis
// block.
GenesisSiafundAllocation []SiafundOutput
GenesisTimestamp Timestamp
InitialCoinbase = uint64(300e3)
MaturityDelay BlockHeight
MaxAdjustmentDown *big.Rat
MaxAdjustmentUp *big.Rat
MedianTimestampWindow = uint64(11)
MinimumCoinbase uint64
// GenesisTimestamp is the timestamp when genesis block was mined
GenesisTimestamp Timestamp
// InitialCoinbase is the coinbase reward of the Genesis block.
InitialCoinbase = uint64(300e3)
// MaturityDelay specifies the number of blocks that a maturity-required output
// is required to be on hold before it can be spent on the blockchain.
// Outputs are maturity-required if they are highly likely to be altered or
// invalidated in the event of a small reorg. One example is the block reward,
// as a small reorg may invalidate the block reward. Another example is a siafund
// payout, as a tiny reorg may change the value of the payout, and thus invalidate
// any transactions spending the payout. File contract payouts also are subject to
// a maturity delay.
MaturityDelay BlockHeight
// MaxAdjustmentDown restrict how much the block difficulty is allowed to
// change in a single step, which is important to limit the effect of difficulty
// raising and lowering attacks.
MaxAdjustmentDown *big.Rat
// MaxAdjustmentUp restrict how much the block difficulty is allowed to
// change in a single step, which is important to limit the effect of difficulty
// raising and lowering attacks.
MaxAdjustmentUp *big.Rat
// MedianTimestampWindow tells us how many blocks to look back when calculating
// the median timestamp over the previous n blocks. The timestamp of a block is
// not allowed to be less than or equal to the median timestamp of the previous n
// blocks, where for Sia this number is typically 11.
MedianTimestampWindow = uint64(11)
// MinimumCoinbase is the minimum coinbase reward for a block.
// The coinbase decreases in each block after the Genesis block,
// but it will not decrease past MinimumCoinbase.
MinimumCoinbase uint64
// Oak hardfork constants. Oak is the name of the difficulty algorithm for
// Sia following a hardfork at block 135e3.
OakDecayDenom int64
OakDecayNum int64
OakHardforkBlock BlockHeight
OakHardforkFixBlock BlockHeight
// OakDecayDenom is the denominator for how much the total timestamp is decayed
// each step.
OakDecayDenom int64
// OakDecayNum is the numerator for how much the total timestamp is decayed each
// step.
OakDecayNum int64
// OakHardforkBlock is the height at which the hardfork to switch to the oak
// difficulty adjustment algorithm is triggered.
OakHardforkBlock BlockHeight
// OakHardforkFixBlock is the height at which the hardfork to switch from the broken
// oak difficulty adjustment algorithm to the fixed oak difficulty adjustment
// algorithm is triggered.
OakHardforkFixBlock BlockHeight
// OakHardforkTxnSizeLimit is the maximum size allowed for a transaction, a change
// which I believe was implemented simultaneously with the oak hardfork.
OakHardforkTxnSizeLimit = uint64(64e3) // 64 KB
OakMaxBlockShift int64
OakMaxDrop *big.Rat
OakMaxRise *big.Rat
// OakMaxBlockShift is the maximum number of seconds that the oak algorithm will shift
// the difficulty.
OakMaxBlockShift int64
// OakMaxDrop is the drop is the maximum amount that the difficulty will drop each block.
OakMaxDrop *big.Rat
// OakMaxRise is the maximum amount that the difficulty will rise each block.
OakMaxRise *big.Rat
RootDepth = Target{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
RootTarget Target
// RootDepth is the cumulative target of all blocks. The root depth is essentially
// the maximum possible target, there have been no blocks yet, so there is no
// cumulated difficulty yet.
RootDepth = Target{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
// RootTarget is the target for the genesis block - basically how much work needs
// to be done in order to mine the first block. The difficulty adjustment algorithm
// takes over from there.
RootTarget Target
// SiacoinPrecision is the number of base units in a siacoin. The Sia network has a very
// large number of base units. We call 10^24 of these a siacoin.
//
// The base unit for Bitcoin is called a satoshi. We call 10^8 satoshis a bitcoin,
// even though the code itself only ever works with satoshis.
SiacoinPrecision = NewCurrency(new(big.Int).Exp(big.NewInt(10), big.NewInt(24), nil))
SiafundCount = NewCurrency64(10000)
SiafundPortion = big.NewRat(39, 1000)
TargetWindow BlockHeight
// SiafundCount is the total number of Siafunds in existence.
SiafundCount = NewCurrency64(10000)
// SiafundPortion is the percentage of siacoins that is taxed from FileContracts.
SiafundPortion = big.NewRat(39, 1000)
// TargetWindow is the number of blocks to look backwards when determining how much
// time has passed vs. how many blocks have been created. It's only used in the old,
// broken difficulty adjustment algorithm.
TargetWindow BlockHeight
)
// init checks which build constant is in place and initializes the variables
......
......@@ -64,8 +64,8 @@ func (x Currency) Add(y Currency) (c Currency) {
// Big returns the value of c as a *big.Int. Importantly, it does not provide
// access to the c's internal big.Int object, only a copy.
func (c Currency) Big() *big.Int {
return new(big.Int).Set(&c.i)
func (x Currency) Big() *big.Int {
return new(big.Int).Set(&x.i)
}
// Cmp compares two Currency values. The return value follows the convention
......@@ -116,7 +116,7 @@ func (x Currency) Mul64(y uint64) (c Currency) {
// COMPATv0.4.0 - until the first 10e3 blocks have been archived, MulFloat is
// needed while verifying the first set of blocks.
//
// MulFloat returns a new Currency value y = c * x, where x is a float64.
// Behavior is undefined when x is negative.
func (x Currency) MulFloat(y float64) (c Currency) {
......@@ -158,8 +158,8 @@ func (x Currency) RoundDown(y Currency) (c Currency) {
}
// IsZero returns true if the value is 0, false otherwise.
func (c Currency) IsZero() bool {
return c.i.Sign() <= 0
func (x Currency) IsZero() bool {
return x.i.Sign() <= 0
}
// Sqrt returns a new Currency value y = sqrt(c). Result is rounded down to the
......@@ -188,9 +188,9 @@ func (x Currency) Sub(y Currency) (c Currency) {
// rather than have all user-facing points do input checking, the input
// checking should happen at the base type. This minimizes the chances of a
// rogue user causing a build.Critical to be triggered.
func (c Currency) Uint64() (u uint64, err error) {
if c.Cmp(NewCurrency64(math.MaxUint64)) > 0 {
func (x Currency) Uint64() (u uint64, err error) {
if x.Cmp(NewCurrency64(math.MaxUint64)) > 0 {
return 0, ErrUint64Overflow
}
return c.Big().Uint64(), nil
return x.Big().Uint64(), nil
}
......@@ -9,8 +9,12 @@ import (
)
var (
// ProofMissed indicates that a StorageProof was missed, which means that
// no valid proof was submitted within the proof window.
ProofMissed ProofStatus = false
ProofValid ProofStatus = true
// ProofValid indicates that a valid StorageProof was submitted within the
// proof window.
ProofValid ProofStatus = true
)
type (
......@@ -90,6 +94,7 @@ type (
HashSet []crypto.Hash `json:"hashset"`
}
// ProofStatus indicates whether a StorageProof was valid (true) or missed (false).
ProofStatus bool
)
......
......@@ -15,15 +15,33 @@ import (
)
var (
ErrEntropyKey = errors.New("transaction tries to sign an entproy public key")
ErrFrivolousSignature = errors.New("transaction contains a frivolous signature")
ErrInvalidPubKeyIndex = errors.New("transaction contains a signature that points to a nonexistent public key")
// ErrEntropyKey is the error when a transaction tries to sign an entropy
// public key
ErrEntropyKey = errors.New("transaction tries to sign an entropy public key")
// ErrFrivolousSignature is the error when a transaction contains a frivolous
// signature
ErrFrivolousSignature = errors.New("transaction contains a frivolous signature")
// ErrInvalidPubKeyIndex is the error when a transaction contains a signature
// that points to a nonexistent public key
ErrInvalidPubKeyIndex = errors.New("transaction contains a signature that points to a nonexistent public key")
// ErrInvalidUnlockHashChecksum is the error when the provided unlock hash has
// an invalid checksum
ErrInvalidUnlockHashChecksum = errors.New("provided unlock hash has an invalid checksum")
ErrMissingSignatures = errors.New("transaction has inputs with missing signatures")
ErrPrematureSignature = errors.New("timelock on signature has not expired")
ErrPublicKeyOveruse = errors.New("public key was used multiple times while signing transaction")
ErrSortedUniqueViolation = errors.New("sorted unique violation")
ErrUnlockHashWrongLen = errors.New("marshalled unlock hash is the wrong length")
// ErrMissingSignatures is the error when a transaction has inputs with missing
// signatures
ErrMissingSignatures = errors.New("transaction has inputs with missing signatures")
// ErrPrematureSignature is the error when the timelock on signature has not
// expired
ErrPrematureSignature = errors.New("timelock on signature has not expired")
// ErrPublicKeyOveruse is the error when public key was used multiple times while
// signing transaction
ErrPublicKeyOveruse = errors.New("public key was used multiple times while signing transaction")
// ErrSortedUniqueViolation is the error when a sorted unique violation occurs
ErrSortedUniqueViolation = errors.New("sorted unique violation")
// ErrUnlockHashWrongLen is the error when a marshalled unlock hash is the wrong
// length
ErrUnlockHashWrongLen = errors.New("marshalled unlock hash is the wrong length")
// ErrWholeTransactionViolation is the error when there's a covered fields violation
ErrWholeTransactionViolation = errors.New("covered fields violation")
// FullCoveredFields is a covered fileds object where the
......@@ -35,7 +53,10 @@ var (
// by this implementation. If a signature's type is unrecognized, the
// signature is treated as valid. Signatures using the special "entropy"
// type are always treated as invalid; see Consensus.md for more details.
// SignatureEd25519 is a specifier for Ed22519
SignatureEd25519 = Specifier{'e', 'd', '2', '5', '5', '1', '9'}
// SignatureEntropy is a specifier for entropy
SignatureEntropy = Specifier{'e', 'n', 't', 'r', 'o', 'p', 'y'}
)
......
......@@ -21,6 +21,8 @@ type (
)
var (
// ErrNegativeTarget is an error when a negative value used when converting
// to target
ErrNegativeTarget = errors.New("negative value used when converting to target")
)
......@@ -43,16 +45,16 @@ func (x Target) Cmp(y Target) int {
}
// Difficulty returns the difficulty associated with a given target.
func (t Target) Difficulty() Currency {
if t == (Target{}) {
func (x Target) Difficulty() Currency {
if x == (Target{}) {
return NewCurrency(RootDepth.Int())
}
return NewCurrency(new(big.Int).Div(RootDepth.Int(), t.Int()))
return NewCurrency(new(big.Int).Div(RootDepth.Int(), x.Int()))
}
// Int converts a Target to a big.Int.
func (t Target) Int() *big.Int {
return new(big.Int).SetBytes(t[:])
func (x Target) Int() *big.Int {
return new(big.Int).SetBytes(x[:])
}
// IntToTarget converts a big.Int to a Target. Negative inputs trigger a panic.
......@@ -75,12 +77,12 @@ func IntToTarget(i *big.Int) (t Target) {
}
// Inverse returns the inverse of a Target as a big.Rat
func (t Target) Inverse() *big.Rat {
return new(big.Rat).Inv(t.Rat())
func (x Target) Inverse() *big.Rat {
return new(big.Rat).Inv(x.Rat())
}
// Mul multiplies the difficulty of a target by y. The product is defined by:
// y / x
// MulDifficulty multiplies the difficulty of a target by y. The product is defined by:
// y / x
func (x Target) MulDifficulty(y *big.Rat) (t Target) {
product := new(big.Rat).Mul(y, x.Inverse())
product = product.Inv(product)
......@@ -88,8 +90,8 @@ func (x Target) MulDifficulty(y *big.Rat) (t Target) {
}
// Rat converts a Target to a big.Rat.
func (t Target) Rat() *big.Rat {
return new(big.Rat).SetInt(t.Int())
func (x Target) Rat() *big.Rat {
return new(big.Rat).SetInt(x.Int())
}
// RatToTarget converts a big.Rat to a Target.
......
......@@ -8,7 +8,9 @@ import (
)
type (
Timestamp uint64
// Timestamp is a Unix timestamp, i.e. the number of the seconds since Jan 1 1970.
Timestamp uint64
// TimestampSlice is an array of timestamps
TimestampSlice []Timestamp
)
......
......@@ -14,6 +14,7 @@ import (
)
const (
// SpecifierLen is the length in bytes of a Specifier.
SpecifierLen = 16
// UnlockHashChecksumSize is the size of the checksum used to verify
......@@ -59,11 +60,17 @@ type (
// are constructed by hashing specific fields of the type, along with a
// Specifier. While all of these types are hashes, defining type aliases
// gives us type safety and makes the code more readable.
TransactionID crypto.Hash
// TransactionID uniquely identifies a transaction
TransactionID crypto.Hash
// SiacoinOutputID uniquely identifies a siacoin output
SiacoinOutputID crypto.Hash
// SiafundOutputID uniquely identifies a siafund output
SiafundOutputID crypto.Hash
FileContractID crypto.Hash
OutputID crypto.Hash
// FileContractID uniquely identifies a file contract
FileContractID crypto.Hash
// OutputID uniquely identifies an output
OutputID crypto.Hash
// A Transaction is an atomic component of a block. Transactions can contain
// inputs and outputs, file contracts, storage proofs, and even arbitrary
......
......@@ -10,18 +10,41 @@ import (
)
var (
ErrDoubleSpend = errors.New("transaction uses a parent object twice")
ErrFileContractOutputSumViolation = errors.New("file contract has invalid output sums")
ErrFileContractWindowEndViolation = errors.New("file contract window must end at least one block after it starts")
// ErrDoubleSpend is an error when a transaction uses a parent object
// twice
ErrDoubleSpend = errors.New("transaction uses a parent object twice")
// ErrFileContractOutputSumViolation is an error when a file contract
// has invalid output sums
ErrFileContractOutputSumViolation = errors.New("file contract has invalid output sums")
// ErrFileContractWindowEndViolation is an error when a file contract
// window must end at least one block after it starts
ErrFileContractWindowEndViolation = errors.New("file contract window must end at least one block after it starts")
// ErrFileContractWindowStartViolation is an error when a file contract
// window must start in the future
ErrFileContractWindowStartViolation = errors.New("file contract window must start in the future")
ErrNonZeroClaimStart = errors.New("transaction has a siafund output with a non-zero siafund claim")
ErrNonZeroRevision = errors.New("new file contract has a nonzero revision number")
ErrStorageProofWithOutputs = errors.New("transaction has both a storage proof and other outputs")
ErrTimelockNotSatisfied = errors.New("timelock has not been met")
ErrTransactionTooLarge = errors.New("transaction is too large to fit in a block")
ErrZeroMinerFee = errors.New("transaction has a zero value miner fee")
ErrZeroOutput = errors.New("transaction cannot have an output or payout that has zero value")
ErrZeroRevision = errors.New("transaction has a file contract revision with RevisionNumber=0")
// ErrNonZeroClaimStart is an error when a transaction has a siafund
// output with a non-zero siafund claim
ErrNonZeroClaimStart = errors.New("transaction has a siafund output with a non-zero siafund claim")
// ErrNonZeroRevision is an error when a new file contract has a
// nonzero revision number
ErrNonZeroRevision = errors.New("new file contract has a nonzero revision number")
// ErrStorageProofWithOutputs is an error when a transaction has both
// a storage proof and other outputs
ErrStorageProofWithOutputs = errors.New("transaction has both a storage proof and other outputs")
// ErrTimelockNotSatisfied is an error when a timelock has not been met
ErrTimelockNotSatisfied = errors.New("timelock has not been met")
// ErrTransactionTooLarge is an error when a transaction is too large
// to fit in a block
ErrTransactionTooLarge = errors.New("transaction is too large to fit in a block")
// ErrZeroMinerFee is an error when a transaction has a zero value miner
// fee
ErrZeroMinerFee = errors.New("transaction has a zero value miner fee")
// ErrZeroOutput is an error when a transaction cannot have an output
// or payout that has zero value
ErrZeroOutput = errors.New("transaction cannot have an output or payout that has zero value")
// ErrZeroRevision is an error when a transaction has a file contract
// revision with RevisionNumber=0
ErrZeroRevision = errors.New("transaction has a file contract revision with RevisionNumber=0")
)
// correctFileContracts checks that the file contracts adhere to the file
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment