Commit 518bd104 authored by David Vorick's avatar David Vorick

consolidate transaction verification

parent 6ef65f68
......@@ -6,7 +6,6 @@ import (
"sort"
"github.com/NebulousLabs/Sia/crypto"
"github.com/NebulousLabs/Sia/encoding"
)
// StateInfo contains basic information about the State.
......@@ -266,51 +265,3 @@ func (s *State) StorageProofSegment(fcid FileContractID) (index uint64, err erro
defer s.mu.RUnlock(counter)
return s.storageProofSegment(fcid)
}
// ValidTransaction checks that a transaction is valid within the context of
// the current consensus set.
func (s *State) ValidTransaction(t Transaction) (err error) {
counter := s.mu.RLock()
defer s.mu.RUnlock(counter)
return s.validTransaction(t)
}
// ValidTransactionComponents checks that a transaction follows basic rules,
// such as the storage proof rules, and it checks that all of the signatures
// are valid, but it does not check that all of the inputs, storage proofs, and
// terminations act on existing outputs and contracts. This function is
// primarily for the transaction pool, which has access to unconfirmed
// transactions. ValidTransactionComponents will not return an error simply
// because there are missing inputs. ValidTransactionComponents will return an
// error if the state height is not sufficient to fulfill all of the
// requirements of the transaction.
func (s *State) ValidTransactionComponents(t Transaction) (err error) {
counter := s.mu.RLock()
defer s.mu.RUnlock(counter)
// This will stop too-large transactions from accidentally being validated.
// This check doesn't happen when checking blocks, because the size of the
// block was already checked.
if len(encoding.Marshal(t)) > BlockSizeLimit-5e3 {
return errors.New("transaction is too large")
}
err = t.FollowsStorageProofRules()
if err != nil {
return
}
err = s.validFileContracts(t)
if err != nil {
return
}
err = s.validStorageProofs(t)
if err != nil {
return
}
err = s.validSignatures(t)
if err != nil {
return
}
return
}
......@@ -87,7 +87,7 @@ func (t Transaction) validCoveredFields() error {
}
// validSignatures checks the validaty of all signatures in a transaction.
func (s *State) validSignatures(t Transaction) error {
func (t *Transaction) validSignatures(currentHeight BlockHeight) error {
// Check that all covered fields objects follow the rules.
err := t.validCoveredFields()
if err != nil {
......@@ -149,7 +149,7 @@ func (s *State) validSignatures(t Transaction) error {
return errors.New("one public key was used twice while signing an input")
}
// Check that the timelock has expired.
if sig.Timelock > s.height() {
if sig.Timelock > currentHeight {
return errors.New("signature used before timelock expiration")
}
......
This diff is collapsed.
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